]> jfr.im git - irc/quakenet/qwebirc.git/commitdiff
Add (forced) dependency checking.
authorChris Porter <redacted>
Wed, 3 Jun 2009 22:40:06 +0000 (23:40 +0100)
committerChris Porter <redacted>
Wed, 3 Jun 2009 22:40:06 +0000 (23:40 +0100)
.hgignore
bin/compile.py
bin/dependencies.py [new file with mode: 0644]
bin/dependencies_b.py [new file with mode: 0644]
clean.py
run.py

index d93c407884409050d29d16dc41186749ce5ea0a6..26ddb70dc9d1cf789ce424df50e93e281bc9a815 100644 (file)
--- a/.hgignore
+++ b/.hgignore
@@ -14,3 +14,5 @@ defargs.conf
 Thumbs.db
 [dD]esktop.ini
 static/{ugly,swm,mocha,q}ui{,debug}.html
+{bin/,}.checked
+{bin/,}.compiled
index b383e7dbb21d0dce0331defe22b284517e9c71fe..bde88c057926ee94dfb61d5ce07082a2bb599740 100644 (file)
@@ -1,4 +1,7 @@
 #!/usr/bin/env python
+import dependencies
+dependencies.vcheck()
+
 import pages, os, subprocess, pagegen, shutil, sys
 
 COPYRIGHT = open("js/copyright.js", "rb").read()
@@ -92,6 +95,33 @@ def main(outputdir=".", produce_debug=True):
     
   os.rmdir(coutputdir)
   
+  f = open(".compiled", "w")
+  f.close()
+  
+def has_compiled():
+  try:
+    f = open(".compiled", "r")
+    f.close()
+    return True
+  except:
+    pass
+    
+  try:
+    f = open(os.path.join("bin", ".compiled"), "r")
+    f.close()
+    return True
+  except:
+    pass
+  
+  return False
+  
+def vcheck():
+  if has_compiled():
+    return
+    
+  print >>sys.stderr, "error: not yet compiled, run compile.py first."
+  sys.exit(1)
+  
 if __name__ == "__main__":
   main()
   
\ No newline at end of file
diff --git a/bin/dependencies.py b/bin/dependencies.py
new file mode 100644 (file)
index 0000000..b04811d
--- /dev/null
@@ -0,0 +1,45 @@
+import sys\r
+\r
+def check_dependencies():\r
+  def fail(message):\r
+    sys.stderr.write(message + "\n")\r
+    sys.stderr.flush()\r
+    sys.exit(1)\r
+    \r
+  major, minor = sys.version_info[:2]\r
+  if major >= 3:\r
+    fail("qwebirc cannot run on python >=3 yet, install python 2.6.X:\nhttp://www.python.org/download/")\r
+    \r
+  if major < 2 or minor < 5:\r
+    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])))\r
+       \r
+  # this is done so we can use Python 2.5 syntax...\r
+  import dependencies_b\r
+  dependencies_b.check_dependencies()\r
+\r
+def has_checked():\r
+  try:\r
+    f = open(".checked", "r")\r
+    f.close()\r
+    return True\r
+  except:\r
+    pass\r
+    \r
+  try:\r
+    f = open(os.path.join("bin", ".checked"), "r")\r
+    f.close()\r
+    return True\r
+  except:\r
+    pass\r
+  \r
+  return False\r
+  \r
+def vcheck():\r
+  if not has_checked():\r
+    sys.stderr.write("first run, checking dependencies...\n")\r
+    sys.stderr.flush()\r
+    check_dependencies()\r
+\r
+if __name__ == "__main__":\r
+  check_dependencies()\r
+  
\ No newline at end of file
diff --git a/bin/dependencies_b.py b/bin/dependencies_b.py
new file mode 100644 (file)
index 0000000..3ea7c4b
--- /dev/null
@@ -0,0 +1,105 @@
+# this is seperate to allow us to use python 2.5 syntax without\r
+# the dependency checker breaking on earlier versions.\r
+\r
+import sys\r
+import subprocess\r
+\r
+def fail(*message):\r
+  print >>sys.stderr, "\n".join(message)\r
+  sys.exit(1)\r
+  \r
+def warn(*message):\r
+  print >>sys.stderr, "warning:", "\nwarning: ".join(message), "\n"\r
+\r
+def check_dependencies():\r
+  i = 0\r
+  \r
+  check_twisted()\r
+  check_win32()\r
+  i+=check_java()\r
+  i+=check_hg()\r
+  \r
+  print "0 errors, %d warnings." % i\r
+  \r
+  if i == 0:\r
+    print "looks like you've got everything you need to run qwebirc!"\r
+  else:\r
+    print "you can run qwebirc despite these."\r
+\r
+  f = open(".checked", "w")\r
+  f.close()\r
+  \r
+def check_win32():\r
+  if not sys.platform.startswith("win"):\r
+    return\r
+  \r
+  try:\r
+    import win32con\r
+  except ImportError:\r
+    fail("qwebirc requires pywin32, see:", "http://sourceforge.net/project/showfiles.php?group_id=78018")\r
+  \r
+def check_java():\r
+  def java_warn(specific):\r
+    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/")\r
+    \r
+  try:\r
+    p = subprocess.Popen(["java", "-version"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)\r
+    p.communicate()\r
+    if p.wait() != 0:\r
+      java_warn("something went wrong looking for java.")\r
+      return 1\r
+  except WindowsError:\r
+    java_warn("couldn't find java.")\r
+    return 1\r
+    \r
+  return 0\r
+  \r
+def check_hg():\r
+  def hg_warn(specific):\r
+    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/")\r
+    \r
+  try:\r
+    p = subprocess.Popen(["hg", "id"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)\r
+    p.communicate()\r
+    if p.wait() != 0:\r
+      hg_warn("something went wrong looking for mercurial.")\r
+      return 1\r
+  except WindowsError:\r
+    hg_warn("couldn't find mercurial.")\r
+    return 1\r
+    \r
+  return 0\r
+  \r
+def check_twisted():\r
+  try:\r
+    import twisted\r
+  except ImportError:\r
+    fail("qwebirc requires twisted (at least 8.2.0), see http://twistedmatrix.com/")\r
+\r
+  twisted_fail = lambda x, y=None: fail("you don't seem to have twisted's %s module." % x,\r
+                                        "your distro is most likely modular, look for a twisted web package%s." % (" %s" % y if y else "",))\r
+\r
+  try:\r
+    import twisted.names\r
+  except ImportError:\r
+    twisted_fail("names")\r
+\r
+  try:\r
+    import twisted.mail\r
+  except ImportError:\r
+    twisted_fail("mail")\r
+    fail("you don't seem to have twisted's mail module, your distro is most likely modular, look for a twisted mail package.")\r
+\r
+  try:\r
+    import twisted.web\r
+  except ImportError:\r
+    twisted_fail("web", "(not web2)")\r
+\r
+  try:\r
+    import twisted.words\r
+  except ImportError:\r
+    twistedfail("words")\r
+\r
+if __name__ == "__main__":\r
+  import dependencies\r
+  dependencies.check_dependencies()\r
index 9f309e5608769eddd3d71e1969749eed1f472265..6722d4258d6a38fff9110c6c8d4c020439df70d5 100755 (executable)
--- a/clean.py
+++ b/clean.py
@@ -11,7 +11,11 @@ for x in pages.UIs:
   tryunlink("static", "css", x + ".css")
   tryunlink("static", "%s.html" % x)
   tryunlink("static", "%sdebug.html" % x)  
-
+  tryunlink(".checked")
+  tryunlink(".compiled")
+  tryunlink("bin", ".checked")
+  tryunlink("bin", ".compiled")
+  
 if __name__ == "__main__":
   tryunlink("static", "js", "qwebirc.js")
   cleanpyc.main()
diff --git a/run.py b/run.py
index 8011d56ae32fcf7d07f82d3d7792466910bd6819..c5851327cf45e537232d5e8ae74e851d4b92f35c 100755 (executable)
--- a/run.py
+++ b/run.py
@@ -1,5 +1,8 @@
 #!/usr/bin/env python
 # this entire thing is a hack and badly needs reimplementing
+import bin.compile
+bin.compile.vcheck()
+
 DEFAULT_PORT = 9090
 
 from twisted.scripts.twistd import run