Python shutil.copytree() Examples

The following are 30 code examples of shutil.copytree(). 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 shutil , or try the search function .
Example #1
Source File: make_package.py    From gltf-blender-importer with MIT License 8 votes vote down vote up
def make_package(suffix=None):
    this_dir = os.path.dirname(os.path.abspath(__file__))
    dist_dir = os.path.join(this_dir, 'dist')

    if not os.path.exists(dist_dir):
        os.makedirs(dist_dir)

    with tempfile.TemporaryDirectory() as tmpdir:
        shutil.copytree(
            os.path.join(this_dir, 'addons', 'io_scene_gltf_ksons'),
            os.path.join(tmpdir, 'io_scene_gltf_ksons'),
            ignore=shutil.ignore_patterns('__pycache__'))

        zip_name = 'io_scene_gltf_ksons'
        if suffix:
            zip_name += '-' + suffix

        shutil.make_archive(
            os.path.join('dist', zip_name),
            'zip',
            tmpdir) 
Example #2
Source File: train.py    From PoseWarper with Apache License 2.0 6 votes vote down vote up
def copy_prev_models(prev_models_dir, model_dir):
    import shutil

    vc_folder = '/hdfs/' \
        + '/' + os.environ['PHILLY_VC']
    source = prev_models_dir
    # If path is set as "sys/jobs/application_1533861538020_2366/models" prefix with the location of vc folder
    source = vc_folder + '/' + source if not source.startswith(vc_folder) \
        else source
    destination = model_dir

    if os.path.exists(source) and os.path.exists(destination):
        for file in os.listdir(source):
            source_file = os.path.join(source, file)
            destination_file = os.path.join(destination, file)
            if not os.path.exists(destination_file):
                print("=> copying {0} to {1}".format(
                    source_file, destination_file))
            shutil.copytree(source_file, destination_file)
    else:
        print('=> {} or {} does not exist'.format(source, destination)) 
Example #3
Source File: encoder_unittest.py    From compare-codecs with Apache License 2.0 6 votes vote down vote up
def testReadResultFromAlternateDir(self):
    context = StorageOnlyContext()
    otherdir_path = os.path.join(encoder_configuration.conf.sysdir(),
                                 'otherdir')
    os.mkdir(otherdir_path)
    cache = encoder.EncodingDiskCache(context)
    other_cache = encoder.EncodingDiskCache(context, scoredir='otherdir')
    my_encoder = encoder.Encoder(
        context,
        encoder.OptionValueSet(encoder.OptionSet(), '--parameters'))
    cache.StoreEncoder(my_encoder)
    videofile = encoder.Videofile('x/foo_640_480_20.yuv')
    my_encoding = encoder.Encoding(my_encoder, 123, videofile)

    testresult = {'foo': 'bar'}
    my_encoding.result = testresult
    cache.StoreEncoding(my_encoding)
    my_encoding.result = None
    result = other_cache.ReadEncodingResult(my_encoding)
    self.assertIsNone(result)
    shutil.rmtree(otherdir_path)
    shutil.copytree(encoder_configuration.conf.workdir(), otherdir_path)
    result = other_cache.ReadEncodingResult(my_encoding)
    self.assertEquals(result, testresult) 
Example #4
Source File: file_system.py    From glazier with Apache License 2.0 6 votes vote down vote up
def Run(self):
    remove_existing = False
    try:
      src = self._args[0]
      dst = self._args[1]
      if len(self._args) > 2:
        remove_existing = self._args[2]
    except IndexError:
      raise ActionError('Unable to determine source and destination from %s.' %
                        str(self._args))
    try:
      if os.path.exists(dst) and remove_existing:
        logging.info('Deleting existing destination: %s', dst)
        shutil.rmtree(dst)
    except (shutil.Error, OSError) as e:
      raise ActionError('Unable to delete existing destination folder %s: %s' %
                        (dst, str(e)))
    try:
      logging.info('Copying directory: %s to %s', src, dst)
      shutil.copytree(src, dst)
    except (shutil.Error, OSError) as e:
      raise ActionError('Unable to copy %s to %s: %s' % (src, dst, str(e))) 
Example #5
Source File: package.py    From pearl with GNU General Public License v3.0 6 votes vote down vote up
def create_package(pearl_env: PearlEnvironment, args: Namespace):
    """
    Creates package from template.
    """
    static = Path(pkg_resources.resource_filename('pearllib', 'static/'))
    pearl_config_template = static / 'templates/pearl-config.template'
    dest_pearl_config = args.dest_dir / 'pearl-config'
    if dest_pearl_config.exists():
        raise PackageCreateError('The pearl-config directory already exists in {}'.format(args.dest_dir))
    shutil.copytree(str(pearl_config_template), str(dest_pearl_config))

    messenger.info('Updating {} to add package in local repository...'.format(pearl_env.config_filename))
    with pearl_env.config_filename.open('a') as pearl_conf_file:
        pearl_conf_file.write('PEARL_PACKAGES["{}"] = {{"url": "{}"}}\n'.format(args.name, args.dest_dir))

    messenger.info('Run "pearl search local" to see your new local package available') 
Example #6
Source File: toolchain.py    From calmjs with GNU General Public License v2.0 6 votes vote down vote up
def compile_bundle_entry(self, spec, entry):
        """
        Handler for each entry for the bundle method of the compile
        process.  This copies the source file or directory into the
        build directory.
        """

        modname, source, target, modpath = entry
        bundled_modpath = {modname: modpath}
        bundled_target = {modname: target}
        export_module_name = []
        if isfile(source):
            export_module_name.append(modname)
            copy_target = join(spec[BUILD_DIR], target)
            if not exists(dirname(copy_target)):
                makedirs(dirname(copy_target))
            shutil.copy(source, copy_target)
        elif isdir(source):
            copy_target = join(spec[BUILD_DIR], modname)
            shutil.copytree(source, copy_target)

        return bundled_modpath, bundled_target, export_module_name 
Example #7
Source File: cloud_mlengine.py    From fine-lm with MIT License 6 votes vote down vote up
def tar_and_copy_usr_dir(usr_dir, train_dir):
  """Package, tar, and copy usr_dir to GCS train_dir."""
  tf.logging.info("Tarring and pushing t2t_usr_dir.")
  usr_dir = os.path.abspath(os.path.expanduser(usr_dir))
  # Copy usr dir to a temp location
  top_dir = os.path.join(tempfile.gettempdir(), "t2t_usr_container")
  tmp_usr_dir = os.path.join(top_dir, usr_dir_lib.INTERNAL_USR_DIR_PACKAGE)
  shutil.rmtree(top_dir, ignore_errors=True)
  shutil.copytree(usr_dir, tmp_usr_dir)
  # Insert setup.py if one does not exist
  top_setup_fname = os.path.join(top_dir, "setup.py")
  setup_file_str = get_setup_file(
      name="DummyUsrDirPackage",
      packages=get_requirements(usr_dir)
  )
  with tf.gfile.Open(top_setup_fname, "w") as f:
    f.write(setup_file_str)
  usr_tar = _tar_and_copy(top_dir, train_dir)
  return usr_tar 
Example #8
Source File: mainHelp.py    From pytorch_NER_BiLSTM_CNN_CRF with Apache License 2.0 6 votes vote down vote up
def save_dictionary(config):
    """
    :param config: config
    :return:
    """
    if config.save_dict is True:
        if os.path.exists(config.dict_directory):
            shutil.rmtree(config.dict_directory)
        if not os.path.isdir(config.dict_directory):
            os.makedirs(config.dict_directory)

        config.word_dict_path = "/".join([config.dict_directory, config.word_dict])
        config.label_dict_path = "/".join([config.dict_directory, config.label_dict])
        print("word_dict_path : {}".format(config.word_dict_path))
        print("label_dict_path : {}".format(config.label_dict_path))
        save_dict2file(config.create_alphabet.word_alphabet.words2id, config.word_dict_path)
        save_dict2file(config.create_alphabet.label_alphabet.words2id, config.label_dict_path)
        # copy to mulu
        print("copy dictionary to {}".format(config.save_dir))
        shutil.copytree(config.dict_directory, "/".join([config.save_dir, config.dict_directory]))


# load data / create alphabet / create iterator 
Example #9
Source File: cats_and_dogs.py    From vergeml with MIT License 6 votes vote down vote up
def __call__(self, args, env):
        samples_dir = env.get('samples-dir')
        for label in ("cat", "dog"):
            dest = os.path.join(samples_dir, label)
            if os.path.exists(dest):
                raise VergeMLError("Directory {} already exists in samples dir: {}".format(label, dest))
        print("Downloading cats and dogs to {}.".format(samples_dir))
        src_dir = self.download_files([(_URL, "catsdogs.zip")], env)
        path = os.path.join(src_dir, "catsdogs.zip")

        print("Extracting data.")
        zipf = zipfile.ZipFile(path, 'r')
        zipf.extractall(src_dir)
        zipf.close()

        for file, dest in (("PetImages/Dog", "dog"), ("PetImages/Cat", "cat")):
            shutil.copytree(os.path.join(src_dir, file), os.path.join(samples_dir, dest))

        shutil.rmtree(src_dir)

        # WTF?
        os.unlink(os.path.join(samples_dir, "cat", "666.jpg"))
        os.unlink(os.path.join(samples_dir, "dog", "11702.jpg"))

        print("Finished downloading cats and dogs.") 
Example #10
Source File: dcc.py    From dcc with Apache License 2.0 6 votes vote down vote up
def copy_compiled_libs(project_dir, decompiled_dir):
    compiled_libs_dir = os.path.join(project_dir, "libs")
    decompiled_libs_dir = os.path.join(decompiled_dir, "lib")
    if not os.path.exists(compiled_libs_dir):
        return
    if not os.path.exists(decompiled_libs_dir):
        shutil.copytree(compiled_libs_dir, decompiled_libs_dir)
        return

    for abi in os.listdir(decompiled_libs_dir):
        dst = os.path.join(decompiled_libs_dir, abi)
        src = os.path.join(compiled_libs_dir, abi)
        if not os.path.exists(src) and abi == 'armeabi':
            src = os.path.join(compiled_libs_dir, 'armeabi-v7a')
            logger.warning('Use armeabi-v7a for armeabi')

        if not os.path.exists(src):
            raise Exception("ABI %s is not supported!" % abi)

        libnc = os.path.join(src, LIBNATIVECODE)
        shutil.copy(libnc, dst) 
Example #11
Source File: merge_helpers.py    From pyGSTi with Apache License 2.0 6 votes vote down vote up
def rsync_offline_dir(outputDir):
    """
    Copy the pyGSTi 'offline' directory into `outputDir` by creating or updating
    any outdated files as needed.
    """
    destDir = _os.path.join(str(outputDir), "offline")
    offlineDir = _os.path.join(_os.path.dirname(_os.path.abspath(__file__)),
                               "templates", "offline")  # TODO package resources?
    if not _os.path.exists(destDir):
        _shutil.copytree(offlineDir, destDir)

    else:
        for dirpath, _, filenames in _os.walk(str(offlineDir)):
            for nm in filenames:
                srcnm = _os.path.join(dirpath, nm)
                relnm = _os.path.relpath(srcnm, offlineDir)
                destnm = _os.path.join(destDir, relnm)

                if not _os.path.isfile(destnm) or \
                        (_os.path.getmtime(destnm) < _os.path.getmtime(srcnm)):
                    _shutil.copyfile(srcnm, destnm)
                    #print("COPYING to %s" % destnm) 
Example #12
Source File: testTutorials.py    From pyGSTi with Apache License 2.0 6 votes vote down vote up
def test_tutorials():
    with TemporaryDirectory() as tmp:
        tmp_path = Path(tmp)

        # Copy tutorial file resources
        for f_path in _TUTORIAL_FILES:
            src = _TUTORIALS_ROOT / f_path
            dest = tmp_path / f_path
            dest.parent.mkdir(parents=True, exist_ok=True)
            if src.is_dir():
                shutil.copytree(src, dest)
            else:
                shutil.copy(src, dest)

        # Emit a test for each notebook
        for nb_path in notebooks_in_path(_TUTORIALS_ROOT):
            rel_path = nb_path.relative_to(_TUTORIALS_ROOT)
            workdir = tmp_path / rel_path.parent
            workdir.mkdir(parents=True, exist_ok=True)
            description = "Running notebook {}".format(rel_path)
            yield attr(description=description)(run_notebook), nb_path, workdir 
Example #13
Source File: trust_store_repository.py    From sslyze with GNU Affero General Public License v3.0 6 votes vote down vote up
def update_default(cls) -> "TrustStoresRepository":
        """Update the default trust stores used by SSLyze.

        The latest stores will be downloaded from https://github.com/nabla-c0d3/trust_stores_observatory.
        """
        temp_path = Path(mkdtemp())
        try:
            # Download the latest trust stores
            archive_path = temp_path / "trust_stores_as_pem.tar.gz"
            urlretrieve(cls._UPDATE_URL, archive_path)

            # Extract the archive
            extract_path = temp_path / "extracted"
            tarfile.open(archive_path).extractall(extract_path)

            # Copy the files to SSLyze and overwrite the existing stores
            shutil.rmtree(cls._DEFAULT_TRUST_STORES_PATH)
            shutil.copytree(extract_path, cls._DEFAULT_TRUST_STORES_PATH)
        finally:
            shutil.rmtree(temp_path)

        # Re-generate the default repo - not thread-safe
        cls._DEFAULT_REPOSITORY = cls(cls._DEFAULT_TRUST_STORES_PATH)
        return cls._DEFAULT_REPOSITORY 
Example #14
Source File: files.py    From pysploit-framework with GNU General Public License v2.0 6 votes vote down vote up
def move(src,dst):
    if type(src) == list:
        if type(dst) == list:
            try:
                for i in range(0,10000000):
                    if os.path.isfile(src[i]):
                        shutil.move(src[i], dst[i])
                    else:
                        shutil.copytree(src[i], dst[i]+'/'+src[i])
                        shutil.rmtree(src[i])
            except IndexError:
                pass
        else:
            for src_el in src:
                if os.path.isfile(src_el):
                    shutil.move(src_el,dst)
                else:
                    shutil.copytree(src_el,dst+'/'+src_el)
                    shutil.rmtree(src_el)
    else:
        if os.path.isfile(src):
            shutil.move(src,dst)
        else:
            shutil.copytree(src,dst+'/'+src)
            shutil.rmtree(src) 
Example #15
Source File: cmd.py    From recipes-py with Apache License 2.0 6 votes vote down vote up
def export_protos(destination):
  """Exports the compiled protos for the bundle.

  The engine initialization process has already built all protos and made them
  importable as `PB`. We rely on `PB.__path__` because this allows the
  `--proto-override` flag to work.

  Args:
    * repo (RecipeRepo) - The repo to export.
    * destination (str) - The absolute path we're exporting to (we'll export to
      a subfolder `_pb/PB`).
  """
  shutil.copytree(
      PB_PATH[0], # root of generated PB folder.
      os.path.join(destination, '_pb', 'PB'),
      ignore=lambda _base, names: [n for n in names if n.endswith('.pyc')],
  ) 
Example #16
Source File: test.py    From PoseWarper with Apache License 2.0 6 votes vote down vote up
def copy_prev_models(prev_models_dir, model_dir):
    import shutil

    vc_folder = '/hdfs/' \
        + '/' + os.environ['PHILLY_VC']
    source = prev_models_dir
    # If path is set as "sys/jobs/application_1533861538020_2366/models" prefix with the location of vc folder
    source = vc_folder + '/' + source if not source.startswith(vc_folder) \
        else source
    destination = model_dir

    if os.path.exists(source) and os.path.exists(destination):
        for file in os.listdir(source):
            source_file = os.path.join(source, file)
            destination_file = os.path.join(destination, file)
            if not os.path.exists(destination_file):
                print("=> copying {0} to {1}".format(
                    source_file, destination_file))
                shutil.copytree(source_file, destination_file)
    else:
        print('=> {} or {} does not exist'.format(source, destination)) 
Example #17
Source File: import_videos_csv_project_ini.py    From simba with GNU Lesser General Public License v3.0 6 votes vote down vote up
def copy_frame_folders(source,inifile):
    source = str(source) + '\\'
    dest = str(os.path.dirname(inifile))
    dest1 = str((dest) + '\\frames\\input')
    files = []

    ########### FIND FILES ###########
    for i in os.listdir(source):
        files.append(i)

    for f in files:
        filetocopy = source + f
        if os.path.exists(dest1 + '\\' + f):
            print(f, 'already exist in', dest1)

        elif not os.path.exists(dest1 + '\\' + f):
            print('Copying frames of',f)
            shutil.copytree(filetocopy, dest1+'\\'+f)
            nametoprint = os.path.join('',*(splitall(dest1)[-4:]))
            print(f, 'copied to', nametoprint)

    print('Finished copying frames.') 
Example #18
Source File: local_mode.py    From sagemaker-xgboost-container with Apache License 2.0 6 votes vote down vote up
def create_hosting_dir(model_dir, customer_script, optml, image, additional_volumes,
                       additional_env_vars,
                       cluster_size=1, source_dir=None, entrypoint=None, use_gpu=False):
    tmpdir = os.path.abspath(optml)
    print('creating hosting dir in {}'.format(tmpdir))

    hosts = create_host_names(cluster_size)
    print('creating hosts: {}'.format(hosts))

    if model_dir:
        for h in hosts:
            host_dir = os.path.join(tmpdir, h)
            os.makedirs(host_dir)
            shutil.copytree(model_dir, os.path.join(tmpdir, h, 'model'))

    write_docker_file('serve', tmpdir, hosts, image, additional_volumes, additional_env_vars,
                      customer_script,
                      source_dir, entrypoint, use_gpu)

    print("hosting dir: \n{}".format(
        str(subprocess.check_output(['ls', '-lR', tmpdir]).decode('utf-8'))))

    return tmpdir 
Example #19
Source File: conftest.py    From yatsm with MIT License 6 votes vote down vote up
def example_results(request, tmpdir):
    dst = os.path.join(tmpdir.mkdir('data').strpath, 'results')
    shutil.copytree(os.path.join(here, 'data', 'results'), dst)

    results = {
        'root': dst,
        'results_dir': os.path.join(dst, 'YATSM'),
        'results_dir_classified': os.path.join(dst, 'YATSM_classified'),
        'example_img': os.path.join(dst, 'example_image.gtif'),
        'classify_config': os.path.join(dst, example_classify_config),
        'example_classify_pickle': os.path.join(dst, example_classify_pickle)
    }

    make_example_classifier(results['example_classify_pickle'])

    return results 
Example #20
Source File: conanfile.py    From conan-center-index with MIT License 6 votes vote down vote up
def package(self):
        self.copy(pattern="COPYING", src=self._source_subfolder, dst="licenses")
        if self.settings.compiler == "Visual Studio":
            arch_subdir = {
                "x86_64": "x64",
                "x86": "x86",
            }[str(self.settings.arch)]
            self.copy("*.lib", src=os.path.join(self._source_subfolder, "msvc", arch_subdir, self._msvc_build_type), dst=os.path.join(self.package_folder, "lib"))
            self.copy("*.dll", src=os.path.join(self._source_subfolder, "msvc", arch_subdir, self._msvc_build_type), dst=os.path.join(self.package_folder, "bin"))
            self.copy("jemalloc.h", src=os.path.join(self._source_subfolder, "include", "jemalloc"), dst=os.path.join(self.package_folder, "include", "jemalloc"), keep_path=True)
            shutil.copytree(os.path.join(self._source_subfolder, "include", "msvc_compat"),
                            os.path.join(self.package_folder, "include", "msvc_compat"))
        else:
            autotools = self._configure_autotools()
            # Use install_lib_XXX and install_include to avoid mixing binaries and dll's
            autotools.make(target="install_lib_shared" if self.options.shared else "install_lib_static")
            autotools.make(target="install_include")
            if self.settings.os == "Windows" and self.settings.compiler == "gcc":
                os.rename(os.path.join(self.package_folder, "lib", "{}.lib".format(self._library_name)),
                          os.path.join(self.package_folder, "lib", "lib{}.a".format(self._library_name)))
                if not self.options.shared:
                    os.unlink(os.path.join(self.package_folder, "lib", "jemalloc.lib")) 
Example #21
Source File: conanfile.py    From conan-center-index with MIT License 6 votes vote down vote up
def _copy_sources(self):
        # Copy CMakeLists wrapper
        shutil.copy(os.path.join(self.source_folder, "CMakeLists.txt"), "CMakeLists.txt")

        # Copy patches
        if "patches" in self.conan_data:
            if not os.path.exists("patches"):
                os.mkdir("patches")
            for patch in self.conan_data["patches"][self.version]:
                shutil.copy(os.path.join(self.source_folder, patch["patch_file"]),
                            "patches")

        # Copy PhysX source code
        subfolders_to_copy = [
           "pxshared",
           os.path.join("externals", self._get_cmakemodules_subfolder()),
           os.path.join("physx", "compiler"),
           os.path.join("physx", "include"),
           os.path.join("physx", "source")
        ]
        for subfolder in subfolders_to_copy:
            shutil.copytree(os.path.join(self.source_folder, self._source_subfolder, subfolder),
                            os.path.join(self._source_subfolder, subfolder)) 
Example #22
Source File: file_util.py    From OP_Manager with MIT License 6 votes vote down vote up
def copytree(src, dst, symlinks=False, ignore=shutil.ignore_patterns('.*', '_*')):
    """
    Copy Entire Folder
    :param src: source path
    :param dst: destination path
    :param symlinks: optional
    :param ignore: pass shutil.ignore_patterns('.*', '_*')
    :return:
    """
    for item in os.listdir(src):
        s = os.path.join(src, item)
        d = os.path.join(dst, item)
        if os.path.isdir(s):
            shutil.copytree(s, d, symlinks, ignore)
        else:
            shutil.copy2(s, d) 
Example #23
Source File: conanfile.py    From conan-center-index with MIT License 6 votes vote down vote up
def _build_autotools(self):
        """ Test autotools integration """
        # Copy autotools directory to build folder
        shutil.copytree(os.path.join(self.source_folder, "autotools"), os.path.join(self.build_folder, "autotools"))
        with tools.chdir("autotools"):
            self.run("{} --install --verbose -Wall".format(os.environ["AUTORECONF"]), win_bash=tools.os_info.is_windows)

        tools.mkdir(self._package_folder)
        conf_args = [
            "--prefix={}".format(tools.unix_path(self._package_folder)),
            "--enable-shared", "--enable-static",
        ]

        os.mkdir("bin_autotools")
        with tools.chdir("bin_autotools"):
            with self._build_context():
                autotools = AutoToolsBuildEnvironment(self, win_bash=tools.os_info.is_windows)
                autotools.libs = []
                autotools.configure(args=conf_args, configure_dir=os.path.join(self.build_folder, "autotools"))
                autotools.make(args=["V=1", "-j1"])
                autotools.install() 
Example #24
Source File: v3_migration_cli_tests.py    From arches with GNU Affero General Public License v3.0 6 votes vote down vote up
def test_v3migration_002_generate_rm_configs(self):
        """Test the generation of resource model config file."""

        # copy in the resource model files, to mimic a user creating and
        # then exporting them into this package.
        shutil.copytree(os.path.join(self.pkg_fixture, "graphs", "resource_models"), os.path.join(self.pkg, "graphs", "resource_models"))

        # now run the management command
        management.call_command("v3", "generate-rm-configs", target=self.pkg)

        # test that the file has been created, and that it has the correct
        # number of entries to match the number of resource models.
        self.assertTrue(os.path.isfile(os.path.join(self.pkg, "v3data", "rm_configs.json")))
        num_rms = len(glob(os.path.join(self.pkg, "graphs", "resource_models", "*.json")))
        with open(os.path.join(self.pkg, "v3data", "rm_configs.json"), "rb") as conf:
            data = json.loads(conf.read())
            self.assertEqual(num_rms, len(list(data.keys()))) 
Example #25
Source File: v3_migration_cli_tests.py    From arches with GNU Affero General Public License v3.0 6 votes vote down vote up
def test_v3migration_004_convert_v3_skos(self):
        """Test the conversion of v3 skos data."""

        # copy the v3 skos file from the fixture package to the working
        # package. this mimics the user copy and pasting the v3 export skos
        # into their v3data/reference_data directory.
        shutil.rmtree(os.path.join(self.pkg, "v3data", "reference_data"))
        shutil.copytree(os.path.join(self.pkg_fixture, "v3data", "reference_data"), os.path.join(self.pkg, "v3data", "reference_data"))

        # create anticipated directory locations
        os.mkdir(os.path.join(self.pkg, "reference_data", "concepts"))
        os.mkdir(os.path.join(self.pkg, "reference_data", "collections"))

        # run the conversion command.
        management.call_command("v3", "convert-v3-skos", target=self.pkg)

        # now test that the files exist
        self.load_v4_reference_data(dry_run=True) 
Example #26
Source File: files.py    From pysploit-framework with GNU General Public License v2.0 6 votes vote down vote up
def copy(src,dst):
    if type(src) == list:
        if type(dst) == list:
            try:
                for i in range(0,10000000):
                    if os.path.isfile(src[i]):
                        shutil.copy(src[i], dst[i])
                    else:
                        shutil.copytree(src[i], dst[i]+'/'+src[i])
            except IndexError:
                pass
        else:
            for src_el in src:
                if os.path.isfile(src_el):
                    shutil.copy(src_el,dst)
                else:
                    shutil.copytree(src_el,dst+'/'+src_el)
    else:
        if os.path.isfile(src):
            shutil.copy(src,dst)
        else:
            shutil.copytree(src,dst+'/'+src) 
Example #27
Source File: basenji_sadf_multi.py    From basenji with Apache License 2.0 5 votes vote down vote up
def collect_zarr(file_name, out_dir, num_procs):
  final_zarr_file = '%s/%s' % (out_dir, file_name)

  # seed w/ job0
  job_zarr_file = '%s/job0/%s' % (out_dir, file_name)
  shutil.copytree(job_zarr_file, final_zarr_file)

  # open final
  final_zarr_open = zarr.open_group(final_zarr_file)

  for pi in range(1, num_procs):
    # open job
    job_zarr_file = '%s/job%d/%s' % (out_dir, pi, file_name)
    job_zarr_open = zarr.open_group(job_zarr_file, 'r')

    # append to final
    for key in final_zarr_open.keys():
      if key in ['percentiles', 'target_ids', 'target_labels']:
        # once is enough
        pass

      elif key[-4:] == '_pct':
        # average
        u_k1 = np.array(final_zarr_open[key])
        x_k = np.array(job_zarr_open[key])
        final_zarr_open[key] = u_k1 + (x_k - u_k1) / (pi+1)

      else:
        # append
        final_zarr_open[key].append(job_zarr_open[key]) 
Example #28
Source File: dogs.py    From vergeml with MIT License 5 votes vote down vote up
def __call__(self, args, env):
        samples_dir = env.get('samples-dir')

        for label in ['affenpinscher', 'afghan-hound', 'african-hunting-dog', 'airedale', 'american-staffordshire-terrier', 'appenzeller', 'australian-terrier', 'basenji', 'basset', 'beagle', 'bedlington-terrier', 'bernese-mountain-dog', 'black-and-tan-coonhound', 'blenheim-spaniel', 'bloodhound', 'bluetick', 'border-collie', 'border-terrier', 'borzoi', 'boston-bull', 'bouvier-des-flandres', 'boxer', 'brabancon-griffon', 'briard', 'brittany-spaniel', 'bull-mastiff', 'cairn', 'cardigan', 'chesapeake-bay-retriever', 'chihuahua', 'chow', 'clumber', 'cocker-spaniel', 'collie', 'curly-coated-retriever', 'dandie-dinmont', 'dhole', 'dingo', 'doberman', 'english-foxhound', 'english-setter', 'english-springer', 'entlebucher', 'eskimo-dog', 'flat-coated-retriever', 'french-bulldog', 'german-shepherd', 'german-short-haired-pointer', 'giant-schnauzer', 'golden-retriever', 'gordon-setter', 'great-dane', 'great-pyrenees', 'greater-swiss-mountain-dog', 'groenendael', 'ibizan-hound', 'irish-setter', 'irish-terrier', 'irish-water-spaniel', 'irish-wolfhound', 'italian-greyhound', 'japanese-spaniel', 'keeshond', 'kelpie', 'kerry-blue-terrier', 'komondor', 'kuvasz', 'labrador-retriever', 'lakeland-terrier', 'leonberg', 'lhasa', 'malamute', 'malinois', 'maltese-dog', 'mexican-hairless', 'miniature-pinscher', 'miniature-poodle', 'miniature-schnauzer', 'newfoundland', 'norfolk-terrier', 'norwegian-elkhound', 'norwich-terrier', 'old-english-sheepdog', 'otterhound', 'papillon', 'pekinese', 'pembroke', 'pomeranian', 'pug', 'redbone', 'rhodesian-ridgeback', 'rottweiler', 'saint-bernard', 'saluki', 'samoyed', 'schipperke', 'scotch-terrier', 'scottish-deerhound', 'sealyham-terrier', 'shetland-sheepdog', 'shih-tzu', 'siberian-husky', 'silky-terrier', 'soft-coated-wheaten-terrier', 'staffordshire-bullterrier', 'standard-poodle', 'standard-schnauzer', 'sussex-spaniel', 'tibetan-mastiff', 'tibetan-terrier', 'toy-poodle', 'toy-terrier', 'vizsla', 'walker-hound', 'weimaraner', 'welsh-springer-spaniel', 'west-highland-white-terrier', 'whippet', 'wire-haired-fox-terrier', 'yorkshire-terrier']:
            dest = os.path.join(samples_dir, label)
            if os.path.exists(dest):
                raise VergeMLError("Directory {} already exists in samples dir: {}".format(label, dest))

        print("Downloading Stanford dogs to {}.".format(samples_dir))

        src_dir = self.download_files([_URL], env=env, dir=env.get('cache-dir'))
        path = os.path.join(src_dir, "images.tar")

        print("Extracting data...")

        tarf = tarfile.TarFile(path, 'r')
        tarf.extractall(src_dir)
        tarf.close()

        for src_file in os.listdir(os.path.join(src_dir, "Images")):
            if src_file.startswith("."):
                continue

            _, dest_file = src_file.split("-", maxsplit=1)
            dest_file = dest_file.replace("_", "-")
            dest_file = dest_file.lower()
            shutil.copytree(os.path.join(src_dir, "Images", src_file),
                            os.path.join(samples_dir, dest_file))

        shutil.rmtree(src_dir)

        print("Finished downloading Stanford dogs.") 
Example #29
Source File: dispatcher.py    From resolwe with Apache License 2.0 5 votes vote down vote up
def _prepare_executor(self, data, executor):
        """Copy executor sources into the destination directory.

        :param data: The :class:`~resolwe.flow.models.Data` object being
            prepared for.
        :param executor: The fully qualified name of the executor that
            is to be used for this data object.
        :return: Tuple containing the relative fully qualified name of
            the executor class ('relative' to how the executor will be
            run) and the path to the directory where the executor will
            be deployed.
        :rtype: (str, str)
        """
        logger.debug(__("Preparing executor for Data with id {}", data.id))

        # Both of these imports are here only to get the packages' paths.
        import resolwe.flow.executors as executor_package

        exec_dir = os.path.dirname(inspect.getsourcefile(executor_package))
        dest_dir = self._get_per_data_dir(
            "RUNTIME_DIR", data.location.default_storage_location.subpath
        )
        dest_package_dir = os.path.join(dest_dir, "executors")
        shutil.copytree(exec_dir, dest_package_dir)
        dir_mode = self.settings_actual.get("FLOW_EXECUTOR", {}).get(
            "RUNTIME_DIR_MODE", 0o755
        )
        os.chmod(dest_dir, dir_mode)

        class_name = executor.rpartition(".executors.")[-1]
        return ".{}".format(class_name), dest_dir 
Example #30
Source File: test_euler.py    From EulerPy with MIT License 5 votes vote down vote up
def setUp(self):
        # Copy problem and solution files to temporary directory
        self.temp_dir = tempfile.mkdtemp()
        os.chdir(self.temp_dir)
        eulerDir = os.path.dirname(os.path.dirname(__file__))
        dataDir = os.path.join(eulerDir, 'EulerPy', 'data')
        tempData = os.path.join(os.getcwd(), 'EulerPy', 'data')
        shutil.copytree(dataDir, tempData)