m_Librarian.
Author: Oleg Broytman <phd@phdru.name>.
-Copyright (C) 2015-2017 PhiloSoft Design.
+Copyright (C) 2015-2018 PhiloSoft Design.
License: GPL.
This hopefully will be a collection of programs to index LibRusEc and
Использование::
- ml-import.py [-C] [-D] [file.inpx ...]
+ ml-import.py [-C] [-D] [-P] [file.inpx ...]
Опции::
-C, --config config Путь к файлу конфигурации
-D, --database database Использовать указанную БД
+ -P, --no-pbar Не показывать индикатор процесса
Инициализирует базу данных, импортирует список жанров и список файлов
INPX, перечисленных в командной строке. При повторных запусках не
Автор: Олег Бройтман <phd@phdru.name>.
-Copyright (C) 2015-2017 PhiloSoft Design.
+Copyright (C) 2015-2018 PhiloSoft Design.
License
Usage::
- ml-import.py [-C] [-D] [file.inpx ...]
+ ml-import.py [-C] [-D] [-P] [file.inpx ...]
Options::
-C, --config config Configuration file
-D, --database database Open this database by pathname/db uri
+ -P, --no-pbar Inhibit progress bar
Initialize database, import genres list and import a list of INPX files
listed in the command line. On subsequent runs doesn’t destroy DB or
Created by Oleg Broytman <phd@phdru.name>.
-Copyright (C) 2015-2017 PhiloSoft Design.
+Copyright (C) 2015-2018 PhiloSoft Design.
License
pip install --trusted-host phdru.name --find-links=http://phdru.name/Software/Python/ m_librarian
+Progress bar
+============
+
+To allow ``ml-import.py`` to display progress bar the program requires
+library ``m_lib``. You can install the library separately using, e.g.,
+command ``pip install m_lib``. Or you can install the library with
+``m_librarian``: ``pip install m_librarian[pbar]``.
+
Installation from sources
=========================
News
====
+Version 0.0.16 (2018-03-22)
+---------------------------
+
+* Script ``ml-import.py`` displays progress bar.
+ Option ``-P`` prevents it.
+
Version 0.0.15 (2017-04-26)
---------------------------
Version 0.0.7 (2016-05-25)
---------------------------
-* Extend ml-serach.py to search books by authors, extensions, genres,
+* Extend ml-search.py to search books by authors, extensions, genres,
* languages.
Version 0.0.6 (2016-05-21)
---------------------------
-* Extend ml-serach.py to search books by title, series, archive, file.
+* Extend ml-search.py to search books by title, series, archive, file.
Version 0.0.5 (2016-05-14)
---------------------------
-* Extend script ml-serach.py to search extensions/genres/languages.
+* Extend script ml-search.py to search extensions/genres/languages.
Version 0.0.4 (2016-05-11)
---------------------------
-__version__ = '0.0.15'
+__version__ = '0.0.16'
import_inp_line(archive, parts)
-def import_inpx(path):
+def import_inpx(path, pbar_cb=None):
inpx = ZipFile(path)
+ if pbar_cb:
+ inp_count = 0
+ for name in inpx.namelist():
+ ext = os.path.splitext(name)[1]
+ if ext == '.inp':
+ inp_count += 1
+ pbar_cb.set_max(inp_count)
+ inp_count = 0
for name in inpx.namelist():
archive, ext = os.path.splitext(name)
if ext != '.inp':
continue
+ if pbar_cb:
+ inp_count += 1
+ pbar_cb.display(inp_count)
inp = inpx.open(name)
sqlhub.doInTransaction(import_inp, archive + '.zip', inp)
inp.close()
connection.query("VACUUM %s" % table.sqlmeta.table)
elif connection.dbName == 'sqlite':
connection.query("VACUUM")
+ if pbar_cb:
+ pbar_cb.close()
--- /dev/null
+
+try:
+ from m_lib.pbar.tty_pbar import ttyProgressBar
+except ImportError:
+ ttyProgressBar = None
+
+if ttyProgressBar:
+ class ml_ttyProgressBar(object):
+ def __init__(self, width=20):
+ self.max = None
+ self.pbar = None
+ self.width = width
+
+ def set_max(self, max_value):
+ self.max = max_value
+ self.pbar = ttyProgressBar(0, max_value, width1=self.width)
+
+ def display(self, value):
+ if self.pbar:
+ self.pbar.display(value)
+
+ def close(self):
+ if self.pbar:
+ self.pbar.erase()
+ self.pbar = None
#! /usr/bin/env python
+from __future__ import print_function
import argparse
+import sys
+
from m_librarian.config import get_config
from m_librarian.db import open_db, init_db, update_counters
from m_librarian.glst import import_glst
from m_librarian.inp import import_inpx
+from m_librarian.pbar import ttyProgressBar
+if ttyProgressBar:
+ from m_librarian.pbar import ml_ttyProgressBar
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Import')
parser.add_argument('-C', '--config', help='configuration file')
parser.add_argument('-D', '--database', help='database URI')
+ parser.add_argument('-P', '--no-pbar', action='store_true',
+ help='inhibit progress bar')
parser.add_argument('inpx', nargs='+', help='INPX files to import')
args = parser.parse_args()
init_db()
import_glst()
for inpx in args.inpx:
- import_inpx(inpx)
+ if ttyProgressBar and not args.no_pbar:
+ if len(inpx) > 25:
+ pbar_fname = inpx[:22] + '...'
+ else:
+ pbar_fname = inpx
+ print(pbar_fname.ljust(20), end=': ')
+ sys.stdout.flush()
+ pbar = ml_ttyProgressBar()
+ import_inpx(inpx, pbar_cb=pbar)
+ else:
+ import_inpx(inpx)
update_counters()
kw = {}
if is_setuptools:
kw['python_requires'] = '>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*'
+ kw['extras_require'] = {
+ 'm_lib': ['m_lib>=3.1'],
+ 'pbar': ['m_lib>=3.1'],
+ }
versionpath = join(abspath(dirname(__file__)), 'm_librarian', '__version__.py')
m_librarian_version = load_source('m_librarian_version', versionpath)