Skip to content

Commit 8f27650

Browse files
committed
Add (forced) dependency checking.
1 parent 8da798f commit 8f27650

File tree

6 files changed

+190
-1
lines changed

6 files changed

+190
-1
lines changed

.hgignore

+2
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,5 @@ defargs.conf
1414
Thumbs.db
1515
[dD]esktop.ini
1616
static/{ugly,swm,mocha,q}ui{,debug}.html
17+
{bin/,}.checked
18+
{bin/,}.compiled

bin/compile.py

+30
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
#!/usr/bin/env python
2+
import dependencies
3+
dependencies.vcheck()
4+
25
import pages, os, subprocess, pagegen, shutil, sys
36

47
COPYRIGHT = open("js/copyright.js", "rb").read()
@@ -92,6 +95,33 @@ def main(outputdir=".", produce_debug=True):
9295

9396
os.rmdir(coutputdir)
9497

98+
f = open(".compiled", "w")
99+
f.close()
100+
101+
def has_compiled():
102+
try:
103+
f = open(".compiled", "r")
104+
f.close()
105+
return True
106+
except:
107+
pass
108+
109+
try:
110+
f = open(os.path.join("bin", ".compiled"), "r")
111+
f.close()
112+
return True
113+
except:
114+
pass
115+
116+
return False
117+
118+
def vcheck():
119+
if has_compiled():
120+
return
121+
122+
print >>sys.stderr, "error: not yet compiled, run compile.py first."
123+
sys.exit(1)
124+
95125
if __name__ == "__main__":
96126
main()
97127

bin/dependencies.py

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import sys
2+
3+
def check_dependencies():
4+
def fail(message):
5+
sys.stderr.write(message + "\n")
6+
sys.stderr.flush()
7+
sys.exit(1)
8+
9+
major, minor = sys.version_info[:2]
10+
if major >= 3:
11+
fail("qwebirc cannot run on python >=3 yet, install python 2.6.X:\nhttp://www.python.org/download/")
12+
13+
if major < 2 or minor < 5:
14+
fail("qwebirc requires python 2.5, you have: %s, install python 2.6.X:\nhttp://www.python.org/download/" % ".".join(map(str, sys.version_info[:3])))
15+
16+
# this is done so we can use Python 2.5 syntax...
17+
import dependencies_b
18+
dependencies_b.check_dependencies()
19+
20+
def has_checked():
21+
try:
22+
f = open(".checked", "r")
23+
f.close()
24+
return True
25+
except:
26+
pass
27+
28+
try:
29+
f = open(os.path.join("bin", ".checked"), "r")
30+
f.close()
31+
return True
32+
except:
33+
pass
34+
35+
return False
36+
37+
def vcheck():
38+
if not has_checked():
39+
sys.stderr.write("first run, checking dependencies...\n")
40+
sys.stderr.flush()
41+
check_dependencies()
42+
43+
if __name__ == "__main__":
44+
check_dependencies()
45+

bin/dependencies_b.py

+105
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
# this is seperate to allow us to use python 2.5 syntax without
2+
# the dependency checker breaking on earlier versions.
3+
4+
import sys
5+
import subprocess
6+
7+
def fail(*message):
8+
print >>sys.stderr, "\n".join(message)
9+
sys.exit(1)
10+
11+
def warn(*message):
12+
print >>sys.stderr, "warning:", "\nwarning: ".join(message), "\n"
13+
14+
def check_dependencies():
15+
i = 0
16+
17+
check_twisted()
18+
check_win32()
19+
i+=check_java()
20+
i+=check_hg()
21+
22+
print "0 errors, %d warnings." % i
23+
24+
if i == 0:
25+
print "looks like you've got everything you need to run qwebirc!"
26+
else:
27+
print "you can run qwebirc despite these."
28+
29+
f = open(".checked", "w")
30+
f.close()
31+
32+
def check_win32():
33+
if not sys.platform.startswith("win"):
34+
return
35+
36+
try:
37+
import win32con
38+
except ImportError:
39+
fail("qwebirc requires pywin32, see:", "http://sourceforge.net/project/showfiles.php?group_id=78018")
40+
41+
def check_java():
42+
def java_warn(specific):
43+
warn(specific, "java is not required, but allows qwebirc to compress output,", "making it faster to download.", "you can get java at http://www.java.com/")
44+
45+
try:
46+
p = subprocess.Popen(["java", "-version"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
47+
p.communicate()
48+
if p.wait() != 0:
49+
java_warn("something went wrong looking for java.")
50+
return 1
51+
except WindowsError:
52+
java_warn("couldn't find java.")
53+
return 1
54+
55+
return 0
56+
57+
def check_hg():
58+
def hg_warn(specific):
59+
warn(specific, "mercurial (hg) is not required, but allows qwebirc to save bandwidth by versioning.", "you can get hg at http://www.selenic.com/mercurial/")
60+
61+
try:
62+
p = subprocess.Popen(["hg", "id"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
63+
p.communicate()
64+
if p.wait() != 0:
65+
hg_warn("something went wrong looking for mercurial.")
66+
return 1
67+
except WindowsError:
68+
hg_warn("couldn't find mercurial.")
69+
return 1
70+
71+
return 0
72+
73+
def check_twisted():
74+
try:
75+
import twisted
76+
except ImportError:
77+
fail("qwebirc requires twisted (at least 8.2.0), see http://twistedmatrix.com/")
78+
79+
twisted_fail = lambda x, y=None: fail("you don't seem to have twisted's %s module." % x,
80+
"your distro is most likely modular, look for a twisted web package%s." % (" %s" % y if y else "",))
81+
82+
try:
83+
import twisted.names
84+
except ImportError:
85+
twisted_fail("names")
86+
87+
try:
88+
import twisted.mail
89+
except ImportError:
90+
twisted_fail("mail")
91+
fail("you don't seem to have twisted's mail module, your distro is most likely modular, look for a twisted mail package.")
92+
93+
try:
94+
import twisted.web
95+
except ImportError:
96+
twisted_fail("web", "(not web2)")
97+
98+
try:
99+
import twisted.words
100+
except ImportError:
101+
twistedfail("words")
102+
103+
if __name__ == "__main__":
104+
import dependencies
105+
dependencies.check_dependencies()

clean.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@
1111
tryunlink("static", "css", x + ".css")
1212
tryunlink("static", "%s.html" % x)
1313
tryunlink("static", "%sdebug.html" % x)
14-
14+
tryunlink(".checked")
15+
tryunlink(".compiled")
16+
tryunlink("bin", ".checked")
17+
tryunlink("bin", ".compiled")
18+
1519
if __name__ == "__main__":
1620
tryunlink("static", "js", "qwebirc.js")
1721
cleanpyc.main()

run.py

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#!/usr/bin/env python
22
# this entire thing is a hack and badly needs reimplementing
3+
import bin.compile
4+
bin.compile.vcheck()
5+
36
DEFAULT_PORT = 9090
47

58
from twisted.scripts.twistd import run

0 commit comments

Comments
 (0)