Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Bjarni R. Einarsson
committed
Jun 21, 2011
1 parent
4cf1edf
commit 8264d33
Showing
1 changed file
with
50 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,65 @@ | ||
#!/usr/bin/python | ||
# | ||
# This is a poor-man's executable builder, for embedding dependencies into | ||
# our pagekite.py file until we have proper packaging. | ||
# | ||
import os, sys | ||
|
||
pydata = { } | ||
data = { } | ||
order = [ ] | ||
for filename in sys.argv[1:]: | ||
fd = open(filename, 'r') | ||
bn = os.path.basename(filename).replace('.py', '') | ||
if filename.endswith('/__init__.py'): | ||
bn = os.path.basename(os.path.dirname(filename)) | ||
else: | ||
bn = os.path.basename(filename).replace('.py', '') | ||
|
||
order.append(bn) | ||
data[bn] = [l.replace('\n', '').replace('\r', '') for l in fd.readlines()] | ||
|
||
fd = open(filename, 'r') | ||
lines = [l.replace('\n', '').replace('\r', '') for l in fd.readlines()] | ||
fd.close() | ||
|
||
print """#!/usr/bin/python' | ||
# This is a compilation of multiple Python files. Search for the string | ||
# 'MODULE' to examine individual parts. | ||
if filename.endswith('.py') or filename.endswith('.pyw'): | ||
pydata[bn] = lines | ||
else: | ||
data[bn] = lines | ||
|
||
print """#!/usr/bin/python | ||
# | ||
# NOTE: This is a compilation of multiple Python files. | ||
# See below for details on individual segments. | ||
# | ||
import sys, imp | ||
""" | ||
|
||
first = order.pop(0) | ||
for mn in order: | ||
print '##[ MODULE: %s ]%s' % (mn, '#' * (65-len(mn))) | ||
print 'class %s(object):' % mn | ||
for line in data[mn]: | ||
print ' %s' % line | ||
if mn in pydata: | ||
what = 'MODULE' | ||
ddict = pydata | ||
else: | ||
what = 'FILE' | ||
ddict = data | ||
|
||
print '%s' % '#' * 79 | ||
if mn != order[-1] and what == 'MODULE': | ||
print 'sys.modules["%s"] = imp.new_module("%s")' % (mn, mn) | ||
print 'exec """' | ||
for line in ddict[mn]: | ||
print '%s' % line.replace('\\', '\\\\').replace('"', '\\"') | ||
print '""" in sys.modules["%s"].__dict__' % mn | ||
|
||
elif what == 'FILE': | ||
print '__DATA_%s = """' % mn.replace('.', '_').upper() | ||
for line in ddict[mn]: | ||
print '%s' % line.replace('\\', '\\\\').replace('"', '\\"') | ||
print '"""' | ||
|
||
print '##[ MAIN: %s ]%s' % (first, '#' * (67-len(first))) | ||
for line in data[first]: | ||
print '%s' % line | ||
else: | ||
for line in ddict[mn]: | ||
print '%s' % line | ||
|
||
|