root/trunk/RBFoundation/RBFoundation/_InstallerHookUtilities.py

Revision 708, 2.6 kB (checked in by sholloway, 5 years ago)

*** empty log message ***

Line 
1 #!/usr/bin/env python
2 ##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3 ##~ License
4 ##~
5 ##- The RuneBlade Foundation library is intended to ease some
6 ##- aspects of writing intricate Jabber, XML, and User Interface (wxPython, etc.)
7 ##- applications, while providing the flexibility to modularly change the
8 ##- architecture. Enjoy.
9 ##~
10 ##~ Copyright (C) 2002  TechGame Networks, LLC.
11 ##~
12 ##~ This library is free software; you can redistribute it and/or
13 ##~ modify it under the terms of the BSD style License as found in the
14 ##~ LICENSE file included with this distribution.
15 ##~
16 ##~ TechGame Networks, LLC can be reached at:
17 ##~ 3578 E. Hartsel Drive #211
18 ##~ Colorado Springs, Colorado, USA, 80920
19 ##~
20 ##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
21
22 """
23 Requires path.py from:
24     Jason Orendorff <jason@jorendorff.com> (and others - see the url!)
25     http://www.jorendorff.com/articles/python/path
26 """
27
28 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
29 #~ Imports
30 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
31
32 import os
33 try:
34     from path import path
35 except ImportError, e:
36     print """Requires path.py from:
37         Jason Orendorff <jason@jorendorff.com> (and others - see the url!)
38         http://www.jorendorff.com/articles/python/path
39     """
40     raise
41
42 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
43 #~ Definitions
44 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
45
46 def PackageFilter(filename):
47     return filename not in ('CVS',)
48
49 def ModuleFilter(filename):
50     return (filename[0]!='_' or filename[1]=='_')
51
52 def MakePackageHook(prefix, file, recurse=True, includefiletypes=('*.py','*.pyw','*.pyc','*.pyo','*.pyd'), packagefilter=PackageFilter, modulefilter=ModuleFilter):
53     def GetPyModules(packagedir):
54         modules = {}
55         for filetype in includefiletypes:
56             for filename in filter(modulefilter, packagedir.files(filetype)):
57                 modules[filename.splitext()[0].name] = True
58
59         if recurse:
60             for dirname in filter(packagefilter, packagedir.dirs()):
61                 for result in GetPyModules(dirname):
62                     modules['%s.%s'%(dirname.name, result)] = True
63         return modules.keys()
64
65     packagedir = path(file)
66     if packagedir.isfile():
67         packagedir = packagedir.splitpath()[0]
68     modules = {}
69     for result in GetPyModules(packagedir):
70         modules['%s.%s'%(prefix, result)] = True
71     return map(str, modules.keys())
72
73 def MakePackageHookVerbose(*args, **kw):
74     print "Hidden imports:"
75     hiddenimports = MakePackageHook(*args, **kw)
76     for each in hiddenimports:
77         print "    \"%s\"" % each
78     return hiddenimports
79
Note: See TracBrowser for help on using the browser.