Repository navigation
Expand file tree
/
Copy pathmakesdist
More file actions
executable file
·54 lines (42 loc) · 1.47 KB
/
Copy pathmakesdist
File metadata and controls
executable file
·54 lines (42 loc) · 1.47 KB
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
#!/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 sys
import os
import subprocess
import glob
import tarfile
import gzip
BASEDIR = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
sys.path.insert(0, BASEDIR)
from setup import versiondata, FALLBACK_VERSION
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")