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)
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 test_file_functions(self): import tempfile tf = tempfile.NamedTemporaryFile() cfg = configuration.from_defaults() configuration.write_to_file(cfg, tf.name) # compare with the limited cfg the configparser can return parsed = configuration.from_configparser(tf.name) assert len(cfg) == len(parsed), '%r <--> %r' % (cfg, parsed) for key in cfg: this, that = cfg[key], parsed[key] assert Key(this.name) == Key(that.name) assert str(this.value) == str(that.value) assert len(cfg) == len(parsed), 'no properties must be added while comparing: %r <--> %r' % (this, that)
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)
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)
def __init__(self, update=None, createNewConfig=False, dropfiledb=False): if createNewConfig: newconfigpath = util.configurationFile() + '.new' configuration.write_to_file(configuration.from_defaults(), newconfigpath) log.i('''New configuration file was written to: ''' + newconfigpath) exit(0) if not util.configurationFileExists(): configuration.write_to_file(configuration.from_defaults(), util.configurationFile()) self.printWelcomeAndExit() self._init_config() self.db = sqlitecache.SQLiteCache(util.databaseFilePath('cherry.cache.db')) if not update == None or dropfiledb: CherryMusic.UpdateThread(self.db,update,dropfiledb).start() else: self.cherrymodel = cherrymodel.CherryModel(self.db) self.httphandler = httphandler.HTTPHandler(config, self.cherrymodel) self.server()
def create_default_config_file(path): """ Creates or overwrites a default configuration file at `path` """ cfg.write_to_file(cfg.from_defaults(), path) log.i(_('Default configuration file written to %(path)r'), {'path': path})