X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=omf%2Fexport-omf.py;h=21db926f30a09dfd9f3765c9d775a1d5924ab680;hb=77f54330355a7071b9f0eea9fc457103066f6fd5;hp=d47047110aebc3b964af4cfa25eae488d3a4c378;hpb=6f2ea4de58517816178930f4899768ecd356b957;p=infrastructure.git diff --git a/omf/export-omf.py b/omf/export-omf.py index d470471..21db926 100755 --- a/omf/export-omf.py +++ b/omf/export-omf.py @@ -1,4 +1,4 @@ -#!/usr/bin/plcsh +#!/usr/bin/python /usr/bin/plcsh # utility to store, read and diff our user base data for exporting to OMF @@ -20,8 +20,7 @@ def getPersons(filter={}): class OmfUserBase: - def __init__ (self, options, filename): - self.filename=filename + def __init__ (self, options): self.options=options @@ -44,12 +43,15 @@ class OmfUserBase: for key_id in person['key_ids']: print >>file, "ssh=%s"%pubkeys_by_id[key_id] - def save(self): + def save(self, output): """ Write configuration store to file. """ - - fileout = open(self.filename, 'w') + + if output: + fileout = open(output, 'w') + else: + fileout=sys.stdout print >>fileout, "# myplc simple userbase extration tools export-omf.py" print >>fileout, "# generated on %s"%time.strftime("%Y-%m-%d @ %H:%M UTC",time.gmtime()) # store all ssh keys by key_id - keep only the public key @@ -65,18 +67,22 @@ class OmfUserBase: def main (): - parser = OptionParser (usage="%prog [options] OUTPUT_FILE") + parser = OptionParser (usage="""%prog [options] +Default output is on stdout""") parser.add_option ("-n","--no-password", action="store_true", dest="no_password", default=False, help="Don't include encrypted passwords") + parser.add_option ("-o","--output", action="store", + dest="output", default=None, help="Specify output filename") options,args = parser.parse_args() - try: - output = args[0] - except IndexError: - parser.error("no output file") + if len(args)!=0: + parser.print_help() + sys.exit(1) + + userbase=OmfUserBase(options) + userbase.save(options.output) - userbase=OmfUserBase(options, output) - userbase.save() + if __name__ == '__main__': main()