summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorFabian Affolter <fabian@bernewireless.net>2010-06-10 22:27:32 +0000
committerSol Jerome <sol.jerome@gmail.com>2010-06-10 17:52:27 -0500
commit9521a85acaa8a1ddd740315b3063146a9392da6f (patch)
treec3aabc9f793f17193b7e3969995ee6db29240af2 /src
parent86ac5bcfd6ae41a7e7b1d053edb73d6fa1e64964 (diff)
downloadbcfg2-9521a85acaa8a1ddd740315b3063146a9392da6f.tar.gz
bcfg2-9521a85acaa8a1ddd740315b3063146a9392da6f.tar.bz2
bcfg2-9521a85acaa8a1ddd740315b3063146a9392da6f.zip
Added new bcfg2-admin bundle list part
git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@5921 ce84e21b-d406-0410-9b95-82705330c041
Diffstat (limited to 'src')
-rw-r--r--src/lib/Server/Admin/Bundle.py90
-rw-r--r--src/lib/Server/Admin/__init__.py3
2 files changed, 78 insertions, 15 deletions
diff --git a/src/lib/Server/Admin/Bundle.py b/src/lib/Server/Admin/Bundle.py
index b9d26758a..92da47c3b 100644
--- a/src/lib/Server/Admin/Bundle.py
+++ b/src/lib/Server/Admin/Bundle.py
@@ -1,10 +1,18 @@
+import lxml.etree
+import glob
+import sys
+import re
import Bcfg2.Server.Admin
+import Bcfg2.Options
from Bcfg2.Server.Plugins.Metadata import MetadataConsistencyError
class Bundle(Bcfg2.Server.Admin.MetadataCore):
__shorthelp__ = "Create or delete bundle entries"
- __longhelp__ = (__shorthelp__ + "\n\nbcfg2-admin bundle add <bundle> "
- "bcfg2-admin bundle del <bundle>")
+ __longhelp__ = (__shorthelp__ + #"\n\nbcfg2-admin bundle add <bundle> "
+ #"\n\nbcfg2-admin bundle del <bundle>"
+ "\n\nbcfg2-admin bundle list-xml"
+ "\n\nbcfg2-admin bundle list-genshi"
+ "\n\nbcfg2-admin bundle show")
__usage__ = ("bcfg2-admin bundle [options] [add|del] [group]")
def __init__(self, configfile):
@@ -13,21 +21,75 @@ class Bundle(Bcfg2.Server.Admin.MetadataCore):
def __call__(self, args):
Bcfg2.Server.Admin.MetadataCore.__call__(self, args)
+ reg='((?:[a-z][a-z\\.\\d\\-]+)\\.(?:[a-z][a-z\\-]+))(?![\\w\\.])'
+
+ #Get all bundles out of the Bundle directory
+ opts = {'repo': Bcfg2.Options.SERVER_REPOSITORY}
+ setup = Bcfg2.Options.OptionParser(opts)
+ setup.parse(sys.argv[1:])
+ repo = setup['repo']
+ xml_list = glob.glob("%s/Bundler/*.xml" % repo)
+ genshi_list = glob.glob("%s/Bundler/*.genshi" % repo)
+
if len(args) == 0:
self.errExit("No argument specified.\n"
"Please see bcfg2-admin bundle help for usage.")
- if args[0] == 'add':
- try:
- self.metadata.add_bundle(args[1])
- except MetadataConsistencyError:
- print "Error in adding bundle"
- raise SystemExit(1)
- elif args[0] in ['delete', 'remove', 'del', 'rm']:
- try:
- self.metadata.remove_bundle(args[1])
- except MetadataConsistencyError:
- print "Error in deleting bundle"
- raise SystemExit(1)
+# if args[0] == 'add':
+# try:
+# self.metadata.add_bundle(args[1])
+# except MetadataConsistencyError:
+# print "Error in adding bundle."
+# raise SystemExit(1)
+# elif args[0] in ['delete', 'remove', 'del', 'rm']:
+# try:
+# self.metadata.remove_bundle(args[1])
+# except MetadataConsistencyError:
+# print "Error in deleting bundle."
+# raise SystemExit(1)
+ elif args[0] in ['list-xml', 'ls-xml']:
+ bundle_name = []
+ for bundle_path in xml_list:
+ rg = re.compile(reg,re.IGNORECASE|re.DOTALL)
+ bundle_name.append(rg.search(bundle_path).group(1))
+ for bundle in bundle_name:
+ print bundle.split('.')[0]
+ elif args[0] in ['list-genshi', 'ls-gen']:
+ bundle_name = []
+ for bundle_path in genshi_list:
+ rg = re.compile(reg,re.IGNORECASE|re.DOTALL)
+ bundle_name.append(rg.search(bundle_path).group(1))
+ for bundle in bundle_name:
+ print bundle.split('.')[0]
+ elif args[0] in ['show']:
+ bundle_name = []
+ bundle_list = xml_list + genshi_list
+ for bundle_path in bundle_list:
+ rg = re.compile(reg,re.IGNORECASE|re.DOTALL)
+ bundle_name.append(rg.search(bundle_path).group(1))
+ text = "Available bundles (Number of bundles: %s)" % \
+ (len(bundle_list))
+ print text
+ print "%s" % (len(text) * "-")
+ for i in range(len(bundle_list)):
+ print "[%i]\t%s" % (i, bundle_name[i])
+ print "Enter the line number of a bundle for details:",
+ lineno = raw_input()
+ if int(lineno) >= int(len(bundle_list)):
+ print "No line with this number."
+ else:
+ if '%s/Bundler/%s' % \
+ (repo, bundle_name[int(lineno)]) in genshi_list:
+ print "Detailed output for *.genshi bundle is not supported."
+ else:
+ print 'Details for the "%s" bundle:' % \
+ (bundle_name[int(lineno)].split('.')[0])
+ tree = lxml.etree.parse(bundle_list[int(lineno)])
+ #Print bundle content
+ #print lxml.etree.tostring(tree)
+ names = ['ConfigFile', 'Package', 'Service']
+ for name in names:
+ for node in tree.findall("//" + name):
+ print "%s:\t%s" % (name, node.attrib["name"])
else:
print "No command specified"
raise SystemExit(1)
diff --git a/src/lib/Server/Admin/__init__.py b/src/lib/Server/Admin/__init__.py
index e46a2e40c..3a088b2fb 100644
--- a/src/lib/Server/Admin/__init__.py
+++ b/src/lib/Server/Admin/__init__.py
@@ -1,7 +1,8 @@
__revision__ = '$Revision$'
__all__ = ['Mode', 'Client', 'Compare', 'Init', 'Minestruct', 'Perf',
- 'Pull', 'Query', 'Reports', 'Snapshots', 'Tidy', 'Viz', 'Xcmd']
+ 'Pull', 'Query', 'Reports', 'Snapshots', 'Tidy', 'Viz',
+ 'Xcmd', 'Group']
import ConfigParser
import logging