Loading db/db_create.sh +2 −0 Original line number Diff line number Diff line Loading @@ -5,6 +5,8 @@ script_genre='genre.sql' run_path=`dirname $0` script_dbcrea=$run_path'/dbcrea.sql' script_genres=$run_path'/genres.sql' script_sp=$run_path'/sp_update_dbl.sql' mysql mysql < $script_dbcrea mysql sopds < $script_genres mysql sopds < $script_sp db/sp_update_dbl.sql 0 → 100644 +35 −0 Original line number Diff line number Diff line DROP PROCEDURE IF EXISTS sp_update_dbl; DELIMITER // CREATE PROCEDURE sp_update_dbl() BEGIN DECLARE done INT DEFAULT 0; DECLARE id, dbl INT; DECLARE dbl_sav, id_sav INT; DECLARE cur CURSOR FOR select book_id, doublicat from books where doublicat!=0 and avail!=0 and doublicat not in (select book_id from books where doublicat=0 and avail=2) order by doublicat, book_id; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; OPEN cur; SET dbl_sav=0; SET id_sav=0; WHILE done=0 DO FETCH cur INTO id, dbl; IF dbl_sav!=dbl THEN UPDATE books SET doublicat=0 WHERE book_id=id; SET dbl_sav=dbl; SET id_sav=id; ELSE UPDATE books SET doublicat=id_sav where book_id=id; END IF; END WHILE; CLOSE cur; END // DELIMITER ; commit; py/__pycache__/sopdsdb.cpython-33.pyc +1.1 KiB (23.8 KiB) File changed.No diff preview for this file type. View original file View changed file py/sopds-scan.py +4 −0 Original line number Diff line number Diff line Loading @@ -198,6 +198,8 @@ opdsdb.openDB() if VERBOSE: opdsdb.printDBerr() opdsdb.avail_check_prepare() if cfg.COVER_EXTRACT: if not os.path.isdir(sopdscfg.COVER_PATH): os.mkdir(sopdscfg.COVER_PATH) Loading @@ -219,6 +221,8 @@ for full_path, dirs, files in os.walk(cfg.ROOT_LIB): file_size=os.path.getsize(file) processfile(opdsdb,fb2parser,name,full_path,file,0,file_size) opdsdb.avail_after_check() opdsdb.update_double() opdsdb.closeDB() t2=datetime.timedelta(seconds=time.time()) Loading py/sopdsdb.py +28 −1 Original line number Diff line number Diff line Loading @@ -85,7 +85,7 @@ class opdsDatabase: self.err="" self.errcode=0 def findbook(self, name, path): def findbook(self, name, path, setavail=0): sql_findbook=("select book_id from "+TBL_BOOKS+" where filename=%s and path=%s") data_findbook=(name,path) cursor=self.cnx.cursor() Loading Loading @@ -490,6 +490,7 @@ class opdsDatabase: cursor=self.cnx.cursor() cursor.execute(sql) rows=cursor.fetchall() cursor.close return rows def zipisscanned(self,zipname): Loading @@ -501,8 +502,34 @@ class opdsDatabase: cat_id=0 else: cat_id=row[0] cursor.close return cat_id # Книги где avail=0 уже известно что удалены # Книги где avail=2 это только что прверенные существующие книги # Устанавливаем avail=1 для книг которые не удалены. Во время проверки если они не удалены им присвоится значение 2 # Книги с avail=0 проверятся не будут и будут убраны из всех выдач и всех обработок. # # три позиции (0,1,2) сделаны для того чтобы сделать возможным корректную работу cgi-скрипта во время сканирования библиотеки # def avail_check_prepare(self): sql='update '+TBL_BOOKS+' set avail=1 where avail!=0' cursor=self.cnx.cursor() cursor.execute(sql) cursor.close def avail_after_check(self): sql='update '+TBL_BOOKS+' set avail=0 where avail=1' cursor=self.cnx.cursor() cursor.execute(sql) cursor.close def update_double(self): sql='call sp_update_dbl()' cursor=self.cnx.cursor() cursor.execute(sql) cursor.close def __del__(self): self.closeDB() Loading
db/db_create.sh +2 −0 Original line number Diff line number Diff line Loading @@ -5,6 +5,8 @@ script_genre='genre.sql' run_path=`dirname $0` script_dbcrea=$run_path'/dbcrea.sql' script_genres=$run_path'/genres.sql' script_sp=$run_path'/sp_update_dbl.sql' mysql mysql < $script_dbcrea mysql sopds < $script_genres mysql sopds < $script_sp
db/sp_update_dbl.sql 0 → 100644 +35 −0 Original line number Diff line number Diff line DROP PROCEDURE IF EXISTS sp_update_dbl; DELIMITER // CREATE PROCEDURE sp_update_dbl() BEGIN DECLARE done INT DEFAULT 0; DECLARE id, dbl INT; DECLARE dbl_sav, id_sav INT; DECLARE cur CURSOR FOR select book_id, doublicat from books where doublicat!=0 and avail!=0 and doublicat not in (select book_id from books where doublicat=0 and avail=2) order by doublicat, book_id; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; OPEN cur; SET dbl_sav=0; SET id_sav=0; WHILE done=0 DO FETCH cur INTO id, dbl; IF dbl_sav!=dbl THEN UPDATE books SET doublicat=0 WHERE book_id=id; SET dbl_sav=dbl; SET id_sav=id; ELSE UPDATE books SET doublicat=id_sav where book_id=id; END IF; END WHILE; CLOSE cur; END // DELIMITER ; commit;
py/__pycache__/sopdsdb.cpython-33.pyc +1.1 KiB (23.8 KiB) File changed.No diff preview for this file type. View original file View changed file
py/sopds-scan.py +4 −0 Original line number Diff line number Diff line Loading @@ -198,6 +198,8 @@ opdsdb.openDB() if VERBOSE: opdsdb.printDBerr() opdsdb.avail_check_prepare() if cfg.COVER_EXTRACT: if not os.path.isdir(sopdscfg.COVER_PATH): os.mkdir(sopdscfg.COVER_PATH) Loading @@ -219,6 +221,8 @@ for full_path, dirs, files in os.walk(cfg.ROOT_LIB): file_size=os.path.getsize(file) processfile(opdsdb,fb2parser,name,full_path,file,0,file_size) opdsdb.avail_after_check() opdsdb.update_double() opdsdb.closeDB() t2=datetime.timedelta(seconds=time.time()) Loading
py/sopdsdb.py +28 −1 Original line number Diff line number Diff line Loading @@ -85,7 +85,7 @@ class opdsDatabase: self.err="" self.errcode=0 def findbook(self, name, path): def findbook(self, name, path, setavail=0): sql_findbook=("select book_id from "+TBL_BOOKS+" where filename=%s and path=%s") data_findbook=(name,path) cursor=self.cnx.cursor() Loading Loading @@ -490,6 +490,7 @@ class opdsDatabase: cursor=self.cnx.cursor() cursor.execute(sql) rows=cursor.fetchall() cursor.close return rows def zipisscanned(self,zipname): Loading @@ -501,8 +502,34 @@ class opdsDatabase: cat_id=0 else: cat_id=row[0] cursor.close return cat_id # Книги где avail=0 уже известно что удалены # Книги где avail=2 это только что прверенные существующие книги # Устанавливаем avail=1 для книг которые не удалены. Во время проверки если они не удалены им присвоится значение 2 # Книги с avail=0 проверятся не будут и будут убраны из всех выдач и всех обработок. # # три позиции (0,1,2) сделаны для того чтобы сделать возможным корректную работу cgi-скрипта во время сканирования библиотеки # def avail_check_prepare(self): sql='update '+TBL_BOOKS+' set avail=1 where avail!=0' cursor=self.cnx.cursor() cursor.execute(sql) cursor.close def avail_after_check(self): sql='update '+TBL_BOOKS+' set avail=0 where avail=1' cursor=self.cnx.cursor() cursor.execute(sql) cursor.close def update_double(self): sql='call sp_update_dbl()' cursor=self.cnx.cursor() cursor.execute(sql) cursor.close def __del__(self): self.closeDB()