Menu

[r47]: / scripts / build.py  Maximize  Restore  History

Download this file

139 lines (109 with data), 3.3 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
""" build.py - Build script to create the web site from source.
This creates a directory 'build' under the source tree and populates
it with stuff.
"""
import os
from os import makedirs
from os.path import dirname, join as joinpath, abspath, isdir
from shutil import copyfile
import zipfile
import compileTests
HERE = dirname(abspath(__file__))
SRCDIR = dirname(HERE)
TGTDIR = joinpath(SRCDIR, 'build')
VERSION = '0.1'
def buildAll():
webFiles = [
'index.html',
'about.html',
'style/tryscheme.css',
'style/docs.css']
copies(webFiles, 'web/htdocs')
compileTests.compileTests(findSource('tests/tests.txt'), findTarget('tests/tests.xml'))
copies(['js/scm/psyntaxpp.js'], '')
miscFiles = ['web/htdocs/'+f for f in webFiles] + ['tests/tests.txt', 'js/scm/psyntaxpp.js']
jsFiles = [
'js/scm/errors.js',
'js/scm/booleans.js',
'js/scm/numbers.js',
'js/scm/objects.js',
'js/scm/io.js',
'js/scm/procedures.js',
'js/scm/parse.js',
'js/scm/eval.js',
'js/scm/vm.js',
'js/scm/lib.js',
'js/scm/compile.js',
'js/scm/psyntax.js',
'js/ui/console.js',
'js/ui/util.js',
'js/ui/test.js'
]
concat(jsFiles, 'js/tryscheme.js')
devFiles = [
'scripts/build.py',
'scripts/compileTests.py'
]
zipTarget = 'tryscheme-%s.zip' % VERSION
mkzip(miscFiles + jsFiles + devFiles, zipTarget)
# --- path nonsense
def findSource(f):
f_segments = f.split('/')
return joinpath(SRCDIR, *f_segments)
def findTarget(f):
f_segments = f.split('/')
return joinpath(TGTDIR, *f_segments)
def joinDirs(realDir, pseudoRelPath):
segments = pseudoRelPath.split('/')
return joinpath(realDir, *segments)
# --- actions
def mkdir(d):
if not isdir(d):
makedirs(d)
def copies(files, srcSubdir):
if srcSubdir != '':
srcSubdir += '/'
for f in files:
srcf = findSource(srcSubdir + f)
tgtf = findTarget(f)
mkdir(dirname(tgtf))
print "Copying %s to %s..." % (srcf, tgtf),
copyfile(srcf, tgtf)
print "done."
def concat(srcfiles, target):
tgtf = findTarget(target)
print "Creating %s..." % tgtf
mkdir(dirname(tgtf))
outf = open(tgtf, 'wb')
for f in srcfiles:
srcf = findSource(f)
print "Adding %s..." % srcf
f = open(srcf, 'rb')
try:
outf.write(f.read())
finally:
f.close()
print "done."
def mkzip(srcFiles, target):
tgtf = findTarget(target)
print "Creating %s..." % tgtf
mkdir(dirname(tgtf))
z = zipfile.ZipFile(tgtf, 'w', zipfile.ZIP_DEFLATED)
for f in srcFiles:
srcf = findSource(f)
print "Adding %s..." % srcf
z.write(srcf, 'tryscheme-%s/%s' % (VERSION, f))
z.close()
print "done."
def main():
global TGTDIR
from optparse import OptionParser
parser = OptionParser()
parser.add_option("-o", "--output-dir", dest="outputDir",
help="put resulting web pages, etc. in DIR", metavar="DIR")
(options, args) = parser.parse_args()
assert len(args) == 0
if options.outputDir is not None:
TGTDIR = joinpath(options.outputDir)
buildAll()
main()
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.