Commit 6f3f4137 authored by mitshel's avatar mitshel
Browse files

Параметр конфигурации zipnorescan = no отменяет повторное сканирование ZIP...

Параметр конфигурации zipnorescan = no отменяет повторное сканирование ZIP архивов. В конце работы скрипта sopds.scan.py выводится статистика рабоы
parent 49a1d8f5
Loading
Loading
Loading
Loading
+52 −13
Original line number Diff line number Diff line
@@ -6,8 +6,20 @@ import sopdsdb
import sopdscfg
import sopdsparse
import zipfile
import time
import datetime

books_added   = 0
books_skipped = 0
arch_scanned = 0
arch_skipped = 0
books_in_archives = 0

def processfile(db,fb2,name,full_path,file,archive=0):
    global books_added
    global books_skipped
    global books_in_archives

    (n,e)=os.path.splitext(name)
    if e.lower() in extensions_set:
       rel_path=os.path.relpath(full_path,sopdscfg.ROOT_LIB)
@@ -42,6 +54,9 @@ def processfile(db,fb2,name,full_path,file,archive=0):
             title=n

          book_id=opdsdb.addbook(name,rel_path,cat_id,e,title,genre,lang,0,archive)
          books_added+=1
          if archive==1:
             books_in_archives+=1
          if VERBOSE:
             print("Added ok.")

@@ -53,10 +68,16 @@ def processfile(db,fb2,name,full_path,file,archive=0):
              opdsdb.addbauthor(book_id,author_id)
              idx+=1
       else:
          books_skipped+=1
          if VERBOSE:
             print("Already in DB.")

def processzip(db,fb2,name,full_path,file):
    global arch_scanned
    global arch_skipped

    rel_path=os.path.relpath(full_path,sopdscfg.ROOT_LIB)
    if sopdscfg.ZIPRESCAN or db.zipisscanned(rel_path)==0:
       z = zipfile.ZipFile(file, 'r')
       filelist = z.namelist()
       for n in filelist:
@@ -67,6 +88,11 @@ def processzip(db,fb2,name,full_path,file):
           except:
               print('Error processing zip atchive:',file,' file: ',n)
       z.close()
       arch_scanned+=1
    else:
       arch_skipped+=1
       if VERBOSE:
          print('Skip ZIP archive: ',full_path,'. Already scanned.')

##########################################################################
# Считываем параметры командной строки
@@ -81,6 +107,8 @@ def processzip(db,fb2,name,full_path,file):
from optparse import OptionParser
from sys import argv

t1=datetime.timedelta(seconds=time.time())

parser=OptionParser(conflict_handler="resolve", version="sopds-scan.py. Version 0.01a", add_help_option=True, usage='sopds-scan.py [options]', description='sopds-scan.py: Simple OPDS Scanner - programm for scan your books directory and store data to MYSQL database.')
parser.add_option('-s','--scan','--scanfull', action='store_true', dest='scanfull', default=True, help='Full rescan all stored files.')
parser.add_option('-l','--scanlast', action='store_false', dest='scanfull', default=True, help='Scan files from date after last scan.')
@@ -92,9 +120,6 @@ VERBOSE=options.verbose

if VERBOSE:
        print('Options set: scanfull =',SCAN_FULL,', verbose =',VERBOSE,', configfile =',sopdscfg.CFG_PATH)
        print('Config file read: DB_NAME =',sopdscfg.DB_NAME,', DB_USER =',sopdscfg.DB_USER,', DB_PASS =',sopdscfg.DB_PASS,', DB_HOST =',sopdscfg.DB_HOST,', ROOT_LIB =',sopdscfg.ROOT_LIB,', FORMATS =',sopdscfg.FORMATS,', DUBLICATES =',sopdscfg.DUBLICATES,', MAXITEMS=',sopdscfg.MAXITEMS)



###########################################################################
# Основной код программы
@@ -121,3 +146,17 @@ for full_path, dirs, files in os.walk(sopdscfg.ROOT_LIB):
       processfile(opdsdb,fb2parser,name,full_path,file)

opdsdb.closeDB()

t2=datetime.timedelta(seconds=time.time())
print()
print('Books added      : ',books_added)
print('Books skipped    : ',books_skipped)
print('Books in archives: ',books_in_archives)
print('Archives scanned : ',arch_scanned)
print('Archives skipped : ',arch_skipped)

t=t2-t1
seconds=t.seconds%60
minutes=((t.seconds-seconds)//60)%60
hours=t.seconds//3600
print('Time estimated:',hours,' hours, ',minutes,' minutes, ',seconds,' seconds.')
+1 −0
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ FORMATS=config.get(CFG_S_GLOBAL,'formats')
DUBLICATES=config.getboolean(CFG_S_GLOBAL,'dublicates')
FB2PARSE=config.getboolean(CFG_S_GLOBAL,'fb2parse')
ZIPSCAN=config.getboolean(CFG_S_GLOBAL,'zipscan')
ZIPRESCAN=config.getboolean(CFG_S_GLOBAL,'ziprescan')
fb2hsize=config.get(CFG_S_GLOBAL,'fb2hsize')
maxitems=config.get(CFG_S_GLOBAL,'maxitems')
splitauthors=config.get(CFG_S_GLOBAL,'splitauthors')
+11 −3
Original line number Diff line number Diff line
@@ -277,9 +277,6 @@ class opdsDatabase:
    cursor.execute(sql_getbook)
    row=cursor.fetchone()
    cursor.close
 #   (file_name,file_path,reg_date,format,title,cat_type)=row
 #   book_path=os.path.join(file_path, file_name)
 #   return (file_name,book_path,reg_date,format,title,cat_type)
    return row

  def getauthors(self,book_id):
@@ -362,6 +359,17 @@ class opdsDatabase:
    rows=cursor.fetchall()
    return rows
  
  def zipisscanned(self,zipname):
    sql='select cat_id from '+TBL_CATALOGS+' where path="'+zipname+'" limit 1'
    cursor=self.cnx.cursor()
    cursor.execute(sql)
    row=cursor.fetchone()
    if row==None:
       cat_id=0
    else:
       cat_id=row[0]
    return cat_id

  def __del__(self):
    self.closeDB()