當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。