From c4f6826b85be5873793741a9fe32f0ce09406f1d Mon Sep 17 00:00:00 2001 From: Tim Laszlo Date: Thu, 15 Jul 2010 20:48:05 +0000 Subject: Admin/Pull: Allow a list of files to be read from stdin git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@5976 ce84e21b-d406-0410-9b95-82705330c041 --- src/lib/Server/Admin/Pull.py | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/lib/Server/Admin/Pull.py b/src/lib/Server/Admin/Pull.py index d6dfa9e5a..71a7b496a 100644 --- a/src/lib/Server/Admin/Pull.py +++ b/src/lib/Server/Admin/Pull.py @@ -1,4 +1,5 @@ import getopt +import sys import Bcfg2.Server.Admin class Pull(Bcfg2.Server.Admin.MetadataCore): @@ -7,19 +8,22 @@ class Pull(Bcfg2.Server.Admin.MetadataCore): """ __shorthelp__ = ("Integrate configuration information " "from clients into the server repository") - __longhelp__ = (__shorthelp__ + "\n\nbcfg2-admin pull [-v] [-f][-I] " + __longhelp__ = (__shorthelp__ + "\n\nbcfg2-admin pull [-v] [-f][-I] [-s]" " ") __usage__ = ("bcfg2-admin pull [options] " "\n\n" " %-25s%s\n" " %-25s%s\n" + " %-25s%s\n" " %-25s%s\n" % ("-v", "be verbose", "-f", "force", "-I", - "interactive")) + "interactive", + "-s", + "stdin")) allowed = ['Metadata', 'BB', "DBStats", "Statistics", "Cfg", "SSHbase"] def __init__(self, configfile): @@ -30,8 +34,9 @@ class Pull(Bcfg2.Server.Admin.MetadataCore): def __call__(self, args): Bcfg2.Server.Admin.Mode.__call__(self, args) + use_stdin = False try: - opts, gargs = getopt.getopt(args, 'vfI') + opts, gargs = getopt.getopt(args, 'vfIs') except: print self.__shorthelp__ raise SystemExit(1) @@ -42,7 +47,22 @@ class Pull(Bcfg2.Server.Admin.MetadataCore): self.mode = 'force' elif opt[0] == '-I': self.mode == 'interactive' - self.PullEntry(gargs[0], gargs[1], gargs[2]) + elif opt[0] == '-s': + use_stdin = True + + if use_stdin: + for line in sys.stdin: + try: + self.PullEntry(*line.split(None, 3)) + except SystemExit: + print " for %s" % line + except: + print "Bad entry: %s" % line.strip() + elif len(gargs) < 3: + print self.__longhelp__ + raise SystemExit(1) + else: + self.PullEntry(gargs[0], gargs[1], gargs[2]) def BuildNewEntry(self, client, etype, ename): """Construct a new full entry for given client/entry from statistics.""" -- cgit v1.2.3-1-g7c22