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