Runs through the query, creating a clone directory structure in the new_root. Then applies process
5281
def shadow(self,new_root,visitor) :
        
        for n in self.walk() :
            sn = n.clone(new_root)
            if n.isdir() :
                visitor.process_dir(n,sn)
            else :
                visitor.process_file(n,sn)
390791
def _create(self):
        """"""
        listDirs = []
        parent = self
        while parent:
            if parent.exists():
                break
            listDirs.append(parent)
            p = parent.up()
            if p is None:
                # Don't use while: - else: for this condition because
                # if so, then parent is None and has no .path attribute.
                raise SCons.Errors.StopError(parent._path)
            parent = p
        listDirs.reverse()
        for dirnode in listDirs:
            try:
                # Don't call dirnode.build(), call the base Node method
                # directly because we definitely *must* create this
                # directory.  The dirnode.build() method will suppress
                # the build if it's the default builder.
                SCons.Node.Node.build(dirnode)
                dirnode.get_executor().nullify()
                # The build() action may or may not have actually
                # created the directory, depending on whether the -n
                # option was used or not.  Delete the _exists and
                # _rexists attributes so they can be reevaluated.
                dirnode.clear()
            except OSError:
                pass
377823
def clone_source_dir(source_dir, dest_dir):
    
    if os.path.isdir(dest_dir):
        print('removing', dest_dir)
        shutil.rmtree(dest_dir)
    shutil.copytree(source_dir, dest_dir)
994118
def clone(self, newname, config_path=None, flags=0, bdevtype=None,
              bdevdata=None, newsize=0, hookargs=()):
        

        args = {}
        args['newname'] = newname
        args['flags'] = flags
        args['newsize'] = newsize
        args['hookargs'] = hookargs
        if config_path:
            args['config_path'] = config_path
        if bdevtype:
            args['bdevtype'] = bdevtype
        if bdevdata:
            args['bdevdata'] = bdevdata

        if _lxc.Container.clone(self, **args):
            return Container(newname, config_path=config_path)
        else:
            return False
798411
def clone(self, folder, git_repository):
        
        os.makedirs(folder)
        git.Git().clone(git_repository, folder)
157266
private void createRepositoryDirectoryStructure(File rootDir) {
		this.objs = new File(rootDir, OBJECT_DIR);
		if (!objs.exists()) {
			if (!objs.mkdirs()) {
				throw new RuntimeException("Could not create dir: " + objs.getAbsolutePath());
			}
		}

		this.refs = new File(rootDir, REFERENCE_DIR);
		if (!refs.exists()) {
			if (!refs.mkdirs()) {
				throw new RuntimeException("Could not create dir: " + refs.getAbsolutePath());
			}
		}
	}
563026
def query
      q = @root.clone

      # Navigation paths come first in the query
      q << "/#{@navigation_paths.join("/")}" unless @navigation_paths.empty?

      # Handle links queries, this isn't just a standard query option
      q << "/$links/#{@links_navigation_property}" if @links_navigation_property

      # Handle count queries, this isn't just a standard query option
      q << "/$count" if @count
      query_options = generate_query_options

      q << "?#{query_options.join('&')}" if !query_options.empty?
      q
    end
377472
def create(self, name):
        """"""
        if not os.path.exists(self.directory):
            os.makedirs(self.directory)

        filename = self.get_new_filename(name)
        with open(os.path.join(self.directory, filename), 'w') as fp:
            fp.write("def up(db): pass\n\n\n")
            fp.write("def down(db): pass\n")
            logger.info(filename)
1136259
def add_dir_entry(backup_run, dir_entry_path, process_bar, result):
    
    # print(dir_entry_path.pformat())
    # print(dir_entry_path.stat.st_nlink)

    backup_entry = Path2(dir_entry_path.path)
    filesize = dir_entry_path.stat.st_size
    hash_filepath = Path2("%s%s%s" % (backup_entry.path, os.extsep, phlb_config.hash_name))
    if hash_filepath.is_file():
        with hash_filepath.open("r") as hash_file:
            hash_hexdigest = hash_file.read().strip()
        if filesize > 0:
            process_bar.update(filesize)
    else:
        with hash_filepath.open("w") as hash_file:
            callback = HashCallback(process_bar)
            with backup_entry.open("rb") as f:
                hash = calculate_hash(f, callback)

            hash_hexdigest = hash.hexdigest()
            hash_file.write(hash_hexdigest)

    old_backup_entry = deduplicate(backup_entry, hash_hexdigest)
    if old_backup_entry is None:
        result.add_new_file(filesize)
    else:
        result.add_stined_file(filesize)

    BackupEntry.objects.create(
        backup_run, dir_entry_path.path_instance, hash_hexdigest=hash_hexdigest  # Path2() instance
    )
1171389
def _copy_folder_and_get_directory_listings(
            self):
        
        self.log.info(
            'starting the ``_copy_folder_and_get_directory_listings`` method')

        # COPY TEMPLATE STRUCTURE TO /tmp/
        basename = os.path.basename(self.pathToTemplate)
        tmpPath = "/tmp/%(basename)s" % locals()
        try:
            shutil.rmtree(tmpPath)
        except:
            pass
        shutil.copytree(self.pathToTemplate, tmpPath)

        directoryContents = recursive_directory_listing(
            log=self.log,
            baseFolderPath=tmpPath,
            whatToList="all"  # all | files | dirs
        )

        self.directoryContents = directoryContents
        self.tmpPath = tmpPath

        self.log.info(
            'completed the ``_copy_folder_and_get_directory_listings`` method')
        return None
1177285
def clone_psql_db(db_to_clone):
    """"""
    # If db_to_clone is a path, assume it is a SQL dump...
    if os.path.isfile(db_to_clone):
        logger.info("Treating %s as a path to a SQL dump", repr(db_to_clone))
        # ...and use it to populate our database
        populate_db(db_to_clone)
    # Otherwise, assume it is a database name...
    else:
        logger.info("Treating %s as a database name", repr(db_to_clone))
        # ...create a temp file to dump it into...
        with NamedTemporaryFile(prefix="{}.sql.".format(db_to_clone)) as backup_file:
            # ...perform the dump...
            pg_dump(db_to_clone, backup_file.name)
            # ...and load the contents of the dump into our DB
            populate_db(backup_file.name)
589861
def _prepare(self):
        """"""
        names = []

        added_directories = set()

        def add_directory(short_path):
            # Do not continue if this directory has already been added
            if short_path in added_directories:
                return

            # Scan for first super-directory that has already been added
            dir_base  = short_path
            dir_parts = []
            while dir_base:
                dir_base, dir_name = os.path.split(dir_base)
                dir_parts.append(dir_name)
                if dir_base in added_directories:
                    break

            # Add missing intermediate directory nodes in the right order
            while dir_parts:
                dir_base = os.path.join(dir_base, dir_parts.pop())

                # Create an empty, fake file to represent the directory
                mock_file = io.StringIO()
                mock_file.write(u'')
                # Add this directory to those that will be sent
                names.append(('files',
                             (dir_base.replace(os.sep, '/'), mock_file, 'application/x-directory')))
                # Remember that this directory has already been sent
                added_directories.add(dir_base)

        def add_file(short_path, full_path):
            try:
                # Always add files in wildcard directories
                names.append(('files', (short_name.replace(os.sep, '/'),
                                        open(full_path, 'rb'),
                                        'application/octet-stream')))
            except OSError:
                # File might have disappeared between `os.walk()` and `open()`
                pass

        def match_short_path(short_path):
            # Remove initial path component so that all files are based in
            # the target directory itself (not one level above)
            if os.sep in short_path:
                path = short_path.split(os.sep, 1)[1]
            else:
                return False

            # Convert all path seperators to POSIX style
            path = path.replace(os.sep, '/')

            # Do the matching and the simplified path
            for pattern in self.patterns:
                if pattern.match(path):
                    return True
            return False

        # Identify the unecessary portion of the relative path
        truncate = os.path.dirname(self.directory)
        # Traverse the filesystem downward from the target directory's uri
        # Errors: `os.walk()` will simply return an empty generator if the
        #         target directory does not exist.
        wildcard_directories = set()
        for curr_dir, _, files in os.walk(self.directory):
            # find the path relative to the directory being added
            if len(truncate) > 0:
                _, _, short_path = curr_dir.partition(truncate)
            else:
                short_path = curr_dir
            # remove leading / or \ if it is present
            if short_path.startswith(os.sep):
                short_path = short_path[1:]

            wildcard_directory = False
            if os.path.split(short_path)[0] in wildcard_directories:
                # Parent directory has matched a pattern, all sub-nodes should
                # be added too
                wildcard_directories.add(short_path)
                wildcard_directory = True
            else:
                # Check if directory path matches one of the patterns
                if match_short_path(short_path):
                    # Directory matched pattern and it should therefor
                    # be added along with all of its contents
                    wildcard_directories.add(short_path)
                    wildcard_directory = True

            # Always add directories within wildcard directories - even if they
            # are empty
            if wildcard_directory:
                add_directory(short_path)

            # Iterate across the files in the current directory
            for filename in files:
                # Find the filename relative to the directory being added
                short_name = os.path.join(short_path, filename)
                filepath = os.path.join(curr_dir, filename)

                if wildcard_directory:
                    # Always add files in wildcard directories
                    add_file(short_name, filepath)
                else:
                    # Add file (and all missing intermediary directories)
                    # if it matches one of the patterns
                    if match_short_path(short_name):
                        add_directory(short_path)
                        add_file(short_name, filepath)
        # Send the request and present the response body to the user
        req = requests.Request("POST", 'http://localhost', files=names)
        prep = req.prepare()
        return prep
1149920
def clone(cls, repo_url, dest, binary='git'):
    
    cmd = [binary, 'clone', repo_url, dest]
    process, out = cls._invoke(cmd)
    cls._check_result(cmd, process.returncode)
    return cls(binary=binary, worktree=dest)
1312904
public function newDirectory()
    {
        $target_full_path = $this->getTargetFile()->getFilepath(true);
        $this->event(YouweFileManagerEvents::BEFORE_FILE_DIR_CREATED);
        $this->getDriver()->makeDir($target_full_path);
        $this->getCurrentFile()->updateFilepath($target_full_path);
        $this->event(YouweFileManagerEvents::AFTER_FILE_DIR_CREATED);
    }
1140529
def create(cls, path_name=None, name=None, project_id=None,
               log_modified_at=None, crawlable=True):
        """"""
        result = cls(path_name, name, project_id, log_modified_at, crawlable)

        db.session.add(result)
        db.session.commit()

        crawl_result(result, True)

        return result
704678
def clone(self, repo, ref, deps=()):
        """"""

        if os.path.isdir(repo):
            repo = os.path.abspath(repo)

        def clone_strategy(directory):
            env = git.no_git_env()

            def _git_cmd(*args):
                cmd_output('git', *args, cwd=directory, env=env)

            _git_cmd('init', '.')
            _git_cmd('remote', 'add', 'origin', repo)

            try:
                self._shallow_clone(ref, _git_cmd)
            except CalledProcessError:
                self._complete_clone(ref, _git_cmd)

        return self._new_repo(repo, ref, deps, clone_strategy)
930534
def step_a_new_working_directory(context):
    
    command_util.ensure_context_attribute_exists(context, "workdir", None)
    command_util.ensure_workdir_exists(context)
    shutil.rmtree(context.workdir, ignore_errors=True)