3 # Script for basic access to the PlanetLab Central (PLC) configuration
6 # Mark Huang <mlhuang@cs.princeton.edu>
7 # Copyright (C) 2006 The Trustees of Princeton University
17 from plc_config import PLCConfiguration
22 Script to access the PLC configuration file store.
24 Usage: %s [OPTION]... [FILES]
27 --shell Output shell configuration file
28 --python Output Python configuration file
29 --php Output PHP configuration file
33 --variables List names of all variables
34 --packages List names of all packages
35 --comps List comps.xml from configuration
37 Basic variable value manipulation:
39 --category= Category identifier
40 --variable= Variable identifier
41 --value= Variable value
43 Basic package list manipulation:
45 --group= Package group identifier
46 --package= Package name
51 -h, --help This message
52 -s, --save Save changes to first configuration file
53 """.lstrip() % sys.argv[0]
57 def deprecated (message):
58 print "%s: deprecated usage"%sys.argv[0]
63 plc = PLCConfiguration()
74 longopts = ["shell", "bash", "python",
81 "category=", "variable=", "value=",
82 "group=", "package=", "type=",
87 (opts, argv) = getopt.gnu_getopt(sys.argv[1:], shortopts, longopts)
88 except Exception, err:
89 sys.stderr.write("Error: " + str(err) + os.linesep)
92 for (opt, optval) in opts:
93 if opt == "--shell" or \
96 output = plc.output_shell
98 output = plc.output_php
100 output = plc.output_xml
101 elif opt == "--variables":
102 output = plc.output_variables
103 elif opt == "--packages":
104 # output = plc.output_packages
105 deprecated("option --packages deprecated -- use .lst files instead")
106 elif opt == "--groups":
107 # output = plc.output_groups
108 deprecated("option --groups deprecated -- use .lst files instead")
109 elif opt == "--comps":
110 # output = plc.output_comps
111 deprecated("option --comps deprecated -- use .lst files instead")
112 elif opt == "--category":
113 category['id'] = optval
114 elif opt == "--variable":
115 variable['id'] = optval
116 elif opt == "--value":
117 variable['value'] = optval
118 elif opt == "--group":
119 # group['id'] = optval
120 deprecated("option --group deprecated -- use .lst files instead")
121 elif opt == "--package":
122 # package['name'] = optval
123 deprecated("option --package deprecated -- use .lst files instead")
124 elif opt == "--type":
125 package['type'] = optval
126 elif opt == '-s' or opt == "--save":
129 print 'parsed save option',optval
131 elif opt == '-h' or opt == "--help":
136 argv = ["/etc/planetlab/plc_config.xml"]
144 except Exception, err:
145 sys.stderr.write("Error: %s: %s" % (file, str(err)) + os.linesep)
148 # --category, --variable, --value
149 if category.has_key('id') and variable.has_key('id'):
150 if variable.has_key('value'):
151 plc.set(category, variable)
153 (category, variable) = plc.get(category['id'], variable['id'])
154 if variable.has_key('value'):
155 print variable['value']
157 # --shell, --php, --xml
158 if output is not None:
159 sys.stdout.write(output())
163 # create directory if needed
164 # so that plc.d/{api,postgres} can create configs/site.xml
165 dirname = os.path.dirname (save)
166 if (not os.path.exists (dirname)):
167 os.makedirs(dirname,0755)
168 if (not os.path.exists (dirname)):
169 print "Cannot create dir %s - exiting" % dirname
175 if __name__ == '__main__':