~therp-nl/anybox.recipe.openerp/jbaudoux-relative_paths_resolve_conflict

« back to all changes in this revision

Viewing changes to anybox/recipe/openerp/utils.py

[MRG] Update with target branch

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
logger = logging.getLogger(__name__)
8
8
 
9
9
 
 
10
MAJOR_VERSION_RE = re.compile(r'(\d+)[.](\d*)(\w*)')
 
11
 
 
12
 
10
13
class WorkingDirectoryKeeper(object):
11
14
    """A context manager to get back the working directory as it was before.
12
15
 
43
46
            yield f
44
47
 
45
48
 
46
 
NIGHTLY_VERSION_RE = re.compile(r'(\d+)[.](\d+)-(\d+-\d+)$')
47
 
 
48
 
MAJOR_VERSION_RE = re.compile(r'(\d+)[.](\d+)')
49
 
 
50
 
 
51
49
def major_version(version_string):
52
50
    """The least common denominator of OpenERP versions : two numbers.
53
51
 
55
53
    releases, bzr versions etc. It's almost impossible to compare them without
56
54
    an a priori knowledge of release dates and revisions.
57
55
 
 
56
    Here are some examples::
 
57
 
 
58
       >>> major_version('1.2.3-foo.bar')
 
59
       (1, 2)
 
60
       >>> major_version('6.1-20121003-233130')
 
61
       (6, 1)
 
62
       >>> major_version('7.0alpha')
 
63
       (7, 0)
 
64
 
58
65
    Beware, the packaging script does funny things, such as labeling current
59
66
    nightlies as 6.2-date-time whereas version_info is (7, 0, 0, ALPHA)
60
67
    We can in recipe code check for >= (6, 2), that's not a big issue.
 
68
 
 
69
    Regarding OpenERP saas releases (e.g. 7.saas~1) that are short-lived stable
 
70
    versions between two "X.0" LTS releases, the second version number does not
 
71
    contain a numeric value. The value X.5 will be returned (e.g. 7.5)::
 
72
 
 
73
       >>> major_version('7.saas~1')
 
74
       (7, 5)
 
75
 
61
76
    """
62
77
 
63
78
    m = MAJOR_VERSION_RE.match(version_string)
64
 
    if m is not None:
65
 
        return tuple(int(m.group(i)) for i in (1, 2))
 
79
 
 
80
    if m is None:
 
81
        raise ValueError("Unparseable version string: %r" % version_string)
 
82
 
 
83
    major = int(m.group(1))
 
84
    minor = m.group(2)
 
85
    if not minor and m.group(3).startswith('saas'):
 
86
        return major, 5
 
87
 
 
88
    try:
 
89
        return major, int(minor)
 
90
    except TypeError:
 
91
        raise ValueError(
 
92
            "Unrecognized second version segment in %r" % version_string)
66
93
 
67
94
 
68
95
def mkdirp(path):