4 Create src/allmydata/version.py, based upon the latest darcs release tag.
6 If your source tree is coming from darcs (i.e. there exists a _darcs
7 directory), this tool will determine the most recent release tag, count the
8 patches that have been applied since then, and compute a version number to be
9 written into version.py . This version number will be available by doing:
11 from allmydata import __version__
13 Source trees that do not come from darcs (release tarballs, nightly tarballs)
14 do not have a _darcs directory. Instead, they should have a version.py that
15 was generated before the tarball was produced. In this case, this script will
16 quietly exit without modifying the existing version.py .
18 FYI, src/allmydata/__init__.py will attempt to import version.py and use the
19 version number therein. If it cannot, it will announce a version of
20 'UNKNOWN'. This should only happen if someone manages to get hold of a
21 non-_darcs/ source tree.
23 'release tags' are tags in the tahoe source tree that match the following
26 ^allmydata-tahoe-\d+\.\d+\.\d+\w*$
28 This excludes zfec tags (which start with 'zfec '). It also excludes
29 'developer convenience tags', which look like 'hoping to fix bug -warner'.
30 (the original goal was to use release tags that lacked the 'allmydata-tahoe-'
31 prefix, but it turns out to be more efficient to keep it in, because I can't
32 get 'darcs changes --from-tag=' to accept real regexps).
37 import xml.dom.minidom
38 from subprocess import Popen, PIPE
40 def get_text(nodelist):
43 if node.nodeType == node.TEXT_NODE:
48 from util.version import Version
50 # This is the version of this tree, as created by misc/make-version.py from
51 # the Darcs patch information: the main version number is taken from the most
52 # recent release tag. If some patches have been added since the last release,
53 # this will have a -NN "build number" suffix. Please see
54 # allmydata.util.version for a description of what the different fields mean.
57 __version__ = Version(verstr)
60 def write_version_py(verstr):
61 f = open("src/allmydata/version.py", "wt")
62 f.write(VERSION_BODY % (verstr,))
66 if not os.path.exists("_darcs") or not os.path.isdir("_darcs"):
67 if os.path.exists("src/allmydata/version.py"):
68 print "no _darcs/ and version.py exists, leaving it alone"
70 print "no _darcs/ but no version.py either: how did you get this tree?"
72 cmd = ["darcs", "changes", "--from-tag=^allmydata-tahoe", "--xml-output"]
73 p = Popen(cmd, stdout=PIPE)
74 output = p.communicate()[0]
77 print "unable to run 'darcs changes':"
79 print "so I'm leaving version.py alone"
82 # windows' weird ssh process prepends some 'plink: unknown option "-O"'
83 # junk to the beginning of the otput. To overcome this, manually scan for
84 # the opening <changelog> tag before giving anything to the xml parser.
86 output = output[output.find("<changelog>"):]
89 doc = xml.dom.minidom.parseString(output)
90 except xml.parsers.expat.ExpatError:
91 print "unable to parse darcs XML output:"
94 changelog = doc.getElementsByTagName("changelog")[0]
95 patches = changelog.getElementsByTagName("patch")
97 version_re = re.compile("^TAG allmydata-tahoe-(\d+\.\d+\.\d+\w*)$")
99 name = get_text(patch.getElementsByTagName("name")[0].childNodes)
100 m = version_re.match(name)
102 last_tag = m.group(1)
103 last_tag = last_tag.encode("ascii")
107 print "unable to find a matching tag"
109 print "so I'm leaving version.py alone"
113 # this is an interim version
114 verstr = "%s-%d" % (last_tag, count)
119 write_version_py(verstr)
120 print "wrote '%s' into src/allmydata/version.py" % (verstr,)
123 if __name__ == '__main__':