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]
58 plc = PLCConfiguration()
69 longopts = ["shell", "bash", "python",
75 "category=", "variable=", "value=",
76 "group=", "package=", "type=",
81 (opts, argv) = getopt.gnu_getopt(sys.argv[1:], shortopts, longopts)
82 except Exception, err:
83 sys.stderr.write("Error: " + str(err) + os.linesep)
86 for (opt, optval) in opts:
87 if opt == "--shell" or \
90 output = plc.output_shell
92 output = plc.output_php
94 output = plc.output_xml
95 elif opt == "--variables":
96 output = plc.output_variables
97 elif opt == "--packages":
98 output = plc.output_packages
99 elif opt == "--comps":
100 output = plc.output_comps
101 elif opt == "--category":
102 category['id'] = optval
103 elif opt == "--variable":
104 variable['id'] = optval
105 elif opt == "--value":
106 variable['value'] = optval
107 elif opt == "--group":
109 elif opt == "--package":
110 package['name'] = optval
111 elif opt == "--type":
112 package['type'] = optval
113 elif opt == '-s' or opt == "--save":
115 elif opt == '-h' or opt == "--help":
120 argv = ["/etc/planetlab/plc_config.xml"]
128 except Exception, err:
129 sys.stderr.write("Error: %s: %s" % (file, str(err)) + os.linesep)
132 # --category, --variable, --value
133 if category.has_key('id') and variable.has_key('id'):
134 if variable.has_key('value'):
135 plc.set(category, variable)
137 (category, variable) = plc.get(category['id'], variable['id'])
138 if variable.has_key('value'):
139 print variable['value']
141 # --shell, --php, --xml
142 if output is not None:
143 sys.stdout.write(output())
150 if __name__ == '__main__':