# -*- coding: utf-8 -*- import subprocess import os from itertools import chain def system(cmd): ''' @summary: excute a subprocess return util subprocess stopped @param cmd: a string that need to excute in subprocess @result: return_code, stdout, stderr ''' process = subprocess.Popen( args=cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) std_out, std_err = process.communicate() return_code = process.poll() return return_code, std_out, std_err def mkdirs(dirname): if not os.path.exists(dirname): os.makedirs(dirname) def get_all_file(dirname): result = [os.path.join(dp, f) for dp, dn, filenames in os.walk(dirname) for f in filenames] return result def filter_files(files, filter_names): ret = [] for filename in files: try: if filename.split(".")[-1] in filter_names: ret.append(filename) except: pass return ret def write_error_to_file(file): with open(file, 'w+') as f: f.write("0")