def _onchange_name(self): if self.name: set_cache(None) isbn = canonical(self.name) bookdata = meta(isbn, self.service) if bookdata: authors_alias = [] if bookdata['Title']: self.title = bookdata['Title'] if bookdata['Year']: self.year = bookdata['Year'] if bookdata['Publisher'] and bookdata['Publisher'] != '': publisher_alias_id = self.env['bd.publisher.alias'].search( [('name', '=', bookdata['Publisher'])], limit=1) if not publisher_alias_id: publisher_alias_id = self.env[ 'bd.publisher.alias'].create({ 'name': bookdata['Publisher'], }) self.publisher_alias_id = publisher_alias_id if bookdata['Authors']: for author_alias in bookdata['Authors']: if author_alias != '': author_alias_id = self.env[ 'bd.author.alias'].search( [('name', '=', author_alias)], limit=1) if not author_alias_id: author_alias_id = self.env[ 'bd.author.alias'].create({ 'name': author_alias, }) authors_alias.append(author_alias_id.id) if authors_alias: self.author_alias_ids = [(6, 0, authors_alias)] self._onchange_author_alias_ids()
# set CONF_PATH if not CONF_PATH: if VIRTUAL: CONF_PATH = os.path.join(sys.prefix, 'isbntools') else: CONF_PATH = (os.path.join(os.getenv('APPDATA'), 'isbntools') if WINDOWS else os.path.expanduser('~/.isbntools')) # make the folder if it doesn't exist (see issue #101)! try: # pragma: no cover os.mkdir(CONF_PATH) except: pass # set metadata cache if config.options.get('CACHE', 'UNDEFINED').lower() == 'none': registry.set_cache(None) else: CACHE_FILE = '.metacache' cache_path = os.path.join(CONF_PATH, CACHE_FILE) from ._shelvecache import ShelveCache try: registry.set_cache(ShelveCache(cache_path)) except: # stay with the default in-memory cache pass # set logger fmt = '%(asctime)s;%(levelname)s;%(message)s' if CONF_PATH: log_path = os.path.join(CONF_PATH, 'isbntools.log')
# however this should be done at top level due to strong side effects... socket.setdefaulttimeout(SOCKETS_TIMEOUT) # THREADS_TIMEOUT is a parameter used downstream by Thread calls (see vias.py) config.setthreadstimeout(THREADS_TIMEOUT) # set CONF_PATH if CONF_PATH is None: if VIRTUAL: CONF_PATH = os.path.join(sys.prefix, 'isbntools') else: CONF_PATH = os.path.expanduser('~/isbntools') # set metadata cache if config.options.get('CACHE', 'UNDEFINED').lower() == 'no': registry.set_cache(None) else: CACHE_FILE = '.metacache' cache_path = os.path.join(CONF_PATH, CACHE_FILE) from isbnlib.dev.helpers import ShelveCache try: registry.set_cache(ShelveCache(cache_path)) except: # stay with the default in-memory cache pass # set covers cache if config.options.get('COVERSCACHE', 'UNDEFINED').lower() == 'no': registry.set_covers_cache(None) else: