def on_run(self, *params) -> bool: Printer.yellow_line('======> dump begin') Printer.blue_line('EC') Printer.green_line(' Dir: %s' % self.cfg.cfgProgramDir) Printer.green_line(' cmd dir: %s' % self.cfg.cfgProgramCmdDir) Printer.green_line(' cmd list: %s' % self.cfg.cfgProgramCmdList) Printer.green_line(' cfg dir: %s' % self.cfg.cfgProgramCfgDir) Printer.green_line(' cfg list: %s' % self.cfg.cfgProgramCfgList) Printer.green_line(' cfg file: %s' % self.cfg.cfgProgramCfgFile) Printer.blue_line('Global') Printer.green_line(' base dir: %s' % self.cfg.cfgGlobalBaseDir) Printer.green_line(' pull url: %s' % self.cfg.cfgGlobalUrlRepoPull) Printer.green_line(' push url: %s' % self.cfg.cfgGlobalUrlRepoPush) Printer.green_line(' user name: %s' % self.cfg.cfgGlobalUserName) Printer.green_line(' user email: %s' % self.cfg.cfgGlobalUserEmail) Printer.blue_line('Project') Printer.green_line(' name: %s' % self.cfg.cfgProjectName) Printer.green_line(' branch: %s' % self.cfg.cfgProjectBranch) Printer.green_line(' root dir: %s' % self.cfg.cfgProjectRootDir) Printer.green_line(' out dir: %s' % self.cfg.cfgProjectOutDir) Printer.green_line(' env setup: %s' % self.cfg.cfgProjectEnvSetup) Printer.green_line(' env config: %s' % self.cfg.cfgProjectEnvConfig) Printer.green_line(' flash map: %s' % self.cfg.cfgProjectFlashMap) Printer.green_line(' pull url: %s' % self.cfg.cfgProjectUrlRepoPull) Printer.green_line(' push url: %s' % self.cfg.cfgProjectUrlRepoPush) Printer.green_line(' repo bin: %s' % self.cfg.cfgProjectRepoBin) Printer.yellow_line('<====== dump end') return True
def on_run(self, *params) -> bool: target_product = self.cfg.cfgProjectName current_product = os.environ.get('ENV_PRODUCT') if current_product == target_product: Printer.yellow_line('Already initialized for %s!!!' % current_product) return True elif current_product is not None and current_product != '': Printer.red_line( 'Already initialized for [%s]. Please start a new terminal.' % current_product) return False else: # notify start Printer.green_line('Initializing for [%s] ...' % target_product) # begin env setup self.shell('source %s' % self.cfg.cfgProjectEnvSetup) self.shell('%s' % self.cfg.cfgProjectEnvConfig) # save current product self.shell('export ENV_PRODUCT=%s' % target_product) # notify done Printer.green_line('Done => Current Project: [%s]' % target_product) return True
def link(self, link: str, target: str) -> bool: if os.path.exists(target): self.shell('rm -rf %s' % link) # remove old link self.shell('ln -s %s %s' % (target, link)) # create new link Printer.green_line('create link: %s => %s' % (link, target)) return True else: Printer.yellow_line('target [%s] not exists. ignore it' % target) return False
def on_run(self, *params) -> bool: # assign path flash_path = self.cfg.cfgProjectOutDir if len(params) > 0 and (params[0] == '--path' or params[0] == '-p'): if len(params) < 2: Printer.red_line('invalid format of command') self.help() return False flash_path = os.path.abspath(params[1]) params = params[2:] # get flash list flash_dict = self.cfg.cfgProjectFlashMap if len(params) > 0: tmp_dict = dict() for p in params: if p in flash_dict: tmp_dict[p] = flash_dict[p] else: Printer.red_line('unknown partition: %s' % p) self.help() return False flash_dict = tmp_dict # do flash flashed = False self.shell('sudo adb reboot bootloader') for partition, img in flash_dict.items(): path = '%s/%s' % (flash_path, img) if os.path.exists(path): flashed = True Printer.green_line('flashing [%s] ...' % img) self.shell('sudo fastboot flash %s %s' % (partition, path)) Printer.green_line('Done') self.shell('sudo fastboot reboot') # warning for not flash if not flashed: Printer.yellow_line('No img found to be flashed!!') return True
def on_run(self, *params) -> bool: with open('%s/VERSION' % self.cfg.cfgProgramDir, 'r') as file: local_version = file.readline().strip() remote_version = version.http_get(version._URL_VERSION).strip() # check need update need_update = remote_version > local_version # do update if necessary if not need_update: msg = 'Up to date!! local: [%s], remote: [%s]' % (local_version, remote_version) set_last_check(int(time.time()), msg) # show message Printer.green_line(msg) else: msg = 'Need update! local: [%s], remote: [%s]' % (local_version, remote_version) set_last_check(int(time.time()), msg) set_has_update(remote_version) # show message Printer.yellow_line(msg) return True
def help(self): Printer.yellow_line('Show help of the command') Printer.yellow_line('') Printer.yellow_line('cmd: %s' % self.cfg.cfgProgramCmdList)
def help(self): for line in self._HELP_MESSAGE: Printer.yellow_line(line)
def on_run(self, *params) -> bool: # True: success, False: failed Printer.yellow_line('empty implement of run()# params: %s' % params) return True
def w(tag: str, msg: str): Printer.yellow_line(Log._make_message(tag, msg))
def shell(self, argv): shell = Shell() with shell: # ignore program path argv = argv[1:] # check argv if len(argv) <= 0: Printer.red_line('No project input!!!') self.help() return # get print flag do_print = False print_flag = argv[0].strip() if print_flag == '--print' or print_flag == '-p': do_print = True shell.fake_exec(True) argv = argv[1:] # check argv if len(argv) <= 0: Printer.red_line('No project input!!!') self.help() return # get project project = argv[0].strip() if do_print else print_flag # get command command = ' '.join(argv[1:]).strip() # parser argv cmd_list = list(map(str.strip, command.split(','))) # env env = Env() # load cfg cfg = env.load_cfg(project) if cfg is None: Printer.red_line('invalid project: %s' % project) Printer.yellow_line('available project: %s' % env.cfgProgramCfgList) return # check cmd cmd_checked = [] for c in cmd_list: cmd_parts = list(map(str.strip, c.split(' '))) cmd_name = cmd_parts[0] cmd_params = cmd_parts[1:] cmd = env.load_cmd(cmd_name) if cmd is None: Printer.red_line('invalid command: %s.' % cmd_name) Printer.yellow_line('available cmd: %s' % env.cfgProgramCmdList) return else: cmd_checked.append({'cmd': cmd, 'params': cmd_params}) # run cmd for c in cmd_checked: c['cmd'].run(shell, cfg, *tuple(c['params']))
def help(): Printer.yellow_line('ec [--print|-p|-P] <project> CMD1 [PARAM1], [CMD2] [PARAM2]') Printer.yellow_line('\t [--print|-p|-P]: print the command instead of execute on shell')