本文整理匯總了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
示例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
示例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
示例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
示例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()
示例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
示例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()