CMS 3D CMS Logo

Public Member Functions | Public Attributes

ValidationMatrix_v2::ReleaseComparison Class Reference

List of all members.

Public Member Functions

def __init__
def compare
def was_compared

Public Attributes

 clear_db
 db_name
 Download needed files.
 dry
 no_url
 use_external_script_to_compare_files
 work_path
 Create working directory if not given.

Detailed Description

Generates release comparison information and stores it on SQLite3 .db file.

Definition at line 120 of file ValidationMatrix_v2.py.


Constructor & Destructor Documentation

def ValidationMatrix_v2::ReleaseComparison::__init__ (   self,
  work_path = None,
  db_name = None,
  clear_db = False,
  dry = False,
  no_url = False,
  use_external = False 
)

Definition at line 122 of file ValidationMatrix_v2.py.

00123                                                                                                                  :
00124         self.work_path = work_path
00125         self.db_name = db_name
00126         self.clear_db = clear_db
00127         self.dry = dry
00128         self.no_url = no_url
00129         self.use_external_script_to_compare_files = use_external


Member Function Documentation

def ValidationMatrix_v2::ReleaseComparison::compare (   self,
  rel1,
  frags1,
  rel2,
  frags2,
  st_tests,
  url = None,
  title = None 
)

Definition at line 141 of file ValidationMatrix_v2.py.

00142                                                                                  :
00143         print '\n#################     Searching for files     ###################'
00144         if self.no_url:
00145             print 'Searching for files on disk at %s' % (self.work_path)
00146             files1, files2 = search_on_disk(self.work_path, rel1, frags1, rel2, frags2)
00147             file_pairs = make_file_pairs(files1, files2)
00148         else:
00149             print 'Searching for files online at:'
00150             files_with_urls1, files_with_urls2 = recursive_search_online(url, rel1, frags1, rel2, frags2)
00151             file_pairs = make_file_pairs(files_with_urls1, files_with_urls2)
00152             files_with_urls1.update(files_with_urls2)
00153             files1, files2 = zip(*file_pairs)
00154             paired_files_with_urls = [(file, files_with_urls1[file]) for file in files1 + files2]
00155 
00156             if self.dry:
00157                 print 'DRY: nothing to do. Exiting.'
00158                 exit()
00159 
00160             ## Create working directory if not given.
00161             if not self.work_path:
00162                 self.work_path = '%s___VS___%s' % (get_version(files1[0]), get_version(files2[0]))
00163                 if self.db_name:
00164                     self.db_name = join(self.work_path, self.db_name)
00165 
00166             if not exists(self.work_path):
00167                 print '\n###################      Preparing directory     ###################'
00168                 print 'Creating working directory: %s ...' % self.work_path,
00169                 makedirs(self.work_path)
00170                 print 'Done.'
00171 
00172             print '\n#################     Downloading the files     ###################'
00173             total_size, files_to_download = get_size_to_download(self.work_path, paired_files_with_urls)
00174             check_disk_for_space(self.work_path, total_size)
00175 
00176             ## Download needed files.
00177             q = Queue()
00178             show_status_bar.q = q
00179             auth_download_file.q = q
00180             auth_download_file.work_dir = self.work_path
00181 
00182             Process(target=show_status_bar, args=(total_size,)).start()
00183             Pool(2).map(auth_download_file, files_to_download)
00184             if total_size:
00185                 print "Done."
00186 
00187         ## Create database
00188         print '\n#################     Preparing Database     ###################'
00189         if not self.db_name:
00190             self.db_name = '%s___VS___%s.db' % (get_version(file_pairs[0][0]), get_version(file_pairs[0][1]))
00191 
00192         if self.clear_db:
00193             print 'Clearing DB: %s...' % self.db_name,
00194             open(join(self.work_path, self.db_name), 'w').close()
00195             print 'Done.'
00196 
00197         ## Compare file pairs.
00198         self.db_name = init_database(join(self.work_path, self.db_name))
00199 
00200         # TODO: Use multiprocessing for this task.
00201         for st_test_name in st_tests.split(','):
00202             print '\n#################     Comparing Releases (%s)     ###################' % st_test_name
00203             st_test = tests[st_test_name]()
00204 
00205             some_files_compared = False
00206             file_comparison_ids = []
00207             if self.use_external_script_to_compare_files:
00208                 # Compare files using compare_using_files_v2.py
00209                 arg_list = [list(pair) + [self.work_path, partial_db_name(self.db_name, i),
00210                                                 self.clear_db] for i, pair in enumerate(file_pairs)]
00211                 pool = Pool(7)
00212                 pool.map(call_compare_using_files, arg_list)
00213 
00214                 # Merge databases
00215                 print '\n#################     Merging DBs (%s)     ###################' % st_test_name
00216                 for i, pair in enumerate(file_pairs):
00217                     tmp_db = partial_db_name(self.db_name, i)
00218                     print 'Merging %s...' % (basename(tmp_db),),
00219                     file_comparison_ids.append(merge_dbs(self.db_name, tmp_db))
00220                     remove(tmp_db)
00221                     print 'Done.'
00222                     some_files_compared = True
00223             else:
00224                 file_comparison = RootFileComparison(self.db_name)
00225 
00226                 for file1, file2 in file_pairs:
00227                     # TODO: If files are not found desplay nice message.
00228                     # TODO: Maybe subprocces would control the unwanted reports of RootFileComparison.compare()
00229                     file1_path = join(self.work_path, file1)
00230                     file2_path = join(self.work_path, file2)
00231 
00232                     if not file_comparison.was_compared(file1, file2, st_test_name):
00233                         print "Comparing:\n%s\n%s\n" % (file1, file2)
00234                         file_comparison_id = file_comparison.compare(file1_path, file2_path, st_test)
00235                         file_comparison_ids.append(file_comparison_id)
00236                         some_files_compared = True
00237                     else:
00238                         print "Already compared:\n%s\n%s\n" % (file1, file2)
00239 
00240             ## Calculate statistics for the release.
00241             release1 = get_version(file_pairs[0][0])
00242             release2 = get_version(file_pairs[0][1])
00243             if some_files_compared:
00244                 release_comparison_id = self.was_compared(release1, release2, st_test_name)
00245                 conn = sqlite3.connect(self.db_name)
00246                 c = conn.cursor()
00247                 if not release_comparison_id:
00248                     print 'Inserting release "%s  VS  %s" description.\n' % (release1, release2)
00249                     if not title:
00250                         title = "%s__VS__%s" % (release1, release2)
00251                     c.execute('''INSERT INTO ReleaseComparison(title, release1, release2,
00252                                    statistical_test) VALUES (?, ?, ?, ?)''', (title,
00253                                 release1, release2, st_test_name))
00254                     release_comparison_id = c.lastrowid
00255                 c.executemany('''UPDATE RootFileComparison SET release_comparison_id = ?
00256                         WHERE id == ?''', [(release_comparison_id, fid) for fid in file_comparison_ids])
00257                 conn.commit()
00258                 conn.close()
00259 

def ValidationMatrix_v2::ReleaseComparison::was_compared (   self,
  release1,
  release2,
  st_test_name 
)

Definition at line 130 of file ValidationMatrix_v2.py.

00131                                                             :
00132         conn = sqlite3.connect(self.db_name)
00133         c = conn.cursor()
00134         c.execute('''SELECT id FROM ReleaseComparison WHERE release1=? AND
00135                 release2=? AND statistical_test=?''', (release1, release2, st_test_name))
00136         release_comparison_id = c.fetchone()
00137         conn.close()
00138         if release_comparison_id:
00139             return release_comparison_id[0]
00140         return False


Member Data Documentation

Definition at line 122 of file ValidationMatrix_v2.py.

Download needed files.

Compare file pairs.

Create database

Definition at line 122 of file ValidationMatrix_v2.py.

Definition at line 122 of file ValidationMatrix_v2.py.

Definition at line 122 of file ValidationMatrix_v2.py.

Definition at line 122 of file ValidationMatrix_v2.py.

Create working directory if not given.

Definition at line 122 of file ValidationMatrix_v2.py.