]> git.openstreetmap.org Git - osqa.git/blob - forum/management/commands/checkinstall.py
Make RequestHolder thread-safe
[osqa.git] / forum / management / commands / checkinstall.py
1 import re
2 import sys, traceback
3 from django.core.management.base import NoArgsCommand
4
5 OK_MESSAGE = "  Found %(what)s version %(version)s - OK"
6
7 OLD_VERSION_ERROR = """  ERROR: Found %(what)s version %(version)s - you should upgrade it to at least %(minimum)s.
8                 Package installers like apt-get or yum usually maintain old versions of libraries in the repositories."""
9
10 NOT_FOUND_ERROR = "ERROR: %(what)s was not found on your system."
11
12 HOW_TO_INSTALL = """  Try easy_install %(what)s or download it from %(where)s"""
13
14 IMPORT_ERROR_MESSAGE = """Importing %(what)s is throwing an exception. Here's the full stack trace:"""
15
16 class Command(NoArgsCommand):
17     def handle_noargs(self, **options):
18         print "Checking dependencies:"
19
20         try:
21             import html5lib
22             print "  Found html5lib - OK"
23         except ImportError:
24             print NOT_FOUND_ERROR % dict(what='html5lib')
25             print HOW_TO_INSTALL % dict(what='html5lib', where='http://code.google.com/p/html5lib/')
26         except Exception, e:
27             print IMPORT_ERROR_MESSAGE % dict(what='html5lib')
28             traceback.print_exc(file=sys.stdout)
29
30         try:
31             import markdown
32             version = int(re.findall('^\d+', markdown.version)[0])
33             if version < 2:
34                 print OLD_VERSION_ERROR % dict(what='markdown', version=markdown.version, minimum='2.0')
35                 print HOW_TO_INSTALL % dict(what='markdown', where='http://www.freewisdom.org/projects/python-markdown/')
36             else:
37                 print OK_MESSAGE % dict(what='markdown', version=markdown.version)
38         except ImportError:
39             print NOT_FOUND_ERROR % dict(what='markdown')
40             print HOW_TO_INSTALL % dict(what='markdown', where='http://www.freewisdom.org/projects/python-markdown/')
41         except Exception, e:
42             print IMPORT_ERROR_MESSAGE % dict(what='markdown')
43             traceback.print_exc(file=sys.stdout)
44
45         try:
46             import south
47             version = re.findall('\d+', south.__version__)
48
49             if int(version[1]) < 6 and int(version[0]) == 0:
50                 print OLD_VERSION_ERROR % dict(what='south', version=south.__version__, minimum='0.6')
51                 print HOW_TO_INSTALL % dict(what='south', where='http://south.aeracode.org/')
52             else:
53                 print OK_MESSAGE % dict(what='south', version=south.__version__)
54
55
56         except ImportError:
57             print NOT_FOUND_ERROR % dict(what='south')
58             print HOW_TO_INSTALL % dict(what='south', where='http://south.aeracode.org/')
59         except Exception, e:
60             print IMPORT_ERROR_MESSAGE % dict(what='south')
61             traceback.print_exc(file=sys.stdout)
62
63
64         print "\n\nChecking database connection:"
65
66         try:
67             from forum.models import User
68             User.objects.all().count()
69             print "  Connection OK"
70         except Exception, e:
71             print "There seems to be a problem with your database: %s" % str(e)
72
73
74
75         from django.conf import settings
76
77         print "\n\nChecking important settings:"
78
79         if not re.match('^https?:\/\/\w+', settings.APP_URL):
80             print " Your APP_URL does not seem to be a valid url. Please fill this setting with the URL of your OSQA installation"
81         else:
82             print " APP_URL - %s" % settings.APP_URL
83             print " APP_BASE_URL - %s" % settings.APP_BASE_URL
84
85