home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2011 January / maximum-cd-2011-01.iso / DiscContents / calibre-0.7.26.msi / file_1426 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-10-31  |  3.9 KB  |  81 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. __license__ = 'GPL v3'
  5. __copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
  6. __docformat__ = 'restructuredtext en'
  7. import sys
  8. from threading import Thread
  9. from calibre.library.server import server_config as config
  10. from calibre.library.server.base import LibraryServer
  11. from calibre.constants import iswindows
  12. import cherrypy
  13.  
  14. def start_threaded_server(db, opts):
  15.     server = LibraryServer(db, opts, embedded = True)
  16.     server.thread = Thread(target = server.start)
  17.     server.thread.setDaemon(True)
  18.     server.thread.start()
  19.     return server
  20.  
  21.  
  22. def stop_threaded_server(server):
  23.     server.exit()
  24.     server.thread = None
  25.  
  26.  
  27. def create_wsgi_app(path_to_library = None, prefix = ''):
  28.     db = db
  29.     import calibre.library
  30.     cherrypy.config.update({
  31.         'environment': 'embedded' })
  32.     db = db(path_to_library)
  33.     parser = option_parser()
  34.     (opts, args) = parser.parse_args([
  35.         'calibre-server'])
  36.     opts.url_prefix = prefix
  37.     server = LibraryServer(db, opts, wsgi = True, show_tracebacks = True)
  38.     return cherrypy.Application(server, script_name = None, config = server.config)
  39.  
  40.  
  41. def option_parser():
  42.     parser = config().option_parser('%prog ' + _('[options]\n\nStart the calibre content server. The calibre content server\nexposes your calibre library over the internet. The default interface\nallows you to browse you calibre library by categories. You can also\naccess an interface optimized for mobile browsers at /mobile and an\nOPDS based interface for use with reading applications at /opds.\n\nThe OPDS interface is advertised via BonJour automatically.\n'))
  43.     parser.add_option('--with-library', default = None, help = _('Path to the library folder to serve with the content server'))
  44.     parser.add_option('--pidfile', default = None, help = _('Write process PID to the specified file'))
  45.     parser.add_option('--daemonize', default = False, action = 'store_true', help = 'Run process in background as a daemon. No effect on windows.')
  46.     parser.add_option('--restriction', default = None, help = _('Specifies a restriction to be used for this invocation. This option overrides any per-library settings specified in the GUI'))
  47.     parser.add_option('--auto-reload', default = False, action = 'store_true', help = _('Auto reload server when source code changes. May not work in all environments.'))
  48.     return parser
  49.  
  50.  
  51. def main(args = sys.argv):
  52.     LibraryDatabase2 = LibraryDatabase2
  53.     import calibre.library.database2
  54.     parser = option_parser()
  55.     (opts, args) = parser.parse_args(args)
  56.     if opts.daemonize and not iswindows:
  57.         Daemonizer = Daemonizer
  58.         import cherrypy.process.plugins
  59.         d = Daemonizer(cherrypy.engine)
  60.         d.subscribe()
  61.     
  62.     if opts.pidfile is not None:
  63.         PIDFile = PIDFile
  64.         import cherrypy.process.plugins
  65.         PIDFile(cherrypy.engine, opts.pidfile).subscribe()
  66.     
  67.     cherrypy.log.screen = True
  68.     prefs = prefs
  69.     import calibre.utils.config
  70.     if opts.with_library is None:
  71.         opts.with_library = prefs['library_path']
  72.     
  73.     db = LibraryDatabase2(opts.with_library)
  74.     server = LibraryServer(db, opts)
  75.     server.start()
  76.     return 0
  77.  
  78. if __name__ == '__main__':
  79.     sys.exit(main())
  80.  
  81.