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 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()
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()
from backport import input import re import os import codecs import sys import threading import signal import gettext from cherrymusicserver import pathprovider from audiotranscode import MimeTypes if sys.version_info < (3,): gettext.install('default', unicode=True, localedir=pathprovider.getResourcePath('res/i18n')) else: gettext.install('default', localedir=pathprovider.getResourcePath('res/i18n')) # woraround for cherrypy 3.2.2: # https://bitbucket.org/cherrypy/cherrypy/issue/1163/attributeerror-in-cherrypyprocessplugins if sys.version_info >= (3, 3): threading._Timer = threading.Timer import cherrypy def version(): return """CherryMusic Server {cm_version} a standalone music server
from backport import input import re import os import codecs import sys import threading import signal import gettext from cherrymusicserver import pathprovider if sys.version_info < (3, ): gettext.install('default', unicode=True, localedir=pathprovider.getResourcePath('res/i18n')) else: gettext.install('default', localedir=pathprovider.getResourcePath('res/i18n')) # woraround for cherrypy 3.2.2: # https://bitbucket.org/cherrypy/cherrypy/issue/1163/attributeerror-in-cherrypyprocessplugins if sys.version_info >= (3, 3): threading._Timer = threading.Timer import cherrypy def version(): return """CherryMusic Server {cm_version}
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()