]> arthur.barton.de Git - bup.git/blob - cmd/version-cmd.py
cleanup-mounts-under: Don't fail when /proc/mounts isn't readable
[bup.git] / cmd / version-cmd.py
1 #!/usr/bin/env python
2 import sys
3 from bup import options
4 from bup import _version
5
6 optspec = """
7 bup version [--date|--commit|--tag]
8 --
9 date    display the date this version of bup was created
10 commit  display the git commit id of this version of bup
11 tag     display the tag name of this version.  If no tag is available, display the commit id
12 """
13 o = options.Options(optspec)
14 (opt, flags, extra) = o.parse(sys.argv[1:])
15
16
17 total = (opt.date or 0) + (opt.commit or 0) + (opt.tag or 0)
18 if total > 1:
19     o.fatal('at most one option expected')
20
21
22 def version_date():
23     """Format bup's version date string for output."""
24     return _version.DATE.split(' ')[0]
25
26
27 def version_commit():
28     """Get the commit hash of bup's current version."""
29     return _version.COMMIT
30
31
32 def version_tag():
33     """Format bup's version tag (the official version number).
34
35     When generated from a commit other than one pointed to with a tag, the
36     returned string will be "unknown-" followed by the first seven positions of
37     the commit hash.
38     """
39     names = _version.NAMES.strip()
40     assert(names[0] == '(')
41     assert(names[-1] == ')')
42     names = names[1:-1]
43     l = [n.strip() for n in names.split(',')]
44     for n in l:
45         if n.startswith('tag: bup-'):
46             return n[9:]
47     return 'unknown-%s' % _version.COMMIT[:7]
48
49
50 if opt.date:
51     print version_date()
52 elif opt.commit:
53     print version_commit()
54 else:
55     print version_tag()