Debian Codegraph @

rpython/tool/udir.py

raw symbols SCIP
1 #
2 # Common entry point to access a temporary directory (for testing, etc.)
3 # This uses the py lib's logic to create numbered directories. The last
4 # three temporary directories are kept.
5 #
6 # The udir is created with the following name:
7 #
8 # $PYPY_USESSION_DIR/usession-$PYPY_USESSION_BASENAME-N
9 #
10 # where N is a small number. If supported, a symlink is created for
11 # convenience too, pointing to (the most recent) udir:
12 #
13 # $PYPY_USESSION_DIR/usession-$PYPY_USESSION_BASENAME-$USER
14 #
15 # The default value for $PYPY_USESSION_DIR is the system's tmp.
16 # The default value for $PYPY_USESSION_BASENAME is the name
17 # of the current Mercurial branch.
18 #
19
20 import os
21 import sys
22
23 from rpython.tool.version import get_repo_version_info
24 import py
25
26 PYPY_KEEP = int(os.environ.get('PYPY_USESSION_KEEP', '3'))
27
28 def make_udir(dir=None, basename=None):
29 if dir is not None:
30 dir = py.path.local(dir)
31 if basename is None:
32 info = get_repo_version_info()
33 if info:
34 hgtag, hgid = info
35 basename = hgtag
36 if basename == '?':
37 basename = 'unknown' # directories with ? are not fun
38 # especially on windows
39 else:
40 basename = ''
41 basename = basename.replace('/', '--')
42 if not basename.startswith('-'):
43 basename = '-' + basename
44 if not basename.endswith('-'):
45 basename = basename + '-'
46 return py.path.local.make_numbered_dir(rootdir = dir,
47 prefix = 'usession' + basename,
48 keep = PYPY_KEEP)
49
50 udir = make_udir(dir = os.environ.get('PYPY_USESSION_DIR'),
51 basename = os.environ.get('PYPY_USESSION_BASENAME'))