File: Version.py

package info (click to toggle)
swift-im 2.0~beta1%2Bdev47-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 13,508 kB
  • sloc: cpp: 79,149; python: 1,397; xml: 546; sh: 150; ansic: 54; makefile: 40
file content (32 lines) | stat: -rw-r--r-- 1,028 bytes parent folder | download
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
import subprocess, os, datetime, re, os.path

def getGitBuildVersion(project) :
  tag = git("describe --tags --exact --match \"" + project + "-*\"")
  if tag :
    return tag.rstrip()[len(project)+1:]
  tag = git("describe --tags --match \"" + project + "-*\"")
  if tag :
    m = re.match(project + "-(.*)-(.*)-(.*)", tag)
    if m :
      return m.group(1) + "-dev" + m.group(2)
  return None
    
def git(cmd) :
  p = subprocess.Popen("git " + cmd, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=(os.name != "nt"))
  gitVersion = p.stdout.read()
  p.stdin.close()
  return gitVersion if p.wait() == 0 else None

def getBuildVersion(root, project) :
  versionFilename = os.path.join(root, "VERSION." + project)
  if os.path.isfile(versionFilename) :
    f = open(versionFilename)
    version = f.read().strip()
    f.close()
    return version

  gitVersion = getGitBuildVersion(project) 
  if gitVersion :
    return gitVersion

  return datetime.date.today().strftime("%Y%m%d")