def main(): allFilesList = [] allKeysDict = {} utils.removedirs(outDir) allKeysDict["." + srcStr.lower()] = "." + outStr.lower() allKeysDict[srcStr] = outStr allKeysDict[srcStr.lower() + "Proxy"] = outStr.lower() + "Proxy" allKeysDict["/" + srcStr.lower()] = "/" + outStr.lower() allKeysDict[srcCmd] = outCmd for root, dirs, files in os.walk(fileDir): for dir in dirs: # 遍历文件夹 print(os.path.join(root, dir)) for file in files: allFilesList.append(os.path.join(root, file)) for file in allFilesList: newfile = file.replace(fileDir, outDir) newfile = newfile.replace(srcStr, outStr) newfile = newfile.replace(srcStr.lower(), outStr.lower()) utils.mkdirs(newfile) with codecs.open(file, 'r', encoding='utf-8') as f: with codecs.open(newfile, 'w', encoding='utf-8') as newf: lines = f.readlines() for line in lines: for key in allKeysDict: line = line.replace(key, allKeysDict[key]) newf.write(line)
def __get_kvm_host(host=None): evn = BASE_DIR + "/conf/kvm_host.json" data_list = open_read_json(evn) if not data_list: mkdirs(evn) data1 = dict(host="192.168.88.86:8001", hostname="192.168.88.86", vnc_lite_host="192.168.88.86", vnc_host="192.168.88.86", vnc_port="8007") data2 = dict(host="192.168.88.87:8008", hostname="192.168.88.87", vnc_lite_host="192.168.88.87", vnc_host="192.168.88.87", vnc_port="8007") data_list = [data1, data2] open_write_json(evn, data_list) hos_datas_list = [] local_bean = None for item in data_list: h = None if host and item["host"] == host: item["selected"] = True h = HostData(**item) local_bean = h else: h = HostData(**item) hos_datas_list.append(h) return hos_datas_list, local_bean
def main(root=cd, dirname=None): if dirname is None: print("please enter dirname, for example: dsHg") return fileDir = os.path.join(os.path.join(root, dirname)) outDir = os.path.join(os.path.join(root, "out")) print("outDir", outDir) utils.removedirs(outDir) for root, dirs, files in os.walk(fileDir): for dir in dirs: # 遍历文件夹 #print(os.path.join(root, dir)) pass for file in files: filePath = os.path.join(root, file) if file.endswith('.' + checkSuffix): guessSuffix = filetype.guess_extension(filePath) if not guessSuffix == checkSuffix: print('{0} error: {1} -> {2}'.format( filePath, checkSuffix, guessSuffix)) outPath = filePath.replace(fileDir, outDir) outPath = outPath.replace('.' + checkSuffix, '.' + guessSuffix) if os.path.exists(filePath): utils.mkdirs(outPath) shutil.copyfile(filePath, outPath)
def __get_kvm_info_json_file(diqu): evn = BASE_DIR + "/media/kvm/" mkdirs(evn) kvm_info_dict = {} kvm_json_file = evn + "kvm_%s.json" % str(diqu).replace( ".", "_").replace(":", "_") try: with open(kvm_json_file, "r") as kvm_info: kvm_info_dict = json.load(kvm_info) except Exception as e: traceback.print_exc() pass return kvm_info_dict pass
def main(root=cd, dirname=None): if dirname is None: print("please enter dirname, for example: dsHg") return fileDir = os.path.join(os.path.join(root, dirname)) outDir = os.path.join(os.path.join(root, "i2tOut")) print("outDir", outDir) utils.removedirs(outDir) for root, dirs, files in os.walk(fileDir): for dir in dirs: # 遍历文件夹 #print(os.path.join(root, dir)) pass for file in files: filePath = os.path.join(root, file) result = getImageToTextReslut(filePath) if result and result["prism_wnum"] > 0: outPath = filePath.replace(fileDir, outDir) utils.mkdirs(outPath) shutil.copyfile(filePath, outPath)
def main(root=cd, dirname=None): if dirname is None: print("please enter dirname, for example: dsHg") return fileDir = os.path.join(os.path.join(root, dirname)) resDir = os.path.join(os.path.join(fileDir, "src")) checkDir = os.path.join(os.path.join(fileDir, "hot")) outDir = os.path.join(os.path.join(fileDir, "out")) utils.removedirs(outDir) for root, dirs, files in os.walk(resDir): for dir in dirs: # 遍历文件夹 #print(os.path.join(root, dir)) pass for file in files: filePath = os.path.join(root, file) checkPath = filePath.replace(resDir, checkDir) outPath = filePath.replace(resDir, outDir) if not os.path.exists(checkPath): #print(filePath) utils.mkdirs(outPath) shutil.copyfile(filePath, outPath)
def __init__(self): super(GraphSetting, self).__init__() self.numpy_list = os.listdir(os.path.join(self.save_path, 'mask',self.dataset, self.label)) self.numpy_list = [ f for f in self.numpy_list if 'npy' in f] self.feature_save_path = os.path.join(self.save_path,'feature', self.dataset, self.label, ) self.distance_save_path = os.path.join(self.save_path,'coordinate', self.dataset, self.label) mkdirs(self.distance_save_path) mkdirs(self.feature_save_path) mkdirs(self.distance_save_path.replace('coordinate', 'distance'))
def split(filePath): print("filePath", filePath) folderPath, fileName = os.path.split(filePath) fname, suffix = os.path.splitext(fileName) pngName = fname + ".png" pngFile = os.path.join(folderPath, pngName) if os.path.exists(pngFile): big_image = Image.open(pngFile) with open(filePath, 'r') as atlas: # _line = atlas.readline() while _line.find("repeat"): #直到找到repeat这一行 _line = atlas.readline() rl = None while True: if rl is None: rl = atlas.readline() # name if len(rl) == 0: break else: dict = {} while True: #直到找到有:分割符的 args = rl.split(":") if len(args) < 2: dict["name"] = utils.trim(args[0]) rl = atlas.readline() else: break while len(args) > 1: #开始解析 dict[utils.trim(args[0])] = utils.trim( args[1]).split(",") rl = atlas.readline() # rotate args = rl.split(":") print(dict) name = dict["name"] + ".png" # rotate,size,orig,offset,index args = dict["size"] width = int(args[0]) height = int(args[1]) args = dict["xy"] ltx = int(args[0]) lty = int(args[1]) rbx = ltx + width rby = lty + height #print(name,width,height,ltx,lty,rbx,rby) result_image = Image.new("RGBA", (width, height), (0, 0, 0, 0)) rect_on_big = big_image.crop((ltx, lty, rbx, rby)) #print(rect_on_big) result_image.paste(rect_on_big, (0, 0, width, height)) outPath = os.path.join( folderPath.replace("splitAtlas", "splitAtlasOut"), name) utils.mkdirs(outPath) result_image.save(outPath) print("success")