summaryrefslogtreecommitdiff
path: root/rdiff-backup/dist/makedist
blob: 89dd24163645e4e956d0b8d5b271982c0c90cf2e (plain)
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
#!/usr/bin/env python

import os, re, shutil, time

SourceDir = "src"
filelist = [SourceDir + "/rdiff-backup", "CHANGELOG",
			"COPYING", "README", "FAQ.html"]


# Various details about the files must also be specified by the rpm
# spec template.
spec_template = "dist/rdiff-backup.spec"
redhat_spec_template = "dist/rdiff-backup.rh7x.spec"

def GetVersion():
	"""Return version string by reading in ./rdiff-backup"""
	fp = open(SourceDir + "/rdiff-backup", "r")
	match = re.search("Version (.*?) ", fp.read())
	fp.close()
	return match.group(1)

def CopyMan(destination, version):
	"""Create updated man page at the specified location"""
	fp = open(destination, "w")
	date = time.strftime("%B %Y", time.localtime(time.time()))
	version = "Version "+version
	firstline = ('.TH RDIFF-BACKUP 1 "%s" "%s" "User Manuals"\n' %
				 (date, version))
	fp.write(firstline)
	infp = open("rdiff-backup.1", "r")
	infp.readline()
	fp.write(infp.read())
	fp.close()
	infp.close()

def MakeFAQ():
	"""Create FAQ.html and FAQ.wml files from FAQ-body.html"""
	faqbody_fp = open("FAQ-body.html", "r")
	faqbody_string = faqbody_fp.read()
	faqbody_fp.close()

	wml_fp = open("FAQ.wml", "w")
	wml_fp.write(
"""#include 'template.wml' curpage=faq title="rdiff-backup: FAQ"

<divert body>
<p><h2>FAQ:</h2>

""")
	wml_fp.write(faqbody_string)
	wml_fp.write("\n</divert>\n")
	wml_fp.close()

	html_fp = open("FAQ.html", "w")
	html_fp.write(
"""<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
  <head>
    <title>rdiff-backup FAQ</title>
  </head>

  <body>
  <h1>rdiff-backup FAQ</h1>
""")
	html_fp.write(faqbody_string)
	html_fp.write("\n</body></html>")
	html_fp.close()

def MakeTar(version):
	"""Create rdiff-backup tar file"""
	tardir = "rdiff-backup-%s" % version
	tarfile = "rdiff-backup-%s.tar.gz" % version
	try:
		os.lstat(tardir)
		os.system("rm -rf " + tardir)
	except OSError: pass
	os.mkdir(tardir)
	for file in filelist: os.system("cp -a %s %s" % (file, tardir))
	os.chmod(os.path.join(tardir, "rdiff-backup"), 0755)
	CopyMan(os.path.join(tardir, "rdiff-backup.1"), version)
	os.system("tar -cvzf %s %s" % (tarfile, tardir))
	shutil.rmtree(tardir)
	return tarfile

def MakeSpecFile(version):
	"""Create spec file using spec template"""
	def helper(spec_template, specfile):
		"""Added now that there are special redhat rpms"""
		outfp = open(specfile, "w")
		outfp.write("Version: %s\n" % version)
		infp = open(spec_template, "r")
		outfp.write(infp.read())
		infp.close()
		outfp.close()

	specfile = "rdiff-backup-%s-1.spec" % version
	redhat_specfile = "rdiff-backup-%s-1.rh7x.spec" % version
	helper(spec_template, specfile)
	helper(redhat_spec_template, redhat_specfile)
	return (specfile, redhat_specfile)

def Main():
	cwd = os.getcwd()
	os.chdir(SourceDir)
	assert not os.system("./Make")
	os.chdir(cwd)
	version = GetVersion()
	print "Making FAQ"
	MakeFAQ()
	print "Processing version " + version
	tarfile = MakeTar(version)
	print "Made tar file " + tarfile
	specfiles = MakeSpecFile(version)
	print "Made specfiles %s and %s" % specfiles

if __name__ == "__main__": Main()