/usr/share/pyshared/mdp/repo_revision.py is in python-mdp 3.3-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | import mdp
import os
from subprocess import Popen, PIPE, STDOUT
def get_git_revision():
"""When mdp is run from inside a git repository, this function
returns the current revision that git-describe gives us.
If mdp is installed (or git fails for some other reason),
an empty string is returned.
"""
# TODO: Introduce some fallback method that takes the info from a file
revision = ''
try:
# we need to be sure that we call from the mdp dir
mdp_dir = os.path.dirname(mdp.__file__)
# --tags ensures that most revisions have a name even without
# annotated tags
# --dirty=+ appends a plus if the working copy is modified
command = ["git", "describe", "--tags", "--dirty=+"]
proc = Popen(command, stdout=PIPE, stderr=STDOUT, cwd=mdp_dir,
universal_newlines=True)
exit_status = proc.wait()
# only get the revision if command succeded
if exit_status == 0:
revision = proc.stdout.read().strip()
except OSError:
pass
return revision
|