WIP: index query, updated cursor connection code
This commit is contained in:
		
							parent
							
								
									a39dad4f18
								
							
						
					
					
						commit
						eaba709b46
					
				|  | @ -35,18 +35,23 @@ class FingerprintIndex: | |||
|         logging.info("DB Open SUCCESSFUL") | ||||
|       else: | ||||
|         logging.info("No index file found, creating index now...") | ||||
|         self.createIndex(fp_dir) | ||||
|         self.db_conn = sql.connect(fq_fpidx) | ||||
| 
 | ||||
|         self.__createIndex(fp_dir) | ||||
|         try: | ||||
|           self.cur = self.db_conn.cursor() | ||||
|     except: | ||||
|           self.__populateIndex(fp_dir) | ||||
|         except Exception as ex: | ||||
|           raise FingerprintIndexWrite("Error populating index file\n{}".format(ex)) | ||||
|         logging.info("Successfully populated the index") | ||||
|         self.db_conn = sql.connect(fq_fpidx) | ||||
|     except Exception as ex: | ||||
|       if self.db_conn: | ||||
|         self.db_conn.close() | ||||
|       self.db_conn = None | ||||
|       raise FingerprintIndexOpen("Error opening/creating an index file") | ||||
|       logging.error(ex) | ||||
|       raise FingerprintIndexOpen("Error opening/creating an index file\n") | ||||
| 
 | ||||
|   # | ||||
|   def createIndex(self, fp_dir): | ||||
|   def __createIndex(self, fp_dir): | ||||
|     fq_fpidx = fp_dir + os.path.sep + INDEX_FILENAME | ||||
|     try: | ||||
|       self.db_conn = sql.connect(fq_fpidx) | ||||
|  | @ -64,14 +69,8 @@ class FingerprintIndex: | |||
|           fp_count INTEGER); | ||||
|         ''') | ||||
|       logging.info("Successfully created index table") | ||||
|       self.__populateIndex(fp_dir)  | ||||
|       logging.info("Successfully populated the index") | ||||
|     except Exception as ex: | ||||
|       raise FingerprintIndexWrite("Error creating an index file\n{}".format(ex)) | ||||
|     finally: | ||||
|       if self.db_conn: | ||||
|         self.db_conn.close() | ||||
|       self.db_conn = None | ||||
|       raise FingerprintIndexWrite("Error creating index file\n{}".format(ex)) | ||||
| 
 | ||||
|   # | ||||
|   def qDatabaseMD5(self, md5_db): | ||||
|  | @ -112,11 +111,11 @@ def qTableMD5(self, md5_table): | |||
|           finCount = finCount+1 | ||||
|           if ((finCount % 5) == 0): | ||||
|             self.db_conn.commit() | ||||
|         except Exception as e: | ||||
|           logging.error(e) | ||||
|         except Exception as ex: | ||||
|           logging.error(ex) | ||||
|           failCount = failCount+1 | ||||
|     except: | ||||
|       pass | ||||
|     except Exception as ex: | ||||
|       logging.error(ex) | ||||
|     finally: | ||||
|       self.db_conn.commit() | ||||
|     logging.info("Completed populating the index. Completed: {}  Failed: {} ".format(str(finCount), str(failCount))) | ||||
|  | @ -139,10 +138,10 @@ def qTableMD5(self, md5_table): | |||
|           ''' | ||||
|           UPDATE md5_all SET fp_list=?, fp_count=? WHERE md5_db=? | ||||
|           ''', [fp_list, fp_count, md5_db]) | ||||
|       except Exception as e: | ||||
|         raise FingerprintIndexWrite("Error updating a row\n{}".format(e)) | ||||
|     except Exception as e: | ||||
|       raise FingerprintIndexWrite("Error inserting a row\n{}".format(e)) | ||||
|       except Exception as ex: | ||||
|         raise FingerprintIndexWrite("Error updating a row\n{}".format(ex)) | ||||
|     except Exception as ex: | ||||
|       raise FingerprintIndexWrite("Error inserting a row\n{}".format(ex)) | ||||
| 
 | ||||
|   # | ||||
|   def __insertMod_md5_tables(self, md5_db, filename): | ||||
|  | @ -162,10 +161,10 @@ def qTableMD5(self, md5_table): | |||
|             ''' | ||||
|             UPDATE md5_tables SET fp_list=?, fp_count=? WHERE md5_table=? | ||||
|             ''', [fp_list, fp_count, md5_table]) | ||||
|         except Exception as e: | ||||
|           raise FingerprintIndexWrite("Error updating a row\n{}".format(e)) | ||||
|       except Exception as e: | ||||
|         raise FingerprintIndexWrite("Error inserting a row\n{}".format(e)) | ||||
|         except Exception as ex: | ||||
|           raise FingerprintIndexWrite("Error updating a row\n{}".format(ex)) | ||||
|       except Exception as ex: | ||||
|         raise FingerprintIndexWrite("Error inserting a row\n{}".format(ex)) | ||||
| 
 | ||||
|   # | ||||
|   def __selectFileList(self, md5_db): | ||||
|  | @ -176,8 +175,8 @@ def qTableMD5(self, md5_table): | |||
|         ''', [md5_db]) | ||||
|       for row in rows: | ||||
|         return (row[0], row[1]) | ||||
|     except: | ||||
|       raise FingerprintIndexWrite("Error selecting fp_list\n{}".format(e)) | ||||
|     except Exception as ex: | ||||
|       raise FingerprintIndexWrite("Error selecting fp_list\n{}".format(ex)) | ||||
| 
 | ||||
|   # | ||||
|   def __selectFileList222(self, md5_table): | ||||
|  | @ -188,8 +187,8 @@ def qTableMD5(self, md5_table): | |||
|         ''', [md5_table]) | ||||
|       for row in rows: | ||||
|         return (row[0], row[1]) | ||||
|     except: | ||||
|       raise FingerprintIndexWrite("Error selecting fp_list\n{}".format(e)) | ||||
|     except Exception as ex: | ||||
|       raise FingerprintIndexWrite("Error selecting fp_list\n{}".format(ex)) | ||||
| 
 | ||||
|   # | ||||
|   def __checkIntegrity(self): | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	 JohnE
						JohnE