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
15 from plc_config import PLCConfiguration
20 Script to access the PLC configuration file store.
22 Usage: %s [OPTION]... [FILES]
25 --shell Output shell configuration file
26 --python Output Python configuration file
27 --php Output PHP configuration file
31 --variables List names of all variables
32 --packages List names of all packages
33 --comps List comps.xml from configuration
35 Basic variable value manipulation:
37 --category= Category identifier
38 --variable= Variable identifier
39 --value= Variable value
41 Basic package list manipulation:
43 --group= Package group identifier
44 --package= Package name
49 -h, --help This message
50 -s, --save Save changes to first configuration file
51 """.lstrip() % sys.argv[0]
55 def deprecated (message):
56 print "%s: deprecated usage"%sys.argv[0]
61 plc = PLCConfiguration()
72 longopts = ["shell", "bash", "python",
79 "category=", "variable=", "value=",
80 "group=", "package=", "type=",
85 (opts, argv) = getopt.gnu_getopt(sys.argv[1:], shortopts, longopts)
86 except Exception, err:
87 sys.stderr.write("Error: " + str(err) + os.linesep)
90 for (opt, optval) in opts:
91 if opt == "--shell" or \
94 output = plc.output_shell
96 output = plc.output_php
98 output = plc.output_xml
99 elif opt == "--variables":
100 output = plc.output_variables
101 elif opt == "--packages":
102 # output = plc.output_packages
103 deprecated("option --packages deprecated -- use .lst files instead")
104 elif opt == "--groups":
105 # output = plc.output_groups
106 deprecated("option --groups deprecated -- use .lst files instead")
107 elif opt == "--comps":
108 # output = plc.output_comps
109 deprecated("option --comps deprecated -- use .lst files instead")
110 elif opt == "--category":
111 category['id'] = optval
112 elif opt == "--variable":
113 variable['id'] = optval
114 elif opt == "--value":
115 variable['value'] = optval
116 elif opt == "--group":
117 # group['id'] = optval
118 deprecated("option --group deprecated -- use .lst files instead")
119 elif opt == "--package":
120 # package['name'] = optval
121 deprecated("option --package deprecated -- use .lst files instead")
122 elif opt == "--type":
123 package['type'] = optval
124 elif opt == '-s' or opt == "--save":
127 print 'parsed save option',optval
129 elif opt == '-h' or opt == "--help":
134 argv = ["/etc/planetlab/plc_config.xml"]
142 except Exception, err:
143 sys.stderr.write("Error: %s: %s" % (file, str(err)) + os.linesep)
146 # --category, --variable, --value
147 if category.has_key('id') and variable.has_key('id'):
148 if variable.has_key('value'):
149 plc.set(category, variable)
151 (category, variable) = plc.get(category['id'], variable['id'])
152 if variable.has_key('value'):
153 print variable['value']
155 # --shell, --php, --xml
156 if output is not None:
157 sys.stdout.write(output())
161 # create directory if needed
162 # so that plc.d/{api,postgres} can create configs/site.xml
163 dirname = os.path.dirname (save)
164 if (not os.path.exists (dirname)):
165 os.makedirs(dirname,0755)
166 if (not os.path.exists (dirname)):
167 print "Cannot create dir %s - exiting" % dirname
173 if __name__ == '__main__':