1
2
3 """
4 Drupy CGI and CLI execution script.
5
6 @package base
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-01-10
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 time
39 import re
40 import sys
41 from lib.drupy import DrupyPHP as php
42 from lib.drupy import DrupyImport
43 from includes import bootstrap as lib_bootstrap
44 from includes import database as lib_database
45 from includes import plugin as lib_plugin
46 from includes import theme as lib_theme
47
48
49 phases = (
50 (lib_bootstrap.DRUPAL_BOOTSTRAP_CONFIGURATION, \
51 'DRUPAL_BOOTSTRAP_CONFIGURATION'),
52 (lib_bootstrap.DRUPAL_BOOTSTRAP_EARLY_PAGE_CACHE, \
53 'DRUPAL_BOOTSTRAP_EARLY_PAGE_CACHE'),
54 (lib_bootstrap.DRUPAL_BOOTSTRAP_DATABASE, \
55 'DRUPAL_BOOTSTRAP_DATABASE'),
56 (lib_bootstrap.DRUPAL_BOOTSTRAP_ACCESS, \
57 'DRUPAL_BOOTSTRAP_ACCESS'),
58 (lib_bootstrap.DRUPAL_BOOTSTRAP_SESSION, \
59 'DRUPAL_BOOTSTRAP_SESSION'),
60 (lib_bootstrap.DRUPAL_BOOTSTRAP_LATE_PAGE_CACHE, \
61 'DRUPAL_BOOTSTRAP_LATE_PAGE_CACHE'),
62 (lib_bootstrap.DRUPAL_BOOTSTRAP_LANGUAGE, \
63 'DRUPAL_BOOTSTRAP_LANGUAGE'),
64 (lib_bootstrap.DRUPAL_BOOTSTRAP_PATH, \
65 'DRUPAL_BOOTSTRAP_PATH'),
66 (lib_bootstrap.DRUPAL_BOOTSTRAP_FULL, \
67 'DRUPAL_BOOTSTRAP_FULL')
68 );
69
70 which_phase = phases[8];
71 lib_bootstrap.drupal_bootstrap(which_phase[0]);
72 stamp, revised = time.strftime("%c GMT||%m/%d/%Y", time.gmtime()).split('||')
73
74 out_plugins = php.print_r(lib_plugin.plugins, True)
75 out_plugins_html = php.htmlspecialchars(out_plugins)
76
77 out_themes = php.print_r(lib_theme.processors, True)
78 out_themes_html = php.htmlspecialchars(out_themes)
79
80 out_users = php.print_r(lib_database.query(\
81 'SELECT * FROM users WHERE users.uid > 0'), True)
82 out_users_html = php.htmlspecialchars(out_users)
83
84 out_vars = php.print_r(vars(), True)
85 out_vars = re.sub('[a-zA-Z0-9_\.-]+@.+?\.[a-zA-Z]+', '********', out_vars)
86 out_vars = re.sub('[a-zA-Z0-9]{32}', \
87 '********************************', out_vars)
88 out_vars = php.htmlspecialchars(out_vars)
89
90 out_mods = php.print_r(DrupyImport.modules(), True)
91 out_mods = php.htmlspecialchars(out_mods)
92
93
94
95
96 if php.SERVER['WEB']:
97 print "<?xml version='1.0' encoding='UTF-8'?>"
98 print "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' " + \
99 "'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>"
100 print "<html xmlns='http://www.w3.org/1999/xhtml'>"
101 print "<head>"
102 print "<title>Drupy: Drupal in Python</title>"
103 print "<meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />"
104 print "<meta name='revised' content='DrupyStatus, %s' />" % revised
105 print "</head>"
106 print "<body>"
107 print "<h1>Drupy Bootstrap Diagnostic Status</h1>"
108 print "<h2>Bootstrap: Completed Phase '%s' (%s)</h2>" % \
109 (which_phase[1],which_phase[0])
110 print "<h3>Generated: %s</h3>" % stamp
111 print "<h4 style='color:blue;'>"
112 print "The following Drupy plugins are loaded. "
113 print "A Drupy plugin is the equivalent of a Drupal module."
114 print "</h4>"
115 print "<pre style='background-color:yellow;'>%s</pre>" % out_plugins_html
116 print "<h4 style='color:blue;'>"
117 print "The following theme processors are loaded. "
118 print "drupytemplate is the equivalent of Drupal's phptemplate"
119 print "</h4>"
120 print "<pre style='background-color:yellow;'>%s</pre>" % out_themes_html
121 print "<h4 style='color:blue;'>"
122 print "The following Drupy users are registered. "
123 print "</h4>"
124 print "<pre style='background-color:yellow;'>%s</pre>" % out_users_html
125 print "<h4 style='color:blue;'>Global Scope Objects</h4>"
126 print "<pre style='background-color:yellow;'>%s</pre>" % out_vars
127 print "<h4 style='color:blue;'>Loaded Python Modules</h4>"
128 print "<pre style='background-color:yellow;'>%s</pre>" % out_mods
129 print "</body>"
130 print "</html>"
131
132
133
134 else:
135 print "Drupy Bootstrap Diagnostic Status"
136 print "Bootstrap: Completed Phase '%s' (%s)" % \
137 (which_phase[1],which_phase[0])
138 print "Generated: %s" % stamp
139 print
140 print "The following Drupy plugins are loaded."
141 print "A Drupy plugin is the equivalent of a Drupal plugin"
142 print
143 print out_plugins
144 print
145 print "The following Drupy theme processors are loaded."
146 print "drupytemplate is the equivalent of Drupal's phptemplate"
147 print
148 print out_themes
149 print
150 print "You may now query any Drupal Bootstrap object."
151 print
152
153
154
155
156 php.flush()
157