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