3636on_windows = 'win32' in sys .platform
3737
3838# boolean field name
39- boolean_fields = ['redistribute' , 'attribute' , 'track_change' , 'modified' , 'internal_use_only' ]
40- file_fields = ['about_resource' , 'notice_file' , 'changelog_file' , 'author_file' ]
39+ boolean_fields = ['redistribute' , 'attribute' ,
40+ 'track_change' , 'modified' , 'internal_use_only' ]
41+ file_fields = ['about_resource' , 'notice_file' ,
42+ 'changelog_file' , 'author_file' ]
4143
4244
4345def to_posix (path ):
@@ -56,7 +58,8 @@ def to_posix(path):
5658UNC_PREFIXES = (UNC_PREFIX_POSIX , UNC_PREFIX ,)
5759
5860valid_file_chars = '_-.+()~[]{}@%!$,'
59- invalid_file_chars = string .punctuation .translate (str .maketrans ("" , "" , valid_file_chars ))
61+ invalid_file_chars = string .punctuation .translate (
62+ str .maketrans ("" , "" , valid_file_chars ))
6063
6164
6265def invalid_chars (path ):
@@ -260,13 +263,15 @@ def load_csv(location):
260263 """
261264 results = []
262265 with open (location , mode = 'r' , encoding = 'utf-8-sig' ,
263- errors = 'replace' ) as csvfile :
266+ errors = 'replace' ) as csvfile :
264267 for row in csv .DictReader (csvfile ):
265268 # convert all the column keys to lower case
266- updated_row = {key .lower ().strip (): value for key , value in row .items ()}
269+ updated_row = {key .lower ().strip (): value for key ,
270+ value in row .items ()}
267271 results .append (updated_row )
268272 return results
269273
274+
270275def load_json (location ):
271276 """
272277 Read JSON file at `location` and return a list of ordered dicts, one for
@@ -394,9 +399,11 @@ def copy_license_notice_files(fields, base_dir, reference_dir, afp):
394399 continue
395400
396401 for copy_file_name in file_list :
397- from_lic_path = posixpath .join (to_posix (reference_dir ), copy_file_name )
402+ from_lic_path = posixpath .join (
403+ to_posix (reference_dir ), copy_file_name )
398404 about_file_dir = os .path .dirname (to_posix (afp )).lstrip ('/' )
399- to_lic_path = posixpath .join (to_posix (base_dir ), about_file_dir )
405+ to_lic_path = posixpath .join (
406+ to_posix (base_dir ), about_file_dir )
400407 if not os .path .exists (posixpath .join (to_lic_path , copy_file_name )):
401408 err = copy_file (from_lic_path , to_lic_path )
402409 if err :
@@ -449,6 +456,7 @@ def copy_file(from_path, to_path):
449456 error = Error (CRITICAL , msg )
450457 return error
451458
459+
452460def ungroup_licenses_from_sctk (value ):
453461 # Return a list of dictionary with lic_key and score
454462 # extracted from SCTK scan
@@ -461,6 +469,8 @@ def ungroup_licenses_from_sctk(value):
461469 return detected_license_list
462470
463471# FIXME: we should use a license object instead
472+
473+
464474def ungroup_licenses (licenses ):
465475 """
466476 Ungroup multiple licenses information
@@ -537,7 +547,8 @@ def format_about_dict_for_json_output(about_dictionary_list):
537547 row_list [key ] = element [key ]
538548
539549 # Group the same license information in a list
540- license_group = list (zip_longest (license_key , license_name , license_file , license_url ))
550+ license_group = list (zip_longest (
551+ license_key , license_name , license_file , license_url ))
541552 if license_group :
542553 licenses_list = []
543554 for lic_group in license_group :
@@ -616,6 +627,7 @@ def build_temp_dir(prefix='attributecode-'):
616627 create_dir (location )
617628 return location
618629
630+
619631def get_file_text (file_name , reference ):
620632 """
621633 Return the file content from the license_file/notice_file field from the
@@ -629,10 +641,11 @@ def get_file_text(file_name, reference):
629641 error = Error (CRITICAL , msg )
630642 else :
631643 with codecs .open (file_path , 'rb' , encoding = 'utf-8-sig' , errors = 'replace' ) as txt :
632- # with io.open(file_path, encoding='utf-8') as txt:
644+ # with io.open(file_path, encoding='utf-8') as txt:
633645 text = txt .read ()
634646 return error , text
635647
648+
636649def convert_object_to_dict (about ):
637650 """
638651 Convert the list of field object
@@ -650,6 +663,7 @@ def convert_object_to_dict(about):
650663 about_dict [key ] = value
651664 return about_dict
652665
666+
653667def load_scancode_json (location ):
654668 """
655669 Read the scancode JSON file at `location` and return a list of dictionaries.
@@ -671,6 +685,7 @@ def load_scancode_json(location):
671685 updated_results .append (updated_dict )
672686 return updated_results
673687
688+
674689def load_excel (location , worksheet = None ):
675690 """
676691 Read XLSX at `location`, return a list of ordered dictionaries, one
@@ -723,6 +738,7 @@ def load_excel(location, worksheet=None):
723738 results .append (row_dict )
724739 return errors , results
725740
741+
726742def write_licenses (lic_dict , location ):
727743 import io
728744
0 commit comments