@@ -893,12 +893,11 @@ def notice_text(self):
893893
894894
895895class AboutCollector (object ):
896- def __init__ (self , input_path , output_path , verbosity ):
896+ def __init__ (self , input_path , verbosity ):
897897 # Setup the input and output paths
898898 self .original_input_path = input_path
899899 self .input_path = abspath (input_path )
900900 assert exists (self .input_path )
901- self .output_path = output_path
902901
903902 # Setup the verbosity
904903 self .display_error = self .display_warning = False
@@ -909,10 +908,12 @@ def __init__(self, input_path, output_path, verbosity):
909908
910909 self .about_files = []
911910 self .about_objects = []
911+ self .about_data_list = []
912912
913913 # Running the files collection and objects creation on instantiation
914914 self .collect_about_files ()
915915 self .create_about_objects_from_files ()
916+ self .extract_about_data_from_objects ()
916917
917918 def collect_about_files (self ):
918919 """
@@ -940,10 +941,13 @@ def create_about_objects_from_files(self):
940941
941942 self .about_objects = about_objects
942943
943- def extract_about_info (self ):
944+ def extract_about_data_from_objects (self ):
944945 """
945946 Builds rows for each stored about objects.
946947 """
948+ if self .about_data_list : # Process only once.
949+ return
950+
947951 about_data_list = []
948952 warnings_count = errors_count = 0
949953
@@ -982,21 +986,24 @@ def extract_about_info(self):
982986 if about_object .warnings :
983987 print ("WARNING: %s\n " % about_object .warnings )
984988
985- self .write_to_csv (about_data_list )
989+ self .about_data_list = about_data_list
990+
986991 if errors_count :
987992 print ("%d errors detected." % errors_count )
988993 if warnings_count :
989994 print ("%d warnings detected.\n " % warnings_count )
990995
991- def write_to_csv (self , about_data_list ):
996+ def write_to_csv (self , output_path ):
992997 """
993998 Write results in CSV file at output_path.
994999 """
995- with open (self .output_path , 'wb' ) as output_file :
1000+ header_row = ['about_file' ] + MANDATORY_FIELDS + OPTIONAL_FIELDS + \
1001+ ['warnings' , 'errors' ]
1002+
1003+ with open (output_path , 'wb' ) as output_file :
9961004 about_spec_writer = csv .writer (output_file )
997- about_spec_writer .writerow (['about_file' ] + MANDATORY_FIELDS +
998- OPTIONAL_FIELDS + ['warnings' , 'errors' ])
999- for row in about_data_list :
1005+ about_spec_writer .writerow (header_row )
1006+ for row in self .about_data_list :
10001007 about_spec_writer .writerow (row )
10011008
10021009 def generate_attribution (self , template_path = 'templates/default.html' ,
@@ -1105,8 +1112,8 @@ def main(parser, options, args):
11051112 sys .exit (errno .EEXIST )
11061113
11071114 if not exists (output_path ) or (exists (output_path ) and overwrite ):
1108- collector = AboutCollector (input_path , output_path , verbosity )
1109- collector .extract_about_info ( )
1115+ collector = AboutCollector (input_path , verbosity )
1116+ collector .write_to_csv ( output_path )
11101117 else :
11111118 # we should never reach this
11121119 assert False , "Unsupported option(s)."
0 commit comments