1 | #!/usr/bin/env python |
---|
2 | |
---|
3 | """ |
---|
4 | This file is part of the web2py Web Framework |
---|
5 | Copyrighted by Massimo Di Pierro <mdipierro@cs.depaul.edu> |
---|
6 | License: LGPLv3 (http://www.gnu.org/licenses/lgpl.html) |
---|
7 | |
---|
8 | This file is not strictly required by web2py. It is used for three purposes: |
---|
9 | |
---|
10 | 1) check that all required modules are installed properly |
---|
11 | 2) provide py2exe and py2app a list of modules to be packaged in the binary |
---|
12 | 3) (optional) preload modules in memory to speed up http responses |
---|
13 | |
---|
14 | """ |
---|
15 | |
---|
16 | import os |
---|
17 | import sys |
---|
18 | |
---|
19 | base_modules = ['aifc', 'anydbm', 'array', 'asynchat', 'asyncore', 'atexit', |
---|
20 | 'audioop', 'base64', 'BaseHTTPServer', 'Bastion', 'binascii', |
---|
21 | 'binhex', 'bisect', 'bz2', 'calendar', 'cgi', 'CGIHTTPServer', |
---|
22 | 'cgitb', 'chunk', 'cmath', 'cmd', 'code', 'codecs', 'codeop', |
---|
23 | 'collections', 'colorsys', 'compileall', 'compiler', |
---|
24 | 'compiler.ast', 'compiler.visitor', 'ConfigParser', |
---|
25 | 'contextlib', 'Cookie', 'cookielib', 'copy', 'copy_reg', |
---|
26 | 'collections', |
---|
27 | 'cPickle', 'cProfile', 'cStringIO', 'csv', 'ctypes', |
---|
28 | 'datetime', 'decimal', 'difflib', 'dircache', 'dis', |
---|
29 | 'doctest', 'DocXMLRPCServer', 'dumbdbm', 'dummy_thread', |
---|
30 | 'dummy_threading', 'email', 'email.charset', 'email.encoders', |
---|
31 | 'email.errors', 'email.generator', 'email.header', |
---|
32 | 'email.iterators', 'email.message', 'email.mime', |
---|
33 | 'email.mime.audio', 'email.mime.base', 'email.mime.image', |
---|
34 | 'email.mime.message', 'email.mime.multipart', |
---|
35 | 'email.mime.nonmultipart', 'email.mime.text', 'email.parser', |
---|
36 | 'email.utils', 'encodings.idna', 'errno', 'exceptions', |
---|
37 | 'filecmp', 'fileinput', 'fnmatch', 'formatter', 'fpformat', |
---|
38 | 'ftplib', 'functools', 'gc', 'getopt', 'getpass', 'gettext', |
---|
39 | 'glob', 'gzip', 'hashlib', 'heapq', 'hmac', 'hotshot', |
---|
40 | 'hotshot.stats', 'htmlentitydefs', 'htmllib', 'HTMLParser', |
---|
41 | 'httplib', 'imaplib', 'imghdr', 'imp', 'inspect', |
---|
42 | 'itertools', 'keyword', 'linecache', 'locale', 'logging', |
---|
43 | 'macpath', 'mailbox', 'mailcap', 'marshal', 'math', |
---|
44 | 'mimetools', 'mimetypes', 'mmap', 'modulefinder', 'mutex', |
---|
45 | 'netrc', 'new', 'nntplib', 'operator', 'optparse', 'os', |
---|
46 | 'parser', 'pdb', 'pickle', 'pickletools', 'pkgutil', |
---|
47 | 'platform', 'poplib', 'pprint', 'py_compile', 'pyclbr', |
---|
48 | 'pydoc', 'Queue', 'quopri', 'random', 're', 'repr', |
---|
49 | 'rexec', 'rfc822', 'rlcompleter', 'robotparser', 'runpy', |
---|
50 | 'sched', 'select', 'sgmllib', 'shelve', |
---|
51 | 'shlex', 'shutil', 'signal', 'SimpleHTTPServer', |
---|
52 | 'SimpleXMLRPCServer', 'site', 'smtpd', 'smtplib', |
---|
53 | 'sndhdr', 'socket', 'SocketServer', 'sqlite3', |
---|
54 | 'stat', 'statvfs', 'string', 'StringIO', |
---|
55 | 'stringprep', 'struct', 'subprocess', 'sunau', 'symbol', |
---|
56 | 'tabnanny', 'tarfile', 'telnetlib', 'tempfile', 'textwrap', 'thread', 'threading', |
---|
57 | 'time', 'timeit', 'Tix', 'Tkinter', 'token', |
---|
58 | 'tokenize', 'trace', 'traceback', 'types', |
---|
59 | 'unicodedata', 'unittest', 'urllib', 'urllib2', |
---|
60 | 'urlparse', 'user', 'UserDict', 'UserList', 'UserString', |
---|
61 | 'uu', 'uuid', 'warnings', 'wave', 'weakref', 'webbrowser', |
---|
62 | 'whichdb', 'wsgiref', 'wsgiref.handlers', 'wsgiref.headers', |
---|
63 | 'wsgiref.simple_server', 'wsgiref.util', 'wsgiref.validate', |
---|
64 | 'xdrlib', 'xml.dom', 'xml.dom.minidom', 'xml.dom.pulldom', |
---|
65 | 'xml.etree.ElementTree', 'xml.parsers.expat', 'xml.sax', |
---|
66 | 'xml.sax.handler', 'xml.sax.saxutils', 'xml.sax.xmlreader', |
---|
67 | 'xmlrpclib', 'zipfile', 'zipimport', 'zlib', 'mhlib', |
---|
68 | 'MimeWriter', 'mimify', 'multifile', 'sets'] |
---|
69 | |
---|
70 | contributed_modules = [] |
---|
71 | |
---|
72 | # Python base version |
---|
73 | python_version = sys.version[:3] |
---|
74 | |
---|
75 | # Modules which we want to raise an Exception if they are missing |
---|
76 | alert_dependency = ['hashlib', 'uuid'] |
---|
77 | |
---|
78 | # Now we remove the blacklisted modules if we are using the stated |
---|
79 | # python version. |
---|
80 | # |
---|
81 | # List of modules deprecated in Python 2.7 that are in the above list |
---|
82 | py27_deprecated = ['mhlib', 'multifile', 'mimify', 'sets', 'MimeWriter'] # And ['optparse'] but we need it for now |
---|
83 | |
---|
84 | if python_version >= '2.7': |
---|
85 | base_modules += ['argparse', 'json', 'multiprocessing'] |
---|
86 | base_modules = list(set(base_modules).difference(set(py27_deprecated))) |
---|
87 | |
---|
88 | # Now iterate in the base_modules, trying to do the import |
---|
89 | for module in base_modules + contributed_modules: |
---|
90 | try: |
---|
91 | __import__(module, globals(), locals(), []) |
---|
92 | except: |
---|
93 | # Raise an exception if the current module is a dependency |
---|
94 | if module in alert_dependency: |
---|
95 | msg = "Missing dependency: %(module)s\n" % locals() |
---|
96 | msg += "Try the following command: " |
---|
97 | msg += "easy_install-%(python_version)s -U %(module)s" % locals() |
---|
98 | raise ImportError(msg) |
---|