3 # Script for basic access to the SFA configuration file store.
13 from sfa.util.config import Config
18 Script to access the SFA configuration file store.
20 Usage: %s [OPTION]... [FILES]
23 --shell Output shell configuration file
24 --python Output Python configuration file
25 --php Output PHP configuration file
29 --variables List names of all variables
30 --packages List names of all packages
31 --comps List comps.xml from configuration
33 Basic variable value manipulation:
35 --category= Category identifier
36 --variable= Variable identifier
37 --value= Variable value
39 Basic package list manipulation:
41 --group= Package group identifier
42 --package= Package name
47 -h, --help This message
48 -s, --save Save changes to first configuration file
49 """.lstrip() % sys.argv[0]
53 def deprecated (message):
54 print "%s: deprecated usage"%sys.argv[0]
70 longopts = ["shell", "bash", "python",
77 "category=", "variable=", "value=",
78 "group=", "package=", "type=",
83 (opts, argv) = getopt.gnu_getopt(sys.argv[1:], shortopts, longopts)
84 except Exception, err:
85 sys.stderr.write("Error: " + str(err) + os.linesep)
88 for (opt, optval) in opts:
89 if opt == "--shell" or \
91 output = config.output_shell
92 elif opt == "--python":
93 output = config.output_python
95 output = config.output_php
97 output = config.output_xml
98 elif opt == "--variables":
99 output = config.output_variables
100 elif opt == "--packages":
101 deprecated("option --packages deprecated -- use .lst files instead")
102 elif opt == "--groups":
103 deprecated("option --groups deprecated -- use .lst files instead")
104 elif opt == "--comps":
105 deprecated("option --comps deprecated -- use .lst files instead")
106 elif opt == "--category":
107 category['id'] = optval
108 elif opt == "--variable":
109 variable['id'] = optval
110 elif opt == "--value":
111 variable['value'] = optval
112 elif opt == "--group":
113 # group['id'] = optval
114 deprecated("option --group deprecated -- use .lst files instead")
115 elif opt == "--package":
116 # package['name'] = optval
117 deprecated("option --package deprecated -- use .lst files instead")
118 elif opt == "--type":
119 package['type'] = optval
120 elif opt == '-s' or opt == "--save":
123 print 'parsed save option',optval
125 elif opt == '-h' or opt == "--help":
130 argv = ["/etc/sfa/sfa_config"]
138 except Exception, err:
139 sys.stderr.write("Error: %s: %s" % (file, str(err)) + os.linesep)
142 # --category, --variable, --value
143 if category.has_key('id') and variable.has_key('id'):
144 if variable.has_key('value'):
145 config.set(category['id'], variable['id'], variable['value'])
147 value = config.get(category['id'], variable['id'])
150 # --shell, --php, --xml
151 if output is not None:
152 sys.stdout.write(output())
156 # create directory if needed
157 # so that plc.d/{api,postgres} can create configs/site.xml
158 dirname = os.path.dirname (save)
159 if (not os.path.exists (dirname)):
160 os.makedirs(dirname,0755)
161 if (not os.path.exists (dirname)):
162 print "Cannot create dir %s - exiting" % dirname
167 if __name__ == '__main__':