X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=config%2Fsfa-config;h=346356bc326502cdbdb8ed4580381b7b69a6510f;hb=30c88e06c911e0297db4f13bc584be4d5634480e;hp=e623ed84408c0dae45694fe3cf1f0ebd680b5cb7;hpb=ae74d4304bb1033d1fe1dcde29360ad5fe73df63;p=sfa.git diff --git a/config/sfa-config b/config/sfa-config index e623ed84..346356bc 100755 --- a/config/sfa-config +++ b/config/sfa-config @@ -1,20 +1,20 @@ -#!/usr/bin/python +#!/usr/bin/env python3 # # Script for basic access to the SFA configuration file store. # import sys import os -import fcntl +#import fcntl import getopt -import signal +#import signal from sfa.util.config import Config def usage(): - print """ + print(""" Script to access the SFA configuration file store. - + Usage: %s [OPTION]... [FILES] Conversion: @@ -44,15 +44,16 @@ Usage: %s [OPTION]... [FILES] -h, --help This message -s, --save Save changes to first configuration file -""".lstrip() % sys.argv[0] +""".lstrip() % sys.argv[0]) sys.exit(1) -def deprecated (message): - print "%s: deprecated usage"%sys.argv[0] - print message +def deprecated(message): + print("%s: deprecated usage" % sys.argv[0]) + print(message) sys.exit(1) + def main(): config = Config() fileobjs = [] @@ -79,13 +80,13 @@ def main(): try: (opts, argv) = getopt.gnu_getopt(sys.argv[1:], shortopts, longopts) - except Exception, err: + except Exception as err: sys.stderr.write("Error: " + str(err) + os.linesep) sys.exit(1) for (opt, optval) in opts: if opt == "--shell" or \ - opt == "--bash": + opt == "--bash": output = config.output_shell elif opt == "--python": output = config.output_python @@ -108,17 +109,17 @@ def main(): elif opt == "--value": variable['value'] = optval elif opt == "--group": -# group['id'] = optval + # group['id'] = optval deprecated("option --group deprecated -- use .lst files instead") elif opt == "--package": -# package['name'] = optval + # package['name'] = optval deprecated("option --package deprecated -- use .lst files instead") elif opt == "--type": package['type'] = optval elif opt == '-s' or opt == "--save": if not optval: usage() - print 'parsed save option',optval + print('parsed save option', optval) save = optval elif opt == '-h' or opt == "--help": usage() @@ -133,17 +134,17 @@ def main(): config.load(file) except IOError: pass - except Exception, err: + except Exception as err: sys.stderr.write("Error: %s: %s" % (file, str(err)) + os.linesep) sys.exit(1) # --category, --variable, --value - if category.has_key('id') and variable.has_key('id'): - if variable.has_key('value'): + if 'id' in category and 'id' in variable: + if 'value' in variable: config.set(category['id'], variable['id'], variable['value']) else: value = config.get(category['id'], variable['id']) - print value + print(value) # --shell, --php, --xml if output is not None: @@ -152,12 +153,12 @@ def main(): # --save if save: # create directory if needed - # so that plc.d/{api,postgres} can create configs/site.xml - dirname = os.path.dirname (save) - if (not os.path.exists (dirname)): - os.makedirs(dirname,0755) - if (not os.path.exists (dirname)): - print "Cannot create dir %s - exiting" % dirname + # so that plc.d/{api,postgres} can create configs/site.xml + dirname = os.path.dirname(save) + if (not os.path.exists(dirname)): + os.makedirs(dirname, 0o755) + if (not os.path.exists(dirname)): + print("Cannot create dir %s - exiting" % dirname) sys.exit(1) config.save(save)