def info(): import locale import platform from audiotranscode import AudioTranscode audiotranscode = AudioTranscode() encoders = [ '%s (%s)' % (enc.filetype, enc.command[0]) for enc in audiotranscode.available_encoders ] decoders = [ '%s (%s)' % (enc.filetype, enc.command[0]) for enc in audiotranscode.available_decoders ] return """CherryMusic Server {cm_version} CherryPy: {cp_version} Python: {py_version} Platform: {platform} configuration dir: {confdir} server data dir: {datadir} static resources dir: {resourcedir} server package dir: {packdir} process working dir: {workdir} locale: {locale}, default: {deflocale} filesystem encoding: {fs_encoding} Available Decoders: {decoders} Available Encoders: {encoders} (Do not parse this output.)""".format( cm_version=REPO_VERSION or VERSION, cp_version=cherrypy.__version__, py_version=platform.python_implementation() + ' ' + platform.python_version(), platform=platform.platform(), workdir=os.path.abspath(os.curdir), packdir=os.path.abspath(__path__[0]), confdir=pathprovider.getConfigPath(), datadir=pathprovider.getUserDataPath(), resourcedir=pathprovider.getResourcePath(''), locale=str(locale.getlocale()), deflocale=str(locale.getdefaultlocale()), fs_encoding=sys.getfilesystemencoding(), encoders='\n '.join(encoders), decoders='\n '.join(decoders), )
def info(): import locale import platform from audiotranscode import AudioTranscode audiotranscode = AudioTranscode() encoders = ['%s (%s)' % (enc.filetype, enc.command[0]) for enc in audiotranscode.available_encoders] decoders = ['%s (%s)' % (enc.filetype, enc.command[0]) for enc in audiotranscode.available_decoders] return """CherryMusic Server {cm_version} CherryPy: {cp_version} Python: {py_version} Platform: {platform} configuration dir: {confdir} server data dir: {datadir} static resources dir: {resourcedir} server package dir: {packdir} process working dir: {workdir} locale: {locale}, default: {deflocale} filesystem encoding: {fs_encoding} Available Decoders: {decoders} Available Encoders: {encoders} (Do not parse this output.)""".format( cm_version=REPO_VERSION or VERSION, cp_version=cherrypy.__version__, py_version=platform.python_implementation() + ' ' + platform.python_version(), platform=platform.platform(), workdir=os.path.abspath(os.curdir), packdir=os.path.abspath(__path__[0]), confdir=pathprovider.getConfigPath(), datadir=pathprovider.getUserDataPath(), resourcedir=pathprovider.getResourcePath(''), locale=str(locale.getlocale()), deflocale=str(locale.getdefaultlocale()), fs_encoding=sys.getfilesystemencoding(), encoders='\n '.join(encoders), decoders='\n '.join(decoders), )
def configureAndStartCherryPy(port): if not port: port = 8080 socket_host = "0.0.0.0" resourcedir = os.path.abspath(pathprovider.getResourcePath('res')) userdatapath = pathprovider.getUserDataPath() cherrypy.config.update({ 'server.socket_port': port, 'log.error_file': os.path.join(userdatapath, 'server.log'), 'environment': 'production', 'server.socket_host': socket_host, 'server.thread_pool': 30, 'tools.sessions.on': True, 'tools.sessions.timeout': 60 * 24, }) resource_config = { '/res': { 'tools.staticdir.on': True, 'tools.staticdir.dir': resourcedir, 'tools.staticdir.index': 'index.html', 'tools.caching.on': False, }, '/favicon.ico': { 'tools.staticfile.on': True, 'tools.staticfile.filename': resourcedir + '/favicon.ico', } } cherrypy.tree.mount(SetupHandler(), '/', config=resource_config) print( _(''' Starting setup server on port {port} ... Open your browser and put the server IP:{port} in the address bar. If you run the server locally, use: localhost:{port}. '''.format(port=port))) cherrypy.lib.caching.expires(0) cherrypy.engine.timeout_monitor.frequency = 1 cherrypy.engine.start() cherrypy.engine.block()
def _printMigrationNotice(): print( _(""" ========================================================================== Oops! CherryMusic changed some file locations while you weren't looking. (To better comply with best practices, if you wanna know.) To continue, please move the following: $ mv {src} {tgt}""".format(src=os.path.join(pathprovider.fallbackPath(), 'config'), tgt=pathprovider.configurationFile()) + """ $ mv {src} {tgt}""".format(src=os.path.join(pathprovider.fallbackPath(), '*'), tgt=pathprovider.getUserDataPath()) + """ Thank you, and enjoy responsibly. :) ========================================================================== """))
def _printMigrationNotice(): print(_(""" ========================================================================== Oops! CherryMusic changed some file locations while you weren't looking. (To better comply with best practices, if you wanna know.) To continue, please move the following: $ mv {src} {tgt}""".format( src=os.path.join(pathprovider.fallbackPath(), 'config'), tgt=pathprovider.configurationFile()) + """ $ mv {src} {tgt}""".format( src=os.path.join(pathprovider.fallbackPath(), '*'), tgt=pathprovider.getUserDataPath()) + """ Thank you, and enjoy responsibly. :) ========================================================================== """))
def info(): import locale import platform return """CherryMusic Server {cm_version} CherryPy: {cp_version} Python: {py_version} Platform: {platform} configuration dir: {confdir} server data dir: {datadir} static resources dir: {resourcedir} server package dir: {packdir} process working dir: {workdir} locale: {locale}, default: {deflocale} filesystem encoding: {fs_encoding} (Do not parse this output.)""".format( cm_version=REPO_VERSION or VERSION, cp_version=cherrypy.__version__, py_version=platform.python_implementation() + ' ' + platform.python_version(), platform=platform.platform(), workdir=os.path.abspath(os.curdir), packdir=os.path.abspath(__path__[0]), confdir=pathprovider.getConfigPath(), datadir=pathprovider.getUserDataPath(), resourcedir=pathprovider.getResourcePath(''), locale=str(locale.getlocale()), deflocale=str(locale.getdefaultlocale()), fs_encoding=sys.getfilesystemencoding(), )
def configureAndStartCherryPy(port): if not port: port = 8080 socket_host = "0.0.0.0" resourcedir = os.path.abspath(pathprovider.getResourcePath('res')) userdatapath = pathprovider.getUserDataPath() cherrypy.config.update({ 'server.socket_port': port, 'log.error_file': os.path.join(userdatapath, 'server.log'), 'environment': 'production', 'server.socket_host': socket_host, 'server.thread_pool': 30, 'tools.sessions.on': True, 'tools.sessions.timeout': 60 * 24, }) resource_config = { '/res': { 'tools.staticdir.on': True, 'tools.staticdir.dir': resourcedir, 'tools.staticdir.index': 'index.html', 'tools.caching.on': False, }, '/favicon.ico': { 'tools.staticfile.on': True, 'tools.staticfile.filename': resourcedir+'/favicon.ico', } } cherrypy.tree.mount(SetupHandler(), '/', config=resource_config) print(_(''' Starting setup server on port {port} ... Open your browser and put the server IP:{port} in the address bar. If you run the server locally, use: localhost:{port}. '''.format(port=port))) cherrypy.lib.caching.expires(0) cherrypy.engine.timeout_monitor.frequency = 1 cherrypy.engine.start() cherrypy.engine.block()
) handler_console = logging.StreamHandler(stream=sys.stdout) handler_console.formatter = formatter_briefest handler_console.level = DEBUG handler_console.addFilter(LowPass(WARNING)) handler_console.addFilter(relocator) handler_console_priority = logging.StreamHandler(stream=sys.stderr) handler_console_priority.formatter = formatter_brief handler_console_priority.level = WARNING handler_console_priority.addFilter(relocator) handler_file_error = logging.FileHandler(os.path.join( pathprovider.getUserDataPath(), 'error.log'), mode='a', delay=True) handler_file_error.formatter = formatter_full handler_file_error.level = ERROR handler_file_error.addFilter(relocator) logging.root.setLevel(LOGLEVEL) logging.root.addHandler(handler_console) logging.root.addHandler(handler_console_priority) logging.root.addHandler(handler_file_error) testlogger = logging.getLogger('test') testlogger.setLevel(CRITICAL) testlogger.addHandler(handler_console) testlogger.addHandler(handler_console_priority)
def start_server(self, httphandler): """use the configuration to setup and start the cherrypy server """ cherrypy.config.update({'log.screen': True}) ipv6_enabled = config['server.ipv6_enabled'] if config['server.localhost_only']: socket_host = "::1" if ipv6_enabled else "127.0.0.1" else: socket_host = "::" if ipv6_enabled else "0.0.0.0" resourcedir = os.path.abspath(pathprovider.getResourcePath('res')) if config['server.ssl_enabled']: cert = pathprovider.absOrConfigPath(config['server.ssl_certificate']) pkey = pathprovider.absOrConfigPath(config['server.ssl_private_key']) cherrypy.config.update({ 'server.ssl_certificate': cert, 'server.ssl_private_key': pkey, 'server.socket_port': config['server.ssl_port'], }) # Create second server for redirecting http to https: redirecter = cherrypy._cpserver.Server() redirecter.socket_port = config['server.port'] redirecter._socket_host = socket_host redirecter.thread_pool = 10 redirecter.subscribe() else: cherrypy.config.update({ 'server.socket_port': config['server.port'], }) cherrypy.config.update({ 'log.error_file': os.path.join( pathprovider.getUserDataPath(), 'server.log'), 'environment': 'production', 'server.socket_host': socket_host, 'server.thread_pool': 30, 'tools.sessions.on': True, 'tools.sessions.timeout': 60 * 24, }) if not config['server.keep_session_in_ram']: sessiondir = os.path.join( pathprovider.getUserDataPath(), 'sessions') if not os.path.exists(sessiondir): os.mkdir(sessiondir) cherrypy.config.update({ 'tools.sessions.storage_type': "file", 'tools.sessions.storage_path': sessiondir, }) basedirpath = config['media.basedir'] if sys.version_info < (3,0): basedirpath = codecs.encode(basedirpath, 'utf-8') scriptname = codecs.encode(config['server.rootpath'], 'utf-8') else: # fix cherrypy unicode issue (only for Python3) # see patch to cherrypy.lib.static.serve_file way above and # https://bitbucket.org/cherrypy/cherrypy/issue/1148/wrong-encoding-for-urls-containing-utf-8 basedirpath = codecs.decode(codecs.encode(basedirpath, 'utf-8'), 'latin-1') scriptname = config['server.rootpath'] cherrypy.tree.mount( httphandler, scriptname, config={ '/res': { 'tools.staticdir.on': True, 'tools.staticdir.dir': resourcedir, 'tools.staticdir.index': 'index.html', 'tools.caching.on': False, 'tools.gzip.mime_types': ['text/html', 'text/plain', 'text/javascript', 'text/css'], 'tools.gzip.on': True, }, '/serve': { 'tools.staticdir.on': True, 'tools.staticdir.dir': basedirpath, # 'tools.staticdir.index': 'index.html', if ever needed: in py2 MUST utf-8 encode 'tools.staticdir.content_types': MimeTypes, 'tools.encode.on': True, 'tools.encode.encoding': 'utf-8', 'tools.caching.on': False, 'tools.cm_auth.on': True, 'tools.cm_auth.httphandler': httphandler, }, '/favicon.ico': { 'tools.staticfile.on': True, 'tools.staticfile.filename': resourcedir + '/img/favicon.ico', }}) api.v1.mount('/api/v1') log.i(_('Starting server on port %s ...') % config['server.port']) cherrypy.lib.caching.expires(0) # disable expiry caching cherrypy.engine.start() cherrypy.engine.block()
formatter_brief = logging.Formatter(fmt='[%(asctime)s] %(levelname)-8s: %(message)s', datefmt='%y%m%d-%H:%M') formatter_full = logging.Formatter(fmt=('-'*80)+ '\n%(levelname)-8s [%(asctime)s] : %(name)-20s : from line (%(lineno)d) at\n\t%(pathname)s\n\t--\n\t%(message)s\n') handler_console = logging.StreamHandler(stream=sys.stdout) handler_console.formatter = formatter_briefest handler_console.level = DEBUG handler_console.addFilter(LowPass(WARNING)) handler_console.addFilter(relocator) handler_console_priority = logging.StreamHandler(stream=sys.stderr) handler_console_priority.formatter = formatter_brief handler_console_priority.level = WARNING handler_console_priority.addFilter(relocator) handler_file_error = logging.FileHandler(os.path.join(pathprovider.getUserDataPath(), 'error.log'), mode='a', delay=True) handler_file_error.formatter = formatter_full handler_file_error.level = ERROR handler_file_error.addFilter(relocator) logging.root.setLevel(LOGLEVEL) logging.root.addHandler(handler_console) logging.root.addHandler(handler_console_priority) logging.root.addHandler(handler_file_error) testlogger = logging.getLogger('test') testlogger.setLevel(CRITICAL) testlogger.addHandler(handler_console) testlogger.addHandler(handler_console_priority) testlogger.propagate = False
def start(self, httphandler): socket_host = "127.0.0.1" if config['server.localhost_only'] else "0.0.0.0" resourcedir = os.path.abspath(pathprovider.getResourcePath('res')) if config['server.ssl_enabled']: cherrypy.config.update({ 'server.ssl_certificate': config['server.ssl_certificate'], 'server.ssl_private_key': config['server.ssl_private_key'], 'server.socket_port': config['server.ssl_port'], }) # Create second server for http redirect: redirecter = cherrypy._cpserver.Server() redirecter.socket_port = config['server.port'] redirecter._socket_host = socket_host redirecter.thread_pool = 10 redirecter.subscribe() else: cherrypy.config.update({ 'server.socket_port': config['server.port'], }) cherrypy.config.update({ 'log.error_file': os.path.join( pathprovider.getUserDataPath(), 'server.log'), 'environment': 'production', 'server.socket_host': socket_host, 'server.thread_pool': 30, 'tools.sessions.on': True, 'tools.sessions.timeout': 60 * 24, }) if not config['server.keep_session_in_ram']: sessiondir = os.path.join( pathprovider.getUserDataPath(), 'sessions') if not os.path.exists(sessiondir): os.mkdir(sessiondir) cherrypy.config.update({ 'tools.sessions.storage_type': "file", 'tools.sessions.storage_path': sessiondir, }) cherrypy.tree.mount( httphandler, '/', config={ '/res': { 'tools.staticdir.on': True, 'tools.staticdir.dir': resourcedir, 'tools.staticdir.index': 'index.html', 'tools.caching.on': False, }, '/serve': { 'tools.staticdir.on': True, 'tools.staticdir.dir': config['media.basedir'], 'tools.staticdir.index': 'index.html', 'tools.encode.on': True, 'tools.encode.encoding': 'utf-8', 'tools.caching.on': False, }, '/favicon.ico': { 'tools.staticfile.on': True, 'tools.staticfile.filename': resourcedir + '/favicon.ico', }}) log.i('Starting server on port %s ...' % config['server.port']) cherrypy.lib.caching.expires(0) # disable expiry caching cherrypy.engine.start() cherrypy.engine.block()