]> jfr.im git - irc/quakenet/qwebirc.git/blame - bin/mkstatic.py
hg -> git
[irc/quakenet/qwebirc.git] / bin / mkstatic.py
CommitLineData
01a3d0e1
CP
1#!/usr/bin/env python
2import compile, pages, sys, os, shutil, compileall
3
4def trymkdir(*dir):
5 try:
6 os.mkdir(os.path.join(*dir))
7 except:
8 pass
9
10def copywalk(src, dest, visitor):
11 for root, dirs, files in os.walk(src):
ed6e8651
CP
12 if ".git" in dirs:
13 dirs.remove(".git")
01a3d0e1
CP
14
15 newdir = os.path.join(dest, root)
16 if not os.path.exists(newdir):
17 os.mkdir(newdir)
18 for file in files:
19 if not visitor(file):
20 continue
21
22 destfile = os.path.join(dest, root, file)
23 dir, _ = os.path.split(destfile)
24 if not os.path.exists(dir):
25 os.mkdir(dir)
26 shutil.copy2(os.path.join(root, file), destfile)
27
28def copypydir(src, dest):
29 copywalk(src, dest, lambda file: os.path.splitext(file)[1] == ".py")
30
31def copypycdir(src, dest):
32 copywalk(src, dest, lambda file: os.path.splitext(file)[1] == ".py")
33
34def copydir(src, dest):
35 copywalk(src, dest, lambda file: os.path.splitext(file)[1] != ".pyc")
36
15295989
CP
37def copy(src, dest, nojoin=0):
38 if not nojoin:
39 dest = os.path.join(dest, src)
40 shutil.copy2(src, dest)
01a3d0e1
CP
41
42def compile_python(dest):
43 compileall.compile_dir(dest, quiet=1, force=1)
44
45def remove_python(dest, ignore=[]):
46 ignore = set(ignore)
47 for root, dirs, files in os.walk(dest):
48 for file in files:
49 if file in ignore:
50 continue
51 if os.path.splitext(file)[1] == ".py":
52 rfile = os.path.join(root, file)
53 os.unlink(rfile)
54
55def main():
56 if len(sys.argv) < 2:
57 print >>sys.stderr, "syntax: %s [destination directory]" % sys.argv[0]
58 sys.exit(0)
59 DEST = sys.argv[1]
60
61 trymkdir(DEST)
62 trymkdir(DEST, "static")
63 trymkdir(DEST, "static", "js")
64
60ce7bee 65 compile.main(DEST, produce_debug=False)
01a3d0e1 66
becfa850 67 for x in "authgate qwebirc esimplejson twisted".split(" "):
01a3d0e1 68 copypydir(x, DEST)
60ce7bee 69 for x in "images panes sound".split(" "):
01a3d0e1 70 copydir(os.path.join("static", x), DEST)
60ce7bee
CP
71 for x in pages.JS_EXTRA:
72 copy(os.path.join("static", "js", x + ".js"), DEST)
01a3d0e1
CP
73
74 for x in pages.UIs.values():
60ce7bee 75 e = x.get("extrajs")
01a3d0e1
CP
76 if e is None:
77 continue
78 for x2 in e:
79 file = os.path.join("static", "js", "%s.js" % x2)
80 destfile = os.path.join(DEST, file)
81 dir, _ = os.path.split(destfile)
82 if not os.path.exists(dir):
83 os.mkdir(dir)
84 copy(file, DEST)
60ce7bee 85
01a3d0e1
CP
86 copy(os.path.join("static/favicon.ico"), DEST)
87
88 if 0:
89 compile_python(DEST)
90 remove_python(DEST)
91 else:
15295989 92 copy(os.path.join("bin", "cleanpyc.py"), os.path.join(DEST, "cleanpyc.py"), nojoin=1)
01a3d0e1
CP
93
94 copy("run.py", DEST)
95 copy("config.py.example", DEST)
96
97 if os.path.exists("config.py"):
98 print "NOT copying current config.py!"
99 #copy("config.py", DEST)
100
101if __name__ == "__main__":
102 main()
ed6e8651 103