def show_error(self, command=None, error_code=None): logger.hr("Update failed", 0) self.show_config() logger.info("") logger.info(f"Last command: {command}\nerror_code: {error_code}") logger.info("Please check your deploy settings in config/deploy.yaml " "and re-open Alas.exe")
def app_update(self): logger.hr(f'Update app.asar', 0) if not self.AutoUpdate: logger.info('AutoUpdate is disabled, skip') return False return self.app_asar_replace(os.getcwd())
def show_config(self): logger.hr("Show deploy config", 1) for k, v in self.config.items(): if k in ("Password", "SSHUser"): continue if self.config_template[k] == v: continue logger.info(f"{k}: {v}") logger.info(f"Rest of the configs are the same as default")
def kill_by_name(self, name): """ Args: name (str): Process name """ logger.hr(f'Kill {name}', 1) for row in self.iter_process_by_name(name): logger.info(' '.join(map(str, row))) self.execute(f'taskkill /f /pid {row[2]}', allow_failure=True, output=False)
def git_install(self): logger.hr('Update Alas', 0) if not self.AutoUpdate: logger.info('AutoUpdate is disabled, skip') return self.git_repository_init( repo=self.Repository, source='origin', branch=self.Branch, proxy=self.GitProxy, keep_changes=self.KeepLocalChanges, )
def pip_install(self): logger.hr('Update Dependencies', 0) if not self.InstallDependencies: logger.info('InstallDependencies is disabled, skip') return logger.hr('Check Python', 1) self.execute(f'"{self.python}" --version') arg = [] if self.PypiMirror: mirror = self.PypiMirror arg += ['-i', mirror] # Trust http mirror if 'http:' in mirror: arg += ['--trusted-host', urlparse(mirror).hostname] # Don't update pip, just leave it. # logger.hr('Update pip', 1) # self.execute(f'"{self.pip}" install --upgrade pip{arg}') arg += ['--disable-pip-version-check'] logger.hr('Update Dependencies', 1) arg = ' ' + ' '.join(arg) if arg else '' self.execute(f'{self.pip} install -r {self.requirements_file}{arg}')
def adb_install(self): logger.hr('Start ADB service', 0) emulator = EmulatorConnect(adb=self.adb) if self.ReplaceAdb: logger.hr('Replace ADB', 1) emulator.adb_replace() elif self.AutoConnect: logger.hr('ADB Connect', 1) emulator.brute_force_connect() if self.InstallUiautomator2: logger.hr('Uiautomator2 Init', 1) try: import adbutils except ModuleNotFoundError as e: message = str(e) for module in ['apkutils2', 'progress']: # ModuleNotFoundError: No module named 'apkutils2' # ModuleNotFoundError: No module named 'progress.bar' if module in message: show_fix_tip(module) exit(1) # Remove global proxies, or uiautomator2 will go through it for k in list(os.environ.keys()): if k.lower().endswith('_proxy'): del os.environ[k] from uiautomator2.init import Initer for device in adbutils.adb.iter_device(): init = Initer(device, loglevel=logging.DEBUG) init.set_atx_agent_addr('127.0.0.1:7912') try: init.install() except AssertionError: logger.info( f'AssertionError when installing uiautomator2 on device {device.serial}' ) logger.info( 'If you are using BlueStacks or LD player or WSA, ' 'please enable ADB in the settings of your emulator') exit(1) init._device.shell(["rm", "/data/local/tmp/minicap"]) init._device.shell(["rm", "/data/local/tmp/minicap.so"])
def alas_kill(self): logger.hr(f'Kill existing Alas', 0) self.kill_by_name('alas.exe') self.kill_by_name('python.exe')
def git_repository_init(self, repo, source='origin', branch='master', proxy='', keep_changes=False): logger.hr('Git Init', 1) self.execute(f'"{self.git}" init') logger.hr('Set Git Proxy', 1) if proxy: self.execute(f'"{self.git}" config --local http.proxy {proxy}') self.execute(f'"{self.git}" config --local https.proxy {proxy}') else: self.execute(f'"{self.git}" config --local --unset http.proxy', allow_failure=True) self.execute(f'"{self.git}" config --local --unset https.proxy', allow_failure=True) logger.hr('Set Git Repository', 1) if not self.execute(f'"{self.git}" remote set-url {source} {repo}', allow_failure=True): self.execute(f'"{self.git}" remote add {source} {repo}') logger.hr('Fetch Repository Branch', 1) self.execute(f'"{self.git}" fetch {source} {branch}') logger.hr('Pull Repository Branch', 1) # Remove git lock lock_file = './.git/index.lock' if os.path.exists(lock_file): logger.info(f'Lock file {lock_file} exists, removing') os.remove(lock_file) if keep_changes: if self.execute(f'"{self.git}" stash', allow_failure=True): self.execute(f'"{self.git}" pull --ff-only {source} {branch}') if self.execute(f'"{self.git}" stash pop', allow_failure=True): pass else: # No local changes to existing files, untracked files not included logger.info( 'Stash pop failed, there seems to be no local changes, skip instead' ) else: logger.info( 'Stash failed, this may be the first installation, drop changes instead' ) self.execute(f'"{self.git}" reset --hard {source}/{branch}') self.execute(f'"{self.git}" pull --ff-only {source} {branch}') else: self.execute(f'"{self.git}" reset --hard {source}/{branch}') self.execute(f'"{self.git}" pull --ff-only {source} {branch}') logger.hr('Show Version', 1) self.execute(f'"{self.git}" log --no-merges -1')