| 1 |
|
|---|
| 2 |
execfile('scripts/make_docs.py') |
|---|
| 3 |
execfile('scripts/pack.py') |
|---|
| 4 |
import os |
|---|
| 5 |
import sys |
|---|
| 6 |
import glob |
|---|
| 7 |
import zipfile |
|---|
| 8 |
import re |
|---|
| 9 |
def json_encode(o, indent=0): |
|---|
| 10 |
if isinstance(o, dict): |
|---|
| 11 |
if len(o) == 0: |
|---|
| 12 |
yield '{}' |
|---|
| 13 |
else: |
|---|
| 14 |
yield '{\n' |
|---|
| 15 |
first = True |
|---|
| 16 |
for key, value in o.iteritems(): |
|---|
| 17 |
if first: |
|---|
| 18 |
first = False |
|---|
| 19 |
else: |
|---|
| 20 |
yield ',\n' |
|---|
| 21 |
yield ' ' * (indent + 4) |
|---|
| 22 |
assert isinstance(key, (basestring, float, int, long)) |
|---|
| 23 |
for chunk in json_encode(key): |
|---|
| 24 |
yield chunk |
|---|
| 25 |
yield ': ' |
|---|
| 26 |
for chunk in json_encode(value, indent + 4): |
|---|
| 27 |
yield chunk |
|---|
| 28 |
yield '\n' + (' ' * indent) + '}' |
|---|
| 29 |
elif isinstance(o, list): |
|---|
| 30 |
if len(o) == 0: |
|---|
| 31 |
yield '[]' |
|---|
| 32 |
else: |
|---|
| 33 |
yield '[\n' |
|---|
| 34 |
first = True |
|---|
| 35 |
for value in o: |
|---|
| 36 |
if first: |
|---|
| 37 |
first = False |
|---|
| 38 |
else: |
|---|
| 39 |
yield ',\n' |
|---|
| 40 |
yield ' ' * (indent + 4) |
|---|
| 41 |
for chunk in json_encode(value, indent + 4): |
|---|
| 42 |
yield chunk |
|---|
| 43 |
yield '\n' + (' ' * indent) + ']' |
|---|
| 44 |
elif isinstance(o, basestring): |
|---|
| 45 |
yield '"' + o.replace('\\', '\\\\').replace('"', '\\"') + '"' |
|---|
| 46 |
elif isinstance(o, (float, int, long)): |
|---|
| 47 |
yield str(o) |
|---|
| 48 |
else: |
|---|
| 49 |
raise NotImplementedError |
|---|
| 50 |
VERSION = re.search( |
|---|
| 51 |
r"""(?mxs)MochiKit.MochiKit.VERSION\s*=\s*['"]([^'"]+)""", |
|---|
| 52 |
file('MochiKit/MochiKit.js').read() |
|---|
| 53 |
).group(1) |
|---|
| 54 |
META = dict( |
|---|
| 55 |
name='MochiKit', |
|---|
| 56 |
author=['Bob Ippolito <bob@redivi.com>'], |
|---|
| 57 |
abstract='Python-inspired JavaScript kit', |
|---|
| 58 |
license='mit', |
|---|
| 59 |
version=VERSION, |
|---|
| 60 |
build_requires={'Test.Simple': '0.11'}, |
|---|
| 61 |
recommends={'JSAN': '0.10'}, |
|---|
| 62 |
provides={}, |
|---|
| 63 |
generated_by="MochiKit's build script", |
|---|
| 64 |
) |
|---|
| 65 |
FILES = glob.glob('lib/MochiKit/*.js') |
|---|
| 66 |
for fn in FILES: |
|---|
| 67 |
modname = os.path.splitext(os.path.basename(fn))[0] |
|---|
| 68 |
META['provides'][modname] = dict(file=fn, version=VERSION) |
|---|
| 69 |
if not os.path.exists('dist'): |
|---|
| 70 |
os.makedirs('dist') |
|---|
| 71 |
|
|---|
| 72 |
pkg = '%(name)s-%(version)s' % META |
|---|
| 73 |
z = zipfile.ZipFile( |
|---|
| 74 |
os.path.join('dist', pkg) + '.zip', |
|---|
| 75 |
'w', |
|---|
| 76 |
zipfile.ZIP_DEFLATED |
|---|
| 77 |
) |
|---|
| 78 |
MANIFEST = ['Changes', 'META.json', 'MANIFEST\t\t\tThis list of files'] |
|---|
| 79 |
z.writestr(os.path.join(pkg, 'META.json'), ''.join(json_encode(META))) |
|---|
| 80 |
z.write( |
|---|
| 81 |
os.path.join('doc', 'rst', 'MochiKit', 'VersionHistory.rst'), |
|---|
| 82 |
os.path.join(pkg, 'Changes') |
|---|
| 83 |
) |
|---|
| 84 |
|
|---|
| 85 |
IGNOREDIRS = ['.svn', 'dist', 'scripts'] |
|---|
| 86 |
src = os.path.join('.', '') |
|---|
| 87 |
dst = os.path.join(pkg, '') |
|---|
| 88 |
|
|---|
| 89 |
for root, dirs, files in os.walk(src): |
|---|
| 90 |
for ex in IGNOREDIRS: |
|---|
| 91 |
if ex in dirs: |
|---|
| 92 |
dirs.remove(ex) |
|---|
| 93 |
for fn in files: |
|---|
| 94 |
if fn.startswith('.'): |
|---|
| 95 |
continue |
|---|
| 96 |
fn = os.path.join(root, fn) |
|---|
| 97 |
mfn = fn[len(src):] |
|---|
| 98 |
MANIFEST.append(mfn) |
|---|
| 99 |
if mfn.startswith('MochiKit/'): |
|---|
| 100 |
mfn = 'lib/' + mfn |
|---|
| 101 |
dstfn = os.path.join(dst, mfn) |
|---|
| 102 |
if os.path.splitext(fn)[1] == '.html': |
|---|
| 103 |
s = file(fn).read() |
|---|
| 104 |
s = s.replace('/MochiKit/', '/lib/MochiKit/') |
|---|
| 105 |
s = s.replace( |
|---|
| 106 |
"JSAN.addRepository('..');", |
|---|
| 107 |
'JSAN.addRepository("../lib");', |
|---|
| 108 |
) |
|---|
| 109 |
z.writestr(dstfn, s) |
|---|
| 110 |
else: |
|---|
| 111 |
z.write(fn, dstfn) |
|---|
| 112 |
|
|---|
| 113 |
z.writestr(os.path.join(pkg, 'MANIFEST'), '\n'.join(MANIFEST + [''])) |
|---|
| 114 |
|
|---|
| 115 |
z.close() |
|---|