python类make_archive()的实例源码

conffiles.py 文件源码 项目:guifiadmin 作者: guifi-org 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def tinc_client_openwrt_config_tar(client):
    basedir = mkdtemp()
    tinc_config_base = os.path.join(basedir, 'etc', 'tinc', client.gateway.nickname)
    os.makedirs(tinc_config_base)
    os.makedirs(os.path.join(tinc_config_base, 'hosts'))

    with open(os.path.join(tinc_config_base, 'tinc.conf'), 'w') as conffile:
        conffile.write(tinc_client_conf(client))

    with open(os.path.join(tinc_config_base, 'tinc_up'), 'w') as conffile:
        conffile.write(tinc_client_tinc_up(client))

    with open(os.path.join(tinc_config_base, 'tinc_down'), 'w') as conffile:
        conffile.write(tinc_client_tinc_down(client))

    with open(os.path.join(tinc_config_base, 'hosts', client.gateway.nickname), 'w') as conffile:
        conffile.write(tinc_gateway_host(client.gateway))

    with open(os.path.join(tinc_config_base, 'hosts', client.member.username), 'w') as conffile:
        conffile.write(tinc_client_host(client))

    openwrt_config_base = os.path.join(basedir, 'etc', 'config')
    os.makedirs(openwrt_config_base)

    with open(os.path.join(openwrt_config_base, 'firewall'), 'w') as conffile:
        conffile.write(tinc_client_openwrt_firewall_config(client))

    with open(os.path.join(openwrt_config_base, 'tinc'), 'w') as conffile:
        conffile.write(tinc_client_openwrt_tinc_config(client))

    tarfile = make_archive('openwrt_config', 'gztar', root_dir=basedir)
    with open(tarfile, 'rb') as tarfile:
        return tarfile.read()
finish.py 文件源码 项目:cuckoo-headless 作者: evandowning 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def compress(path):
    if not os.path.exists(path):
        print 'Error: {0} does not exist'.format(path)
        sys.exit(1)

    shutil.make_archive(path, 'zip', path)

    return path + '.zip'
compile.py 文件源码 项目:MUBench 作者: stg-tud 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def __create_jar(classes_path, jar_path):
        zip_path = shutil.make_archive(jar_path, 'zip', classes_path)
        os.rename(zip_path, jar_path)
cli.py 文件源码 项目:tight-cli 作者: Lululemon 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def artifact(*args, **kwargs):
    """
    Generate an artifact for the app. Will be located at ./build

    :param args:
    :param kwargs:
    :return:
    """
    target = kwargs.pop('target')
    name = get_config(target)['name']
    zip_name = '{}/builds/{}-artifact-{}'.format(target, name, int(time.time()))
    builds_dir = '{}/builds'.format(target)
    if os.path.exists(builds_dir):
        shutil.rmtree(builds_dir)

    os.mkdir(builds_dir)
    os.mkdir('{}/{}-artifact'.format(builds_dir, name))

    directory_list = ['{}/app'.format(target)]
    file_list = ['{}/app_index.py'.format(target), '{}/env.dist.yml'.format(target), '{}/tight.yml'.format(target)]

    create_zip = ['zip', '-9', zip_name]
    subprocess.call(create_zip)
    artifact_dir = '{}/builds/{}-artifact/'.format(target, name)

    for dir in directory_list:
        cp_dir_command = ['cp', '-R', dir, artifact_dir]
        subprocess.call(cp_dir_command)

    for file_name in file_list:
        cp_file_command = ['cp', file_name, artifact_dir]
        subprocess.call(cp_file_command)

    shutil.make_archive(zip_name, 'zip', root_dir=artifact_dir)
debug_snapshot.py 文件源码 项目:ceph-lcm 作者: Mirantis 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def main(pool):
    options = get_options()
    options.compose_file.close()
    syslog.syslog(syslog.LOG_INFO, "Options are {0}".format(options))

    compose_cmd = get_compose_cmd(options)
    container_ids = get_container_id_mapping(pool, compose_cmd)
    syslog.syslog(syslog.LOG_INFO, "Container ID mapping {0}".format(
        container_ids))

    tmp_dir = tempfile.mkdtemp()
    atexit.register(lambda: shutil.rmtree(tmp_dir))
    syslog.syslog(syslog.LOG_INFO, "Temporary directory: {0}".format(tmp_dir))

    snapshot_dir = os.path.join(tmp_dir, "snapshot")
    for name in container_ids:
        os.makedirs(os.path.join(snapshot_dir, name))

    with closing_pool(pool):
        process_main_files(pool, snapshot_dir, compose_cmd, container_ids)

        for name, container_id in container_ids.items():
            process_service_files(pool, name, container_id, snapshot_dir,
                                  compose_cmd)

    syslog.syslog(syslog.LOG_INFO, "Information was collected.")
    make_archive(tmp_dir, options.snapshot_path)
    syslog.syslog(syslog.LOG_INFO, "Data is collected")
debug_snapshot.py 文件源码 项目:ceph-lcm 作者: Mirantis 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def make_archive(collected_dir, result_path):
    formats = {name for name, description in shutil.get_archive_formats()}
    for fmt in "xztar", "bztar", "gztar":
        if fmt in formats:
            archive_format = fmt
            break
    else:
        archive_format = "tar"

    shutil.make_archive(result_path, archive_format, collected_dir, "snapshot")
CAM.py 文件源码 项目:CAM 作者: PolitoInc 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def exportProj(self, event):
        self.chooser.setDialogTitle("Save project")
        Ffilter = FileNameExtensionFilter("Zip files", ["zip"])
        self.chooser.setFileFilter(Ffilter)
        returnVal = self.chooser.showSaveDialog(None)
        if returnVal == JFileChooser.APPROVE_OPTION:
            dst = str(self.chooser.getSelectedFile())
            shutil.make_archive(dst, "zip", self.getCurrentProjPath())
            self.popup("Project exported successfully")
game_engine_publishing.py 文件源码 项目:blender-addons 作者: scorpion81 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def execute(self, context):
        ps = context.scene.ge_publish_settings

        if ps.publish_default_platform:
            print("Publishing default platform")
            blender_bin_path = bpy.app.binary_path
            blender_bin_dir = os.path.dirname(blender_bin_path)
            ext = os.path.splitext(blender_bin_path)[-1].lower()
            WriteRuntime(os.path.join(blender_bin_dir, 'blenderplayer' + ext),
                         os.path.join(ps.output_path, 'default', ps.runtime_name),
                         ps.asset_paths,
                         True,
                         True,
                         True,
                         ps.make_archive,
                         self.report
                         )
        else:
            print("Skipping default platform")

        for platform in ps.platforms:
            if platform.publish:
                print("Publishing", platform.name)
                WriteRuntime(platform.player_path,
                            os.path.join(ps.output_path, platform.name, ps.runtime_name),
                            ps.asset_paths,
                            True,
                            True,
                            True,
                            ps.make_archive,
                            self.report
                            )
            else:
                print("Skipping", platform.name)

        return {'FINISHED'}
extractor.py 文件源码 项目:firmflaws 作者: Ganapati 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def _check_rootfs(self):
        """
        If this file contains a known filesystem type, extract it.
        """

        if not self.get_rootfs_status():
            for module in binwalk.scan(self.item, "-e", "-r", "-y",
                                       "filesystem", signature=True,
                                       quiet=True):
                for entry in module.results:
                    self.printf(">>>> %s" % entry.description)
                    break

                if module.extractor.directory:
                    unix = Extractor.io_find_rootfs(module.extractor.directory)

                    if not unix[0]:
                        self.printf(">>>> Extraction failed!")
                        return False

                    self.printf(">>>> Found Linux filesystem in %s!" % unix[1])
                    if self.output:
                        shutil.make_archive(self.output, "gztar",
                                            root_dir=unix[1])
                    else:
                        self.extractor.do_rootfs = False
                    return True
        return False
fileUtils.py 文件源码 项目:Javascript-Compiler 作者: Nidre 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def createZipFile(source_dir, zip_path):
    print printer.title("Creating zip File: ") + zip_path
    try:
        if os.path.exists(zip_path):
            os.remove(zip_path)

        shutil.make_archive(zip_path, 'zip', source_dir)
    except:
        e = sys.exc_info()[0]
        print e
    print printer.okGreen("DONE!")
    return
build_updater.py 文件源码 项目:webupdate 作者: Bakterija 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def build(self, ver):
        var1 = ('apd_ver'+ver, 'apd_ver'+ver+'.zip')
        var2 = self.www_path
        home = expanduser("~")
        pwd = os.getcwd()

        self.printer('Archiving buildozer/android/app/ contents into %s' % (var1[1]))
        shutil.make_archive(home+'/'+var1[0], 'zip', root_dir='.buildozer/android/app/')
        r = self.try_move(home+'/'+var1[1], var2)

        if r == True:
            self.printer(colorama.Fore.GREEN + 'Build update successful')
        else:
            self.printer(colorama.Fore.RED + 'Build update failed')
build_updater.py 文件源码 项目:webupdate 作者: Bakterija 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def build_no_buildozer(self, ver):
        var1 = ('apd_ver'+ver, 'apd_ver'+ver+'.zip')
        var2 = self.www_path
        home = expanduser("~")
        pwd = os.getcwd()
        tempdir = 'temporary_apupdater_folder1111'
        temppath = '%s/Desktop/%s/' % (home, tempdir)
        self.printer('Creating tempdir "%s"' % (temppath))
        self.mkdir(temppath)

        self.printer('Moving bin and .buildozer to tempdir')
        self.try_move('bin', temppath)
        self.try_move('.buildozer', temppath)

        self.printer('Archiving active folder contents into %s' % (var1[1]))
        shutil.make_archive(home+'/'+var1[0], 'zip', root_dir='.')
        r = self.try_move(home+'/'+var1[1], var2)

        self.printer('Moving bin and .buildozer back to active dir')
        self.try_move(temppath+'/bin', pwd+'/')
        self.try_move(temppath+'/.buildozer', pwd+'/')

        self.printer('Removing tempdir')
        self.rmdir(temppath)
        if r == True:
            self.printer(colorama.Fore.GREEN + 'Build update successful')
        else:
            self.printer(colorama.Fore.RED + 'Build update failed')
build_updater.py 文件源码 项目:webupdate 作者: Bakterija 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def build(self, ver):
        var1 = ('apd_ver'+ver, 'apd_ver'+ver+'.zip')
        var2 = self.www_path
        home = expanduser("~")
        pwd = os.getcwd()

        self.printer('Archiving buildozer/android/app/ contents into %s' % (var1[1]))
        shutil.make_archive(home+'/'+var1[0], 'zip', root_dir='.buildozer/android/app/')
        r = self.try_move(home+'/'+var1[1], var2)

        if r == True:
            self.printer(colorama.Fore.GREEN + 'Build update successful')
        else:
            self.printer(colorama.Fore.RED + 'Build update failed')
build_updater.py 文件源码 项目:webupdate 作者: Bakterija 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def build_no_buildozer(self, ver):
        var1 = ('apd_ver'+ver, 'apd_ver'+ver+'.zip')
        var2 = self.www_path
        home = expanduser("~")
        pwd = os.getcwd()
        tempdir = 'temporary_apupdater_folder1111'
        temppath = '%s/Desktop/%s/' % (home, tempdir)
        self.printer('Creating tempdir "%s"' % (temppath))
        self.mkdir(temppath)

        self.printer('Moving bin and .buildozer to tempdir')
        self.try_move('bin', temppath)
        self.try_move('.buildozer', temppath)

        self.printer('Archiving active folder contents into %s' % (var1[1]))
        shutil.make_archive(home+'/'+var1[0], 'zip', root_dir='.')
        r = self.try_move(home+'/'+var1[1], var2)

        self.printer('Moving bin and .buildozer back to active dir')
        self.try_move(temppath+'/bin', pwd+'/')
        self.try_move(temppath+'/.buildozer', pwd+'/')

        self.printer('Removing tempdir')
        self.rmdir(temppath)
        if r == True:
            self.printer(colorama.Fore.GREEN + 'Build update successful')
        else:
            self.printer(colorama.Fore.RED + 'Build update failed')
package.py 文件源码 项目:Coffer 作者: Max00355 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def createArchive(path, name):
    print (text.creatingPackage)
    shutil.make_archive(name, "tar", path)
AnalyzeControl.py 文件源码 项目:HaboMalHunter 作者: Tencent 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def compress_log(cfg):
    tmp_compressed_path = "/tmp/output.zip"
    if os.path.exists(tmp_compressed_path):
        os.remove(tmp_compressed_path)
    dest = os.path.join(cfg.file_log_dir,"output.zip")
    if os.path.exists(dest):
        os.remove(dest)
    f_name = shutil.make_archive("/tmp/output","zip",cfg.file_log_dir)
    shutil.move(f_name,dest)
    log.info("log files were packed into %s",cfg.file_log_dir)
local.py 文件源码 项目:NASA-Project 作者: dvircohen 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def _zip_and_upload_code(self):
        self._logger.debug('Zipping project code in preparation to send')
        archive_dir = os.path.abspath(os.path.join(self._project_path, '..'))
        place = os.path.join(self._project_path, 'full_code')
        shutil.make_archive(base_name=place,
                            format='zip',
                            root_dir=archive_dir,
                            base_dir='NASA_Project')
        self._logger.debug('Zipping done')
        self._s3_client.upload_file(self._project_bucket,
                                    os.path.join(self._project_path, 'full_code.zip'),
                                    'full_code.zip')
commands.py 文件源码 项目:markdownreveal 作者: markdownreveal 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def zip(markdown_file: Path):
    """
    Generate a ZIP file with the presentation.
    """
    markdown_file = Path(markdown_file)

    # We copy the directory because `make_archive` cannot follow symlinks...
    with TemporaryDirectory() as tmpdir:
        tmpdir = Path(tmpdir) / 'out'
        generate(markdown_file)
        config = load_config()
        copytree(src=str(config['output_path']), dst=str(tmpdir))
        make_archive(markdown_file.stem, format='zip', root_dir=str(tmpdir))
views.py 文件源码 项目:fileserver 作者: ReCodEx 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def store_submission(id, dirs: DirectoryStructure):
    """
    Store files submitted by a user and create an archive for workers convenience.
    Expects that the body of the POST request uses file paths as keys and the 
    content of the files as values.
    """

    # Make a separate directory for the submitted files
    job_dir = os.path.join(dirs.submission_dir, id)
    os.makedirs(job_dir, exist_ok=True)

    # Save each received file
    for name, content in request.files.items():
        # Get the directory of the file path and create it, if necessary
        dirname = os.path.dirname(name)
        if dirname:
            os.makedirs(os.path.join(job_dir, dirname), exist_ok=True)

        # Save the file
        with open(os.path.join(job_dir, name), 'wb') as f:
            content.save(f)

    # Make an archive that contains the submitted files
    shutil.make_archive(os.path.join(dirs.archive_dir, id), "zip", root_dir=dirs.submission_dir, base_dir=id)

    # Return the path to the archive
    return json.dumps({
        "archive_path": url_for('fileserver.get_submission_archive', id=id, ext='zip'),
        "result_path": url_for('fileserver.store_result', id=id, ext='zip')
    })
saf.py 文件源码 项目:pysaf 作者: cstarcher 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def zip_archive(self):
        """Create ZIP files for all archive directories."""
        dst_folder_list = os.listdir(self.archive_path)
        for folder in dst_folder_list:
            folder_path = os.path.join(self.archive_path, folder)
            if folder in self.saf_folder_list and os.path.isdir(folder_path):
                shutil.make_archive(folder_path, 'zip', folder_path)


问题


面经


文章

微信
公众号

扫码关注公众号