/usr/share/pyshared/nibabel/pkg_info.py is in python-nibabel 1.3.0-2.
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 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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | import os
import sys
import subprocess
from ConfigParser import ConfigParser
COMMIT_INFO_FNAME = 'COMMIT_INFO.txt'
def pkg_commit_hash(pkg_path):
''' Get short form of commit hash given directory `pkg_path`
There should be a file called 'COMMIT_INFO.txt' in `pkg_path`. This is a
file in INI file format, with at least one section: ``commit hash``, and two
variables ``archive_subst_hash`` and ``install_hash``. The first has a
substitution pattern in it which may have been filled by the execution of
``git archive`` if this is an archive generated that way. The second is
filled in by the installation, if the installation is from a git archive.
We get the commit hash from (in order of preference):
* A substituted value in ``archive_subst_hash``
* A written commit hash value in ``install_hash`
* git's output, if we are in a git repository
If all these fail, we return a not-found placeholder tuple
Parameters
----------
pkg_path : str
directory containing package
Returns
-------
hash_from : str
Where we got the hash from - description
hash_str : str
short form of hash
'''
# Try and get commit from written commit text file
pth = os.path.join(pkg_path, COMMIT_INFO_FNAME)
if not os.path.isfile(pth):
raise IOError('Missing commit info file %s' % pth)
cfg_parser = ConfigParser()
cfg_parser.read(pth)
archive_subst = cfg_parser.get('commit hash', 'archive_subst_hash')
if not archive_subst.startswith('$Format'): # it has been substituted
return 'archive substitution', archive_subst
install_subst = cfg_parser.get('commit hash', 'install_hash')
if install_subst != '':
return 'installation', install_subst
# maybe we are in a repository
proc = subprocess.Popen('git rev-parse --short HEAD',
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
cwd=pkg_path, shell=True)
repo_commit, _ = proc.communicate()
if repo_commit:
return 'repository', repo_commit.strip()
return '(none found)', '<not found>'
def get_pkg_info(pkg_path):
''' Return dict describing the context of this package
Parameters
----------
pkg_path : str
path containing __init__.py for package
Returns
-------
context : dict
with named parameters of interest
'''
src, hsh = pkg_commit_hash(pkg_path)
import numpy
return dict(
pkg_path=pkg_path,
commit_source=src,
commit_hash=hsh,
sys_version=sys.version,
sys_executable=sys.executable,
sys_platform=sys.platform,
np_version=numpy.__version__)
|