From 8ac787d2f018e6e69e9b15933656a62a99db55d9 Mon Sep 17 00:00:00 2001 From: Sol Jerome Date: Fri, 22 Aug 2008 16:13:48 +0000 Subject: Perform schema checks for all Xinclude files in groups.xml git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@4890 ce84e21b-d406-0410-9b95-82705330c041 --- src/sbin/bcfg2-repo-validate | 45 +++++++++++++++++++++++++++++++------------- 1 file changed, 32 insertions(+), 13 deletions(-) (limited to 'src/sbin/bcfg2-repo-validate') diff --git a/src/sbin/bcfg2-repo-validate b/src/sbin/bcfg2-repo-validate index d067d4e74..459032346 100755 --- a/src/sbin/bcfg2-repo-validate +++ b/src/sbin/bcfg2-repo-validate @@ -10,6 +10,14 @@ import glob, lxml.etree, os, sys import Bcfg2.Options +try: + pdlist = set +except: + class pdlist(list): + def add(self, item): + if item not in self: + self.append(item) + if __name__ == '__main__': opts = {'repo': Bcfg2.Options.SERVER_REPOSITORY, 'prefix': Bcfg2.Options.INSTALL_PREFIX, @@ -31,16 +39,31 @@ if __name__ == '__main__': if filename.endswith('info.xml'): info_list.append(os.path.join(root, filename)) - # get all XIncluded bundles - ref_bundles = [] - unref_bundles = [] + # get metadata list (with all included files) + metadata_list = glob.glob("%s/Metadata/groups.xml" % repo) + ref_bundles = pdlist() xdata = lxml.etree.parse("%s/Metadata/groups.xml" % repo) + included = pdlist([ent.get('href') for ent in \ + xdata.findall('./{http://www.w3.org/2001/XInclude}include')]) + while included: + try: + filename = included.pop() + except KeyError: + continue + metadata_list.append("%s/Metadata/%s" % (repo, filename)) + groupdata = lxml.etree.parse("%s/Metadata/%s" % (repo, filename)) + group_ents = [ent.get('href') for ent in \ + groupdata.findall('./{http://www.w3.org/2001/XInclude}include')] + for ent in group_ents: + included.add(ent) + included.discard(filename) + + # get all XIncluded bundles xdata.xinclude() for bundle in xdata.findall("//Bundle"): - ref_bundles.append("%s/Bundler/%s.xml" % (repo,bundle.get('name'))) + ref_bundles.add("%s/Bundler/%s.xml" % (repo, bundle.get('name'))) # get lists of all other xml files to validate - metadata_list = glob.glob("%s/Metadata/groups.xml" % repo) clients_list = glob.glob("%s/Metadata/clients.xml" % repo) bundle_list = glob.glob("%s/Bundler/*.xml" % repo) pkg_list = glob.glob("%s/Pkgmgr/*.xml" % repo) @@ -50,11 +73,6 @@ if __name__ == '__main__': services_list = glob.glob("%s/Svcmgr/*.xml" % repo) deps_list = glob.glob("%s/Deps/*.xml" % repo) - # find all unreferenced bundles - for bundle in ref_bundles: - if bundle not in bundle_list: - unref_bundles.append(bundle) - filesets = {'metadata':(metadata_list, "%s/metadata.xsd"), 'clients':(clients_list, "%s/clients.xsd"), 'info':(info_list, "%s/info.xsd"), @@ -104,8 +122,9 @@ if __name__ == '__main__': # print out missing bundle information if verbose: print("") - for bundle in unref_bundles: - print ("*** Warning: Bundle %s referenced, but does not " - "exist." % bundle) + for bundle in ref_bundles: + if bundle not in bundle_list: + print ("*** Warning: Bundle %s referenced, but does not " + "exist." % bundle) raise SystemExit, failures -- cgit v1.2.3-1-g7c22