File: ancient-python-version-field.py

package info (click to toggle)
lintian-brush 0.147
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 9,872 kB
  • sloc: python: 17,649; makefile: 814; sh: 140; xml: 119; javascript: 3; ansic: 2
file content (67 lines) | stat: -rwxr-xr-x 2,225 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/python3

import os
import sys
from lintian_brush.fixer import (
    LintianIssue,
    control,
    report_result,
)
from lintian_brush.lintian import LINTIAN_DATA_PATH


def parse(t):
    return tuple([int(v) for v in t.split(".")])


PYTHON_VERSIONS_PATH = os.path.join(
    LINTIAN_DATA_PATH, 'python/versions')


python_versions = {}
try:
    with open(os.path.join(PYTHON_VERSIONS_PATH)) as f:
        for line in f:
            line = line.strip()
            if not line:
                continue
            key, value = line.split('=')
            python_versions[key.strip()] = parse(value.strip())
except FileNotFoundError:
    sys.exit(2)


with control as updater:
    # Remove anything that involves python 2.6, 2.7, 3.3
    if ("X-Python-Version" in updater.source and
            updater.source["X-Python-Version"].strip().startswith(">= 2.")):
        vers = updater.source["X-Python-Version"].split(">=")[1].strip()
        if parse(vers) <= python_versions['old-python2']:
            if parse(vers) <= python_versions['ancient-python2']:
                kind = 'ancient'
            else:
                kind = 'old'
        issue = LintianIssue(
            updater.source, '%s-python-version-field' % kind,
            'x-python-version %s' % updater.source['X-Python-Version'])
        if issue.should_fix():
            del updater.source["X-Python-Version"]
            issue.report_fixed()
    if ("X-Python3-Version" in updater.source and
            updater.source["X-Python3-Version"].strip().startswith(">=")):
        vers = updater.source["X-Python3-Version"].split(">=")[1].strip()
        if parse(vers) <= python_versions['old-python3']:
            if parse(vers) <= python_versions['ancient-python3']:
                kind = 'ancient'
            else:
                kind = 'old'
            issue = LintianIssue(
                updater.source, '%s-python-version-field' % kind,
                'x-python3-version %s' % updater.source['X-Python3-Version'])
            if issue.should_fix():
                del updater.source["X-Python3-Version"]
                issue.report_fixed()


report_result(
    "Remove unnecessary X-Python{,3}-Version field in debian/control.")