Writes the Zip-encoded file to a directory.

        :param target_path: The directory path to add.
        :type target_path: str
        :param zip_path: The file path of the ZIP archive.
        :type zip_path: str
764577
def archive(self, target_path=None, zip_path=None):
        
        if target_path:
            self.target_path = target_path

        if zip_path:
            self.zip_path = zip_path

        if self.has_path is False or os.path.isdir(self.target_path) is False:
            raise RuntimeError("")

        zip = zipfile.ZipFile(
            self.zip_path,
            'w',
            zipfile.ZIP_DEFLATED
        )

        for root, _, files in os.walk(self.target_path):
            for file in files:
                if file in ARCHIVE_IGNORE_FILES:
                    continue

                current_dir = os.path.relpath(root, self.target_path)

                if current_dir == ".":
                    file_path = file
                else:
                    file_path = os.path.join(current_dir, file)

                print("Archive {}".format(file))

                zip.write(
                    os.path.join(root, file),
                    file_path
                )

        zip.close()
401527
def _is_target_a_directory(link, rel_target):
	
	target = os.path.join(os.path.dirname(link), rel_target)
	return os.path.isdir(target)
328541
def mkdir(self, target_folder):
        
        self.printv("Making directory: %s" % target_folder)
        self.k.key = re.sub(r"^/|/$", "", target_folder) + "/"
        self.k.set_contents_from_string('')
        self.k.close()
635796
private function writeStubs(string $target_path, string $source_file): void
    {
        @mkdir(dirname($target_path), 0775, true);
        
        
        $this->updatePlaceholders([
            "/*<FILENAME>*/" => preg_replace("#\.php$#", "", basename($target_path)),
        ]);
        $content = $this->replacePlaceholdersInText(file_get_contents($source_file));
        
        
        //var_dump($content);
        file_put_contents($target_path, $content);
    }
581989
public static void writeTarGz(Path dirPath, OutputStream output)
      throws IOException, InterruptedException {
    GzipCompressorOutputStream zipStream = new GzipCompressorOutputStream(output);
    TarArchiveOutputStream archiveStream = new TarArchiveOutputStream(zipStream);
    for (Path subPath : Files.walk(dirPath).collect(toList())) {
      if (Thread.interrupted()) {
        throw new InterruptedException();
      }
      File file = subPath.toFile();
      TarArchiveEntry entry = new TarArchiveEntry(file, dirPath.relativize(subPath).toString());
      archiveStream.putArchiveEntry(entry);
      if (file.isFile()) {
        try (InputStream fileIn = Files.newInputStream(subPath)) {
          IOUtils.copy(fileIn, archiveStream);
        }
      }
      archiveStream.closeArchiveEntry();
    }
    archiveStream.finish();
    zipStream.finish();
  }
953585
public function zip_plugin_folder($folderpath, $targetzip) {

        if (file_exists($targetzip)) {
            throw new coding_exception('Attempting to create already existing ZIP file', $targetzip);
        }

        if (!is_writable(dirname($targetzip))) {
            throw new coding_exception('Target ZIP location not writable', dirname($targetzip));
        }

        if (!is_dir($folderpath)) {
            throw new coding_exception('Attempting to ZIP non-existing source directory', $folderpath);
        }

        $files = $this->list_plugin_folder_files($folderpath);
        $fp = get_file_packer('application/zip');
        return $fp->archive_to_pathname($files, $targetzip, false);
    }
720876
def zip(self, destination: typing.Union[str, Path] = None, encode: bool = True) -> str:
        
        if encode:
            self._encode()

        if destination is None:
            destination_path = self.miz_path.parent.joinpath(f'{self.miz_path.stem}_EMIZ.miz')
        else:
            destination_path = elib.path.ensure_file(destination, must_exist=False)

        LOGGER.debug('zipping mission to: %s', destination_path)

        destination_path.write_bytes(dummy_miz)

        with ZipFile(str(destination_path), mode='w', compression=8) as zip_file:

            for root, _, items in os.walk(self.temp_dir.absolute()):
                for item in items:
                    item_abs_path = Path(root, item).absolute()
                    item_rel_path = Path(item_abs_path).relative_to(self.temp_dir)
                    zip_file.write(item_abs_path, arcname=item_rel_path)

        return str(destination_path)
529537
def export_data(target_path):
    
    tasks.export_data_dir(target_path)
    tasks.export_database(target_path)
    tasks.export_context(target_path)
    return target_path
1139931
def write_file(file_path, txt, **kws):
    
    if not os.path.exists(file_path):
        upDir = os.path.dirname(file_path)
        if not os.path.isdir(upDir):
            os.makedirs(upDir)

    kw = {"mode":"w", "encoding":"utf-8"}
    if kws:
        for k,v in kws.items():
            kw[k] = v
    with open(file_path, **kw) as afile:
        afile.write(txt)
924181
def import_context(target_zip):
    
    context_path = tasks.get_context_path()
    with zipfile.ZipFile(target_zip) as unzipped_data:
        with open(context_path, 'w') as context:
            context.write(unzipped_data.read('context.json'))
713562
def save(path)
      update
      Zip::OutputStream.open(path) do |out|
        zip.each do |entry|
          next unless entry.file?
          out.put_next_entry(entry.name)

          if @replace[entry.name]
            out.write(@replace[entry.name])
          else
            out.write(zip.read(entry.name))
          end
        end
      end
      zip.close
    end
436736
def add_dir(self, path, compress):
        
        if not os.path.isdir(path):
            raise ValueError('{} is not a directory'.format(path))
        for root, dirs, files in os.walk(path):
            for f in files:
                self.add_file(os.path.join(root, f), compress)
808345
def write_path(self, path_value):
        
        parent_dir = os.path.dirname(self.path)
        try:
            os.makedirs(parent_dir)
        except OSError:
            pass
        with open(self.path, "w") as fph:
            fph.write(path_value.value)
729650
def maybe_copy_file_to_directory(source_filepath, target_directory):
  
  if not tf.gfile.Exists(target_directory):
    tf.logging.info("Creating directory %s" % target_directory)
    os.mkdir(target_directory)
  target_filepath = os.path.join(target_directory,
                                 os.path.basename(source_filepath))
  if not tf.gfile.Exists(target_filepath):
    tf.logging.info("Copying %s to %s" % (source_filepath, target_filepath))
    tf.gfile.Copy(source_filepath, target_filepath)
    statinfo = os.stat(target_filepath)
    tf.logging.info("Successfully copied %s, %s bytes." % (target_filepath,
                                                           statinfo.st_size))
  else:
    tf.logging.info("Not copying, file already found: %s" % target_filepath)
  return target_filepath
538599
def write(self, location, text, encoding):
        
        location = os.path.expanduser(location)

        with gzip.open(location, 'wb') as f:
            f.write(text.encode(encoding))
830243
def zipdir(path, ziph, **kwargs):
    
    str_arcroot = ""
    for k, v in kwargs.items():
        if k == 'arcroot':  str_arcroot = v

    for root, dirs, files in os.walk(path):
        for file in files:
            str_arcfile = os.path.join(root, file)
            if len(str_arcroot):
                str_arcname = str_arcroot.split('/')[-1] + str_arcfile.split(str_arcroot)[1]
            else:
                str_arcname = str_arcfile
            try:
                ziph.write(str_arcfile, arcname = str_arcname)
            except:
                print("Skipping %s" % str_arcfile)
958923
private function deep_copy($source, $target_path)
    {
        // Loop through $source dir.
        $contents = \scandir($source);

        if (empty($contents)) {
            return;
        }

        foreach ($contents as $file) {
            if ('.' === $file || '..' === $file) {
                continue;
            }

            $src_path = \trailingslashit($source) . $file;
            $new_path = \trailingslashit($target_path) . $file;

            if (\is_dir($src_path)) {
                $this->mkdir($new_path);
                $this->deep_copy($src_path, $new_path);
                continue;
            }

            if ($this->file->copy($src_path, $new_path, $this->force)) {
                $this->copied[] = $new_path;
            }
        }
    }