/usr/lib/python3/dist-packages/click/framework.py is in python3-click-package 0.4.43+16.04.20160203-0ubuntu2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 | # Copyright (C) 2014 Canonical Ltd.
# Author: Michael Vogt <michael.vogt@canonical.com>
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 3 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""Pure python click framework handling support."""
import logging
import os
import re
try:
import apt_pkg
except:
pass
import click.paths
class ClickFrameworkInvalid(Exception):
pass
# python version of the vala parse_deb822_file()
def parse_deb822_file(filename):
data = {}
with open(filename) as f:
for line in f:
line = line.strip()
# from deb822.vala
field_re_posix = (
r'^([^:[:space:]]+)[[:space:]]*:[[:space:]]'
'([^[:space:]].*?)[[:space:]]*$')
# python does not do posix char classes
field_re = field_re_posix.replace("[:space:]", "\s")
blank_re_posix = r'^[[:space:]]*$'
blank_re = blank_re_posix.replace("[:space:]", "\s")
if re.match(blank_re, line):
break
match = re.match(field_re, line)
if match and match.group(1) and match.group(2):
data[match.group(1).lower()] = match.group(2)
return data
# python version of vala get_frameworks_dir
def get_frameworks_dir():
return click.paths.frameworks_dir
def get_framework_path(framework_name):
framework_path = os.path.join(
get_frameworks_dir(), framework_name+".framework")
return framework_path
# python version of the vala click_framework_get_base_version()
def click_framework_get_base_version(framework_name):
deb822 = parse_deb822_file(get_framework_path(framework_name))
return deb822.get("base-version", None)
# python version of the vala click_framework_get_base_version()
def click_framework_get_base_name(framework_name):
deb822 = parse_deb822_file(get_framework_path(framework_name))
return deb822.get("base-name", None)
# python version of the vala click_framework_has_framework
def click_framework_has_framework(framework_name):
return os.path.exists(get_framework_path(framework_name))
def validate_framework(framework_string, ignore_missing_frameworks=False):
try:
apt_pkg
except NameError:
logging.warning("No apt_pkg module, skipping validate_framework")
return
try:
parsed_framework = apt_pkg.parse_depends(framework_string)
except ValueError:
raise ClickFrameworkInvalid(
'Could not parse framework "%s"' % framework_string)
base_name_versions = {}
missing_frameworks = []
for or_dep in parsed_framework:
if len(or_dep) > 1:
raise ClickFrameworkInvalid(
'Alternative dependencies in framework "%s" not yet '
'allowed' % framework_string)
if or_dep[0][1] or or_dep[0][2]:
raise ClickFrameworkInvalid(
'Version relationship in framework "%s" not yet allowed' %
framework_string)
# now verify that different base versions are not mixed
framework_name = or_dep[0][0]
if not click_framework_has_framework(framework_name):
missing_frameworks.append(framework_name)
continue
# ensure we do not use different base versions for the same base-name
framework_base_name = click_framework_get_base_name(
framework_name)
framework_base_version = click_framework_get_base_version(
framework_name)
prev = base_name_versions.get(framework_base_name, None)
if prev and prev != framework_base_version:
raise ClickFrameworkInvalid(
'Multiple frameworks with different base versions are not '
'allowed. Found: {} ({} != {})'.format(
framework_base_name,
framework_base_version,
base_name_versions[framework_base_name]))
base_name_versions[framework_base_name] = framework_base_version
if not ignore_missing_frameworks:
if len(missing_frameworks) > 1:
raise ClickFrameworkInvalid(
'Frameworks %s not present on system (use '
'--force-missing-framework option to override)' %
", ".join('"%s"' % f for f in missing_frameworks))
elif missing_frameworks:
raise ClickFrameworkInvalid(
'Framework "%s" not present on system (use '
'--force-missing-framework option to override)' %
missing_frameworks[0])
else:
if len(missing_frameworks) > 1:
logging.warning("Ignoring missing frameworks %s" % (
", ".join('"%s"' % f for f in missing_frameworks)))
elif missing_frameworks:
logging.warning('Ignoring missing framework "%s"' % (
missing_frameworks[0]))
|