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
30 --ruby Output Ruby configuration file
34 --variables List names of all variables
35 --packages List names of all packages
36 --comps List comps.xml from configuration
38 Basic variable value manipulation:
40 --category= Category identifier
41 --variable= Variable identifier
42 --value= Variable value
44 Basic package list manipulation:
46 --group= Package group identifier
47 --package= Package name
52 -h, --help This message
53 -s, --save Save changes to first configuration file
54 """.lstrip() % sys.argv[0]
58 def deprecated (message):
59 print "%s: deprecated usage"%sys.argv[0]
64 plc = PLCConfiguration()
75 longopts = ["shell", "bash", "python",
83 "category=", "variable=", "value=",
84 "group=", "package=", "type=",
89 (opts, argv) = getopt.gnu_getopt(sys.argv[1:], shortopts, longopts)
90 except Exception, err:
91 sys.stderr.write("Error: " + str(err) + os.linesep)
94 for (opt, optval) in opts:
95 if opt == "--shell" or \
98 output = plc.output_shell
100 output = plc.output_ruby
102 output = plc.output_php
104 output = plc.output_xml
105 elif opt == "--variables":
106 output = plc.output_variables
107 elif opt == "--packages":
108 # output = plc.output_packages
109 deprecated("option --packages deprecated -- use .lst files instead")
110 elif opt == "--groups":
111 # output = plc.output_groups
112 deprecated("option --groups deprecated -- use .lst files instead")
113 elif opt == "--comps":
114 # output = plc.output_comps
115 deprecated("option --comps deprecated -- use .lst files instead")
116 elif opt == "--category":
117 category['id'] = optval
118 elif opt == "--variable":
119 variable['id'] = optval
120 elif opt == "--value":
121 variable['value'] = optval
122 elif opt == "--group":
123 # group['id'] = optval
124 deprecated("option --group deprecated -- use .lst files instead")
125 elif opt == "--package":
126 # package['name'] = optval
127 deprecated("option --package deprecated -- use .lst files instead")
128 elif opt == "--type":
129 package['type'] = optval
130 elif opt == '-s' or opt == "--save":
133 print 'parsed save option',optval
135 elif opt == '-h' or opt == "--help":
140 argv = ["/etc/planetlab/plc_config.xml"]
148 except Exception, err:
149 sys.stderr.write("Error: %s: %s" % (file, str(err)) + os.linesep)
152 # --category, --variable, --value
153 if category.has_key('id') and variable.has_key('id'):
154 if variable.has_key('value'):
155 plc.set(category, variable)
157 (category, variable) = plc.get(category['id'], variable['id'])
158 if variable.has_key('value'):
159 print variable['value']
161 # --shell, --php, --xml
162 if output is not None:
163 sys.stdout.write(output())
167 # create directory if needed
168 # so that plc.d/{api,postgres} can create configs/site.xml
169 dirname = os.path.dirname (save)
170 if (not os.path.exists (dirname)):
171 os.makedirs(dirname,0755)
172 if (not os.path.exists (dirname)):
173 print "Cannot create dir %s - exiting" % dirname
179 if __name__ == '__main__':