|
1 | 1 | #!/usr/bin/env python |
2 | 2 |
|
3 | | -'''Create source distribution tar.gz archive, where each file belongs |
| 3 | +"""Create source distribution tar.gz archive, where each file belongs |
4 | 4 | to a root user and modification time is set to the git commit time. |
5 | | -''' |
| 5 | +""" |
6 | 6 |
|
7 | | -import sys |
| 7 | +import glob |
| 8 | +import gzip |
8 | 9 | import os |
9 | 10 | import subprocess |
10 | | -import glob |
| 11 | +import sys |
11 | 12 | import tarfile |
12 | | -import gzip |
13 | 13 |
|
14 | 14 | BASEDIR = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) |
15 | 15 | sys.path.insert(0, BASEDIR) |
16 | 16 |
|
17 | | -from setup import versiondata, FALLBACK_VERSION |
18 | | -timestamp = versiondata.getint('DEFAULT', 'timestamp') |
| 17 | +from setup import FALLBACK_VERSION, versiondata |
19 | 18 |
|
20 | | -vfb = versiondata.get('DEFAULT', 'version').split('.post')[0] + '.post0' |
| 19 | +timestamp = versiondata.getint("DEFAULT", "timestamp") |
| 20 | + |
| 21 | +vfb = versiondata.get("DEFAULT", "version").split(".post")[0] + ".post0" |
21 | 22 | emsg = "Invalid FALLBACK_VERSION. Expected %r got %r." |
22 | 23 | assert vfb == FALLBACK_VERSION, emsg % (vfb, FALLBACK_VERSION) |
23 | 24 |
|
| 25 | + |
24 | 26 | def inform(s): |
25 | 27 | sys.stdout.write(s) |
26 | 28 | sys.stdout.flush() |
27 | 29 | return |
28 | 30 |
|
| 31 | + |
29 | 32 | inform('Run "setup.py sdist --formats=tar" ') |
30 | | -cmd_sdist = [sys.executable] + 'setup.py sdist --formats=tar'.split() |
31 | | -ec = subprocess.call(cmd_sdist, cwd=BASEDIR, stdout=open(os.devnull, 'w')) |
32 | | -if ec: sys.exit(ec) |
| 33 | +cmd_sdist = [sys.executable] + "setup.py sdist --formats=tar".split() |
| 34 | +ec = subprocess.call(cmd_sdist, cwd=BASEDIR, stdout=open(os.devnull, "w")) |
| 35 | +if ec: |
| 36 | + sys.exit(ec) |
33 | 37 | inform("[done]\n") |
34 | 38 |
|
35 | | -tarname = max(glob.glob(BASEDIR + '/dist/*.tar'), key=os.path.getmtime) |
| 39 | +tarname = max(glob.glob(BASEDIR + "/dist/*.tar"), key=os.path.getmtime) |
36 | 40 |
|
37 | 41 | tfin = tarfile.open(tarname) |
38 | | -fpout = gzip.GzipFile(tarname + '.gz', 'w', mtime=0) |
39 | | -tfout = tarfile.open(fileobj=fpout, mode='w') |
| 42 | +fpout = gzip.GzipFile(tarname + ".gz", "w", mtime=0) |
| 43 | +tfout = tarfile.open(fileobj=fpout, mode="w") |
| 44 | + |
40 | 45 |
|
41 | 46 | def fixtarinfo(tinfo): |
42 | 47 | tinfo.uid = tinfo.gid = 0 |
43 | | - tinfo.uname = tinfo.gname = 'root' |
| 48 | + tinfo.uname = tinfo.gname = "root" |
44 | 49 | tinfo.mtime = timestamp |
45 | 50 | tinfo.mode &= ~0o022 |
46 | 51 | return tinfo |
47 | 52 |
|
48 | | -inform('Filter %s --> %s.gz ' % (2 * (os.path.basename(tarname),))) |
| 53 | + |
| 54 | +inform("Filter %s --> %s.gz " % (2 * (os.path.basename(tarname),))) |
49 | 55 | for ti in tfin: |
50 | 56 | tfout.addfile(fixtarinfo(ti), tfin.extractfile(ti)) |
51 | 57 |
|
|
0 commit comments