def get_installer_dirs(): if not fs.isdir(s.installersdir): print('Error: Installersdirectory ({0}) not found!'.format(s.installersdir)) exit(1) installerlist = fs.ls(s.installersdir) for item in list(installerlist): if not fs.isdir(s.installersdir,item): installerlist.remove(item) return installerlist
def make_apkpath(path): if path.endswith('.apk'): return [path] elif fs.isdir(path): result=[] for item in fs.ls(path): if not fs.isdir(path, item) and item.endswith('.apk'): result.append(fs.join(path,item)) print('Found {0} apk\'s in directory'.format(len(result))) return result return []
def analysis_menu(self): if not fs.isdir(s.resultsdir) or not fs.ls(s.resultsdir): print('Nothing to analyse.') return while True: print('Results for which run do you want to analyse?') options = self.get_result_dirs() chosenopts, result = menu.standard_menu( options, lambda x: fs.basename(str(x))) if result == menu.MenuResults.CHOSEN: if len(chosenopts) == 1: self.current_path = fs.join(self.current_path, chosenopts[0]) self.analysis_submenu() return elif len(chosenopts) > 1: self.analyse_all(chosenopts) return elif result == menu.MenuResults.EVERYTHING: self.analyse_all(chosenopts) return elif result == menu.MenuResults.BACK: return
def get_config_files(): configs = [] for item in fs.ls(s.execconfdir): if not fs.isdir(s.execconfdir, item) and item.endswith('.conf'): configs.append(fs.join(s.execconfdir,item)) configs.sort() return configs
def extract(self, task): target = fs.join(task.directory, task.name) basicstring = printer.format('extracter', printer.Color.CAN) extractstring = printer.format('extracting', printer.Color.YEL) print('[{0}] {1} {2}'.format(basicstring, extractstring, task.name)) if self.is_tar(task.url): ttar = tarfile.open(target, 'r') ttar.extractall(path=task.directory) elif self.is_zip(task.url): tzip = zipfile.ZipFile(target, 'r') tzip.extractall(task.directory) tzip.close() elif self.is_gzip(task.url): with gzip.open(target, 'rb') as f_in: with open(task.directory, 'wb') as f_out: fs.cp(f_in, f_out) else: return finishedstring = printer.format('extracted', printer.Color.GRN) print('[{0}] {1} {2}'.format(basicstring, finishedstring, task.name)) fs.rm(fs.join(task.directory, task.name)) dircontents = fs.ls(task.directory) if len(dircontents) == 1 and fs.isdir(task.directory, dircontents[0]): subdircontents = fs.ls(task.directory, dircontents[0]) for file in subdircontents: path = fs.join(task.directory, dircontents[0]) fs.mv(fs.join(path, file), task.directory) fs.rm(task.directory, dircontents[0], ignore_errors=True)
def get_result_dirs(self): if not fs.isdir(self.current_path): return [] return_list = fs.lsonlydir(self.current_path, full_paths=True) if fs.isdir(s.analyseddir): already_analysed = fs.lsonlydir(s.analyseddir) else: already_analysed = [] regex = '[0-9]+-[0-9]{2}-[0-9]{2}\([0-9]{2}:[0-9]{2}:[0-9]{2}\)' pattern = re.compile(regex) for item in return_list: basename = fs.basename(item) if (not pattern.match(basename)) or (basename in already_analysed): return_list.remove(item) return return_list
def get_execution_components(components): execomponents = [] if fs.isdir(s.resultsdir): for item in fs.lsonlydir(s.resultsdir, full_paths=True): if fs.isfile(item, s.runconf): execomponents.append( comp.ExecutionComponent(components, fs.join(item, s.runconf))) return execomponents
def get_java_env(self): if not fs.isdir(s.dependencydir, 'jdk8'): raise RuntimeError( 'Error: Could not find jdk8 directory in {0}'.format( s.dependencydir)) path_to_java = fs.join(s.dependencydir, 'jdk8') env = os.environ.copy() env['JAVA_HOME'] = path_to_java env['PATH'] = '{0}:{1}'.format(os.path.join(path_to_java, 'bin'), env['PATH']) return env
def ask_directory(question, must_exist=True): while True: print(question) print('Paths may be absolute or relative to your working directory') print('Working directory: {0}'.format(fs.cwd())) print('Please specify a directory:') choice = input('') choice = fs.abspath(choice) if must_exist: if not fs.isdir(choice): print('Error: no such directory - "{0}"'.format(choice)) else: return choice else: if fs.isdir(choice): print('"{0}" already exists'.format(choice)) if standard_yesno('continue?'): return choice else: return choice print('')
def test_apkpath(testpath): try: if fs.isfile(testpath) and testpath.endswith('.apk'): return True elif fs.isdir(testpath): for item in fs.ls(testpath): if fs.isfile(fs.join(testpath,item)) and item.endswith('.apk'): return True print('Specified directory has no apk files in it') return False except Exception as e: print('{0} does not exist'.format(testpath)) return False
def ask_path(question, must_exist=True): while True: print(question) print('Paths may be absolute or relative to your working directory') print('Working directory: {0}'.format(fs.cwd())) print('Please specify a path:') choice = input('') choice = fs.abspath(choice) if not fs.isdir(fs.dirname(choice)): print('Error: no such directory - "{0}"'.format( fs.dirname(choice))) elif must_exist: if fs.exists(choice): return choice else: print('"{0}" does not exist'.format(choice)) else: if fs.isfile(choice): if standard_yesno('"{0}" exists, override?'.format(choice)): return choice elif fs.isdir(choice): print('"{0}" is a directory'.format(choice)) print('')