Commit 9468a20c authored by Mattia Bondanza's avatar Mattia Bondanza

Now first check if the database already exists and if exist continue working on the existing one.

parent bd30faaf
......@@ -3,6 +3,7 @@
import sqlite3
import hashlib
import settings
import os
def md5sum( path ):
f = open( path, "rb" )
......@@ -11,6 +12,10 @@ def md5sum( path ):
return out.hexdigest()
def db_init( db_file, analysis_directory ):
if os.path.exists( db_file ):
if settings.verbosity_level_numeric > 0:
print( "[database]\tThe database already exists. Continuing the work on the existing database." )
else:
db_con = sqlite3.connect( db_file )
db_cur = db_con.cursor()
db_cur.execute( "CREATE TABLE library ( md5, path )" )
......@@ -27,7 +32,7 @@ def add_book( db_file, path ):
if len( query_results ) > 0:
if settings.verbosity_level_numeric > 0:
print( "[database]\tOne file with the same md5 of {} are already present in the database, this probably means"
" that you have a duplicate file in your library.".format( path ))
" that you have a duplicate file in your library, or that you have already analyzed this book.".format( path ))
db_con.close()
return False
else:
......
......@@ -62,7 +62,6 @@ if not os.path.exists( args.tmp_directory[0] ):
for path, subdirs, files in os.walk( args.directory[0] ):
for name in files:
if fnmatch(name, args.pattern[0]):
print os.path.join( path, name )
total_files += 1 #Statistics
if not add_book( db_file_path, os.path.join( path, name ) ) :
break
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment