Exemple #1
0
 def export_config(self, base_dir, library_usage_stats):
     for key, relpath in self.metadata['config_dir']:
         f = self.start_file(key, relpath)
         path = os.path.join(base_dir, relpath.replace('/', os.sep))
         try:
             with lopen(path, 'wb') as dest:
                 shutil.copyfileobj(f, dest)
         except EnvironmentError:
             os.makedirs(os.path.dirname(path))
             with lopen(path, 'wb') as dest:
                 shutil.copyfileobj(f, dest)
         f.close()
     gpath = os.path.join(base_dir, 'global.py')
     try:
         with lopen(gpath, 'rb') as f:
             raw = f.read()
     except EnvironmentError:
         raw = b''
     try:
         lpath = library_usage_stats.most_common(1)[0][0]
     except Exception:
         lpath = None
     c = create_global_prefs(StringConfig(raw, 'calibre wide preferences'))
     c.set('installation_uuid', str(uuid.uuid4()))
     c.set('library_path', lpath)
     raw = c.src
     if not isinstance(raw, bytes):
         raw = raw.encode('utf-8')
     with lopen(gpath, 'wb') as f:
         f.write(raw)
     gprefs = JSONConfig('gui', base_path=base_dir)
     gprefs['library_usage_stats'] = dict(library_usage_stats)
Exemple #2
0
def server_config(defaults=None):
    desc=_('Settings to control the calibre content server')
    c = Config('server', desc) if defaults is None else StringConfig(defaults, desc)

    c.add_opt('port', ['-p', '--port'], default=8080,
              help=_('The port on which to listen. Default is %default'))
    c.add_opt('timeout', ['-t', '--timeout'], default=120,
              help=_('The server timeout in seconds. Default is %default'))
    c.add_opt('thread_pool', ['--thread-pool'], default=30,
              help=_('The max number of worker threads to use. Default is %default'))
    c.add_opt('password', ['--password'], default=None,
              help=_('Set a password to restrict access. By default access is unrestricted.'))
    c.add_opt('username', ['--username'], default='calibre',
              help=_('Username for access. By default, it is: %default'))
    c.add_opt('develop', ['--develop'], default=False,
              help=_('Development mode. Server automatically restarts on file changes and serves code files (html, css, js) from the file system instead of calibre\'s resource system.'))
    c.add_opt('max_cover', ['--max-cover'], default='600x800',
              help=_('The maximum size for displayed covers. Default is %default.'))
    c.add_opt('max_opds_items', ['--max-opds-items'], default=30,
            help=_('The maximum number of matches to return per OPDS query. '
            'This affects Stanza, WordPlayer, etc. integration.'))
    c.add_opt('max_opds_ungrouped_items', ['--max-opds-ungrouped-items'],
            default=100,
            help=_('Group items in categories such as author/tags '
                'by first letter when there are more than this number '
                'of items. Default: %default. Set to a large number '
                'to disable grouping.'))
    c.add_opt('url_prefix', ['--url-prefix'], default='',
              help=_('Prefix to prepend to all URLs. Useful for reverse'
                  'proxying to this server from Apache/nginx/etc.'))

    return c