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).
36 import os, sys, commands, re
37 import xml.dom.minidom
39 def get_text(nodelist):
42 if node.nodeType == node.TEXT_NODE:
47 from util.version import Version
49 # This is the version of this tree, as created by misc/make-version.py from
50 # the Darcs patch information: the main version number is taken from the most
51 # recent release tag. If some patches have been added since the last release,
52 # this will have a -NN "build number" suffix. Please see
53 # allmydata.util.version for a description of what the different fields mean.
56 __version__ = Version(verstr)
59 def write_version_py(verstr):
60 f = open("src/allmydata/version.py", "wt")
61 f.write(VERSION_BODY % (verstr,))
65 if not os.path.exists("_darcs") or not os.path.isdir("_darcs"):
66 if os.path.exists("src/allmydata/version.py"):
67 print "no _darcs/ and version.py exists, leaving it alone"
69 print "no _darcs/ but no version.py either: how did you get this tree?"
71 cmd = "darcs changes --from-tag=^allmydata-tahoe --xml-output"
72 (rc, output) = commands.getstatusoutput(cmd)
74 print "unable to run 'darcs changes':"
76 print "so I'm leaving version.py alone"
79 # windows' weird ssh process prepends some 'plink: unknown option "-O"'
80 # junk to the beginning of the otput. To overcome this, manually scan for
81 # the opening <changelog> tag before giving anything to the xml parser.
83 output = output[output.find("<changelog>"):]
86 doc = xml.dom.minidom.parseString(output)
87 except xml.parsers.expat.ExpatError:
88 print "unable to parse darcs XML output:"
91 changelog = doc.getElementsByTagName("changelog")[0]
92 patches = changelog.getElementsByTagName("patch")
94 version_re = re.compile("^TAG allmydata-tahoe-(\d+\.\d+\.\d+\w*)$")
96 name = get_text(patch.getElementsByTagName("name")[0].childNodes)
97 m = version_re.match(name)
100 last_tag = last_tag.encode("ascii")
104 print "unable to find a matching tag"
106 print "so I'm leaving version.py alone"
110 # this is an interim version
111 verstr = "%s-%d" % (last_tag, count)
116 write_version_py(verstr)
117 print "wrote '%s' into src/allmydata/version.py" % (verstr,)
120 if __name__ == '__main__':