File: version.py

package info (click to toggle)
stgit 0.18-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 1,728 kB
  • ctags: 1,741
  • sloc: python: 10,106; sh: 4,939; lisp: 2,678; makefile: 130; perl: 42
file content (58 lines) | stat: -rw-r--r-- 1,645 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
from stgit.exception import StgException
from stgit import run, utils
import os, os.path, re, sys

class VersionUnavailable(StgException):
    pass

def git_describe_version():
    path = sys.path[0]
    try:
        v = run.Run('git', 'describe', '--tags', '--abbrev=4'
                    ).cwd(path).discard_stderr().output_one_line()
    except run.RunException, e:
        raise VersionUnavailable(str(e))
    if not re.match(r'^v[0-9]', v):
        raise VersionUnavailable('%s: bad version' % v)
    try:
        dirty = run.Run('git', 'diff-index', '--name-only', 'HEAD'
                        ).cwd(path).discard_stderr().raw_output()
    except run.RunException, e:
        raise VersionUnavailable(str(e))
    if dirty:
        v += '-dirty'
    return utils.strip_prefix('v', v)

def builtin_version():
    try:
        import stgit.builtin_version as bv
    except ImportError:
        raise VersionUnavailable()
    else:
        return bv.version

def _builtin_version_file(ext = 'py'):
    return os.path.join(sys.path[0], 'stgit', 'builtin_version.%s' % ext)

def write_builtin_version():
    try:
        v = git_describe_version()
    except VersionUnavailable:
        return
    f = file(_builtin_version_file(), 'w')
    f.write('# This file was generated automatically. Do not edit by hand.\n'
            'version = %r\n' % v)

def get_version():
    for v in [builtin_version, git_describe_version]:
        try:
            return v()
        except VersionUnavailable:
            pass
    return 'unknown-version'

version = get_version()

# minimum version requirements
git_min_ver = '1.5.2'
python_min_ver = '2.4'