当前位置: 首页>>代码示例>>Python>>正文


Python shutil.make_archive方法代码示例

本文整理汇总了Python中shutil.make_archive方法的典型用法代码示例。如果您正苦于以下问题:Python shutil.make_archive方法的具体用法?Python shutil.make_archive怎么用?Python shutil.make_archive使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在shutil的用法示例。


在下文中一共展示了shutil.make_archive方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: ZipAttachments

# 需要导入模块: import shutil [as 别名]
# 或者: from shutil import make_archive [as 别名]
def ZipAttachments(f_name):
    arch_name = "C:\Users\Public\Intel\Logs\\" + f_name + "Attachments"
    files = os.listdir(dir_zip)

    try:
        shutil.make_archive(arch_name, 'zip', dir_zip)
    except Exception as e:
        pass

    for j in range(len(files)):
        try:
            os.remove(dir_zip + "\\" + files[j])
        except Exception as e:
            print e

#Function to take screenshot 
开发者ID:mehulj94,项目名称:Radium,代码行数:18,代码来源:Radiumkeylogger.py

示例2: post_to_github

# 需要导入模块: import shutil [as 别名]
# 或者: from shutil import make_archive [as 别名]
def post_to_github(self, url):
        """Zip and post the check results as a comment to the github
        issue or pr."""
        report_zip = shutil.make_archive(self.out, "zip", self.out)
        uuid = str(uuid4())
        zip_url = self._post_media_to_gfr([report_zip], uuid)

        url_split = url.split("/")
        repo_slug = "{}/{}".format(url_split[3], url_split[4])
        pull = url_split[-1] if "pull" in url else None

        fontbakery_report = os.path.join(self.out, "Fontbakery", "report.md")
        if os.path.isfile(fontbakery_report):
            with open(fontbakery_report, "r") as fb:
                msg = "{}\n\n## Diff images: [{}]({})".format(
                    fb.read(), os.path.basename(zip_url[0]), zip_url[0]
                )
        else:
            msg = "## Diff images: [{}]({})".format(
                os.path.basename(zip_url[0]), zip_url[0]
            )
        self._post_gh_msg(msg, repo_slug, pull) 
开发者ID:googlefonts,项目名称:gftools,代码行数:24,代码来源:gftools-qa.py

示例3: make_package

# 需要导入模块: import shutil [as 别名]
# 或者: from shutil import make_archive [as 别名]
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) 
开发者ID:ksons,项目名称:gltf-blender-importer,代码行数:23,代码来源:make_package.py

示例4: read_book

# 需要导入模块: import shutil [as 别名]
# 或者: from shutil import make_archive [as 别名]
def read_book(self):
        with HidePrinting():
            KindleUnpack.unpackBook(self.filename, self.extract_path)

        epub_filename = os.path.splitext(
            os.path.basename(self.filename))[0] + '.epub'
        self.epub_filepath = os.path.join(
            self.extract_path, 'mobi8', epub_filename)

        if not os.path.exists(self.epub_filepath):
            zip_dir = os.path.join(self.extract_path, 'mobi7')
            zip_file = os.path.join(
                self.extract_path, epub_filename)
            self.epub_filepath = shutil.make_archive(zip_file, 'zip', zip_dir)

        self.book = EPUB(self.epub_filepath, self.temp_dir) 
开发者ID:BasioMeusPuga,项目名称:Lector,代码行数:18,代码来源:mobi.py

示例5: archive_iou_txt

# 需要导入模块: import shutil [as 别名]
# 或者: from shutil import make_archive [as 别名]
def archive_iou_txt(username, task_id, sub_id,userpath):

    inputdir=os.path.join(userpath,'iouEval_stats')
    
    if not os.path.exists(inputdir):
        print('No txt file is generated for IOU evaluation')
        pass
    
    dest_uploader = 'IOU_stats_archive'
    dest_uploader = os.path.join(userpath, dest_uploader)

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

    zip_file_name = '/' + task_id + '_' + sub_id
    shutil.make_archive(dest_uploader + zip_file_name, 'zip', inputdir)

    # return '/media/' + dest_uploader 
开发者ID:MaliParag,项目名称:ScanSSD,代码行数:20,代码来源:IOUevaluater.py

示例6: zip_file

# 需要导入模块: import shutil [as 别名]
# 或者: from shutil import make_archive [as 别名]
def zip_file(self, app_path, app_name, tmp_path):
        """Zip the App with tcex extension.

        Args:
            app_path (str): The path of the current project.
            app_name (str): The name of the App.
            tmp_path (str): The temp output path for the zip.
        """
        # zip build directory
        zip_file = os.path.join(app_path, self.args.outdir, app_name)
        zip_file_zip = f'{zip_file}.zip'
        zip_file_tcx = f'{zip_file}.tcx'
        shutil.make_archive(zip_file, 'zip', tmp_path, app_name)
        shutil.move(zip_file_zip, zip_file_tcx)
        self._app_packages.append(zip_file_tcx)
        # update package data
        self.package_data['package'].append({'action': 'App Package:', 'output': zip_file_tcx}) 
开发者ID:ThreatConnect-Inc,项目名称:tcex,代码行数:19,代码来源:package.py

示例7: zip_dicom

# 需要导入模块: import shutil [as 别名]
# 或者: from shutil import make_archive [as 别名]
def zip_dicom(directory):
    """
    Function that zip a directory.

    :param directory: path to the directory to zip
     :type directory: str

    :return: archive -> path to the created zip file
     :rtype: str

    """

    archive = directory + '.zip'

    if (os.listdir(directory) == []):
        sys.exit(
            "The directory " + directory + " is empty and will not be zipped.")
    else:
        shutil.make_archive(directory, 'zip', directory)

    if (os.path.exists(archive)):
        shutil.rmtree(directory)
        return archive
    else:
        sys.exit(archive + " could not be created.") 
开发者ID:aces,项目名称:DICAT,代码行数:27,代码来源:dicom_anonymizer_methods.py

示例8: pre_process

# 需要导入模块: import shutil [as 别名]
# 或者: from shutil import make_archive [as 别名]
def pre_process(self):
        save_data = temp_dir()

        train_src, train_tgt = self.train_data
        dev_src, dev_tgt = self.dev_data

        if self.features:
            train_src = list(map(add_features, train_src))
            dev_src = list(map(add_features, dev_src))

        run_param('preprocess.py', {
            "train_src": save_temp(train_src),
            "train_tgt": save_temp(train_tgt),
            "valid_src": save_temp(dev_src),
            "valid_tgt": save_temp(dev_tgt),
            "save_data": save_data + "data",
            "dynamic_dict": None  # This will add a dynamic-dict parameter
        })

        data_zip = shutil.make_archive(base_name=temp_name(), format="gztar", root_dir=save_data)

        f = open(data_zip, "rb")
        bin_data = f.read()
        f.close()
        return bin_data 
开发者ID:AmitMY,项目名称:chimera,代码行数:27,代码来源:open_nmt.py

示例9: fontselector_export_favorites

# 需要导入模块: import shutil [as 别名]
# 或者: from shutil import make_archive [as 别名]
def fontselector_export_favorites(filepath, export_mode, zip, favorites_list, fake_user_list, context) :
    export_path = absolute_path(filepath)
    
    # create folder
    if not os.path.isdir(export_path) :
        os.makedirs(export_path)
    
    # copy fonts
    if export_mode in {"BOTH", "FAVORITES"} :
        for filepath in favorites_list :
            newpath = os.path.join(export_path, os.path.basename(filepath))
            shutil.copy2(filepath, newpath)
            shutil.copystat(filepath, newpath)
    if export_mode in {"BOTH", "FAKE_USER"} :
        for filepath in fake_user_list :
            newpath = os.path.join(export_path, os.path.basename(filepath))
            shutil.copy2(filepath, newpath)
            shutil.copystat(filepath, newpath)

    # create zip archive
    if zip :
        shutil.make_archive(export_path, 'zip', export_path)
        shutil.rmtree(export_path)
 
    return {'FINISHED'} 
开发者ID:samytichadou,项目名称:FontSelector_blender_addon,代码行数:27,代码来源:export_favorites.py

示例10: test_fs_detection_on_container_posix

# 需要导入模块: import shutil [as 别名]
# 或者: from shutil import make_archive [as 别名]
def test_fs_detection_on_container_posix(self):
        # Create a container for testing
        zip_file_name = "test"
        zip_file_path = zip_file_name + ".zip"
        posix_file_path = "file://" + zip_file_path

        # in the zip, the leading slash will be removed
        file_name_zip = self.tmpfile_path.lstrip('/')

        shutil.make_archive(zip_file_name, "zip", base_dir=self.tmpdir.name)

        with pfio.open_as_container(posix_file_path) as container:
            with container.open(file_name_zip, "r") as f:
                self.assertEqual(
                    f.read(), self.test_string_str)

        pfio.remove(zip_file_path) 
开发者ID:pfnet,项目名称:pfio,代码行数:19,代码来源:test_context.py

示例11: make_portable

# 需要导入模块: import shutil [as 别名]
# 或者: from shutil import make_archive [as 别名]
def make_portable(dst_path):
    portpath = os.path.join(dst_path, "superpaper-portable")
    portres = os.path.join(portpath, "superpaper/resources")
    portprof = os.path.join(portpath, "profiles")
    portexec = os.path.join(portpath, "superpaper")
    # copy resources
    copy_tree(os.path.join(SRCPATH, "resources"), portres)
    # copy profiles
    copy_tree(os.path.join(SRCPATH, "profiles-win"), portprof)
    # copy exe-less structure to be used by innosetup
    copy_tree(portpath, INNO_STUB)

    # copy executable
    shutil.copy2("./dist/superpaper.exe", portexec)
    # zip it
    shutil.make_archive(portpath, 'zip', dst_path, "superpaper-portable") 
开发者ID:hhannine,项目名称:superpaper,代码行数:18,代码来源:make-windows-release.py

示例12: _write_dataset

# 需要导入模块: import shutil [as 别名]
# 或者: from shutil import make_archive [as 别名]
def _write_dataset(images, labels, label_to_index, out_dataset_path, limit):
    if limit is not None:
        print('Limiting dataset to {} samples...'.format(limit))
        images = images[:limit]
        labels = labels[:limit]

    with tempfile.TemporaryDirectory() as d:
        # Create images.csv in temp dir for dataset
        # For each (image, label), save image as .png and add row to images.csv
        # Show a progress bar in the meantime
        images_csv_path = os.path.join(d, 'images.csv')
        n = len(images)
        with open(images_csv_path, mode='w') as f:
            writer = csv.DictWriter(f, fieldnames=['path', 'class'])
            writer.writeheader()
            for (i, image, label) in tqdm(zip(range(n), images, labels), total=n, unit='images'):
                image_name = '{}-{}.png'.format(label, i)
                image_path = os.path.join(d, image_name)
                pil_image = Image.fromarray(image, mode='RGB')
                pil_image.save(image_path)
                writer.writerow({ 'path': image_name, 'class': label_to_index[label] })

        # Zip and export folder as dataset
        out_path = shutil.make_archive(out_dataset_path, 'zip', d)
        os.rename(out_path, out_dataset_path) # Remove additional trailing `.zip` 
开发者ID:nginyc,项目名称:rafiki,代码行数:27,代码来源:cifar.py

示例13: _write_dataset

# 需要导入模块: import shutil [as 别名]
# 或者: from shutil import make_archive [as 别名]
def _write_dataset(pil_images, labels, out_dataset_path):
    with tempfile.TemporaryDirectory() as d:
        # Create images.csv in temp dir for dataset
        # For each (image, label), save image as .png and add row to images.csv
        # Show a progress bar in the meantime
        images_csv_path = os.path.join(d, 'images.csv')
        n = len(pil_images)
        with open(images_csv_path, mode='w') as f:
            writer = csv.DictWriter(f, fieldnames=['path', 'class'])
            writer.writeheader()
            for (i, pil_image, label) in tqdm(zip(range(n), pil_images, labels), total=n, unit='images'):
                image_name = '{}-{}.png'.format(label, i)
                image_path = os.path.join(d, image_name)
                pil_image.save(image_path)
                writer.writerow({ 'path': image_name, 'class': label })

        # Zip and export folder as dataset
        out_path = shutil.make_archive(out_dataset_path, 'zip', d)
        os.rename(out_path, out_dataset_path) # Remove additional trailing `.zip` 
开发者ID:nginyc,项目名称:rafiki,代码行数:21,代码来源:load_folder_format.py

示例14: create_stash_zipfile

# 需要导入模块: import shutil [as 别名]
# 或者: from shutil import make_archive [as 别名]
def create_stash_zipfile(self):
        """
        Create a github-like zipfile from this source and return the path.
        :return: path to zipfile
        :rtype: str
        """
        tp = self.get_new_tempdir(create=True)
        toplevel_name = "stash-testing"
        toplevel = os.path.join(tp, toplevel_name)
        zipname = "{}.zip".format(toplevel)
        zippath = os.path.join(tp, zipname)
        zippath_wo_ext = os.path.splitext(zippath)[0]
        sourcepath = self.get_source_path()
        shutil.copytree(sourcepath, toplevel)
        shutil.make_archive(zippath_wo_ext, "zip", tp, toplevel_name)
        return zippath 
开发者ID:ywangd,项目名称:stash,代码行数:18,代码来源:test_getstash.py

示例15: to_byte_array

# 需要导入模块: import shutil [as 别名]
# 或者: from shutil import make_archive [as 别名]
def to_byte_array(self):
        """Serialize the :class:`ProcessingUnit` instance into a bytearray

        This method persists the processing unit in a temporary directory, zip
        the directory and return the zipped file as binary data.

        Returns:
            bytearray: the processing unit as bytearray data
        """
        cleaned_unit_name = _sanitize_unit_name(self.unit_name)
        with temp_dir() as tmp_dir:
            processing_unit_dir = tmp_dir / cleaned_unit_name
            self.persist(processing_unit_dir)
            archive_base_name = tmp_dir / cleaned_unit_name
            archive_name = archive_base_name.with_suffix(".zip")
            shutil.make_archive(
                base_name=str(archive_base_name), format="zip",
                root_dir=str(tmp_dir), base_dir=cleaned_unit_name)
            with archive_name.open(mode="rb") as f:
                processing_unit_bytes = bytearray(f.read())
        return processing_unit_bytes 
开发者ID:snipsco,项目名称:snips-nlu,代码行数:23,代码来源:processing_unit.py


注:本文中的shutil.make_archive方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。