@@ -49,9 +49,11 @@ class DeltaCode(object):
4949 the form of File objects) contained in those scans.
5050 """
5151 def __init__ (self , new_path , old_path , options ):
52- if new_path and old_path :
52+ try :
5353 self .codebase1 = VirtualCodebase (new_path )
5454 self .codebase2 = VirtualCodebase (old_path )
55+ except :
56+ pass
5557 self .new_files_count = 0 #keeps the count of the new file
5658 self .old_files_count = 0 #keeps the count of old files
5759 self .new_files = [] # a list of [[new file1:Original path],[new file2:Original Path],...]
@@ -149,8 +151,9 @@ def similarity(self):
149151 if delta .new_file == None or delta .old_file == None :
150152 continue
151153 # this extracts the fingerprint corresponding to the particular file path
152- new_fingerprint = self .new_files_fingerprint [delta .new_file .path ]
153- old_fingerprint = self .old_files_fingerprint [delta .old_file .path ]
154+
155+ new_fingerprint = self .new_files_fingerprint .get (delta .new_file .path ,None )
156+ old_fingerprint = self .old_files_fingerprint .get (delta .old_file .path ,None )
154157 if new_fingerprint == None or old_fingerprint == None :
155158 continue
156159 new_fingerprint = utils .bitarray_from_hex (self .new_files_fingerprint [delta .new_file .path ])
@@ -294,6 +297,7 @@ def license_diff(self):
294297 ])
295298
296299 for delta in self .deltas :
300+
297301 utils .update_from_license_info (delta , unique_categories )
298302
299303 def copyright_diff (self ):
@@ -415,7 +419,7 @@ def licenses_to_dict(self,file):
415419 """
416420 licenseL = []
417421 try :
418- licenseL = file .license
422+ licenseL = file .licenses
419423 except AttributeError :
420424 # arises when the ScannedResource do not have any license attribute
421425 return []
@@ -427,12 +431,17 @@ def licenses_to_dict(self,file):
427431 all_licenses = []
428432 for i in range (len (licenseL )):
429433 # we iterate over all the licenses
434+ key = licenseL [i ].get ("key" ,None )
435+ score = licenseL [i ].get ("score" ,None )
436+ short_key = licenseL [i ].get ("short_name" ,None )
437+ category = licenseL [i ].get ("category" ,None )
438+ owner = licenseL [i ].get ("owner" ,None )
430439 d = OrderedDict ([
431- ('key' , licenseL [ i ][ " key" ] ),
432- ('score' , licenseL [ i ][ " score" ] ),
433- ('short_name' , licenseL [ i ][ "short_name" ] ),
434- ('category' , licenseL [ i ][ " category" ] ),
435- ('owner' , licenseL [ i ][ " owner" ] )
440+ ('key' , key ),
441+ ('score' , score ),
442+ ('short_name' , short_key ),
443+ ('category' , category ),
444+ ('owner' , owner )
436445 ])
437446 all_licenses .append (d )
438447 return all_licenses
@@ -446,7 +455,7 @@ def new_file_to_dict(self,deltacode):
446455 ("name" ,self .new_file .name ),
447456 ("size" ,self .new_file .size ),
448457 ("sha1" ,self .new_file .sha1 ),
449- ("fingerprint" ,deltacode .new_files_fingerprint [ self .new_file .path ] ),
458+ ("fingerprint" ,deltacode .new_files_fingerprint . get ( self .new_file .path , "" ) ),
450459 ("original_path" ,self .new_file .path ),
451460 # since license itself has many sub fields so we obtain it from another utility function
452461 ("licenses" ,self .licenses_to_dict (self .new_file )),
@@ -463,7 +472,7 @@ def old_file_to_dict(self,deltacode):
463472 ("name" ,self .old_file .name ),
464473 ("size" ,self .old_file .size ),
465474 ("sha1" ,self .old_file .sha1 ),
466- ("fingerprint" ,deltacode .old_files_fingerprint [ self .old_file .path ] ),
475+ ("fingerprint" ,deltacode .old_files_fingerprint . get ( self .old_file .path , "" ) ),
467476 ("original_path" ,self .old_file .path ),
468477 # since license itself has many sub fields so we obtain it from another utility function
469478 ("licenses" ,self .licenses_to_dict (self .old_file )),
0 commit comments