From: Thierry Parmentelat Date: Wed, 16 Jun 2010 15:17:16 +0000 (+0200) Subject: Merge branch 'master' of ssh://git.onelab.eu/git/infrastructure X-Git-Tag: foo~110^2~3 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=689defdf98d5b4c9698c0f64beff4ef61055cac9;hp=859b365b70511014c348bafa36b4b708bc2eb2fd;p=infrastructure.git Merge branch 'master' of ssh://git.onelab.eu/git/infrastructure --- 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() diff --git a/omf/export-omf.sh b/omf/export-omf.sh index 87bf944..8d881ad 100755 --- a/omf/export-omf.sh +++ b/omf/export-omf.sh @@ -16,13 +16,8 @@ DIRNAME=$(dirname $0) cd $DIRNAME -# refresh EXPORT and EXPORT.snip with the python script - -plcsh ./export-omf.py -- -n EXPORT.snip -plcsh ./export-omf.py -- EXPORT - -yes | gpg -r CERTH -e < EXPORT.snip > EXPORT.snip.nitlab -yes | gpg -r CERTH -e < EXPORT > EXPORT.nitlab +# refresh the gpg encrypted version of the export file +plcsh ./export-omf.py | gpg -r CERTH -e --output EXPORT.nitlab.gpg # publish under /var/www/html/download/EXPORT.nitlab -# or whatever the name is +cp EXPORT.nitlab.gpg /var/www/html/download/EXPORT.nitlab.gpg