Vega strike Python Modules doc  0.5.1
Documentation of the " Modules " folder of Vega strike
 All Data Structures Namespaces Files Functions Variables
PyZipFile Class Reference
Inheritance diagram for PyZipFile:
ZipFile

Public Member Functions

def writepy
 
- Public Member Functions inherited from ZipFile
def __init__
 
def namelist
 
def infolist
 
def printdir
 
def testzip
 
def getinfo
 
def read
 
def write
 
def writestr
 
def __del__
 
def close
 

Additional Inherited Members

- Data Fields inherited from ZipFile
 debug
 
 NameToInfo
 
 filelist
 
 compression
 
 mode
 
 filename
 
 start_dir
 
- Static Public Attributes inherited from ZipFile
 fp = None
 

Detailed Description

Class to create ZIP archives with Python library files and packages.

Definition at line 495 of file zipfile.py.

Member Function Documentation

def writepy (   self,
  pathname,
  basename = "" 
)
Add all files from "pathname" to the ZIP archive.

If pathname is a package directory, search the directory and
all package subdirectories recursively for all *.py and enter
the modules into the archive.  If pathname is a plain
directory, listdir *.py and enter all modules.  Else, pathname
must be a Python *.py file and the module will be put into the
archive.  Added modules are always module.pyo or module.pyc.
This method will compile the module.py into module.pyc if
necessary.

Definition at line 498 of file zipfile.py.

References PyZipFile._get_codename(), py_compile.compile(), shlex.debug, FTP.debug, ZipFile.debug, NNTP.debug, dispatcher.debug, Devnull.write(), Pickler.write, openrsrc.write(), _Hqxcoderengine.write(), StreamWriter.write(), GzipFile.write(), StringIO.write(), _Rlecoderengine.write(), InteractiveInterpreter.write(), _fileobject.write(), BinHex.write(), Telnet.write(), StreamReaderWriter.write(), ConfigParser.write(), ZipFile.write(), _SpoofOut.write(), StreamRecoder.write(), Marshaller.write, file_wrapper.write, and PyZipFile.writepy().

499  def writepy(self, pathname, basename = ""):
500  """Add all files from "pathname" to the ZIP archive.
501 
502  If pathname is a package directory, search the directory and
503  all package subdirectories recursively for all *.py and enter
504  the modules into the archive. If pathname is a plain
505  directory, listdir *.py and enter all modules. Else, pathname
506  must be a Python *.py file and the module will be put into the
507  archive. Added modules are always module.pyo or module.pyc.
508  This method will compile the module.py into module.pyc if
509  necessary.
510  """
511  dir, name = os.path.split(pathname)
512  if os.path.isdir(pathname):
513  initname = os.path.join(pathname, "__init__.py")
514  if os.path.isfile(initname):
515  # This is a package directory, add it
516  if basename:
517  basename = "%s/%s" % (basename, name)
518  else:
519  basename = name
520  if self.debug:
521  print "Adding package in", pathname, "as", basename
522  fname, arcname = self._get_codename(initname[0:-3], basename)
523  if self.debug:
524  print "Adding", arcname
525  self.write(fname, arcname)
526  dirlist = os.listdir(pathname)
527  dirlist.remove("__init__.py")
528  # Add all *.py files and package subdirectories
529  for filename in dirlist:
530  path = os.path.join(pathname, filename)
531  root, ext = os.path.splitext(filename)
532  if os.path.isdir(path):
533  if os.path.isfile(os.path.join(path, "__init__.py")):
534  # This is a package directory, add it
535  self.writepy(path, basename) # Recursive call
536  elif ext == ".py":
537  fname, arcname = self._get_codename(path[0:-3],
538  basename)
539  if self.debug:
540  print "Adding", arcname
541  self.write(fname, arcname)
542  else:
543  # This is NOT a package directory, add its files at top level
544  if self.debug:
545  print "Adding files from directory", pathname
546  for filename in os.listdir(pathname):
547  path = os.path.join(pathname, filename)
548  root, ext = os.path.splitext(filename)
549  if ext == ".py":
550  fname, arcname = self._get_codename(path[0:-3],
551  basename)
552  if self.debug:
553  print "Adding", arcname
554  self.write(fname, arcname)
555  else:
556  if pathname[-3:] != ".py":
557  raise RuntimeError, \
558  'Files added with writepy() must end with ".py"'
559  fname, arcname = self._get_codename(pathname[0:-3], basename)
560  if self.debug:
561  print "Adding file", arcname
562  self.write(fname, arcname)

The documentation for this class was generated from the following file: