/[shmookey]/portconf/update-install.py


UCC Code Repository

Contents of /portconf/update-install.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 120 - (show annotations) (download) (as text)
Thu Jun 5 07:30:56 2008 UTC (12 years, 5 months ago) by shmookey
File MIME type: text/x-python
File size: 2744 byte(s)
general improvements, beginning stump of a configuration interface

1 #!/usr/bin/python
2 ''' update-install.py - pact install interface for ajax
3 Built on update.py version 1.0 by Luke Williams
4 '''
5
6 '''
7 Error Codes:
8
9 1000 Missing "action" argument.
10 1001 Action not in command list.
11 1002 Command-specific argument missing.
12 '''
13
14 # CGI Stuff
15 import sys, cgi, cgitb, commands
16 print "Content-Type: text/html"
17 print
18 cgitb.enable ()
19 def RunPage (): pass
20
21 # Import your modules here
22 import Installer
23
24 # Safety-lock any modules you want to protect access to
25 ## We don't safety-lock the Installer module because it's responsible for installing the safety-lock mechanism. It has its own lock.
26
27 ''' Connector functions! If you want your web front-end to be able to call Python functions, add them here.
28 COMMAND NAME: The "action" value in the GET request that you want to map a Python function to.
29 PYTHON FUNCTION: The function you want it to call.
30 ARGUMENT LIST: An ordered list of arguments to look for in the GET request string, and pass to the Python function.
31 RETURN VALUE TRANSLATION: A dictionary of mappings to transform the return value of the Python function into something
32 readable. If a "__default" key exists, use that if a more appropriate key isn't found. Otherwise,
33 just return the raw value. You can also use this field to do things after the function returns.
34 '''
35 actions = {
36 # COMMAND NAME PYTHON FUNCTION ARGUMENT LIST RETURN VALUE TRANSLATOR
37 "setvar" : (Installer.Set, ("name", "value"), lambda x: x),
38 "validate" : (Installer.Install, (), lambda x: X(x,{True:"status='Success';"})),
39 "uninstall" : (Installer.Uninstall, (), lambda x: x)
40 }
41
42 # Exception handling down the bottom. You probably don't need to change these next two functions.
43 #
44
45 def LoginHandler (result):
46 if result == False:
47 print "Failed."
48
49
50 def X (key, translations):
51 if translations.has_key (key):
52 return translations [key]
53 if translations.has_key ("__default"):
54 return translations ["__default"]
55 return key
56
57 def RunPage ():
58 arglist = []
59 form = cgi.FieldStorage ()
60
61 if not form.has_key ("action"):
62 print "Error 1000"
63 return
64 action = form["action"].value
65 if not actions.has_key (action):
66 print "Error 1001"
67 return
68 for arg in actions[action][1]:
69 if not form.has_key (arg):
70 print "Error 1002"
71 return
72 arglist.append (form[arg].value)
73 result = actions[action][0] (*arglist)
74 print actions[action][2] (result)
75
76 try:
77 RunPage ()
78 except Installer.NeedDBName:
79 print "status = 'NeedDBName';"
80 except Installer.NeedDBUser:
81 print "status = 'NeedDBUser';"
82 except Installer.NeedDBPass:
83 print "status = 'NeedDBPass';"
84 except Installer.InvalidDatabaseSettings:
85 print "status = 'InvalidDatabaseSettings';"
86 except Installer.DatabaseError:
87 print "status = 'DatabaseError';"

Properties

Name Value
svn:executable *

Managed by UCC Webmasters ViewVC Help
Powered by ViewVC 1.1.26