1
2
3 """
4 Dynamic import functions.
5
6 @package drupy
7 @see <a href='http://drupy.net'>Drupy Homepage</a>
8 @see <a href='http://drupal.org'>Drupal Homepage</a>
9 @note Drupy is a port of the Drupal project.
10 @author Brendon Crawford
11 @copyright 2008 Brendon Crawford
12 @contact message144 at users dot sourceforge dot net
13 @created 2008-06-27
14 @version 0.1
15 @note License:
16
17 This program is free software; you can redistribute it and/or
18 modify it under the terms of the GNU General Public License
19 as published by the Free Software Foundation; either version 2
20 of the License, or (at your option) any later version.
21
22 This program is distributed in the hope that it will be useful,
23 but WITHOUT ANY WARRANTY; without even the implied warranty of
24 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 GNU General Public License for more details.
26
27 You should have received a copy of the GNU General Public License
28 along with this program; if not, write to:
29
30 The Free Software Foundation, Inc.,
31 51 Franklin Street, Fifth Floor,
32 Boston, MA 02110-1301,
33 USA
34 """
35
36 __version__ = "$Revision: 1 $"
37
38 import os
39 import cgi
40 import cgitb
41 import sys
42
43
45 """
46 Converts a filename to import path
47 @param filename
48 @return Str
49 """
50 name = filename.replace('/', '.')
51 if name[-3:] == '.py':
52 name = name[:-3]
53 mod = __import__(name, globals(), locals(), ['*'], -1)
54 return mod
55
56
58 """
59 Gets fiunction object from plugin
60
61 @param plugin_ Module
62 @param function_ Str
63 @return Function
64 """
65 return getattr(plugin_, function_)
66
67
68
70 """
71 Checks for existance of drupy plugin
72
73 @param filename Str
74 @return Bool
75 """
76 return os.path.exists('%s/__init__.py' % filename)
77
78
80 """
81 Get loaded modules
82 @return List
83 """
84 mods = sys.modules
85 out = {}
86 for k,v in mods.items():
87 if v is not None:
88 out[k] = v
89 return out
90