File: udir.py

package info (click to toggle)
pypy3 7.3.11%2Bdfsg-2%2Bdeb12u3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 201,024 kB
  • sloc: python: 1,950,308; ansic: 517,580; sh: 21,417; asm: 14,419; cpp: 4,263; makefile: 4,228; objc: 761; xml: 530; exp: 499; javascript: 314; pascal: 244; lisp: 45; csh: 11; awk: 4
file content (51 lines) | stat: -rw-r--r-- 1,719 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
#
# Common entry point to access a temporary directory (for testing, etc.)
# This uses the py lib's logic to create numbered directories.  The last
# three temporary directories are kept.
#
# The udir is created with the following name:
#
#    $PYPY_USESSION_DIR/usession-$PYPY_USESSION_BASENAME-N
#
# where N is a small number.  If supported, a symlink is created for
# convenience too, pointing to (the most recent) udir:
#
#    $PYPY_USESSION_DIR/usession-$PYPY_USESSION_BASENAME-$USER
#
# The default value for $PYPY_USESSION_DIR is the system's tmp.
# The default value for $PYPY_USESSION_BASENAME is the name
# of the current Mercurial branch.
#

import os
import sys

from rpython.tool.version import get_repo_version_info
from py.path import local 

PYPY_KEEP = int(os.environ.get('PYPY_USESSION_KEEP', '3'))

def make_udir(dir=None, basename=None):
    if dir is not None:
        dir = local(dir)
    if basename is None:
        info = get_repo_version_info()
        if info:
            hgtag, hgid = info
            basename = hgtag
            if basename == '?':
                basename = 'unknown' # directories with ? are not fun
                # especially on windows
        else:
            basename = ''
    basename = basename.replace('/', '--')
    if not basename.startswith('-'):
        basename = '-' + basename
    if not basename.endswith('-'):
        basename = basename + '-'
    return local.make_numbered_dir(rootdir = dir,
                                   prefix = 'usession' + basename,
                                   keep = PYPY_KEEP)

udir = make_udir(dir      = os.environ.get('PYPY_USESSION_DIR'),
                 basename = os.environ.get('PYPY_USESSION_BASENAME'))