#!/usr/bin/env python import os, re, shutil, time, sys SourceDir = "rdiff_backup" DistDir = "dist" # 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 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"

FAQ:

""") wml_fp.write(faqbody_string) wml_fp.write("\n
\n") wml_fp.close() html_fp = open("FAQ.html", "w") html_fp.write( """ rdiff-backup FAQ

rdiff-backup FAQ

""") html_fp.write(faqbody_string) html_fp.write("\n") html_fp.close() def VersionedCopy(source, dest): """Copy source to dest, substituting $version with version""" fin = open(source, "rb") inbuf = fin.read() assert not fin.close() outbuf = re.sub("\$version", Version, inbuf, 1) if outbuf == inbuf: assert 0, "No $version string replaced" assert not re.search("\$version", outbuf), \ "Two $version strings found in the same file %s" % (source,) fout = open(dest, "wb") fout.write(outbuf) assert not fout.close() def MakeTar(): """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 filename in ["CHANGELOG", "COPYING", "README", "FAQ.html", SourceDir + "/cmodule.c", SourceDir + "/_librsyncmodule.c", DistDir + "/setup.py"]: assert not os.system("cp %s %s" % (filename, tardir)), filename os.mkdir(tardir+"/rdiff_backup") for filename in ["connection.py", "destructive_stepping.py", "FilenameMapping.py", "Hardlink.py", "highlevel.py", "increment.py", "__init__.py", "iterfile.py", "lazy.py", "librsync.py", "log.py", "Main.py", "manage.py", "MiscStats.py", "Rdiff.py", "restore.py", "rlist.py", "robust.py", "rorpiter.py", "rpath.py", "Security.py", "selection.py", "SetConnections.py", "static.py", "statistics.py", "Time.py"]: assert not os.system("cp %s/%s %s/rdiff_backup" % (SourceDir, filename, tardir)), filename VersionedCopy("%s/Globals.py" % (SourceDir,), "%s/rdiff_backup/Globals.py" % (tardir,)) VersionedCopy("rdiff-backup", "%s/rdiff-backup" % (tardir,)) VersionedCopy(DistDir + "/setup.py", "%s/setup.py" % (tardir,)) os.chmod(os.path.join(tardir, "setup.py"), 0755) os.chmod(os.path.join(tardir, "rdiff-backup"), 0644) CopyMan(os.path.join(tardir, "rdiff-backup.1"), Version) os.system("tar -cvzf %s %s" % (tarfile, tardir)) shutil.rmtree(tardir) return tarfile def MakeSpecFile(): """Create spec file using spec template""" specfile = "rdiff-backup-%s-2.spec" % Version VersionedCopy(spec_template, specfile) return specfile def Main(): print "Making FAQ" MakeFAQ() 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] Main()