tags 352940 + patch
thanks

Here's a patch that implements the feature for piuparts to scan packages from 
a changes file. I patched the docbook file as well.

The way I implemented this change was so piuparts would scan the packages of 
each individual changes file separately. There is an option however to allow 
piuparts to scan packages from all changes files together.

An unrelated change I made was with the panic() method. It takes an optional 
parameter to specify what exit status to use. I did this for my own testing. 
No other changes were needed throughout the program and I thought it might be 
useful later so I left it in there. Feel free exclude that change if you 
wish.

Also, I changed some methods from using 'args' to 'package_list'. This more 
accurately represents what is being passed into these methods now.

As a final note. I also attached the python script I used for helping me 
develop the new feature. Also, I've attached a modified form of the shell 
script I've sent earlier that makes use of the new feature. Feel free to use 
both however you wish.

-- 
Regards,
Andres
diff -urN piuparts-0.33/debian/changelog piuparts-0.33.01/debian/changelog
--- piuparts-0.33/debian/changelog	2008-11-08 12:07:41.000000000 -0500
+++ piuparts-0.33.01/debian/changelog	2008-12-07 22:52:26.000000000 -0500
@@ -1,3 +1,9 @@
+piuparts (0.33.01) unstable; urgency=low
+
+  * Allow piuparts to scan packages in a changes file.
+
+ -- Andres Mejia <[EMAIL PROTECTED]>  Sun, 07 Dec 2008 21:43:55 -0500
+
 piuparts (0.33) unstable; urgency=low
 
   * Added --bindmount option, thanks to AnĂ­bal Monsalve Salaza for the patch. 
diff -urN piuparts-0.33/piuparts.docbook piuparts-0.33.01/piuparts.docbook
--- piuparts-0.33/piuparts.docbook	2008-11-08 12:05:59.000000000 -0500
+++ piuparts-0.33.01/piuparts.docbook	2008-12-07 23:05:42.000000000 -0500
@@ -58,6 +58,7 @@
             <arg><option>-l</option> <replaceable>logfile</replaceable></arg>
             <arg><option>-m</option> <replaceable>url</replaceable></arg>
             <arg><option>--bindmount</option> <replaceable>dir</replaceable></arg>
+            <arg><replaceable>changes_file</replaceable></arg>
             <arg><replaceable>package</replaceable></arg>
         </cmdsynopsis>
     </refsynopsisdiv>
@@ -123,11 +124,18 @@
             
         </orderedlist>
         
-        <para>Command line arguments are names of package files by
-        default (e.g., <filename>piuparts_1.0-1_all.deb</filename>) or
-        names of packages, if the <option>-a</option> option is
-        given. All packages will be tested as a group, not one
-        by one.</para>
+        <para>Command line arguments are the paths to changes files
+        (e.g., <filename>piuparts_1.0-1_i386.changes</filename>),
+        paths to package files
+        (e.g., <filename>piuparts_1.0-1_all.deb</filename>), or
+        names of packages, if the <option>--apt</option> option is
+        given. When processing changes files, by default, every package in a
+        changes file will be processed together per each individual changes file
+        given on the command line. Then each package given on the command line
+        is processed in a single group. If the
+        <option>--single-changes-list</option> is used, the packages in every
+        changes file is processed together along with any individual packages
+        that was given on the command line.</para>
         
         <para><command>piuparts</command> outputs to the standard output
         some log messages to show what is going on. If a
@@ -503,6 +511,22 @@
         
             <varlistentry>
             
+                <term><option>--single-changes-list</option></term>
+                
+                <listitem>
+                
+                    <para>When processing changes files, piuparts will process
+                    the packages in each individual changes file seperately.
+                    This option will set piuparts to scan the packages of all
+                    changes files together along with any individual package
+                    files that may have been given on the command line.</para>
+
+                </listitem>
+            
+            </varlistentry>
+
+            <varlistentry>
+            
                 <term><option>-v</option></term>
                 <term><option>--verbose</option></term>
                 
@@ -554,6 +578,17 @@
             <programlisting
             >piuparts -m 'http://gytha/debian main' ../foo_1.0-2_i386.deb</programlisting>
 
+            <para>If you want to do the same as above but for your changes
+            files, pass in your changes files when running piuparts, and
+            piuparts will process each package in the changes files as though
+            you had passed all those packages on the command line to piuparts
+            yourself. For example:</para>
+
+            <programlisting>piuparts ../foo_1.0-2_i386.changes</programlisting>
+            <programlisting
+            >piuparts -m 'http://gytha/debian main' ../foo_1.0-2_i386.changes</programlisting>
+
+
             <para>If you want to test that a package installs properly
             in the stable (etch) Debian release, then can be upgraded
             to the testing (lenny) and unstable (sid) versions, and then
diff -urN piuparts-0.33/piuparts.py piuparts-0.33.01/piuparts.py
--- piuparts-0.33/piuparts.py	2008-11-08 12:05:35.000000000 -0500
+++ piuparts-0.33.01/piuparts.py	2008-12-07 23:05:47.000000000 -0500
@@ -129,6 +129,7 @@
         self.tmpdir = None
         self.scriptsdir = None
         self.keep_tmpdir = False
+        self.single_changes_list = False
         self.max_command_output_size = 1024 * 1024
         self.args_are_package_files = True
         self.debian_mirrors = []
@@ -309,11 +310,11 @@
         handler.flush()
 
 
-def panic():
+def panic(exit=1):
     for i in range(counter):
         if i in on_panic_hooks:
             on_panic_hooks[i]()
-    sys.exit(1)
+    sys.exit(exit)
     
 
 def indent_string(str):
@@ -1336,6 +1337,40 @@
                 list.append(line.split(":", 1)[1].strip())
     return list
 
+# Method to process a changes file, returning a list of all the .deb packages
+# from the 'Files' stanza.
+def process_changes(changes):
+    # Determine the path to the changes file, then check if it's readable.
+    dir_path = ""
+    changes_path = ""
+    if not os.path.dirname(changes):
+        changes_path = os.path.basename(changes)
+    else:
+        dir_path = os.path.dirname(changes) + "/"
+        changes_path = os.path.abspath(changes)
+    if not os.access(changes_path, os.R_OK):
+        print changes_path + " is not readable."
+        return
+
+    # Determine the packages in the changes file through the 'Files' stanza.
+    pattern = re.compile('^Files:\s+\n(.*?)\n([^ ]|$)',
+        re.MULTILINE | re.DOTALL)
+    f = open(changes_path)
+    matches = pattern.split(f.read())
+    f.close()
+
+    # Append all the packages found in the changes file to a package list.
+    package_list = []
+    newline_p = re.compile('\n')
+    package_p = re.compile('.*?([^ ]+\.deb)$')
+    for line in newline_p.split(matches[1]):
+        if package_p.match(line):
+            package = dir_path + package_p.split(line)[1]
+            package_list.append(package)
+
+    # Return the list.
+    return package_list
+
 
 def check_results(chroot, root_info, file_owners, deps_info=None):
     """Check that current chroot state matches 'root_info'.
@@ -1398,7 +1433,7 @@
     return ok
 
 
-def install_purge_test(chroot, root_info, selections, args, packages):
+def install_purge_test(chroot, root_info, selections, package_list, packages):
     """Do an install-purge test. Return True if successful, False if not.
        Assume 'root' is a directory already populated with a working
        chroot, with packages in states given by 'selections'."""
@@ -1407,11 +1442,11 @@
 
     if settings.warn_on_others:
         # Create a metapackage with dependencies from the given packages
-        if args:
+        if package_list:
             control_infos = []
             # We were given package files, so let's get the Depends and
             # Conflicts directly from the .debs
-            for deb in args:
+            for deb in package_list:
                 returncode, output = run(["dpkg", "-f", deb])
                 control = deb822.Deb822(output)
                 control_infos.append(control)
@@ -1449,8 +1484,8 @@
     else:
         deps_info = None
 
-    if args:
-        chroot.install_package_files(args)
+    if package_list:
+        chroot.install_package_files(package_list)
     else:
         chroot.install_packages_by_name(packages)
         chroot.run(["apt-get", "clean"])
@@ -1470,7 +1505,7 @@
     return check_results(chroot, root_info, file_owners, deps_info=deps_info)
 
 
-def install_upgrade_test(chroot, root_info, selections, args, package_names):
+def install_upgrade_test(chroot, root_info, selections, package_list, package_names):
     """Install package via apt-get, then upgrade from package files.
     Return True if successful, False if not."""
 
@@ -1483,7 +1518,7 @@
     chroot.check_for_broken_symlinks()
 
     # Then from the package files.
-    chroot.install_package_files(args)
+    chroot.install_package_files(package_list)
     
     file_owners = chroot.get_files_owned_by_packages()
 
@@ -1737,7 +1772,11 @@
     parser.add_option("-t", "--tmpdir", metavar="DIR",
                       help="Use DIR for temporary storage. Default is " +
                            "$TMPDIR or /tmp.")
-    
+
+    parser.add_option("--single-changes-list", default=False,
+                      action="store_true",
+                      help="test all packages from all changes files together.")
+
     parser.add_option("-v", "--verbose", 
                       action="store_true", default=False,
                       help="No meaning anymore.")
@@ -1745,6 +1784,7 @@
     parser.add_option("--debfoster-options",
                       default="-o MaxPriority=required -o UseRecommends=no -f -n apt debfoster",
 		      help="Run debfoster with different parameters (default: -o MaxPriority=required -o UseRecommends=no -f -n apt debfoster).")
+
     
     (opts, args) = parser.parse_args()
 
@@ -1756,6 +1796,7 @@
     settings.ignored_files += opts.ignore
     settings.ignored_patterns += opts.ignore_regex
     settings.keep_tmpdir = opts.keep_tmpdir
+    settings.single_changes_list = opts.single_changes_list
     settings.keep_sources_list = opts.keep_sources_list
     settings.skip_minimize = opts.skip_minimize
     settings.list_installed_files = opts.list_installed_files
@@ -1830,26 +1871,14 @@
     if settings.adt_virt is None: return Chroot()
     return settings.adt_virt
 
-def main():
-    """Main program. But you knew that."""
-
-    args = parse_command_line()
-
-    logging.info("-" * 78)
-    logging.info("piuparts version %s starting up." % VERSION)
-    logging.info("Command line arguments: %s" % " ".join(sys.argv))
-    logging.info("Running on: %s %s %s %s %s" % os.uname())
-
-    # Make sure debconf does not ask questions and stop everything.
-    # Packages that don't use debconf will lose.
-    os.environ["DEBIAN_FRONTEND"] = "noninteractive"
-
+# Process the packages given in a list
+def process_packages(package_list):
     # Find the names of packages.
     if settings.args_are_package_files:
-        packages = get_package_names_from_package_files(args)
+        packages = get_package_names_from_package_files(package_list)
     else:
-        packages = args
-        args = []
+        packages = package_list
+        package_list = []
 
     if len(settings.debian_distros) == 1:
         chroot = get_chroot()
@@ -1868,7 +1897,7 @@
                     shutil.copy(os.path.join((settings.scriptsdir), file), dest) 
 
         if not install_purge_test(chroot, root_info, selections,
-				  args, packages):
+                  package_list, packages):
             logging.error("FAIL: Installation and purging test.")
             panic()
         logging.info("PASS: Installation and purging test.")
@@ -1878,7 +1907,7 @@
                 logging.info("Can't test upgrades: -a or --apt option used.")
             elif not chroot.apt_get_knows(packages):
                 logging.info("Can't test upgrade: packages not known by apt-get.")
-            elif install_upgrade_test(chroot, root_info, selections, args, 
+            elif install_upgrade_test(chroot, root_info, selections, package_list, 
                                   packages):
                 logging.info("PASS: Installation, upgrade and purging tests.")
             else:
@@ -1888,7 +1917,7 @@
         chroot.remove()
         dont_do_on_panic(id)
     else:
-        if install_and_upgrade_between_distros(args, packages):
+        if install_and_upgrade_between_distros(package_list, packages):
             logging.info("PASS: Upgrading between Debian distributions.")
         else:
             logging.error("FAIL: Upgrading between Debian distributions.")
@@ -1896,6 +1925,42 @@
 
     if settings.adt_virt is not None: settings.adt_virt.shutdown()
 
+def main():
+    """Main program. But you knew that."""
+
+    args = parse_command_line()
+
+    logging.info("-" * 78)
+    logging.info("piuparts version %s starting up." % VERSION)
+    logging.info("Command line arguments: %s" % " ".join(sys.argv))
+    logging.info("Running on: %s %s %s %s %s" % os.uname())
+
+    # Make sure debconf does not ask questions and stop everything.
+    # Packages that don't use debconf will lose.
+    os.environ["DEBIAN_FRONTEND"] = "noninteractive"
+
+
+    changes_packages_list = []
+    regular_packages_list = []
+    changes_p = re.compile('.*\.changes$')
+    for arg in args:
+        if changes_p.match(arg):
+            package_list = process_changes(arg)
+            if settings.single_changes_list:
+                for package in package_list:
+                    regular_packages_list.append(package)
+            else:
+                changes_packages_list.append(package_list)
+        else:
+            regular_packages_list.append(arg)
+
+    if changes_packages_list:
+        for package_list in changes_packages_list:
+            process_packages(package_list)
+
+    if regular_packages_list:
+        process_packages(regular_packages_list)
+
     logging.info("PASS: All tests.")
     logging.info("piuparts run ends.")
 

Attachment: piuparts-test-py
Description: application/python

Attachment: piuparts-changes-test
Description: application/shellscript

Attachment: signature.asc
Description: This is a digitally signed message part.

Reply via email to