11 lib =
"%s/lib/python%s/"%(sys.prefix,sys.version[:3])
13 zf = zipfile.ZipFile(f,
"w", zipfile.ZIP_DEFLATED)
15 for root, _, files
in os.walk(lib):
16 arcroot = os.path.relpath(root, lib)
18 _, ext = os.path.splitext(f)
20 zf.write(os.path.join(root,f), os.path.join(arcroot, f))
22 for s, r
in extra_files:
29 _, prefix = os.path.split(lib)
31 for root, _, files
in os.walk(lib):
33 relpath = os.path.relpath(root, lib)
35 if '.hg' in relpath.split(
'/'):
41 arcroot = os.path.join( lib_dir, os.path.relpath(root, lib) )
43 arcroot = os.path.join(arcroot, prefix)
48 _, ext = os.path.splitext(f)
49 if ext
in [
'.py',
'.so']:
50 add_file( tf, os.path.join(root,f), os.path.join(arcroot, f), 0666, mtime)
53 ti = tarfile.TarInfo(dir)
56 ti.type = tarfile.DIRTYPE
61 ti = tarfile.TarInfo(arcname)
65 f.seek(0, os.SEEK_END)
68 f.seek(0, os.SEEK_SET)
72 print "\t adding %s as %s"%(fname, arcname)
74 with open(fname,
"rb")
as f:
77 def package(pyabc_dir, extra_bin, extra_lib, extra_files, abc_exe, abc_sh, pyabc, ofname, scripts_dir, use_sys):
81 tf = tarfile.open(ofname,
"w:gz")
83 add_dir(tf,
"%s"%pyabc_dir, mtime)
85 add_dir(tf,
"%s/bin"%pyabc_dir, mtime)
87 add_file(tf, abc_exe,
"%s/bin/abc_exe"%pyabc_dir, 0777, mtime)
88 add_file(tf, abc_sh,
"%s/bin/abc"%pyabc_dir, 0777, mtime)
91 for fn
in os.listdir(scripts_dir):
92 if fn.startswith(
'.'):
94 fullname = os.path.join(scripts_dir, fn)
95 if os.path.isfile(fullname):
96 fnroot, fnext = os.path.splitext(fn)
98 add_file( tf, fullname, os.path.join(
"%s/bin"%pyabc_dir, fnroot), 0777, mtime)
99 elif fnext
not in (
'.pyc',
'.pyo'):
100 add_file( tf, fullname, os.path.join(
"%s/scripts"%pyabc_dir, fn), 0666, mtime)
102 for bin
in extra_bin:
103 add_file( tf, bin, os.path.join(
"%s/bin"%pyabc_dir, os.path.basename(bin)), 0777, mtime)
105 lib_dir =
"%s/lib"%pyabc_dir
109 for lib
in extra_lib:
112 for file, dest
in extra_files:
113 add_file(tf, file,
'%s/%s'%(pyabc_dir, dest), 0666, mtime)
115 for entry
in os.listdir(pyabc):
116 if entry.endswith(
'.py'):
117 add_file( tf, os.path.join(pyabc, entry), os.path.join(
"%s/lib"%pyabc_dir, entry), 0666, mtime)
121 zf = tempfile.NamedTemporaryFile(
"w+b")
126 add_fileobj(tf, zf,
"%s/lib/python_library.zip"%pyabc_dir, 0666, mtime)
132 lib_dynload = os.path.join(sys.exec_prefix,
"lib",
"python%s"%sys.version[:3],
"lib-dynload")
134 for fn
in os.listdir(lib_dynload):
135 fullname = os.path.join(lib_dynload, fn)
136 if os.path.isfile(fullname):
137 add_file( tf, fullname, os.path.join(
"%s/lib"%pyabc_dir, fn), 0666, mtime)
144 usage =
"usage: %prog [options]"
146 parser = optparse.OptionParser(usage)
148 parser.add_option(
"-d",
"--pyabc_dir", dest=
"pyabc_dir", help=
"name of generated directory" )
149 parser.add_option(
"-b",
"--extra_bin", dest=
"extra_bin", help=
"extra binaries to pack" )
150 parser.add_option(
"-l",
"--extra_lib", dest=
"extra_lib", help=
"extra directories in lib to pack" )
151 parser.add_option(
"-f",
"--extra_files", dest=
"extra_files", help=
"additional files (comma separated pairs of file:dest" )
152 parser.add_option(
"-a",
"--abc", dest=
"abc", help=
"location of the ABC exeutable")
153 parser.add_option(
"-s",
"--abc_sh", dest=
"abc_sh", help=
"location of the ABC setup script")
154 parser.add_option(
"-p",
"--pyabc", dest=
"pyabc", help=
"location of pyabc.py")
155 parser.add_option(
"-o",
"--out", dest=
"out", help=
"location of output tar gzipped file")
156 parser.add_option(
"-x",
"--scripts", dest=
"scripts", default=
"scripts", help=
"location of scripts")
157 parser.add_option(
"-S",
"--system", action=
"store_false", dest=
"sys", default=
True, help=
"use default python installation")
159 options, args = parser.parse_args(args)
165 if not options.pyabc_dir
or not options.abc
or not options.abc_sh
or not options.pyabc
or not options.out:
169 extra_bin = options.extra_bin.split(
',')
if options.extra_bin
else []
170 extra_lib = options.extra_lib.split(
',')
if options.extra_lib
else []
171 extra_files = [ s.split(
':')
for s
in options.extra_files.split(
',')]
if options.extra_files
else []
173 return package(options.pyabc_dir, extra_bin, extra_lib, extra_files, options.abc, options.abc_sh, options.pyabc, options.out, options.scripts, options.sys)
175 if __name__==
"__main__":