def download_and_install(cls, build, job): volume_name = cls.get_subdir() if volume_name is not None: CmdHelper.run("diskutil eject '" + volume_name + "'") LogHelper.info( "Prepare download Mozy Restore Manager from jenkins, build number is " + job) jh = JenkinsHelper(GLOBAL_CONFIG["JENKINS"]["URL"], GLOBAL_CONFIG["JENKINS"]["USERNAME"], GLOBAL_CONFIG["JENKINS"]["KEY"]) dest = ConfigAdapter.get_installer_path('MACFRYR') LogHelper.info('Clean up existing files') for file in FileHelper.find_file(dest, '*'): LogHelper.debug('Delete file %s' % file) FileHelper.delete_file(file) pattern = 'mozy-fryr' packages = jh.download_packages(jh.get_packages(job, build, pattern), dest=dest) TARGET_APP = '/Applications/Mozy Restore Manager.app' if os.path.exists(TARGET_APP): shutil.rmtree(TARGET_APP) image_path = packages[0] mount_cmd = 'sudo hdiutil attach {package}'.format(package=image_path) CmdHelper.run(mount_cmd) volume_name = cls.get_subdir() ORIGIN_APP = '/Volumes/' + volume_name + '/Mozy Restore Manager.app' shutil.copytree(ORIGIN_APP, TARGET_APP)
def get_archive_name(): download_path = ConfigAdapter.get_installer_path() for file in FileHelper.find_file(download_path, '*'): file = os.path.basename(file) pattern = r'restore_(.+?).zip' if re.match(pattern, file): return file
def stem_impl(context, output_dir): root_path = ConfigAdapter.get_installer_path(product='linux') output_path = os.path.join(ConfigAdapter.get_output_path(product='linux'), output_dir) for mzd_file in FileHelper.find_file(root_path, "*.mzd"): LogHelper.info('restore mzd file %s to %s' % (mzd_file, output_path)) FileHelper.create_directory(output_path) LinuxGUIClient.download_cmd.download(mzd=mzd_file, output=output_path, overwrite=None)
def parse_feature(features, pattern="*.feature"): testfeatures = [] if FileHelper.file_exist(features) and FileHelper.file_ext(features) == "feature": testfeatures.append(features) else: files = FileHelper.find_file(features, pattern) # TODO: refine with FileHelper for file in files: testfeatures.append("features" + file.split("features")[1]) return testfeatures
def clear_restore_folder(folder_name): directory = os.path.expanduser('~/Documents/' + folder_name) if platform.system() == "Windows": directory = "C:/" + folder_name for file in FileHelper.find_file(directory, '*'): LogHelper.debug('Delete file %s' % file) os.remove(file) for folder in FileHelper.find_dir(directory, '*'): LogHelper.debug('Delete folder %s' % folder) try: shutil.rmtree(folder) except: pass
def delete_json_file(filename=None, conf_dir=None): if not conf_dir: conf_dir = LynxCtrl.conf_dir if not filename: filename = "*.json" files = FileHelper.find_file(conf_dir, filename) for file_to_delete in files: FileHelper.delete_file(file_to_delete) return files
def clear_download_folder(): directory = ConfigAdapter.get_installer_path('MACFRYR') if platform.system() == "Windows": directory = "C:/" + ConfigAdapter.get_testdata_path( 'WINFRYR').split('\\\\')[1] for file in FileHelper.find_file(directory, '*'): LogHelper.debug('Delete file %s' % file) os.remove(file) for folder in FileHelper.find_dir(directory, '*'): LogHelper.debug('Delete folder %s' % folder) try: shutil.rmtree(folder) except: pass
def clean_all(self): entities = FileHelper.find_file(self.app_support_dir, '*') for entry in entities: if entry.find('backup.pid') >= 0: continue if entry.find('restore') >= 0: continue if entry.find('network') >= 0: continue cmd = MacController.prefix_for_sudo( ) + 'sudo -S rm -rf "%s"' % entry CmdHelper.run(cmd) # cache_db_path = os.path.join(self.cache_dir, self.cache_db) # cmd = "sudo rm -rf '{path}'".format(path=cache_db_path) # CmdHelper.run(cmd) self.restart_mozypro_pid()
def step_impl(context): LogHelper.info("start to overwrite files") testdata_root = ConfigAdapter.get_testdata_path() for row in context.table: testdata_dir = os.path.join(testdata_root, row.get('file_folder')) testdatas = FileHelper.find_file(testdata_dir, '*') max_size = int(row.get('maxsize')) min_size = int(row.get('minsize')) length = random.randrange(min_size, max_size) for testdata in testdatas: offset_pattern = row.get('offset_pattern') if offset_pattern == 'random': size = FileHelper.file_size(testdata) offset = random.randrange(1, size) elif offset_pattern.isdigit(): size = FileHelper.file_size(testdata) offset = min(int(offset_pattern), size) FileHelper.overwrite_file_random(testdata, offset, length)
def step_impl(context): testdata_root = ConfigAdapter.get_testdata_path() testdata_config = ConfigAdapter.get_testdata_pros() for row in context.table.rows: if "file_folder" in row.headings: testdata_dir = os.path.join(testdata_root, row.get('file_folder') or '') elif "file_dir" in row.headings: testdata_dir = os.path.join(testdata_root, row.get('file_dir') or '') length = row.get('length') or testdata_config.get("FILE_SIZE") or 10 length = int(length) pattern = row.get('content') or 'random' testdatas = FileHelper.find_file(testdata_dir, '*') for testdata in testdatas: LogHelper.info("Patch test files %s %d %s" % (testdata, length, pattern)) FileHelper.append_file_content(testdata, length, pattern)
def delete_test_files(context, params): testdata_root = ConfigAdapter.get_testdata_path() for row in context.table.rows: if "file_folder" in row.headings or "file_dir" in row.headings: testdata_dir = os.path.join( testdata_root, row.get('file_folder') or row.get('file_dir') or '') if params.upper() == "DIRS": LogHelper.debug("Delete dirs " + testdata_dir) FileHelper.delete_directory(testdata_dir) return if params.upper() == "FILES": pattern = row.get('pattern') or '*' file_list = FileHelper.find_file(testdata_dir, pattern) for file in file_list: LogHelper.debug("delete file %s" % file) FileHelper.delete_file(file) return
def decrypt_tar(context, dest): source_root = ConfigAdapter.get_installer_path('LINUX') source_full_path = source_root # for file in os.listdir(source_root): # print(file) # if re.match(r'.*\.tar$', file): # source_full_path = os.path.join(source_root, file) tars = FileHelper.find_file(source_root, "*.tar") LogHelper.info(tars[-1]) for file in tars: LogHelper.info(file) source_full_path = os.path.join(source_root, file) # source_full_path = os.path.join(source_root,source) LogHelper.info("Decrypt src: {source}".format(source=source_full_path)) dest_root = ConfigAdapter.get_output_path('LINUX') dest_full_path = os.path.join(dest_root, dest) FileHelper.create_directory(dest_full_path, True) output = LinuxGUIClient.decrypt_cmd.decrypt(source_full_path, dest_full_path) LogHelper.info("Decrypt output {output}".format(output=output))
def download_and_install(cls, build, job): # pass WinFryR_Installer.uninstall(False) LogHelper.info( "Prepare download Mozy Restore Manager from jenkins, build number is " + job) jh = JenkinsHelper(GLOBAL_CONFIG["JENKINS"]["URL"], GLOBAL_CONFIG["JENKINS"]["USERNAME"], GLOBAL_CONFIG["JENKINS"]["KEY"]) dest = ConfigAdapter.get_installer_path('WINFRYR') LogHelper.info('Clean up existing files') for file in FileHelper.find_file(dest, '*'): LogHelper.debug('Delete file %s' % file) FileHelper.delete_file(file) pattern = 'mozy-fryr' packages = jh.download_packages(jh.get_packages(job, build, pattern), dest=dest) for package in packages: if str(package).endswith('setup.exe'): LogHelper.info("Prepare to install Mozy Restore Manager.") install_cmd = "%s" % (package) CmdHelper.run(install_cmd) break
def clear_installer_folder(product_name): directory = ConfigAdapter.get_installer_path(product_name) for file in FileHelper.find_file(directory, '*'): LogHelper.debug('Delete file %s' % file) FileHelper.delete_file(file)
def step_impl(context, number): LogHelper.info("start to judge whether to create files") testdata_config = ConfigAdapter.get_testdata_pros() testdata_root = ConfigAdapter.get_testdata_path() testdata_dir = testdata_root file_size = 0 for row in context.table: if "file_folder" in row.headings: testdata_dir = os.path.join(testdata_root, row.get('file_folder')) elif "file_dir" in row.headings: testdata_dir = os.path.join(testdata_root, row.get('file_dir')) if not FileHelper.dir_exist(testdata_dir): FileHelper.create_directory(testdata_dir) if not FileHelper.get_file_count_in_dir(testdata_dir) == int(number): FileHelper.delete_file(testdata_dir) for row in context.table: for i in range(0, int(number)): file_prefix = row.get("file_prefix") or testdata_config.get( "FILE_PREFIX") or "td" file_txt = row.get("file_ext") or testdata_config.get( "FILE_EXT") or "txt" name = row.get('file_name') or testdata_config.get( "FILE_NAME") or None if name: file_name = "%s_%s_%s.%s" % (file_prefix, name, i, file_txt) else: file_name = "%s_%s.%s" % (file_prefix, i, file_txt) file_size = row.get("file_size") or testdata_config.get( "FILE_SIZE") or 0 DataHelper.create_testfile(file_name, testdata_dir, int(file_size)) context.file_size = file_size else: for row in context.table: length = row.get('length') or testdata_config.get( "FILE_SIZE") or 10 length = int(length) size = row.get('file_size') or testdata_config.get("FILE_SIZE") pattern = row.get('content') or 'random' testdatas = FileHelper.find_file(testdata_dir, '*') patch_method = row.get('patch_method') if patch_method == "append": for testdata in testdatas: LogHelper.info("Patch test files with %s %s %d %s" % (patch_method, testdata, length, pattern)) FileHelper.append_file_content(testdata, length, pattern) elif patch_method == "truncate": for testdata in testdatas: LogHelper.info("Patch test files with %s %s %d %s" % (patch_method, testdata, length, pattern)) FileHelper.truncate_file(testdata, length) elif patch_method == "insert": for testdata in testdatas: LogHelper.info("Patch test files with %s %s %d %s" % (patch_method, testdata, length, pattern)) size_offset = random.randrange(1, size) FileHelper.insert_file_content(testdata, size_offset, length, pattern)