/[glsr]/trunk/harmonious/server/server.py
Gentoo

Contents of /trunk/harmonious/server/server.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 7 - (show annotations) (download) (as text)
Thu Jun 16 00:41:45 2005 UTC (9 years, 3 months ago) by port001
File MIME type: text/x-python
File size: 3425 byte(s)
Convert Header to Id
1 #!/usr/bin/python
2
3 __id__ = '$Id$'
4 __version__ = '$Revision: $'
5 __modulename__ = 'Harmonious'
6
7 import os
8 import sys
9 import __main__
10 import BaseHTTPServer
11
12 sys.path.insert(0, '/home/port001')
13
14 import harmonious.server.methods
15
16 from harmonious import harm
17 from harmonious._config import Config
18 from harmonious._requestfactory import RequestFactory
19
20 def load_module(module, set_main=False):
21
22 try:
23 module_object = __import__(module, globals(), locals(), [''])
24 except ImportError, e:
25 print >> sys.stderr, "%s: Failed to import module '%s': %s" % (__modulename__, module, e)
26 sys.exit(1)
27
28 if set_main == True:
29
30 setattr(__main__, module_object.__name__, vars(module_object))
31 return None
32
33 else:
34
35 return module_object
36
37 class RequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
38
39 server_version = 'Harmonious/0.1'
40
41 def do_GET(self):
42
43 print "do_GET"
44 harm.request = RequestFactory(self).construct()
45 harmonious.server.methods.get.GET().perform()
46
47 if __name__ == '__main__':
48
49 print "\n%s Starting up...\n" % __modulename__
50
51 print "Reading configuration..."
52
53 harm.config = Config(sys.argv[1])
54
55 print "\nLoading HTTP methods:"
56
57 for key in harmonious.server.methods.__all__.keys():
58
59 try:
60
61 load_module("harmonious.server.methods.%s" % harmonious.server.methods.__all__[key], set_main=True)
62 except ImportError, e:
63
64 print >> sys.stderr, "%s: Failed to load module '%s': %s" % (__modulename__, key, e)
65 sys.exit(1)
66
67 print " %s" % key
68
69 print
70
71 print "Mapping domain modules:"
72
73 def map_domain(arg, path, files):
74
75 if path not in sys.path:
76 sys.path.insert(0, path)
77
78 rel_path = path.split(harm.config.server['DomainPath'])[1]
79
80 if rel_path == '':
81 rel_path = '/'
82 elif rel_path[-1] != '/':
83 rel_path = "%s/" % rel_path
84
85 print rel_path
86
87 for file in files:
88
89 if file.endswith('.py'):
90
91 print " %s" % file[:-3]
92 module_object = load_module(file[:-3], set_main=False)
93
94 try:
95
96 this_module = eval("module_object.%s()" % file[:-3].capitalize())
97 except AttributeError, e:
98
99 print >> sys.stderr, "%s: Malformed domain module '%s': %s" % (__modulename__, file[:-3], e)
100 sys.exit(1)
101
102 if not harm._domain_map.has_key(rel_path):
103
104 harm._domain_map[rel_path] = {}
105
106 harm._domain_map[rel_path][file] = this_module
107
108 del this_module
109 del module_object
110
111 os.path.walk(harm.config.server['DomainPath'], map_domain, None)
112
113 # try:
114 # pid = os.fork()
115 # if pid > 0:
116 # sys.exit(0)
117 # except OSError, e:
118 # print >> sys.stderr, "Failed to fork daemon process: %d '%s'" % (e.errno, e.strerror)
119 # sys.exit(1)
120
121 # os.chdir("/")
122 # os.setsid()
123 # os.umask(0)
124
125 # try:
126 # pid = os.fork()
127 # if pid > 0:
128 # print "PID: %d" % pid
129 # sys.exit(0)
130 # except OSError, e:
131 # print >> sys.stderr, "Failed to fork daemon process: %d '%s'" % (e.errno, e.strerror)
132 # sys.exit(1)
133
134 server = BaseHTTPServer.HTTPServer(('localhost', 8080), RequestHandler)
135 server.serve_forever()
136
137 print "Server Online."

Properties

Name Value
svn:keywords Id

  ViewVC Help
Powered by ViewVC 1.1.20