* Показывать список найденных книг с разбивкой по авторам и сериям.
+* Файл конфигурации, все секции и все ключи сделаны необязательными.
+
Version 0.1.3 (2018-05-25)
--------------------------
* Use filters from config.
+* Config file, all sections and all key are now completely optional.
+
Version 0.1.3 (2018-05-25)
--------------------------
from __future__ import print_function
import os
try:
- from ConfigParser import RawConfigParser
+ from ConfigParser import RawConfigParser, NoSectionError, NoOptionError
except ImportError: # py3
- from configparser import RawConfigParser
+ from configparser import RawConfigParser, NoSectionError, NoOptionError
+
__all__ = ['get_config']
def find_config_dirs():
if os.name == 'posix':
return _find_config_dirs_posix()
- raise OSError("Unknow OS")
+ return None
def find_config_file(config_dirs=None):
if os.path.exists(ml_conf_file):
return ml_conf_file
else:
- raise IOError("Cannot find m_librarian.conf in %s" % config_dirs)
+ return None
_ml_config = None
+class ConfigWrapper(object):
+ def __init__(self, config):
+ self.config = config
+
+ def get(self, section, option, default=None):
+ try:
+ return self.config.get(section, option)
+ except (NoSectionError, NoOptionError):
+ return default
+
+ def set(self, section, option, value):
+ self.config.set(section, option, value)
+
+ def getint(self, section, option, default=0):
+ try:
+ return self.config.getint(section, option)
+ except (NoSectionError, NoOptionError):
+ return default
+ # Do not catch ValueError here, it must be propagated
+
+
def get_config(config_path=None):
global _ml_config
if _ml_config is None:
+ _ml_config = RawConfigParser()
if config_path is None:
config_path = find_config_file()
- _ml_config = RawConfigParser()
- _ml_config.read(config_path)
+ if config_path is not None:
+ _ml_config.read(config_path)
+ _ml_config = ConfigWrapper(_ml_config)
return _ml_config
def open_db(db_uri=None):
if db_uri is None:
- try:
- db_uri = get_config().get('database', 'URI')
- except Exception:
- db_uri = find_sqlite_dburi()
+ db_uri = get_config().get('database', 'URI') or find_sqlite_dburi()
if '://' not in db_uri:
db_uri = 'sqlite://' + os.path.abspath(db_uri).replace(os.sep, '/')
global format, compile_format, compiled_format
if compile_format:
compile_format = False
- try:
- format = get_config().get('download', 'format')
- except Exception:
+ format = get_config().get('download', 'format')
+ if not format:
return
got_percent = False
compiled = []
if lib_path is None:
global _library_path
if _library_path is None:
- _library_path = get_config().get('library', 'path')
+ _library_path = get_config().get('library', 'path') or '.'
lib_path = _library_path
global format, compile_format, compiled_format
-try:
- from configparser import NoSectionError, NoOptionError
-except ImportError: # Python 2
- from ConfigParser import NoSectionError, NoOptionError
-
from sqlobject.sqlbuilder import AND, OR, func
from .config import get_config
from .db import Author, Book, Extension, Genre, Language
orderBy=None, use_filters=False):
if use_filters:
config = get_config()
- try:
- lang_filter = config.get('filters', 'lang')
- except (NoSectionError, NoOptionError):
- lang_filter = None
- try:
- deleted_filter = config.getint('filters', 'deleted')
- except (NoSectionError, NoOptionError):
- deleted_filter = None
+ lang_filter = config.get('filters', 'lang')
+ deleted_filter = config.getint('filters', 'deleted')
if lang_filter:
if join_expressions is None:
join_expressions = []
@route('/books-by-author/<id:int>/', method='GET')
@cheetah_view('books_by_author.tmpl')
def books_by_author(id):
- use_filters = get_config().getint('filters', 'use_in_books_list')
+ use_filters = get_config().getint('filters', 'use_in_books_list', 1)
if use_filters:
join_expressions = []
join_expressions.append(Book.j.authors)
@cheetah_view('download.tmpl')
def download_books():
books_ids = request.forms.getall('books')
- download_path = get_config().get('download', 'path')
+ download_path = get_config().get('download', 'path') or '.'
if books_ids:
for id in books_ids:
book = Book.get(int(id))
currentTime=time.time
__CHEETAH_version__ = '3.1.0'
__CHEETAH_versionTuple__ = (3, 1, 0, 'final', 1)
-__CHEETAH_genTime__ = 1528138831.71884
-__CHEETAH_genTimestamp__ = 'Mon Jun 4 22:00:31 2018'
+__CHEETAH_genTime__ = 1528667817.826233
+__CHEETAH_genTimestamp__ = 'Mon Jun 11 00:56:57 2018'
__CHEETAH_src__ = 'search_books_form.tmpl'
-__CHEETAH_srcLastModified__ = 'Mon Jun 4 22:00:29 2018'
+__CHEETAH_srcLastModified__ = 'Mon Jun 11 00:30:36 2018'
__CHEETAH_docstring__ = 'Autogenerated by Cheetah: The Python-Powered Template Engine'
if __CHEETAH_versionTuple__ < RequiredCheetahVersionTuple:
########################################
## START - generated method body
- if VFFSL(SL,"getVar",False)('use_filters', VFN(VFFSL(SL,"get_config",False)(),"getint",False)('filters', 'use_in_search_forms')): # generated from line 14, col 1
+ if VFFSL(SL,"getVar",False)('use_filters', VFN(VFFSL(SL,"get_config",False)(),"getint",False)('filters', 'use_in_search_forms', 1)): # generated from line 14, col 1
write(u'''checked''')
########################################
#end if
#end def
#def $use_filters_check
-#if $getVar('use_filters', $get_config().getint('filters', 'use_in_search_forms'))
+#if $getVar('use_filters', $get_config().getint('filters', 'use_in_search_forms', 1))
checked#slurp
#end if
#end def
lang = ru en
# Show/hide deleted books; 0 - hide, 1 - show
-deleted = 1
+deleted = 0
# Default value to use filters in search forms
use_in_search_forms = 1
from __future__ import print_function
import argparse
-try:
- from configparser import NoSectionError, NoOptionError
-except ImportError: # Python 2
- from ConfigParser import NoSectionError, NoOptionError
import os
import sys
from sqlobject.sqlbuilder import CONCAT
if args.get or args.get_many:
download_to = args.download_to
if download_to is None:
- try:
- download_to = get_config().get('download', 'path')
- except (NoSectionError, NoOptionError):
- download_to = os.path.curdir
+ download_to = get_config().get('download', 'path') \
+ or os.path.curdir
download(book, download_to, args.path, args.format)
count += 1
print_count(count)