Browse Source

add -p option to restrict package selection

David Rose 14 years ago
parent
commit
3db2e1a13d
2 changed files with 34 additions and 11 deletions
  1. 17 9
      direct/src/p3d/PackageMerger.py
  2. 17 2
      direct/src/p3d/pmerge.py

+ 17 - 9
direct/src/p3d/PackageMerger.py

@@ -136,9 +136,9 @@ class PackageMerger:
         self.contentsSeq = SeqValue()
         self.contentsSeq = SeqValue()
 
 
         # We allow the first one to fail quietly.
         # We allow the first one to fail quietly.
-        self.__readContentsFile(self.installDir)
+        self.__readContentsFile(self.installDir, None)
 
 
-    def __readContentsFile(self, sourceDir):
+    def __readContentsFile(self, sourceDir, packageNames):
         """ Reads the contents.xml file from the indicated sourceDir,
         """ Reads the contents.xml file from the indicated sourceDir,
         and updates the internal set of packages appropriately. """
         and updates the internal set of packages appropriately. """
 
 
@@ -170,10 +170,15 @@ class PackageMerger:
             xpackage = xcontents.FirstChildElement('package')
             xpackage = xcontents.FirstChildElement('package')
             while xpackage:
             while xpackage:
                 pe = self.PackageEntry(xpackage, sourceDir)
                 pe = self.PackageEntry(xpackage, sourceDir)
-                other = self.contents.get(pe.getKey(), None)
-                if not other or pe.isNewer(other):
-                    # Store this package in the resulting output.
-                    self.contents[pe.getKey()] = pe
+
+                # Filter out any packages not listed in
+                # packageNames (unless packageNames is None,
+                # in which case don't filter anything).
+                if packageNames is None or pe.packageName in packageNames:
+                    other = self.contents.get(pe.getKey(), None)
+                    if not other or pe.isNewer(other):
+                        # Store this package in the resulting output.
+                        self.contents[pe.getKey()] = pe
                     
                     
                 xpackage = xpackage.NextSiblingElement('package')
                 xpackage = xpackage.NextSiblingElement('package')
 
 
@@ -268,10 +273,13 @@ class PackageMerger:
             except OSError:
             except OSError:
                 pass
                 pass
 
 
-    def merge(self, sourceDir):
+    def merge(self, sourceDir, packageNames = None):
         """ Adds the contents of the indicated source directory into
         """ Adds the contents of the indicated source directory into
-        the current pool. """
-        if not self.__readContentsFile(sourceDir):
+        the current pool.  If packageNames is not None, it is a list
+        of package names that we wish to include from the source;
+        packages not named in this list will be unchanged. """
+        
+        if not self.__readContentsFile(sourceDir, packageNames):
             message = "Couldn't read %s" % (sourceDir)
             message = "Couldn't read %s" % (sourceDir)
             raise PackageMergerError, message            
             raise PackageMergerError, message            
 
 

+ 17 - 2
direct/src/p3d/pmerge.py

@@ -30,6 +30,14 @@ Options:
      are checked for self-consistency with regards to hashes and
      are checked for self-consistency with regards to hashes and
      timestamps.
      timestamps.
 
 
+  -p packageName[,packageName...]
+     Specifies one or more particular packages by name that are to be
+     included from the input directories.  Any packages not in this
+     list are left unchanged in the install directory, even if there
+     is a newer version in one of the input directories.  If no
+     packages are named, all packages are involved.  This option may
+     be repeated.
+
   -h
   -h
      Display this help
      Display this help
 """
 """
@@ -47,14 +55,17 @@ def usage(code, msg = ''):
     sys.exit(code)
     sys.exit(code)
 
 
 try:
 try:
-    opts, args = getopt.getopt(sys.argv[1:], 'i:h')
+    opts, args = getopt.getopt(sys.argv[1:], 'i:p:h')
 except getopt.error, msg:
 except getopt.error, msg:
     usage(1, msg)
     usage(1, msg)
 
 
 installDir = None
 installDir = None
+packageNames = []
 for opt, arg in opts:
 for opt, arg in opts:
     if opt == '-i':
     if opt == '-i':
         installDir = Filename.fromOsSpecific(arg)
         installDir = Filename.fromOsSpecific(arg)
+    elif opt == '-p':
+        packageNames += arg.split(',')
         
         
     elif opt == '-h':
     elif opt == '-h':
         usage(0)
         usage(0)
@@ -62,6 +73,10 @@ for opt, arg in opts:
         print 'illegal option: ' + arg
         print 'illegal option: ' + arg
         sys.exit(1)
         sys.exit(1)
 
 
+if not packageNames:
+    # No package names means allow all packages.
+    packageNames = None
+
 inputDirs = []
 inputDirs = []
 for arg in args:
 for arg in args:
     inputDirs.append(Filename.fromOsSpecific(arg))
     inputDirs.append(Filename.fromOsSpecific(arg))
@@ -75,7 +90,7 @@ for arg in args:
 try:
 try:
     pm = PackageMerger.PackageMerger(installDir)
     pm = PackageMerger.PackageMerger(installDir)
     for dir in inputDirs:
     for dir in inputDirs:
-        pm.merge(dir)
+        pm.merge(dir, packageNames = packageNames)
     pm.close()
     pm.close()
         
         
 except PackageMerger.PackageMergerError:
 except PackageMerger.PackageMergerError: