|
40 | 40 | import sys |
41 | 41 |
|
42 | 42 | if sys.version_info[0] < 3: # Python 2 |
43 | | - import backports.csv as csv |
44 | | - from itertools import izip_longest as zip_longest |
45 | | - from urlparse import urljoin, urlparse |
46 | | - from urllib2 import urlopen, Request, HTTPError |
| 43 | + import backports.csv as csv # NOQA |
| 44 | + from itertools import izip_longest as zip_longest # NOQA |
| 45 | + from urlparse import urljoin, urlparse # NOQA |
| 46 | + from urllib2 import urlopen, Request, HTTPError # NOQA |
47 | 47 | else: # Python 3 |
48 | | - basestring = str |
49 | | - import csv |
50 | | - from itertools import zip_longest |
51 | | - from urllib.parse import urljoin, urlparse |
52 | | - from urllib.request import urlopen, Request |
53 | | - from urllib.error import HTTPError |
| 48 | + basestring = str # NOQA |
| 49 | + import csv # NOQA |
| 50 | + from itertools import zip_longest # NOQA |
| 51 | + from urllib.parse import urljoin, urlparse # NOQA |
| 52 | + from urllib.request import urlopen, Request # NOQA |
| 53 | + from urllib.error import HTTPError # NOQA |
54 | 54 |
|
55 | 55 | from license_expression import Licensing |
56 | 56 |
|
|
67 | 67 | from attributecode.util import on_windows |
68 | 68 | from attributecode.util import ungroup_licenses |
69 | 69 | from attributecode.util import UNC_PREFIX |
70 | | -from attributecode.util import UNC_PREFIX_POSIX |
71 | 70 |
|
72 | 71 |
|
73 | 72 | class Field(object): |
@@ -666,7 +665,7 @@ def __eq__(self, other): |
666 | 665 | and self.value == other.value) |
667 | 666 |
|
668 | 667 |
|
669 | | -def validate_fields(fields, about_file_path, running_inventory, base_dir, |
| 668 | +def validate_fields(fields, about_file_path, running_inventory, base_dir, |
670 | 669 | license_notice_text_location=None): |
671 | 670 | """ |
672 | 671 | Validate a sequence of Field objects. Return a list of errors. |
@@ -707,7 +706,7 @@ def create_fields(self): |
707 | 706 | is simpler. |
708 | 707 | """ |
709 | 708 | self.fields = OrderedDict([ |
710 | | - #('about_resource', ListField(required=True)), |
| 709 | + # ('about_resource', ListField(required=True)), |
711 | 710 | # ('about_resource', AboutResourceField(required=True)), |
712 | 711 | ('about_resource', AboutResourceField(required=True)), |
713 | 712 | ('name', SingleLineField(required=True)), |
@@ -874,29 +873,6 @@ def as_dict(self, with_paths=False, with_absent=True, with_empty=True): |
874 | 873 | if with_paths: |
875 | 874 | afpa = self.about_file_path_attr |
876 | 875 | as_dict[afpa] = self.about_file_path |
877 | | - arpa = self.about_resource_path_attr |
878 | | - """ |
879 | | - if self.about_resource_path.present: |
880 | | - as_dict[arpa] = self.resolved_resources_paths() |
881 | | - else: |
882 | | - arp = OrderedDict() |
883 | | - # Create a relative 'about_resource_path' if user has not defined |
884 | | - if self.about_resource.present: |
885 | | - for resource_name in self.about_resource.value: |
886 | | - key = u'' |
887 | | - if resource_name == '.': |
888 | | - key = resource_name |
889 | | - else: |
890 | | - key = './' + resource_name |
891 | | - arp[key] = None |
892 | | - as_dict[arpa] = arp |
893 | | - # Return an empty 'about_resource_path' if the 'about_resource' |
894 | | - # key is not found |
895 | | - else: |
896 | | - key = u'' |
897 | | - arp[key] = None |
898 | | - as_dict[arpa] = arp |
899 | | - """ |
900 | 876 |
|
901 | 877 | for field in self.all_fields(with_absent=with_absent, |
902 | 878 | with_empty=with_empty): |
@@ -1050,9 +1026,9 @@ def load(self, location, use_mapping=False, mapping_file=None): |
1050 | 1026 | and then join with the 'about_resource' |
1051 | 1027 | """ |
1052 | 1028 | running_inventory = True |
1053 | | - # wrap the value of the boolean field in quote to avoid |
| 1029 | + # wrap the value of the boolean field in quote to avoid |
1054 | 1030 | # automatically conversion from yaml.load |
1055 | | - input = util.wrap_boolean_value(input_text) |
| 1031 | + input = util.wrap_boolean_value(input_text) # NOQA |
1056 | 1032 | errs = self.load_dict(saneyaml.load(input), base_dir, running_inventory, use_mapping, mapping_file) |
1057 | 1033 | errors.extend(errs) |
1058 | 1034 | except Exception as e: |
@@ -1092,7 +1068,7 @@ def load_dict(self, fields_dict, base_dir, running_inventory=False, |
1092 | 1068 | licenses_field = (key, value) |
1093 | 1069 | fields.remove(licenses_field) |
1094 | 1070 | errors = self.process( |
1095 | | - fields, about_file_path, running_inventory, base_dir, |
| 1071 | + fields, about_file_path, running_inventory, base_dir, |
1096 | 1072 | license_notice_text_location, use_mapping, mapping_file) |
1097 | 1073 | self.errors = errors |
1098 | 1074 | return errors |
@@ -1141,7 +1117,7 @@ def dumps(self, use_mapping=False, mapping_file=False, with_absent=False, with_e |
1141 | 1117 | if lic_group[2]: |
1142 | 1118 | lic_dict['file'] = lic_group[2] |
1143 | 1119 | if lic_group[3]: |
1144 | | - lic_dict['url'] = lic_group[3] |
| 1120 | + lic_dict['url'] = lic_group[3] |
1145 | 1121 | about_data.setdefault('licenses', []).append(lic_dict) |
1146 | 1122 | formatted_about_data = util.format_output(about_data, use_mapping, mapping_file) |
1147 | 1123 | return saneyaml.dump(formatted_about_data) |
@@ -1210,7 +1186,7 @@ def dump_lic(self, location, license_dict): |
1210 | 1186 | # line in the form of "name: value" |
1211 | 1187 | field_declaration = re.compile( |
1212 | 1188 | r'^' |
1213 | | - + field_name + |
| 1189 | + +field_name + |
1214 | 1190 | r'\s*:\s*' |
1215 | 1191 | r'(?P<value>.*)' |
1216 | 1192 | r'\s*$' |
@@ -1382,7 +1358,7 @@ def about_object_to_list_of_dictionary(abouts, with_absent=False, with_empty=Tru |
1382 | 1358 | return abouts_dictionary_list |
1383 | 1359 |
|
1384 | 1360 |
|
1385 | | -def write_output(abouts, location, format, mapping_output=None, with_absent=False, with_empty=True): |
| 1361 | +def write_output(abouts, location, format, mapping_output=None, with_absent=False, with_empty=True): # NOQA |
1386 | 1362 | """ |
1387 | 1363 | Write a CSV/JSON file at location given a list of About objects |
1388 | 1364 | """ |
|
0 commit comments