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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
#!/usr/bin/env python2
# -*- Mode:Python; indent-tabs-mode:nil; tab-width:4 -*-
#
# Copyright 2002 Ben Escoto <ben@emerose.org>
# Copyright 2007 Kenneth Loafman <kenneth@loafman.com>
#
# This file is part of duplicity.
#
# Duplicity is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2 of the License, or (at your
# option) any later version.
#
# Duplicity is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with duplicity; if not, write to the Free Software Foundation,
# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
import os, re, shutil, time, sys, subprocess
SourceDir = "duplicity"
# Various details about the files must also be specified by the rpm
# spec template.
spec_template = "dist/duplicity.spec.template"
def VersionedCopy(source, dest):
"""
Copy source to dest, substituting $version with version
$reldate with today's date, i.e. December 28, 2008.
"""
fin = open(source, "rb")
inbuf = fin.read()
assert not fin.close()
(outbuf, cnt) = re.subn("\$version", Version, inbuf)
assert cnt != 0, "No $version string replaced in" + source
inbuf = outbuf
(outbuf, cnt) = re.subn("\$reldate", Reldate, inbuf)
fout = open(dest, "wb")
fout.write(outbuf)
assert not fout.close()
def MakeTar():
"""Create duplicity tar file"""
tardir = "duplicity-%s" % Version
tarfile = "duplicity-%s.tar.gz" % Version
try:
os.lstat(tardir)
os.system("rm -rf " + tardir)
except OSError: pass
# tarball contains the entire versioned release
os.mkdir(tardir)
bzr = subprocess.Popen(["bzr", "ls", "-RV", "."], stdout=subprocess.PIPE)
testfiles = bzr.communicate()[0].split()
if len(testfiles) == 0:
git = subprocess.Popen(["git", "ls-files"], stdout=subprocess.PIPE)
testfiles = git.communicate()[0].split()
for filename in testfiles:
if os.path.isdir(filename):
os.mkdir(os.path.join(tardir, filename))
else:
assert not os.system("cp --parents %s %s" %
(filename, tardir)), filename
# msgfmt the translation files that we have for release
assert not os.system("cd po && ./update-pot")
linguas = open('po/LINGUAS').readlines()
for line in linguas:
langs = line.split()
for lang in langs:
assert not os.mkdir(os.path.join(tardir, "po", lang)), lang
assert not os.system("cp po/%s.po %s/po/%s" % (lang, tardir, lang)), lang
assert not os.system("msgfmt po/%s.po -o %s/po/%s/duplicity.mo" % (lang, tardir, lang)), lang
# recopy the versioned files and add correct version
VersionedCopy(os.path.join(SourceDir, "globals.py"),
os.path.join(tardir, "duplicity", "globals.py"))
VersionedCopy(os.path.join("bin", "duplicity"),
os.path.join(tardir, "bin", "duplicity"))
VersionedCopy(os.path.join("bin", "rdiffdir"),
os.path.join(tardir, "bin", "rdiffdir"))
VersionedCopy(os.path.join("bin", "duplicity.1"),
os.path.join(tardir, "bin", "duplicity.1"))
VersionedCopy(os.path.join("bin", "rdiffdir.1"),
os.path.join(tardir, "bin", "rdiffdir.1"))
VersionedCopy("setup.py",
os.path.join(tardir, "setup.py"))
# make sure executables are
os.chmod(os.path.join(tardir, "setup.py"), 0755)
os.chmod(os.path.join(tardir, "bin", "duplicity"), 0755)
os.chmod(os.path.join(tardir, "bin", "rdiffdir"), 0755)
os.system("tar -czf %s %s" % (tarfile, tardir))
shutil.rmtree(tardir)
return tarfile
def MakeSpecFile():
"""Create spec file using spec template"""
specfile = "duplicity.spec"
VersionedCopy(spec_template, specfile)
return specfile
def Main():
print "Processing version " + Version
tarfile = MakeTar()
print "Made tar file " + tarfile
specfile = MakeSpecFile()
print "Made specfile " + specfile
if __name__ == "__main__" and not globals().has_key('__no_execute__'):
if len(sys.argv) != 2:
print "Syntax: makedist [version_number]"
sys.exit(1)
Version = sys.argv[1]
Reldate = time.strftime("%B %d, %Y", time.localtime())
Main()
|