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 adb_push(self, msg, src, dst): if os.path.exists(src): Printer.green_line('Pushing %s ...' % msg) self.shell('adb shell mkdir -p %s' % dst) self.shell('adb push %s %s' % (src, dst)) Printer.green_line('Done') return True else: return False
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: backup_list = list(os.listdir(self.cfg.cfgProjectBackupDir)) Printer.green_line('%s backup found.' % len(backup_list)) for i in backup_list: Printer.green_line('[%s] => %s/%s' % (i, self.cfg.cfgProjectBackupDir, i)) return True
def on_run(self, *params) -> bool: self.shell('adb enable-verity') self.shell('adb shell setprop ro.secure 1') self.shell('adb shell setprop ro.debuggable 0') self.shell('adb shell setprop ro.allow.mock.location 0') self.shell('adb shell /system/bin/setenforce 1') self.shell('eval result=`adb shell ps | grep adbd`') self.shell('eval pid=`echo $result | awk -F " " \'{print $2}\'`') self.shell('eval adb shell kill $pid') self.shell('unset result') self.shell('unset pid') Printer.green_line('Unrooted') return True
def on_run(self, *params) -> bool: self.shell('adb shell setprop ro.secure 0') self.shell('adb shell setprop ro.debuggable 1') self.shell('adb shell setprop ro.allow.mock.location 1') self.shell('adb shell setprop persist.sys.usb.config mtp,adb') self.shell('adb wait-for-device') self.shell('adb root') self.shell('adb wait-for-device') self.shell('adb shell /system/bin/setenforce 0') self.shell('adb remount') self.shell('adb disable-verity') Printer.green_line('Rooted') return True
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 on_run(self, *params) -> bool: Printer.green_line('clone ...') project_dir = self.cfg.cfgProjectRootDir date_path = '.date' date = datetime.datetime.now().strftime('%Y-%m-%d-%H-%M-%S') # check -j* pattern = re.compile('-j[\d]+') thread_param = None for p in params: if pattern.fullmatch(p): thread_param = p params = list(params) params.remove(p) # create backup dir if not exists self.shell('mkdir -p %s' % self.cfg.cfgProjectBackupDir) # move project dir to backup old_date = '%s_backup' % date old_date_path = '%s/%s' % (self.cfg.cfgProjectRootDir, date_path) if os.path.exists(old_date_path) and os.path.isfile(old_date_path): with open(old_date_path) as date_file: old_date = date_file.readline().strip() backup_dir = '%s/%s' % (self.cfg.cfgProjectBackupDir, old_date) self.shell('eval mv -f "%s" "%s"' % (project_dir, backup_dir)) # prepare new project dir self.shell('mkdir -p %s' % self.cfg.cfgProjectRootDir) self.cd(self.cfg.cfgProjectRootDir) # switch to temp dir self.shell('eval echo "%s" > ./%s' % (date, date_path)) # create .date file # copy file from old project self.shell('cp -f "%s/.classpath" "%s/.classpath"' % (backup_dir, project_dir)) self.shell('cp -f "%s/.project" "%s/.project"' % (backup_dir, project_dir)) self.shell('cp -rf "%s/.vscode" "%s/.vscode"' % (backup_dir, project_dir)) # prepare the input text & repo command repo_bin = 'python %s/bin/%s' % (self.data_dir(), self.cfg.cfgProjectRepoBin) repo_input = '%s\r%s\ry\r' % (self.cfg.cfgGlobalUserName, self.cfg.cfgGlobalUserEmail) repo_cmd = '%s init -u %s -b master -m %s.xml --depth=1 --config-name' % ( repo_bin, self.cfg.cfgProjectUrlRepoPull, self.cfg.cfgProjectBranch) # start clone with Python2(self): self.shell('eval echo %s | %s' % (repo_input, repo_cmd)) self.shell( '%s sync %s' % (repo_bin, '-j4' if thread_param is None else thread_param)) self.shell('%s start %s --all' % (repo_bin, self.cfg.cfgProjectBranch)) # # move temp dir to project dir # self.shell('eval mv -f "%s" "%s"' % (temp_dir, project_dir)) # apply ccache self.cd(project_dir) self.shell('%s/prebuilts/misc/linux-x86/ccache/ccache -M 50G' % project_dir) Printer.green_line('done') return True
def i(tag: str, msg: str): Printer.green_line(Log._make_message(tag, msg))
def remove(self, path: str): if os.path.exists(path): self.shell('rm -rf %s' % path) Printer.green_line('Removed: %s' % path)
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 close(): Printer.green_line('=====> stop shell') print('==end==')
def open(): Printer.green_line('=====> open shell')