~mitya57/ubuntu/trusty/dh-python/tests-dependencies

« back to all changes in this revision

Viewing changes to .pc/python3.4.diff/dhpython/_defaults.py

  • Committer: Package Import Robot
  • Author(s): Matthias Klose
  • Date: 2013-12-21 17:15:02 UTC
  • mfrom: (4.1.14 trusty-proposed)
  • Revision ID: package-import@ubuntu.com-20131221171502-rlr93udry6or5njx
Tags: 1.20131021-1ubuntu6
Disable the correct failing test.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /usr/bin/python3
 
2
# Copyright © 2013 Piotr Ożarowski <piotr@debian.org>
 
3
#
 
4
# Permission is hereby granted, free of charge, to any person obtaining a copy
 
5
# of this software and associated documentation files (the "Software"), to deal
 
6
# in the Software without restriction, including without limitation the rights
 
7
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 
8
# copies of the Software, and to permit persons to whom the Software is
 
9
# furnished to do so, subject to the following conditions:
 
10
#
 
11
# The above copyright notice and this permission notice shall be included in
 
12
# all copies or substantial portions of the Software.
 
13
#
 
14
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
15
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
16
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 
17
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 
18
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 
19
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 
20
# THE SOFTWARE.
 
21
 
 
22
import logging
 
23
from configparser import ConfigParser
 
24
from os import environ
 
25
from subprocess import Popen, PIPE
 
26
 
 
27
SUPPORTED = {
 
28
    'cpython2': [(2, 7)],
 
29
    'cpython3': [(3, 3)],
 
30
    'pypy': [(2, 0)]}
 
31
DEFAULT = {
 
32
    'cpython2': (2, 7),
 
33
    'cpython3': (3, 3),
 
34
    'pypy': (2, 0)}
 
35
 
 
36
log = logging.getLogger('dhpython')
 
37
 
 
38
 
 
39
def cpython_versions(major):
 
40
    result = [None, None]
 
41
    ver = '' if major == 2 else '3'
 
42
    supported = environ.get("DEBPYTHON{}_SUPPORTED".format(ver))
 
43
    default = environ.get("DEBPYTHON{}_DEFAULT".format(ver))
 
44
    if not supported or not default:
 
45
        config = ConfigParser()
 
46
        config.read("/usr/share/python{}/debian_defaults".format(ver))
 
47
        if not default:
 
48
            default = config.get('DEFAULT', 'default-version', fallback='')[6:]
 
49
        if not supported:
 
50
            supported = config.get('DEFAULT', 'supported-versions', fallback='')\
 
51
                .replace('python', '')
 
52
    if default:
 
53
        try:
 
54
            result[0] = tuple(int(i) for i in default.split('.'))
 
55
        except Exception as err:
 
56
            log.warn('invalid debian_defaults file: %s', err)
 
57
    if supported:
 
58
        try:
 
59
            result[1] = tuple(tuple(int(j) for j in i.strip().split('.'))
 
60
                              for i in supported.split(','))
 
61
        except Exception as err:
 
62
            log.warn('invalid debian_defaults file: %s', err)
 
63
    return result
 
64
 
 
65
 
 
66
def from_file(fpath):
 
67
    if not exists(fpath):
 
68
        raise ValueError("missing interpreter: %s" % fpath)
 
69
    command = "{} --version".format(fpath)
 
70
    with Popen(command, shell=True, stdout=PIPE) as process:
 
71
        stdout, stderr = process.communicate()
 
72
        stdout = str(stdout, 'utf-8')
 
73
 
 
74
    print(stdout)
 
75
 
 
76
 
 
77
cpython2 = cpython_versions(2)
 
78
cpython3 = cpython_versions(3)
 
79
if cpython2[0]:
 
80
    DEFAULT['cpython2'] = cpython2[0]
 
81
if cpython3[0]:
 
82
    DEFAULT['cpython3'] = cpython3[0]
 
83
if cpython2[1]:
 
84
    SUPPORTED['cpython2'] = cpython2[1]
 
85
if cpython3[1]:
 
86
    SUPPORTED['cpython3'] = cpython3[1]
 
87
#from_file('/usr/bin/pypy')
 
88
 
 
89
 
 
90
if __name__ == '__main__':
 
91
    from sys import argv, stderr
 
92
    if len(argv) != 3:
 
93
        print('invalid number of arguments', file=stderr)
 
94
        exit(1)
 
95
    if argv[1] == 'default':
 
96
        print('.'.join(str(i) for i in DEFAULT[argv[2]]))
 
97
    elif argv[1] == 'supported':
 
98
        print(','.join(('.'.join(str(i) for i in v) for v in SUPPORTED[argv[2]])))