1 |
#!/usr/bin/env python |
---|
2 |
|
---|
3 |
import gzip |
---|
4 |
import tarfile |
---|
5 |
import os |
---|
6 |
from os.path import basename |
---|
7 |
import time |
---|
8 |
import shutil |
---|
9 |
|
---|
10 |
mtime = 0 |
---|
11 |
|
---|
12 |
def _write_gzip_header(self): |
---|
13 |
self.fileobj.write('\037\213') # magic header |
---|
14 |
self.fileobj.write('\010') # compression method |
---|
15 |
fname = self.filename[:-3] |
---|
16 |
flags = 0 |
---|
17 |
if fname: |
---|
18 |
flags = gzip.FNAME |
---|
19 |
self.fileobj.write(chr(flags)) |
---|
20 |
gzip.write32u(self.fileobj, long(mtime)) |
---|
21 |
self.fileobj.write('\002') |
---|
22 |
self.fileobj.write('\377') |
---|
23 |
if fname: |
---|
24 |
self.fileobj.write(fname + '\000') |
---|
25 |
|
---|
26 |
gzip.GzipFile._write_gzip_header = _write_gzip_header |
---|
27 |
|
---|
28 |
class MyTarFile(tarfile.TarFile): |
---|
29 |
def gettarinfo(self, name=None, arcname=None, fileobj=None): |
---|
30 |
info = tarfile.TarFile.gettarinfo(self, name, arcname, fileobj) |
---|
31 |
info.uid = info.gid = 0 |
---|
32 |
info.uname = "root" |
---|
33 |
info.gname = "wheel" |
---|
34 |
|
---|
35 |
info.mtime = mtime |
---|
36 |
|
---|
37 |
return info |
---|
38 |
|
---|
39 |
def packageSvn(module, svnModule, extras=[], svnroot='file:///afs/dev.mit.edu/source/svn-repos', revision='HEAD'): |
---|
40 |
global mtime |
---|
41 |
|
---|
42 |
os.system('attach macathena >/dev/null 2>/dev/null') |
---|
43 |
os.chdir('/mit/macathena/build') |
---|
44 |
|
---|
45 |
os.system('svn export -r %s %s/%s %s >/dev/null 2>&1' % (revision, svnroot, svnModule, module)) |
---|
46 |
|
---|
47 |
if extras: |
---|
48 |
for extra in extras: |
---|
49 |
os.system('svn export -r %s %s/%s >/dev/null 2>&1' % (revision, svnroot, extra)) |
---|
50 |
os.system('mv %s %s' % (basename(extra), module)) |
---|
51 |
|
---|
52 |
version_info = os.popen('svn info -r %s %s/%s' % (revision, svnroot, svnModule)).readlines() |
---|
53 |
for line in version_info: |
---|
54 |
if line.startswith('Last Changed Date: '): |
---|
55 |
time_string = line.strip().split(': ')[1][0:19] |
---|
56 |
elif line.startswith('Last Changed Rev: '): |
---|
57 |
revision = line.strip().split(': ')[1] |
---|
58 |
|
---|
59 |
mtime = int(time.strftime("%s", time.strptime(time_string, "%Y-%m-%d %H:%M:%S"))) |
---|
60 |
|
---|
61 |
tarball = "%s-svn%s" % (module, revision) |
---|
62 |
os.rename(module, tarball) |
---|
63 |
|
---|
64 |
tar = MyTarFile.open('%s.tar.gz' % tarball, 'w:gz') |
---|
65 |
tar.add(tarball) |
---|
66 |
tar.close() |
---|
67 |
|
---|
68 |
shutil.move('%s.tar.gz' % tarball, '/mit/macathena/dist/') |
---|
69 |
shutil.rmtree('/mit/macathena/build/%s' % tarball) |
---|
70 |
|
---|
71 |
print 'Created /mit/macathena/dist/%s.tar.gz' % tarball |
---|
72 |
|
---|
73 |
def packageCvs(module, cvsModule, extras=['packs/build/autoconf'], cvsroot='/afs/dev.mit.edu/source/repository', date='tomorrow'): |
---|
74 |
global mtime |
---|
75 |
|
---|
76 |
os.system('attach macathena >/dev/null 2>/dev/null') |
---|
77 |
os.chdir('/mit/macathena/build') |
---|
78 |
|
---|
79 |
os.environ['CVSROOT'] = cvsroot |
---|
80 |
os.system('cvs -R export -D %s %s >/dev/null 2>/dev/null' % (date, cvsModule)) |
---|
81 |
|
---|
82 |
if extras: |
---|
83 |
for extra in extras: |
---|
84 |
os.system('cvs -R export -D %s -d %s %s >/dev/null 2>/dev/null' % (date, cvsModule, extra)) |
---|
85 |
|
---|
86 |
stamp = 0 |
---|
87 |
for root, dirs, files in os.walk(cvsModule): |
---|
88 |
if len(files) > 0: |
---|
89 |
stamp = max(stamp, max(os.stat('%s/%s' % (root, file))[8] for file in files)) |
---|
90 |
|
---|
91 |
mtime = int(time.strftime('%s', time.localtime(stamp))) |
---|
92 |
tarball_time = time.strftime('%Y%m%d', time.localtime(stamp)) |
---|
93 |
tarball = '%s-%s' % (module, tarball_time) |
---|
94 |
os.rename(cvsModule, tarball) |
---|
95 |
|
---|
96 |
tar = MyTarFile.open('%s.tar.gz' % tarball, 'w:gz') |
---|
97 |
tar.add(tarball) |
---|
98 |
tar.close() |
---|
99 |
|
---|
100 |
shutil.move('%s.tar.gz' % tarball, '/mit/macathena/dist/') |
---|
101 |
shutil.rmtree('/mit/macathena/build/%s' % tarball) |
---|
102 |
|
---|
103 |
print 'Created /mit/macathena/dist/%s.tar.gz' % tarball |
---|
104 |
|
---|
105 |
cvsModules = {'moira': ['moira', False, '/afs/athena.mit.edu/astaff/project/moiradev/repository']} |
---|
106 |
|
---|
107 |
svnModules = {'athdir': ['trunk/athena/bin/athdir'], |
---|
108 |
'attachandrun': ['trunk/athena/bin/attachandrun'], |
---|
109 |
'athrun': ['trunk/athena/bin/athrun'], |
---|
110 |
'athinfo': ['trunk/athena/bin/athinfo'], |
---|
111 |
'delete': ['trunk/athena/bin/delete', ['attic/packs/build/aclocal.m4']], |
---|
112 |
'discuss': ['trunk/athena/bin/discuss', ['attic/packs/build/aclocal.m4']], |
---|
113 |
'getcluster': ['trunk/athena/bin/getcluster', ['attic/packs/build/aclocal.m4']], |
---|
114 |
'just': ['trunk/athena/bin/just'], |
---|
115 |
'libathdir': ['trunk/athena/lib/athdir'], |
---|
116 |
'libgms': ['trunk/athena/lib/gms'], |
---|
117 |
'libxj': ['trunk/athena/lib/Xj'], |
---|
118 |
'machtype': ['trunk/athena/bin/machtype'], |
---|
119 |
'xcluster': ['trunk/athena/bin/xcluster', ['attic/packs/build/aclocal.m4']], |
---|
120 |
# Our packages: |
---|
121 |
'add': ['trunk/source/add', False, 'https://macathena.mit.edu/svn'], |
---|
122 |
'attach': ['trunk/source/attach', False, 'https://macathena.mit.edu/svn'], |
---|
123 |
'base': ['trunk/source/base', False, 'https://macathena.mit.edu/svn'], |
---|
124 |
'pyhesiodfs': ['trunk/source/pyhesiodfs', False, 'https://macathena.mit.edu/svn'], |
---|
125 |
'update': ['trunk/source/update', False, 'https://macathena.mit.edu/svn'] |
---|
126 |
} |
---|
127 |
|
---|
128 |
if __name__ == '__main__': |
---|
129 |
import sys |
---|
130 |
|
---|
131 |
if sys.argv[1] == "all": |
---|
132 |
build = cvsModules.keys() + svnModules.keys() |
---|
133 |
else: |
---|
134 |
build = sys.argv[1:] |
---|
135 |
|
---|
136 |
for arg in build: |
---|
137 |
if svnModules.has_key(arg): |
---|
138 |
print "Building %s" % arg |
---|
139 |
apply(packageSvn, [arg] + svnModules[arg]) |
---|
140 |
elif cvsModules.has_key(arg): |
---|
141 |
print "Building %s" % arg |
---|
142 |
apply(packageCvs, [arg] + cvsModules[arg]) |
---|
143 |
else: |
---|
144 |
print "Sorry - I don't know about the module %s" % arg |
---|