Python distutils.dir_util.copy_tree() Examples
The following are 30
code examples of distutils.dir_util.copy_tree().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
distutils.dir_util
, or try the search function
.
Example #1
Source File: test_dir_util.py From setuptools with MIT License | 6 votes |
def test_copy_tree_verbosity(self): mkpath(self.target, verbose=0) copy_tree(self.target, self.target2, verbose=0) self.assertEqual(self._logs, []) remove_tree(self.root_target, verbose=0) mkpath(self.target, verbose=0) a_file = os.path.join(self.target, 'ok.txt') with open(a_file, 'w') as f: f.write('some content') wanted = ['copying %s -> %s' % (a_file, self.target2)] copy_tree(self.target, self.target2, verbose=1) self.assertEqual(self._logs, wanted) remove_tree(self.root_target, verbose=0) remove_tree(self.target2, verbose=0)
Example #2
Source File: template_import.py From lost with MIT License | 6 votes |
def update_pipe_project(self): if os.path.exists(self.dst_pipe_template_path): logging.info('\n\n++++++++++++++++++++++\n\n') for pipe in self.pipes: if not self.checker.check(pipe): logging.error('Pipeline was not updated!') return False for pipe in self.pipes: self.update_pipe(pipe) dir_util.copy_tree(self.src_pipe_template_path, self.dst_pipe_template_path) logging.info("Copyed pipeline template dir from %s to %s"%(self.src_pipe_template_path, self.dst_pipe_template_path)) else: logging.warning(('Cannot update. No such pipe project: *{}*. ' 'Maybe you want to import a pipeline instead ' 'of updating it.').format(self.namespace))
Example #3
Source File: template_import.py From lost with MIT License | 6 votes |
def start_import(self): logging.info('\n\n++++++++++++++++++++++ \n\n') logging.info('Start pipe project import for: {}'.format(self.src_pipe_template_path)) for pipe in self.pipes: if not self.checker.check(pipe): logging.error('Wrong pipeline definition! Did not import pipe project!') return False if os.path.exists(self.dst_pipe_template_path): logging.warning('Cannot import pipeline!') logging.warning('Pipe Template Dir already exist: {}'.format( self.dst_pipe_template_path )) return dir_util.copy_tree(self.src_pipe_template_path, self.dst_pipe_template_path) logging.info("Copyed pipeline template dir from %s to %s"%(self.src_pipe_template_path, self.dst_pipe_template_path)) for pipe in self.pipes: self.import_pipe(pipe)
Example #4
Source File: test_dir_util.py From Imogen with MIT License | 6 votes |
def test_copy_tree_verbosity(self): mkpath(self.target, verbose=0) copy_tree(self.target, self.target2, verbose=0) self.assertEqual(self._logs, []) remove_tree(self.root_target, verbose=0) mkpath(self.target, verbose=0) a_file = os.path.join(self.target, 'ok.txt') with open(a_file, 'w') as f: f.write('some content') wanted = ['copying %s -> %s' % (a_file, self.target2)] copy_tree(self.target, self.target2, verbose=1) self.assertEqual(self._logs, wanted) remove_tree(self.root_target, verbose=0) remove_tree(self.target2, verbose=0)
Example #5
Source File: test_dir_util.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def test_copy_tree_verbosity(self): mkpath(self.target, verbose=0) copy_tree(self.target, self.target2, verbose=0) self.assertEqual(self._logs, []) remove_tree(self.root_target, verbose=0) mkpath(self.target, verbose=0) a_file = os.path.join(self.target, 'ok.txt') with open(a_file, 'w') as f: f.write('some content') wanted = ['copying %s -> %s' % (a_file, self.target2)] copy_tree(self.target, self.target2, verbose=1) self.assertEqual(self._logs, wanted) remove_tree(self.root_target, verbose=0) remove_tree(self.target2, verbose=0)
Example #6
Source File: test_dir_util.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 6 votes |
def test_copy_tree_verbosity(self): mkpath(self.target, verbose=0) copy_tree(self.target, self.target2, verbose=0) self.assertEqual(self._logs, []) remove_tree(self.root_target, verbose=0) mkpath(self.target, verbose=0) a_file = os.path.join(self.target, 'ok.txt') with open(a_file, 'w') as f: f.write('some content') wanted = ['copying %s -> %s' % (a_file, self.target2)] copy_tree(self.target, self.target2, verbose=1) self.assertEqual(self._logs, wanted) remove_tree(self.root_target, verbose=0) remove_tree(self.target2, verbose=0)
Example #7
Source File: main_metadata.py From SalesforceXyTools with Apache License 2.0 | 6 votes |
def main(self): self.sublconsole.showlog("start to refresh %s..." % (self.sel_dirs)) self.meta_api = util.sf_login(self.sf_basic_config, Soap_Type=MetadataApi) retrive_metadata_objects = [] for metaObj in self.meta_api.describeMetadata()["metadataObjects"]: if metaObj['directoryName'] in self.sel_dirs: retrive_metadata_objects.append(metaObj) if len(retrive_metadata_objects) > 0 : tmp_dir = self.sf_basic_config.get_tmp_dir() tmp_file = os.path.join(tmp_dir, "tmp_src.zip") tmp_src_dir = os.path.join(tmp_dir, "tmp_src") if os.path.exists(tmp_file): os.remove(tmp_file) if os.path.exists(tmp_src_dir): shutil.rmtree(tmp_src_dir) self.meta_api.retrieveZip(zip_file_name=tmp_file, retrive_metadata_objects=retrive_metadata_objects) if os.path.exists(tmp_file): self.meta_api.unzipfile(tmp_file, tmp_src_dir, self.settings["src_dir"]) tmp_package_xml_path = os.path.join(tmp_src_dir, self.settings["src_dir"], "package.xml") if os.path.exists(tmp_package_xml_path): os.remove(tmp_package_xml_path) from distutils import dir_util dir_util.copy_tree(os.path.join(tmp_src_dir, self.settings["src_dir"]), os.path.join(self.sf_basic_config.get_src_root(), self.settings["src_dir"])) else: self.sublconsole.showlog("Sorry , Nothing to do. ")
Example #8
Source File: test_dir_util.py From ironpython3 with Apache License 2.0 | 6 votes |
def test_copy_tree_verbosity(self): mkpath(self.target, verbose=0) copy_tree(self.target, self.target2, verbose=0) self.assertEqual(self._logs, []) remove_tree(self.root_target, verbose=0) mkpath(self.target, verbose=0) a_file = os.path.join(self.target, 'ok.txt') with open(a_file, 'w') as f: f.write('some content') wanted = ['copying %s -> %s' % (a_file, self.target2)] copy_tree(self.target, self.target2, verbose=1) self.assertEqual(self._logs, wanted) remove_tree(self.root_target, verbose=0) remove_tree(self.target2, verbose=0)
Example #9
Source File: cmd.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def copy_tree(self, infile, outfile, preserve_mode=1, preserve_times=1, preserve_symlinks=0, level=1): """Copy an entire directory tree respecting verbose, dry-run, and force flags. """ return dir_util.copy_tree( infile, outfile, preserve_mode,preserve_times,preserve_symlinks, not self.force, dry_run=self.dry_run)
Example #10
Source File: deploy_stack.py From nova with MIT License | 5 votes |
def __copy_custom_scripts(self, path_dir): if os.path.exists(path_dir): dir_util.copy_tree(path_dir, self._nova_deploy_dir) return [f for f in os.listdir(path_dir) if isfile(join(path_dir, f))] else: return []
Example #11
Source File: installer.py From aioli with MIT License | 5 votes |
def copy_app_dir(self, **kwargs): for abspath in dir_util.copy_tree(f"{self.template.abspath}/app", f"{self.abspath}/{self.name}", **kwargs): relpath = str(Path(abspath).relative_to(self.abspath)) yield relpath
Example #12
Source File: conf.py From qiskit with Apache License 2.0 | 5 votes |
def load_tutorials(app): tutorials_dir = os.path.join(app.srcdir, 'tutorials') try: with tempfile.TemporaryDirectory() as temp_dir: github_source = 'https://github.com/Qiskit/qiskit-tutorials' subprocess.run(['git', 'clone', github_source, temp_dir], capture_output=True) dir_util.copy_tree( os.path.join(temp_dir, 'tutorials'), tutorials_dir) except FileNotFoundError: warnings.warn('Copy from git failed for %s at %s, skipping...' % (package, sha1), RuntimeWarning)
Example #13
Source File: util.py From guildai with Apache License 2.0 | 5 votes |
def copytree(src, dest, preserve_links=True): from distutils import dir_util dir_util.copy_tree(src, dest, preserve_symlinks=preserve_links)
Example #14
Source File: evaluator_utils.py From monopsr with MIT License | 5 votes |
def copy_kitti_native_code(checkpoint_name): """Copies and compiles kitti native code. It also creates necessary directories for storing the results of the kitti native evaluation code. """ raise RuntimeError('Should not be used') monopsr_root_dir = monopsr.root_dir() kitti_native_code_copy = monopsr_root_dir + '/data/outputs/' + \ checkpoint_name + '/predictions/kitti_native_eval/' # Only copy if the code has not been already copied over if not os.path.exists(kitti_native_code_copy): os.makedirs(kitti_native_code_copy) original_kitti_native_code = monopsr.top_dir() + \ '/scripts/offline_eval/kitti_native_eval/' predictions_dir = monopsr_root_dir + '/data/outputs/' + \ checkpoint_name + '/predictions/' # create dir for it first dir_util.copy_tree(original_kitti_native_code, kitti_native_code_copy) # run the script to compile the c++ code script_folder = predictions_dir + \ '/kitti_native_eval/' make_script = script_folder + 'run_make.sh' subprocess.call([make_script, script_folder]) # Set up the results folders if they don't exist results_dir = monopsr.top_dir() + '/scripts/offline_eval/results' results_low_iou_dir = monopsr.top_dir() + '/scripts/offline_eval/results_low_iou' if not os.path.exists(results_dir): os.makedirs(results_dir) if not os.path.exists(results_low_iou_dir): os.makedirs(results_low_iou_dir)
Example #15
Source File: local_file_proxy.py From flytekit with Apache License 2.0 | 5 votes |
def download_directory(self, from_path, to_path): """ :param Text from_path: :param Text to_path: """ if from_path != to_path: _dir_util.copy_tree(from_path, to_path)
Example #16
Source File: conf.py From qiskit with Apache License 2.0 | 5 votes |
def _git_copy(package, sha1, api_docs_dir): try: with tempfile.TemporaryDirectory() as temp_dir: github_source = 'https://github.com/Qiskit/%s' % package subprocess.run(['git', 'clone', github_source, temp_dir], capture_output=True) subprocess.run(['git', 'checkout', sha1], cwd=temp_dir, capture_output=True) dir_util.copy_tree( os.path.join(temp_dir, 'docs', 'apidocs'), api_docs_dir) except FileNotFoundError: warnings.warn('Copy from git failed for %s at %s, skipping...' % (package, sha1), RuntimeWarning)
Example #17
Source File: ontology_code_generator.py From forte with Apache License 2.0 | 5 votes |
def cleanup_generated_ontology(self, path, is_forced=False) -> ( Tuple[bool, Optional[str]]): """ Deletes the generated files and directories. Generated files are identified by the header `***automatically_generated***`. Generated directories are identified by `.generated` empty marker files. Moves the files to a timestamped folder inside `.deleted` folder located in the parent directory path by default. Args: path: Path of the directory to be searched for generated files. is_forced: Deletes the generated files and directories without moving them to `.deleted` directory. `False` by default. Returns: Whether `path` is empty after the cleanup operation is completed The timestamped `.deleted` directory path """ path = os.path.abspath(path) rel_paths = dir_util.copy_tree(path, '', dry_run=1) rel_paths = [os.path.dirname(file) for file in rel_paths if os.path.basename(file).startswith(AUTO_GEN_FILENAME)] del_dir = None if not is_forced: curr_time_str = datetime.utcnow().strftime('%Y-%m-%d-%H-%M-%S-%f') del_dir = os.path.join(os.path.dirname(path), AUTO_DEL_FILENAME, curr_time_str) for rel_path in rel_paths: joined_path = os.path.join(del_dir, rel_path) Path(joined_path).mkdir(parents=True, exist_ok=True) rel_paths += [''] return (self._cleanup_generated_ontology(path, '', del_dir, rel_paths), del_dir)
Example #18
Source File: cmd.py From PokemonGo-DesktopMap with MIT License | 5 votes |
def copy_tree(self, infile, outfile, preserve_mode=1, preserve_times=1, preserve_symlinks=0, level=1): """Copy an entire directory tree respecting verbose, dry-run, and force flags. """ return dir_util.copy_tree( infile, outfile, preserve_mode,preserve_times,preserve_symlinks, not self.force, dry_run=self.dry_run)
Example #19
Source File: template_updater.py From stdm with GNU General Public License v2.0 | 5 votes |
def move_back_templates(self): """ Moves back the template files from the old_template folder. This is needed for manual update. """ old_path = '{}/old_templates'.format( self.template_path ) error_title = QApplication.translate( 'TemplateContentReader', 'Old Template Restore Error' ) error_access = QApplication.translate( 'TemplateContentReader', 'Failed to restore the old template for re-updating. \n' 'The system cannot access the file because \n' 'it is being used by another process' ) if os.path.exists(old_path): try: dir_util.copy_tree(old_path, self.template_path) except DistutilsFileError as ex: QMessageBox.critical( iface.mainWindow(), error_title, error_access ) self.updater.append_log(str(ex)) except Exception as ex: self.updater.append_log(str(ex))
Example #20
Source File: test_dir_util.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_copy_tree_skips_nfs_temp_files(self): mkpath(self.target, verbose=0) a_file = os.path.join(self.target, 'ok.txt') nfs_file = os.path.join(self.target, '.nfs123abc') for f in a_file, nfs_file: with open(f, 'w') as fh: fh.write('some content') copy_tree(self.target, self.target2) self.assertEqual(os.listdir(self.target2), ['ok.txt']) remove_tree(self.root_target, verbose=0) remove_tree(self.target2, verbose=0)
Example #21
Source File: cmd.py From Splunking-Crime with GNU Affero General Public License v3.0 | 5 votes |
def copy_tree(self, infile, outfile, preserve_mode=1, preserve_times=1, preserve_symlinks=0, level=1): """Copy an entire directory tree respecting verbose, dry-run, and force flags. """ return dir_util.copy_tree( infile, outfile, preserve_mode,preserve_times,preserve_symlinks, not self.force, dry_run=self.dry_run)
Example #22
Source File: test_dir_util.py From setuptools with MIT License | 5 votes |
def test_copy_tree_exception_in_listdir(self): """ An exception in listdir should raise a DistutilsFileError """ with patch("os.listdir", side_effect=OSError()), \ self.assertRaises(errors.DistutilsFileError): src = self.tempdirs[-1] dir_util.copy_tree(src, None)
Example #23
Source File: test_dir_util.py From setuptools with MIT License | 5 votes |
def test_copy_tree_skips_nfs_temp_files(self): mkpath(self.target, verbose=0) a_file = os.path.join(self.target, 'ok.txt') nfs_file = os.path.join(self.target, '.nfs123abc') for f in a_file, nfs_file: with open(f, 'w') as fh: fh.write('some content') copy_tree(self.target, self.target2) self.assertEqual(os.listdir(self.target2), ['ok.txt']) remove_tree(self.root_target, verbose=0) remove_tree(self.target2, verbose=0)
Example #24
Source File: cmd.py From setuptools with MIT License | 5 votes |
def copy_tree(self, infile, outfile, preserve_mode=1, preserve_times=1, preserve_symlinks=0, level=1): """Copy an entire directory tree respecting verbose, dry-run, and force flags. """ return dir_util.copy_tree(infile, outfile, preserve_mode, preserve_times, preserve_symlinks, not self.force, dry_run=self.dry_run)
Example #25
Source File: cmd.py From datafari with Apache License 2.0 | 5 votes |
def copy_tree(self, infile, outfile, preserve_mode=1, preserve_times=1, preserve_symlinks=0, level=1): """Copy an entire directory tree respecting verbose, dry-run, and force flags. """ return dir_util.copy_tree( infile, outfile, preserve_mode,preserve_times,preserve_symlinks, not self.force, dry_run=self.dry_run)
Example #26
Source File: __main__.py From lore with MIT License | 5 votes |
def init(parsed, unknown): root = os.path.normpath(os.path.realpath(parsed.name)) name = os.path.basename(root) if os.path.exists(root): print(ansi.info() + ' converting existing directory to a Lore App') else: print(ansi.info() + ' creating new Lore App!') os.makedirs(root) if not parsed.bare: template = os.path.join(os.path.dirname(__file__), 'template', 'init') if os.listdir(root): sys.exit( ansi.error() + ' "' + parsed.name + '" already exists, and is not empty! Add --bare to avoid clobbering existing files.') dir_util.copy_tree(template, root) shutil.move(os.path.join(root, 'app'), os.path.join(root, name)) os.chdir(root) with open('requirements.txt', 'a+') as file: file.seek(0) lines = file.readlines() if next((line for line in lines if re.match(r'^lore[!<>=]', line)), None) is None: file.write('lore' + os.linesep) python_version = parsed.python_version or lore.env.read_version('runtime.txt') or '3.6.6' open('runtime.txt', 'w').write('python-' + python_version + '\n') module = os.path.join(root, name, '__init__.py') if not os.path.exists(os.path.dirname(module)): os.makedirs(os.path.dirname(module)) with open(module, 'a+') as file: file.seek(0) lines = file.readlines() if next((line for line in lines if re.match(r'\bimport lore\b', line)), None) is None: file.write('import lore' + os.linesep) lore.env.reload(lore.env) install(parsed, unknown)
Example #27
Source File: utils.py From scar with Apache License 2.0 | 5 votes |
def copy_dir(source: str, dest: str) -> None: """Copy directory to specified destination.""" dir_util.copy_tree(source, dest)
Example #28
Source File: results.py From disentanglement_lib with Apache License 2.0 | 5 votes |
def _copy_recursively(path_to_old_dir, path_to_new_dir): return dir_util.copy_tree(path_to_old_dir, path_to_new_dir)
Example #29
Source File: warhorn.py From warriorframework with Apache License 2.0 | 5 votes |
def replace_tools_from_product_repo(node_list, **kwargs): """ This will clone the tools from product repo and then replaces tools directory in warrior main with this tools repo. """ logfile = kwargs.get("logfile") config_file_name = kwargs.get("config_file_name") console_log_name = kwargs.get("console_log_name") print_log_name = kwargs.get("print_log_name") if "tools" in node_list: tools_node = get_node(config_file_name, "tools") tools_url = get_attribute_value(tools_node, "url") tools_root = get_repository_name(tools_url) tools_clone = get_attribute_value(tools_node, "clone") tools_base_path = "" warrior_node = get_node(config_file_name, "warriorframework") warrior_base_path = get_attribute_value(warrior_node, "destination") if tools_url and tools_clone == "yes": tools_base_path = validate_base_path( tools_base_path, logfile=logfile, config_file_name=config_file_name, console_log_name=console_log_name, print_log_name=print_log_name) warrior_base_path = validate_base_path( warrior_base_path, logfile=logfile, config_file_name=config_file_name, console_log_name=console_log_name, print_log_name=print_log_name) warrior_tools_path = os.path.join(warrior_base_path, "warrior", "Tools") product_tools_path = os.path.join(tools_base_path, tools_root, "Tools") dir_util.copy_tree(product_tools_path, warrior_tools_path, update=1) delete_directory(os.path.join(tools_base_path, tools_root), logfile, print_log_name)
Example #30
Source File: cache.py From catalyst with Apache License 2.0 | 5 votes |
def _commit(self): """Sync the temporary directory to the final path. """ dir_util.copy_tree(self.path, self._final_path)