File: cxxtest_misc.py

package info (click to toggle)
0ad 0.0.17-1~bpo70%2B1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy-backports
  • size: 51,252 kB
  • sloc: cpp: 223,208; ansic: 31,240; python: 16,343; perl: 4,083; sh: 1,011; makefile: 914; xml: 733; java: 621; ruby: 229; erlang: 53; sql: 40
file content (78 lines) | stat: -rwxr-xr-x 2,937 bytes parent folder | download | duplicates (22)
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
#-------------------------------------------------------------------------
# CxxTest: A lightweight C++ unit testing library.
# Copyright (c) 2008 Sandia Corporation.
# This software is distributed under the LGPL License v3
# For more information, see the COPYING file in the top CxxTest directory.
# Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
# the U.S. Government retains certain rights in this software.
#-------------------------------------------------------------------------

import sys
import os

def abort( problem ):
    '''Print error message and exit'''
    sys.stderr.write( '\n' )
    sys.stderr.write( problem )
    sys.stderr.write( '\n\n' )
    sys.exit(2)

if sys.version_info < (2,6):    #pragma: no cover
    def resolve_symlinks(orig_path):
        drive,tmp = os.path.splitdrive(os.path.normpath(orig_path))
        if not drive:
            drive = os.path.sep
        parts = tmp.split(os.path.sep)
        actual_path = [drive]
        while parts:
            actual_path.append(parts.pop(0))
            if not os.path.islink(os.path.join(*actual_path)):
                continue
            actual_path[-1] = os.readlink(os.path.join(*actual_path))
            tmp_drive, tmp_path = os.path.splitdrive(
                dereference_path(os.path.join(*actual_path)) )
            if tmp_drive:
                drive = tmp_drive
            actual_path = [drive] + tmp_path.split(os.path.sep)
        return os.path.join(*actual_path)

    def relpath(path, start=None):
        """Return a relative version of a path.
        (provides compatibility with Python < 2.6)"""
        # Some notes on implementation:
        #   - We rely on resolve_symlinks to correctly resolve any symbolic
        #     links that may be present in the paths
        #   - The explicit handling od the drive name is critical for proper
        #     function on Windows (because os.path.join('c:','foo') yields
        #     "c:foo"!).
        if not start:
            start = os.getcwd()
        ref_drive, ref_path = os.path.splitdrive(
            resolve_symlinks(os.path.abspath(start)) )
        if not ref_drive:
            ref_drive = os.path.sep
        start = [ref_drive] + ref_path.split(os.path.sep)
        while '' in start:
            start.remove('')

        pth_drive, pth_path = os.path.splitdrive(
            resolve_symlinks(os.path.abspath(path)) )
        if not pth_drive:
            pth_drive = os.path.sep
        path = [pth_drive] + pth_path.split(os.path.sep)
        while '' in path:
            path.remove('')

        i = 0
        max = min(len(path), len(start))
        while i < max and path[i] == start[i]:
            i += 1

        if i < 2:
            return os.path.join(*path)
        else:
            rel = ['..']*(len(start)-i) + path[i:]
            if rel:
                return os.path.join(*rel)
            else:
                return '.'