From 52408dfd17248cf5a737af1445071da32628dea6 Mon Sep 17 00:00:00 2001 From: Shane Smiskol Date: Wed, 29 Jul 2020 03:03:34 -0500 Subject: [PATCH] Run user's switch command after fork setup (#41) * 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 --- CHANGELOG.md | 6 ++++++ commands/base.py | 3 +++ commands/device/__init__.py | 7 ++++++- commands/fork/__init__.py | 19 ++++++++++--------- emu.py | 1 + install.sh | 2 +- py_utils/emu_utils.py | 9 ++++++--- 7 files changed, 33 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a6c3ac27..80d0ecd3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) ===== diff --git a/commands/base.py b/commands/base.py index ce0ac6fb..0f8604b5 100644 --- a/commands/base.py +++ b/commands/base.py @@ -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)) @@ -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 @@ -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'): diff --git a/commands/device/__init__.py b/commands/device/__init__.py index 0338b59e..bfbe4987 100644 --- a/commands/device/__init__.py +++ b/commands/device/__init__.py @@ -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): @@ -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!') diff --git a/commands/fork/__init__.py b/commands/fork/__init__.py index 29106ace..736696b2 100644 --- a/commands/fork/__init__.py +++ b/commands/fork/__init__.py @@ -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) @@ -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 @@ -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') @@ -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 diff --git a/emu.py b/emu.py index 9149788b..5c303f5a 100644 --- a/emu.py +++ b/emu.py @@ -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() diff --git a/install.sh b/install.sh index 7e421830..938434e9 100755 --- a/install.sh +++ b/install.sh @@ -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 diff --git a/py_utils/emu_utils.py b/py_utils/emu_utils.py index 33b61b83..85739884 100644 --- a/py_utils/emu_utils.py +++ b/py_utils/emu_utils.py @@ -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):