-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathversion
executable file
·35 lines (30 loc) · 1.16 KB
/
version
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
#! /usr/bin/python
#
# This script prints out the version number of this copy of fswms.
#
# This script must be run from the top level of a copy of a fswms git project; it works
# by examining the git history of the project.
#
# If the currently checked out copy has a tag of the form "fswms-*", this script
# prints that tag.
#
# If the currently checked out copy does not have a tag of the form "fswms-*", this script
# prints the current sha, followed by "(with local mods)" if git reports and
# uncommited modifications.
#
import re, os, subprocess, sys
if not os.path.exists(".git"):
print "No .git subdirectory found."
sys.exit(-1)
line = subprocess.Popen(['git', 'log', '-1', '--pretty=format:"%h %ad | %s%d [%an]"', '--date=short'],
stdout=subprocess.PIPE).communicate()[0]
match = re.search(r'tag: (fswms-[^\)]+)', line)
if (match):
version = match.group(1)
else:
match = re.search(r'^"(\S+)', line)
version = match.group(1)
line = subprocess.Popen(['git', 'status'], stdout=subprocess.PIPE).communicate()[0]
if not re.search(r'nothing to commit', line):
version = version + " (with local mods)"
print version