Beispiel #1
0
    def setup_config(self, createNewConfig, browsersetup, cfg_override):
        """start the in-browser configuration server, create a config if
        no configuration is found or provide migration help for old CM
        versions

        initialize the configuration if no config setup is needed/requested
        """
        if browsersetup:
            port = cfg_override.pop('server.port', False)
            cherrymusicserver.browsersetup.configureAndStartCherryPy(port)
        if createNewConfig:
            newconfigpath = pathprovider.configurationFile() + '.new'
            cfg.write_to_file(cfg.from_defaults(), newconfigpath)
            log.i(_('New configuration file was written to:{br}{path}').format(
                path=newconfigpath,
                br=os.linesep
            ))
            sys.exit(0)
        if not pathprovider.configurationFileExists():
            if pathprovider.fallbackPathInUse():   # temp. remove @ v0.30 or so
                self.printMigrationNoticeAndExit()
            else:
                cfg.write_to_file(cfg.from_defaults(), pathprovider.configurationFile())
                self.printWelcomeAndExit()
        self._init_config(cfg_override)
Beispiel #2
0
 def _init_config(self, override_dict):
     defaults = cfg.from_defaults()
     filecfg = cfg.from_configparser(pathprovider.configurationFile())
     custom = defaults.replace(filecfg, on_error=log.e)
     global config
     config = custom.replace(override_dict, on_error=log.e)
     self._check_for_config_updates(defaults, filecfg)
Beispiel #3
0
 def setup_config(self, createNewConfig, browsersetup, cfg_override):
     if browsersetup:
         port = cfg_override.pop('server.port', False)
         cherrymusicserver.browsersetup.configureAndStartCherryPy(port)
     if createNewConfig:
         newconfigpath = pathprovider.configurationFile() + '.new'
         cfg.write_to_file(cfg.from_defaults(), newconfigpath)
         log.i('New configuration file was written to:{br}{path}'.format(
             path=newconfigpath, br=os.linesep))
         sys.exit(0)
     if not pathprovider.configurationFileExists():
         if pathprovider.fallbackPathInUse():  # temp. remove @ v0.30 or so
             self.printMigrationNoticeAndExit()
         else:
             cfg.write_to_file(cfg.from_defaults(),
                               pathprovider.configurationFile())
             self.printWelcomeAndExit()
     self._init_config(cfg_override)
Beispiel #4
0
 def setup_config(self, createNewConfig, browsersetup, cfg_override):
     if browsersetup:
         port = cfg_override.pop('server.port', False)
         cherrymusicserver.browsersetup.configureAndStartCherryPy(port)
     if createNewConfig:
         newconfigpath = pathprovider.configurationFile() + '.new'
         cfg.write_to_file(cfg.from_defaults(), newconfigpath)
         log.i('New configuration file was written to:{br}{path}'.format(
             path=newconfigpath,
             br=os.linesep
         ))
         sys.exit(0)
     if not pathprovider.configurationFileExists():
         if pathprovider.fallbackPathInUse():   # temp. remove @ v0.30 or so
             self.printMigrationNoticeAndExit()
         else:
             cfg.write_to_file(cfg.from_defaults(), pathprovider.configurationFile())
             self.printWelcomeAndExit()
     self._init_config(cfg_override)
Beispiel #5
0
    def _init_config(self, override_dict):
        """update the internal configuration using the following hierarchy:
        command_line_config > file_config > default_config

        check if there are new or deprecated configuration keys in the config
        file
        """
        defaults = cfg.from_defaults()
        filecfg = cfg.from_configparser(pathprovider.configurationFile())
        custom = defaults.replace(filecfg, on_error=log.e)
        global config
        config = custom.replace(override_dict, on_error=log.e)
        self._check_for_config_updates(defaults, filecfg)
 def saveconfig(self, values):
     collect_errors = cfg.error_collector()
     baseconfig = cfg.from_defaults()
     newconfig = json.loads(values, encoding='str')
     customcfg = baseconfig.replace(newconfig, collect_errors)
     if collect_errors:
         badkeys = (e.key for e in collect_errors)
         return json.dumps({"status": "error", 'fields': list(badkeys)})
     cfg.write_to_file(customcfg, pathprovider.configurationFile())
     # kill server in a second
     threading.Timer(1, lambda: cherrypy.engine.exit()).start()
     # so request should still reach client...
     return json.dumps({"status": "success"})
 def saveconfig(self, values):
     collect_errors = cfg.error_collector()
     baseconfig = cfg.from_defaults()
     newconfig = json.loads(values, encoding='str')
     customcfg = baseconfig.replace(newconfig, collect_errors)
     if collect_errors:
         badkeys = (e.key for e in collect_errors)
         return json.dumps({"status": "error", 'fields': list(badkeys)})
     cfg.write_to_file(customcfg, pathprovider.configurationFile())
     # kill server in a second
     threading.Timer(1, lambda: cherrypy.engine.exit()).start()
     # so request should still reach client...
     return json.dumps({"status": "success"})
Beispiel #8
0
    def printWelcomeAndExit(self):
        print(_("""
==========================================================================
Welcome to CherryMusic """ + VERSION + """!

To get this party started, you need to edit the configuration file, which
resides under the following path:

    """ + pathprovider.configurationFile() + """

Then you can start the server and listen to whatever you like.
Have fun!
==========================================================================
"""))
        sys.exit(0)
Beispiel #9
0
def setup_config(override_dict=None):
    """ Updates the internal configuration using the following hierarchy:
        override_dict > file_config > default_config

        Notifies the user if there are new or deprecated configuration keys.

        See :mod:`~cherrymusicserver.configuration`.
    """
    defaults = cfg.from_defaults()
    filecfg = cfg.from_configparser(pathprovider.configurationFile())
    custom = defaults.replace(filecfg, on_error=log.e)
    if override_dict:
        custom = custom.replace(override_dict, on_error=log.e)
    global config
    config = custom
    _notify_about_config_updates(defaults, filecfg)
Beispiel #10
0
def setup_config(override_dict=None):
    """ Updates the internal configuration using the following hierarchy:
        override_dict > file_config > default_config

        Notifies the user if there are new or deprecated configuration keys.

        See :mod:`~cherrymusicserver.configuration`.
    """
    defaults = cfg.from_defaults()
    filecfg = cfg.from_configparser(pathprovider.configurationFile())
    custom = defaults.replace(filecfg, on_error=log.e)
    if override_dict:
        custom = custom.replace(override_dict, on_error=log.e)
    global config
    config = custom
    _notify_about_config_updates(defaults, filecfg)
Beispiel #11
0
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. :)
==========================================================================
"""))