Skip to content

Commit

Permalink
Run user's switch command after fork setup (#41)
Browse files Browse the repository at this point in the history
* this should be all that's needed lul

* fix warning

* debug

* only add newline when flags are present

* debug

* debug

* debug

* debug

* debug

* debug

* debug

* add verbose switching when fetching

* test fetching just branch

* don't think it makes a difference

* make checkout verbose

* add alias to reboot: shutdown -r

* add alias to reboot: shutdown -r

* fix

* fix

* bump version and add changelog
  • Loading branch information
sshane authored Jul 29, 2020
1 parent a336776 commit 52408df
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 14 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
Release 0.1.8 (2020-07-29)
=====

* More verbose fork switching, shows git output
* Only print newline when more information about command is available to better differentiate between commands

Release 0.1.7 (2020-07-24)
=====

Expand Down
3 changes: 3 additions & 0 deletions commands/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def parse_flags(self, parser):
return None, e

def _help(self, cmd, show_description=True, leading=''):
has_extra_info = False
description = self.commands[cmd].description
if show_description:
print('{}>> Description 📚: {}{}'.format(COLORS.CYAN, description, COLORS.ENDC))
Expand All @@ -44,6 +45,7 @@ def _help(self, cmd, show_description=True, leading=''):

flags_to_print = []
if flags is not None and len(flags) > 0:
has_extra_info = True
usage_req = [f.aliases[0] for f in flags if f.required and len(f.aliases) == 1] # if required
usage_non_req = [f.aliases[0] for f in flags if not f.required and len(f.aliases) == 1] # if non-required non-positional
usage_flags = [f.aliases for f in flags if not f.required and len(f.aliases) > 1 or f.aliases[0].startswith('-')] # if flag
Expand Down Expand Up @@ -73,6 +75,7 @@ def _help(self, cmd, show_description=True, leading=''):
for cmd in commands:
cmds_to_print.append(leading + COLORS.FAIL + ' - {}: {}'.format(cmd, success(commands[cmd].description, ret=True)) + COLORS.ENDC)
print('\n'.join(cmds_to_print))
return has_extra_info

class Flag:
def __init__(self, aliases, description, required=False, dtype='bool'):
Expand Down
7 changes: 6 additions & 1 deletion commands/device/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ def __init__(self):

self.commands = {'battery': Command(description='🔋 see information about the state of your battery'),
'reboot': Command(description='⚡ safely reboot your device'),
'shutdown': Command(description='🔌 safely shutdown your device'),
'shutdown': Command(description='🔌 safely shutdown your device',
flags=[Flag(['-r', '--reboot'], 'An alternate way to reboot the device', dtype='bool')]),
'settings': Command(description='⚙️ open the Settings app')}

def _settings(self):
Expand All @@ -23,6 +24,10 @@ def _reboot(self):
success('👋 See you in a bit!')

def _shutdown(self):
flags, e = self.parse_flags(self.commands['shutdown'].parser)
if e is None and flags.reboot:
self._reboot()
return
check_output('am start -n android/com.android.internal.app.ShutdownActivity')
success('🌙 Goodnight!')

Expand Down
19 changes: 10 additions & 9 deletions commands/fork/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,9 @@ def _switch(self):
else:
info('Fetching {}\'s fork, this may take a sec...'.format(flags.username))

r = check_output(['git', '-C', OPENPILOT_PATH, 'fetch', username])
if not r.success:
error(r.output)
r = run(['git', '-C', OPENPILOT_PATH, 'fetch', username])
if not r:
error('Error while fetching remote, please try again')
return
self.__add_fork(username)

Expand Down Expand Up @@ -227,9 +227,9 @@ def _switch(self):
remote_branch = f'{username}/{branch}'
if branch not in installed_forks[username]['installed_branches']:
info('New branch! Tracking and checking out {} from {}'.format(fork_branch, remote_branch))
r = check_output(['git', '-C', OPENPILOT_PATH, 'checkout', '--track', '-b', fork_branch, remote_branch])
if not r.success:
error(r.output)
r = run(['git', '-C', OPENPILOT_PATH, 'checkout', '--track', '-b', fork_branch, remote_branch])
if not r:
error('Error while checking out branch, please try again')
return
self.__add_branch(username, branch) # we can deduce fork branch from username and original branch f({username}_{branch})
else: # already installed branch, checking out fork_branch from remote_branch
Expand Down Expand Up @@ -312,11 +312,11 @@ def _init(self):
if self.fork_params.get('setup_complete'):
if os.path.exists(OPENPILOT_PATH):
r = check_output(['git', '-C', OPENPILOT_PATH, 'remote', 'show'])
if COMMA_ORIGIN_NAME in r.output.split('\n'): # sign that we're set up correctly
if COMMA_ORIGIN_NAME in r.output.split('\n'): # sign that we're set up correctly todo: check all forks exist as remotes
return True
self.fork_params.put('setup_complete', False) # some error with base origin, reclone
self.fork_params.put('setup_complete', False) # renamed origin -> commaai does not exist, restart setup
self.fork_params.reset()
warning('There was an error with your clone of commaai/openpilot, restarting initialization!')
warning('There was an error with your clone of commaai/openpilot, restarting initialization!')

info('To set up emu fork management we will clone commaai/openpilot into {}'.format(OPENPILOT_PATH))
info('Confirm you would like to continue')
Expand Down Expand Up @@ -352,3 +352,4 @@ def _init(self):
self.fork_params.put('current_fork', COMMA_ORIGIN_NAME)
self.fork_params.put('current_branch', COMMA_DEFAULT_BRANCH)
self.__add_fork(COMMA_ORIGIN_NAME)
return True
1 change: 1 addition & 0 deletions emu.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

class Emu(BaseFunctions):
def __init__(self, args):
self.name = 'emu'
self.args = args
self.commands = {cmd.name: cmd for cmd in EMU_COMMANDS}
self.parse()
Expand Down
2 changes: 1 addition & 1 deletion install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ COMMUNITY_BASHRC_PATH=/data/community/.bashrc
OH_MY_COMMA_PATH=/data/community/.oh-my-comma
GIT_BRANCH_NAME=master
GIT_REMOTE_URL=https://github.com/emu-sh/.oh-my-comma.git
OMC_VERSION=0.1.7
OMC_VERSION=0.1.8

update=false
if [ $# -ge 1 ] && [ $1 = "update" ]; then
Expand Down
9 changes: 6 additions & 3 deletions py_utils/emu_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,14 @@ def print_commands(self, error_msg=None, ascii_art=False):
max_cmd = max([len(_c) for _c in self.commands]) + 1
for idx, cmd in enumerate(self.commands):
desc = COLORS.CYAN + self.commands[cmd].description
print(COLORS.OKGREEN + ('- {:<%d} {}' % max_cmd).format(cmd + ':', desc))
print_cmd = '{} {}'.format(self.name, cmd)
if self.name != 'emu':
print_cmd = 'emu {}'.format(print_cmd)
print(COLORS.OKGREEN + ('- {:<%d} {}' % max_cmd).format(print_cmd + ':', desc))
if hasattr(self, '_help'):
# leading is for better differentiating between the different commands
self._help(cmd, show_description=False, leading=' ')
print()
if self._help(cmd, show_description=False, leading=' '):
print() # only add newline when there's more information to sift through
print(COLORS.ENDC, end='')

def next_arg(self, lower=True, ingest=True):
Expand Down

0 comments on commit 52408df

Please sign in to comment.