@@ -70,7 +70,8 @@ def __init__(self, new_path, old_path, options):
7070 self .errors = []
7171
7272 if self .codebase1 != None and self .codebase2 != None :
73- self .enumerate_files_from_codebases ()
73+ self .fetch_files (self .codebase1 ,is_new = True )
74+ self .fetch_files (self .codebase2 ,is_new = False )
7475 self .stats = Stat (self .new_files_count , self .old_files_count )
7576 self .new_files_errors = []
7677 self .old_files_errors = []
@@ -85,7 +86,7 @@ def __init__(self, new_path, old_path, options):
8586 self .deltas .sort (key = lambda Delta : Delta .factors , reverse = False )
8687 self .deltas .sort (key = lambda Delta : Delta .score , reverse = True )
8788
88- def get_files (self ,codebase ,is_new ):
89+ def fetch_files (self ,codebase ,is_new ):
8990 """
9091 Walk through the codebase, then generate the resources it(including all files and its directories)
9192 then we enumerate over this generated codebase to get file, and directories as (obj)
@@ -117,15 +118,6 @@ def get_files(self,codebase,is_new):
117118 if obj .is_file :
118119 # increment the old files count
119120 self .old_files_count += 1
120-
121-
122- def enumerate_files_from_codebases (self ):
123- """
124- An method which call the utility function get_files for generating the codebase
125- """
126- self .get_files (self .codebase1 ,is_new = True )
127- self .get_files (self .codebase2 ,is_new = False )
128-
129121
130122 def align_scans (self ):
131123 """
@@ -450,26 +442,8 @@ def licenses_to_dict(self,file):
450442 all_licenses .append (d )
451443 return all_licenses
452444
453- def new_file_to_dict (self ,deltacode ):
454- # if self.new_file is not empty we return the new file attributes
455- if self .new_file :
456- return OrderedDict ([
457- ("path" ,self .new_file .path ),
458- ("type" ,self .new_file .type ),
459- ("name" ,self .new_file .name ),
460- ("size" ,self .new_file .size ),
461- ("sha1" ,self .new_file .sha1 ),
462- ("fingerprint" ,deltacode .new_files_fingerprint .get (self .new_file .path ,"" )),
463- ("original_path" ,deltacode .new_files_original_path .get (self .new_file .path , "" )),
464- # since license itself has many sub fields so we obtain it from another utility function
465- ("licenses" ,self .licenses_to_dict (self .new_file )),
466- # since copyright itself has many sub fields so we obtain it from another utility function
467- ("copyrights" ,self .copyrights_to_dict (self .new_file ))
468- ])
469-
470-
471- def old_file_to_dict (self ,deltacode ):
472- if self .old_file :
445+ def file_to_dict (self ,deltacode , new_file = True ):
446+ if new_file == False and self .old_file :
473447 return OrderedDict ([
474448 ("path" ,self .old_file .path ),
475449 ("type" ,self .old_file .type ),
@@ -483,7 +457,20 @@ def old_file_to_dict(self,deltacode):
483457 # since copyright itself has many sub fields so we obtain it from another utility function
484458 ("copyrights" ,self .copyrights_to_dict (self .old_file ))
485459 ])
486-
460+ elif new_file and self .new_file :
461+ return OrderedDict ([
462+ ("path" ,self .new_file .path ),
463+ ("type" ,self .new_file .type ),
464+ ("name" ,self .new_file .name ),
465+ ("size" ,self .new_file .size ),
466+ ("sha1" ,self .new_file .sha1 ),
467+ ("fingerprint" ,deltacode .new_files_fingerprint .get (self .new_file .path ,"" )),
468+ ("original_path" ,deltacode .new_files_original_path .get (self .new_file .path , "" )),
469+ # since license itself has many sub fields so we obtain it from another utility function
470+ ("licenses" ,self .licenses_to_dict (self .new_file )),
471+ # since copyright itself has many sub fields so we obtain it from another utility function
472+ ("copyrights" ,self .copyrights_to_dict (self .new_file ))
473+ ])
487474
488475 def to_dict (self ,deltacode ):
489476 """
@@ -505,9 +492,9 @@ def to_dict(self,deltacode):
505492 ('factors' , self .factors ),
506493 ('score' , self .score ),
507494 # receives the detail of the new file
508- ('new' , self .new_file_to_dict (deltacode )),
495+ ('new' , self .file_to_dict (deltacode , new_file = True )),
509496 # receives the details of the old file
510- ('old' , self .old_file_to_dict (deltacode )),
497+ ('old' , self .file_to_dict (deltacode , new_file = False )),
511498 ])
512499
513500class Stat (object ):
0 commit comments