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]
68 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 \
89 output = config.output_shell
90 elif opt == "--python":
91 output = config.output_python
93 output = config.output_php
95 output = config.output_xml
96 elif opt == "--variables":
97 output = config.output_variables
98 elif opt == "--packages":
99 deprecated("option --packages deprecated -- use .lst files instead")
100 elif opt == "--groups":
101 deprecated("option --groups deprecated -- use .lst files instead")
102 elif opt == "--comps":
103 deprecated("option --comps deprecated -- use .lst files instead")
104 elif opt == "--category":
105 category['id'] = optval
106 elif opt == "--variable":
107 variable['id'] = optval
108 elif opt == "--value":
109 variable['value'] = optval
110 elif opt == "--group":
111 # group['id'] = optval
112 deprecated("option --group deprecated -- use .lst files instead")
113 elif opt == "--package":
114 # package['name'] = optval
115 deprecated("option --package deprecated -- use .lst files instead")
116 elif opt == "--type":
117 package['type'] = optval
118 elif opt == '-s' or opt == "--save":
121 print 'parsed save option',optval
123 elif opt == '-h' or opt == "--help":
128 argv = ["/etc/sfa/sfa_config"]
136 except Exception, err:
137 sys.stderr.write("Error: %s: %s" % (file, str(err)) + os.linesep)
140 # --category, --variable, --value
141 if category.has_key('id') and variable.has_key('id'):
142 if variable.has_key('value'):
143 config.set(category['id'], variable['id'], variable['value'])
145 value = config.get(category['id'], variable['id'])
148 # --shell, --php, --xml
149 if output is not None:
150 sys.stdout.write(output())
154 # create directory if needed
155 # so that plc.d/{api,postgres} can create configs/site.xml
156 dirname = os.path.dirname (save)
157 if (not os.path.exists (dirname)):
158 os.makedirs(dirname,0755)
159 if (not os.path.exists (dirname)):
160 print "Cannot create dir %s - exiting" % dirname
165 if __name__ == '__main__':