chiark / gitweb /
ownsrc wip package handling etc.
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Tue, 4 Apr 2017 14:17:18 +0000 (15:17 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Tue, 4 Apr 2017 14:17:18 +0000 (15:17 +0100)
hippotatlib/ownsource.py

index 2f710ca..89bc43f 100644 (file)
@@ -107,7 +107,7 @@ class SourceShipmentPreparer():
     return script
 
   def manifest_append(s, name, infol):
-    s._manifest.append((name, ' '.join(infol)))
+    s._manifest.append({ 'file':name, 'info':' '.join(infol) })
 
   def new_output_name(s, nametail, infol):
     s._outcounter += 1
@@ -157,27 +157,52 @@ class SourceShipmentPreparer():
     dpkg_S_in.seek(0)
     cmdl = ['xargs','-0r','dpkg','-S','--']
     dpkg_S = subprocess.Popen(cmdl,
-                             cwd='/',
-                             stdin=dpkg_S_in,
-                             stdout=subprocess.PIPE,
-                             close_fds=False)
+                              cwd='/',
+                              stdin=dpkg_S_in,
+                              stdout=subprocess.PIPE,
+                              stderr=sys.stderr,
+                              close_fds=False)
     dpkg_show_in = tempfile.TemporaryFile()
     pkginfos = { }
     for l in dpkgs.stdout:
       (pkgs, fname) = l.split(': ',1)
       pkgs = pkgs.split(', ')
       for p in pkgs:
-        pkginfos[
+        pkginfos.setdefault(p,{'files':[]})['files'].append([fname, infol])
         print(p, file=dpkg_show_in)
-
-    dpkg-query --show PACKAGE
+    assert(dpkg_S.wait() == 0)
+    dpkg_show_in.seek(0)
+    cmdl = ['xargs','-r','dpkg-query',
+ r'-f${Package}\t${Architecture}\t${Version}\t${Source}\t${Source-Version}\n'
+            '--show','--']
+    dpkg_show = subprocess.Popen(cmdl,
+                                 cwd='/',
+                                 stdin=dpkg_show_in,
+                                 stdout=subprocess.PIPE,
+                                 stderr=sys.stderr,
+                                 close_fds=False)
+    for l in dpkg_show.stdout:
+      (p,a,v) = l.split('\t')
+      pkginfos[p]['arch'] = a
+      pkginfos[p]['version'] = v
+      pkginfos[p]['source'] = v
+      pkginfos[p]['sourceversion'] = v
+    assert(dpkg_show.wait() == 0)
+    pl = pkginfos.keys()
+    pl.sort()
+    for p in pl:
+      pi = pkginfos[p]
+      debfname = '%s_%s_%s.deb' % (p, pi['version'], pi['arch'])
+      dscfname = '%s_%s.dsc' % (pi['source'], pi['sourceversion'])
+      s._manifest.append({ 'file_print': dscfname, 'info': debfname })
+      for (fname, infol) in pi['files']:
+        s._manifest.append({ 'file_print': fname, 'info': ' '.join(infol) })
 
   def thing_ought_packaged(s, fname):
     return s.thing_matches_globs(fname, s.src_package_globs)
 
   def src_file_packaged(s, fname);
-    try: s._package_files[fname].append(infol)
-    except KeyError: s._package_files[fname] = [infol]
+    s._package_files.setdefault(fname,[]).append(infol)
 
   def src_file(s, fname, infol):
     def fngens():
@@ -220,9 +245,11 @@ class SourceShipmentPreparer():
     cmdl = s.rune_shell + [ s.rune_portmanteau, 'x',
                             s.output_name, s.manifest_name ]
     mfh = s.open_output_fh(s.manifest_name,'w')
-    for (name, info) in s._manifest:
-      if name is not None: cmdl.append(name)
-      print('%s\t%s' % (name,info), file=mfh)
+    for me in s._manifest:
+      try: fname = me['file']
+      except KeyError: fname = me.get('file_print','')
+      else: cmdl.append(name)
+      print('%s\t%s' % (fname, me['info']), file=mfh)
     mfh.close()
     subprocess.run(cmdl,
                    cwd=s._destdir,