From 09ba568f49600999682b1d8652c94044f488b494 Mon Sep 17 00:00:00 2001 From: Mark Wooding Date: Wed, 27 Mar 2013 21:24:16 +0000 Subject: [PATCH] agpl.py: Include a `MANIFEST' file explaining where things came from. --- agpl.py | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/agpl.py b/agpl.py index b89330c..20b6166 100644 --- a/agpl.py +++ b/agpl.py @@ -24,13 +24,18 @@ ### . import contextlib as CTX +import grp as GR import os as OS +import pwd as PW import shlex as SL import shutil as SH import subprocess as SUB import sys as SYS import tarfile as TAR import tempfile as TF +import time as T + +from cStringIO import StringIO from auto import PACKAGE, VERSION import util as U @@ -105,8 +110,32 @@ def source(out): else: tf = TAR.open(fileobj = out, mode = 'w|gz') tf.posix = True - for d in dirs_to_dump(): - dump_dir(d, tf, '%s-%s' % (PACKAGE, VERSION)) + root = '%s-%s' % (PACKAGE, VERSION) + seen = set() + dirmap = [] + festout = StringIO() + for dir in dirs_to_dump(): + dir = dir.rstrip('/') + base = OS.path.basename(dir) + if base not in seen: + name = base + else: + for i in I.count(): + name = '%s.%d' % (base, i) + if name not in seen: break + dirmap.append((dir + '/', name)) + festout.write('%s = %s\n' % (name, dir)) + fest = festout.getvalue() + ti = TAR.TarInfo(OS.path.join(root, 'MANIFEST')) + ti.size = len(fest) + ti.mtime = T.time() + ti.mode = 0664 + ti.type = TAR.REGTYPE + uid = OS.getuid(); ti.uid, ti.uname = uid, PW.getpwuid(uid).pw_name + gid = OS.getgid(); ti.gid, ti.gname = gid, GR.getgrgid(gid).gr_name + tf.addfile(ti, fileobj = StringIO(fest)) + for dir, name in dirmap: + dump_dir(dir, tf, root) tf.close() ###----- That's all, folks -------------------------------------------------- -- 2.11.0