3 # Script for basic access to the SFA configuration file store.
11 from sfa.util.config import Config
16 Script to access the SFA configuration file store.
18 Usage: %s [OPTION]... [FILES]
21 --shell Output shell configuration file
22 --python Output Python configuration file
23 --php Output PHP configuration file
27 --variables List names of all variables
28 --packages List names of all packages
29 --comps List comps.xml from configuration
31 Basic variable value manipulation:
33 --category= Category identifier
34 --variable= Variable identifier
35 --value= Variable value
37 Basic package list manipulation:
39 --group= Package group identifier
40 --package= Package name
45 -h, --help This message
46 -s, --save Save changes to first configuration file
47 """.lstrip() % sys.argv[0]
51 def deprecated(message):
52 print "%s: deprecated usage" % sys.argv[0]
69 longopts = ["shell", "bash", "python",
76 "category=", "variable=", "value=",
77 "group=", "package=", "type=",
82 (opts, argv) = getopt.gnu_getopt(sys.argv[1:], shortopts, longopts)
83 except Exception, err:
84 sys.stderr.write("Error: " + str(err) + os.linesep)
87 for (opt, optval) in opts:
88 if opt == "--shell" or \
90 output = config.output_shell
91 elif opt == "--python":
92 output = config.output_python
94 output = config.output_php
96 output = config.output_xml
97 elif opt == "--variables":
98 output = config.output_variables
99 elif opt == "--packages":
100 deprecated("option --packages deprecated -- use .lst files instead")
101 elif opt == "--groups":
102 deprecated("option --groups deprecated -- use .lst files instead")
103 elif opt == "--comps":
104 deprecated("option --comps deprecated -- use .lst files instead")
105 elif opt == "--category":
106 category['id'] = optval
107 elif opt == "--variable":
108 variable['id'] = optval
109 elif opt == "--value":
110 variable['value'] = optval
111 elif opt == "--group":
112 # group['id'] = optval
113 deprecated("option --group deprecated -- use .lst files instead")
114 elif opt == "--package":
115 # package['name'] = optval
116 deprecated("option --package deprecated -- use .lst files instead")
117 elif opt == "--type":
118 package['type'] = optval
119 elif opt == '-s' or opt == "--save":
122 print 'parsed save option', optval
124 elif opt == '-h' or opt == "--help":
129 argv = ["/etc/sfa/sfa_config"]
137 except Exception, err:
138 sys.stderr.write("Error: %s: %s" % (file, str(err)) + os.linesep)
141 # --category, --variable, --value
142 if category.has_key('id') and variable.has_key('id'):
143 if variable.has_key('value'):
144 config.set(category['id'], variable['id'], variable['value'])
146 value = config.get(category['id'], variable['id'])
149 # --shell, --php, --xml
150 if output is not None:
151 sys.stdout.write(output())
155 # create directory if needed
156 # so that plc.d/{api,postgres} can create configs/site.xml
157 dirname = os.path.dirname(save)
158 if (not os.path.exists(dirname)):
159 os.makedirs(dirname, 0755)
160 if (not os.path.exists(dirname)):
161 print "Cannot create dir %s - exiting" % dirname
166 if __name__ == '__main__':