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


Python PyZipFile.writepy方法代码示例

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


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

示例1: get_module_as_zip_from_module_directory

# 需要导入模块: from zipfile import PyZipFile [as 别名]
# 或者: from zipfile.PyZipFile import writepy [as 别名]
def get_module_as_zip_from_module_directory(module_directory, b64enc=True, src=True):
    """Compress a module directory

    @param module_directory: The module directory
    @param base64enc: if True the function will encode the zip file with base64
    @param src: Integrate the source files

    @return: a stream to store in a file-like object
    """

    RE_exclude = re.compile('(?:^\..+\.swp$)|(?:\.py[oc]$)|(?:\.bak$)|(?:\.~.~$)', re.I)

    def _zippy(archive, path, src=True):
        path = os.path.abspath(path)
        base = os.path.basename(path)
        for f in tools.osutil.listdir(path, True):
            bf = os.path.basename(f)
            if not RE_exclude.search(bf) and (src or bf == '__terp__.py' or not bf.endswith('.py')):
                archive.write(os.path.join(path, f), os.path.join(base, f))

    archname = StringIO()
    archive = PyZipFile(archname, "w", ZIP_DEFLATED)
    archive.writepy(module_directory)
    _zippy(archive, module_directory, src=src)
    archive.close()
    val = archname.getvalue()
    archname.close()

    if b64enc:
        val = base64.encodestring(val)

    return val
开发者ID:MarkNorgate,项目名称:addons-EAD,代码行数:34,代码来源:__init__.py

示例2: build_zip

# 需要导入模块: from zipfile import PyZipFile [as 别名]
# 或者: from zipfile.PyZipFile import writepy [as 别名]
 def build_zip(module_dir):
     # This can fail at writepy if there is something wrong with the files
     #  in xframes.  Go ahead anyway, but things will probably fail if this job is
     #  distributed
     try:
         tf = NamedTemporaryFile(suffix=".zip", delete=False)
         z = PyZipFile(tf, "w")
         z.writepy(module_dir)
         z.close()
         return tf.name
     except:
         logging.warn("Zip file distribution failed -- workers will not get xframes code.")
         logging.warn("Check for unexpected files in xframes directory.")
         return None
开发者ID:Atigeo,项目名称:xpatterns-xframe,代码行数:16,代码来源:spark_context.py

示例3: build_zip

# 需要导入模块: from zipfile import PyZipFile [as 别名]
# 或者: from zipfile.PyZipFile import writepy [as 别名]
 def build_zip():
     if 'XPATTERNS_HOME' not in os.environ:
         return None
     # This can fail at writepy if there is something wrong with the files
     #  in xpatterns.  Go ahead anyway, but things will probably fail of this job is
     #  distributed
     try:
         tf = NamedTemporaryFile(suffix='.zip', delete=False)
         z = PyZipFile(tf, 'w')
         z.writepy(os.path.join(os.environ['XPATTERNS_HOME'], 'xpatterns'))
         z.close()
         return tf.name
     except:
         print 'Zip file distribution failed -- workers will not get xpatterns code.'
         print 'Check for unexpected files in XPATTERNS_HOME/xpatterns.'
         return None
开发者ID:cloudronin,项目名称:xpatterns-xframe,代码行数:18,代码来源:spark_context.py

示例4: get_zip_from_directory

# 需要导入模块: from zipfile import PyZipFile [as 别名]
# 或者: from zipfile.PyZipFile import writepy [as 别名]
def get_zip_from_directory(directory, b64enc=True):
    RE_exclude = re.compile('(?:^\..+\.swp$)|(?:\.py[oc]$)|(?:\.bak$)|(?:\.~.~$)', re.I)

    def _zippy(archive, path):
        path = os.path.abspath(path)
        base = os.path.basename(path)
        for f in tools.osutil.listdir(path, True):
            bf = os.path.basename(f)
            if not RE_exclude.search(bf):
                archive.write(os.path.join(path, f), os.path.join(base, f))

    archname = StringIO()
    archive = PyZipFile(archname, "w", ZIP_DEFLATED)
    archive.writepy(directory)
    _zippy(archive, directory)
    archive.close()
    val = archname.getvalue()
    archname.close()

    if b64enc:
        val = base64.encodestring(val)

    return val
开发者ID:goldenboy,项目名称:razvoj,代码行数:25,代码来源:seance_generate_pdf.py

示例5: build_zip

# 需要导入模块: from zipfile import PyZipFile [as 别名]
# 或者: from zipfile.PyZipFile import writepy [as 别名]
def build_zip(dest):
    print "Writing", dest
    from zipfile import PyZipFile

    f = PyZipFile(dest, "w")
    f.writepy("src/singleshot")
    f.writepy("lib")
    f.writepy("lib/simpletal")
    f.close()
开发者ID:xythian,项目名称:singleshot,代码行数:11,代码来源:singleshotinit.py

示例6: zip_directory

# 需要导入模块: from zipfile import PyZipFile [as 别名]
# 或者: from zipfile.PyZipFile import writepy [as 别名]
def zip_directory(directory, b64enc=True, src=True):
    """Compress a directory

    @param directory: The directory to compress
    @param base64enc: if True the function will encode the zip file with base64
    @param src: Integrate the source files

    @return: a string containing the zip file
    """

    RE_exclude = re.compile('(?:^\..+\.swp$)|(?:\.py[oc]$)|(?:\.bak$)|(?:\.~.~$)', re.I)

    def _zippy(archive, path, src=True):
        path = os.path.abspath(path)
        base = os.path.basename(path)
        for f in tools.osutil.listdir(path, True):
            bf = os.path.basename(f)
            if not RE_exclude.search(bf) and (src or bf in ('__openerp__.py', '__terp__.py') or not bf.endswith('.py')):
                archive.write(os.path.join(path, f), os.path.join(base, f))

    archname = StringIO()
    archive = PyZipFile(archname, "w", ZIP_DEFLATED)

    # for Python 2.5, ZipFile.write() still expects 8-bit strings (2.6 converts to utf-8)
    directory = tools.ustr(directory).encode('utf-8')

    archive.writepy(directory)
    _zippy(archive, directory, src=src)
    archive.close()
    archive_data = archname.getvalue()
    archname.close()

    if b64enc:
        return base64.encodestring(archive_data)

    return archive_data
开发者ID:lcrdcastro,项目名称:viaweb,代码行数:38,代码来源:__init__.py

示例7: PyZipFile

# 需要导入模块: from zipfile import PyZipFile [as 别名]
# 或者: from zipfile.PyZipFile import writepy [as 别名]
#!/usr/bin/env python
#
# Packs Python standard library into zip file python$(ver).zip
#

import os, os.path, shutil, sys
from zipfile import PyZipFile

name = "python%i%i.zip" % (sys.version_info[0], sys.version_info[1])
print "creating %s..." % name

# delete tests, we don't need them:
for root, dirs, files in os.walk("Lib", topdown=False):
    if "test" in dirs:
        shutil.rmtree(os.path.join(root, "test"))

# pack Lib to a zipfile:
zip = PyZipFile(name, mode="w")

for f in os.listdir("Lib"):
    fn = os.path.join("Lib", f)
    if os.path.isdir(fn) or fn.endswith(".py"):
        zip.writepy(fn)
    else:
        print "warning: ignoring file %s" % f

zip.close()
开发者ID:Distrotech,项目名称:bakefile,代码行数:29,代码来源:python-makezip.py


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