abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
package Namespace Reference

Functions

def zip_library
 
def add_python_lib
 
def add_dir
 
def add_fileobj
 
def add_file
 
def package
 
def main
 

Function Documentation

def package.add_dir (   tf,
  dir,
  mtime 
)

Definition at line 52 of file package.py.

52 
53 def add_dir(tf, dir, mtime):
54  ti = tarfile.TarInfo(dir)
55  ti.mode = 0777
56  ti.mtime = mtime
57  ti.type = tarfile.DIRTYPE
58 
59  tf.addfile(ti)
def add_dir
Definition: package.py:52
def package.add_file (   tf,
  fname,
  arcname,
  mode,
  mtime 
)

Definition at line 71 of file package.py.

71 
72 def add_file(tf, fname, arcname, mode, mtime):
73  print "\t adding %s as %s"%(fname, arcname)
74 
75  with open(fname, "rb") as f:
76  add_fileobj(tf, f, arcname, mode, mtime)
def add_fileobj
Definition: package.py:60
def add_file
Definition: package.py:71
def package.add_fileobj (   tf,
  f,
  arcname,
  mode,
  mtime 
)

Definition at line 60 of file package.py.

60 
61 def add_fileobj(tf, f, arcname, mode, mtime):
62  ti = tarfile.TarInfo(arcname)
63  ti.mode = mode
64  ti.mtime = mtime
65 
66  f.seek(0, os.SEEK_END)
67  ti.size = f.tell()
68 
69  f.seek(0, os.SEEK_SET)
70  tf.addfile(ti, f)
def add_fileobj
Definition: package.py:60
def package.add_python_lib (   tf,
  lib_dir,
  lib,
  mtime 
)

Definition at line 27 of file package.py.

27 
28 def add_python_lib(tf, lib_dir, lib, mtime):
29 
30  _, prefix = os.path.split(lib)
31 
32  for root, _, files in os.walk(lib):
33 
34  relpath = os.path.relpath(root, lib)
35 
36  if '.hg' in relpath.split('/'):
37  continue
38 
39  if relpath=='.':
40  arcroot = lib_dir
41  else:
42  arcroot = os.path.join( lib_dir, os.path.relpath(root, lib) )
43 
44  arcroot = os.path.join(arcroot, prefix)
45 
46  add_dir(tf, arcroot, mtime)
47 
48  for f in files:
49  _, ext = os.path.splitext(f)
50  if ext in ['.py', '.so']:
51  add_file( tf, os.path.join(root,f), os.path.join(arcroot, f), 0666, mtime)
def add_dir
Definition: package.py:52
def add_python_lib
Definition: package.py:27
def add_file
Definition: package.py:71
def package.main (   args)

Definition at line 142 of file package.py.

143 def main(args):
144 
145  usage = "usage: %prog [options]"
146 
147  parser = optparse.OptionParser(usage)
148 
149  parser.add_option("-d", "--pyabc_dir", dest="pyabc_dir", help="name of generated directory" )
150  parser.add_option("-b", "--extra_bin", dest="extra_bin", help="extra binaries to pack" )
151  parser.add_option("-l", "--extra_lib", dest="extra_lib", help="extra directories in lib to pack" )
152  parser.add_option("-f", "--extra_files", dest="extra_files", help="additional files (comma separated pairs of file:dest" )
153  parser.add_option("-a", "--abc", dest="abc", help="location of the ABC exeutable")
154  parser.add_option("-s", "--abc_sh", dest="abc_sh", help="location of the ABC setup script")
155  parser.add_option("-p", "--pyabc", dest="pyabc", help="location of pyabc.py")
156  parser.add_option("-o", "--out", dest="out", help="location of output tar gzipped file")
157  parser.add_option("-x", "--scripts", dest="scripts", default="scripts", help="location of scripts")
158  parser.add_option("-S", "--system", action="store_false", dest="sys", default=True, help="use default python installation")
159 
160  options, args = parser.parse_args(args)
161 
162  if len(args) > 1:
163  parser.print_help()
164  return 1
165 
166  if not options.pyabc_dir or not options.abc or not options.abc_sh or not options.pyabc or not options.out:
167  parser.print_help()
168  return 1
169 
170  extra_bin = options.extra_bin.split(',') if options.extra_bin else []
171  extra_lib = options.extra_lib.split(',') if options.extra_lib else []
172  extra_files = [ s.split(':') for s in options.extra_files.split(',')] if options.extra_files else []
173 
174  return package(options.pyabc_dir, extra_bin, extra_lib, extra_files, options.abc, options.abc_sh, options.pyabc, options.out, options.scripts, options.sys)
def main
Definition: package.py:142
def package.package (   pyabc_dir,
  extra_bin,
  extra_lib,
  extra_files,
  abc_exe,
  abc_sh,
  pyabc,
  ofname,
  scripts_dir,
  use_sys 
)

Definition at line 77 of file package.py.

77 
78 def package(pyabc_dir, extra_bin, extra_lib, extra_files, abc_exe, abc_sh, pyabc, ofname, scripts_dir, use_sys):
79 
80  mtime = time.time()
81 
82  tf = tarfile.open(ofname, "w:gz")
83 
84  add_dir(tf, "%s"%pyabc_dir, mtime)
85 
86  add_dir(tf, "%s/bin"%pyabc_dir, mtime)
87 
88  add_file(tf, abc_exe, "%s/bin/abc_exe"%pyabc_dir, 0777, mtime)
89  add_file(tf, abc_sh, "%s/bin/abc"%pyabc_dir, 0777, mtime)
90 
91  if scripts_dir:
92  for fn in os.listdir(scripts_dir):
93  if fn.startswith('.'):
94  continue
95  fullname = os.path.join(scripts_dir, fn)
96  if os.path.isfile(fullname):
97  fnroot, fnext = os.path.splitext(fn)
98  if fnext==".sh":
99  add_file( tf, fullname, os.path.join("%s/bin"%pyabc_dir, fnroot), 0777, mtime)
100  elif fnext not in ( '.pyc', '.pyo'):
101  add_file( tf, fullname, os.path.join("%s/scripts"%pyabc_dir, fn), 0666, mtime)
102 
103  for bin in extra_bin:
104  add_file( tf, bin, os.path.join("%s/bin"%pyabc_dir, os.path.basename(bin)), 0777, mtime)
105 
106  lib_dir = "%s/lib"%pyabc_dir
107 
108  add_dir(tf, lib_dir, mtime)
109 
110  for lib in extra_lib:
111  add_python_lib( tf, lib_dir, lib, mtime)
112 
113  for file, dest in extra_files:
114  add_file(tf, file, '%s/%s'%(pyabc_dir, dest), 0666, mtime)
115 
116  for entry in os.listdir(pyabc):
117  if entry.endswith('.py'):
118  add_file( tf, os.path.join(pyabc, entry), os.path.join("%s/lib"%pyabc_dir, entry), 0666, mtime)
119 
120  if not use_sys:
121  # ZIP standard library
122  zf = tempfile.NamedTemporaryFile("w+b")
123  #zip_library(zf, [(pyabc, "pyabc.py")])
124  zip_library(zf, [])
125  zf.flush()
126 
127  add_fileobj(tf, zf, "%s/lib/python_library.zip"%pyabc_dir, 0666, mtime)
128 
129  zf.close()
130 
131  # add all extensions
132 
133  lib_dynload = os.path.join(sys.exec_prefix,"lib", "python%s"%sys.version[:3], "lib-dynload")
134 
135  for fn in os.listdir(lib_dynload):
136  fullname = os.path.join(lib_dynload, fn)
137  if os.path.isfile(fullname):
138  add_file( tf, fullname, os.path.join("%s/lib"%pyabc_dir, fn), 0666, mtime)
139 
140  tf.close()
141 
def add_dir
Definition: package.py:52
def add_python_lib
Definition: package.py:27
def zip_library
Definition: package.py:10
def add_fileobj
Definition: package.py:60
def package
Definition: package.py:77
def add_file
Definition: package.py:71
def package.zip_library (   f,
  extra_files = [] 
)

Definition at line 10 of file package.py.

10 
11 def zip_library(f, extra_files = []):
12  lib = "%s/lib/python%s/"%(sys.prefix,sys.version[:3])
13 
14  zf = zipfile.ZipFile(f, "w", zipfile.ZIP_DEFLATED)
15 
16  for root, _, files in os.walk(lib):
17  arcroot = os.path.relpath(root, lib)
18  for f in files:
19  _, ext = os.path.splitext(f)
20  if ext in ['.py']:
21  zf.write(os.path.join(root,f), os.path.join(arcroot, f))
22 
23  for s, r in extra_files:
24  zf.write( s, r )
25 
26  zf.close()
def zip_library
Definition: package.py:10