def _check_for_config_updates(self, known_config): new = [] deprecated = [] default = configuration.from_defaults() for property in configuration.to_list(default): #@ReservedAssignment if property.name not in known_config and not property.hidden: new.append(property.name) for property in configuration.to_list(known_config): #@ReservedAssignment if property.name not in default: deprecated.append(property.name) if new: log.i('''New configuration options available: %s Using default values for now.''', '\n\t\t\t'.join(new)) if deprecated: log.i('''The following configuration options are not used anymore: %s''', '\n\t\t\t'.join(deprecated)) if new or deprecated: log.i('''Start with --newconfig to generate a new default config file next to your current one. ''', )
def _check_for_config_updates(self, default, known_config): """check if there are new or deprecated configuration keys in the config file """ new = [] deprecated = [] transform = lambda s: '[{0}]: {2}'.format(*(s.partition('.'))) for property in cfg.to_list(default): if property.key not in known_config and not property.hidden: new.append(transform(property.key)) for property in cfg.to_list(known_config): if property.key not in default: deprecated.append(transform(property.key)) if new: log.i(_('''New configuration options available: %s Using default values for now.'''), '\n\t\t\t'.join(new)) if deprecated: log.i(_('''The following configuration options are not used anymore: %s'''), '\n\t\t\t'.join(deprecated)) if new or deprecated: log.i(_('Start with --newconfig to generate a new default config' ' file next to your current one.'))
def setOptions(self, c): for k in cfg.to_list(c): value = json.dumps(k[1]) key = k[0] sel = self.useroptiondb.conn.execute('''SELECT name, value FROM option WHERE userid = ? AND name = ?''', (self.userid, key)).fetchone() if sel: self.useroptiondb.conn.execute('''UPDATE option SET value = ? WHERE userid = ? AND name = ?''', (value, self.userid, key)) else: self.useroptiondb.conn.execute('''INSERT INTO option (userid, name, value) VALUES (?,?,?)''', (self.userid, key, value)) self.useroptiondb.conn.commit()
def test_from_list(self): self.assertEqual(Configuration(), configuration.from_list([])) self.assertEqual(Configuration('a'), configuration.from_list([('a',), ('b',)], name='a')) self.assertEqual(Configuration(), configuration.from_list([('a',), ('b',)], name='a', rename='')) with self.assertRaises(ValueError): configuration.from_list([('a',), ('b',)], name='c') with self.assertRaises(configuration.ConfigKeyError): configuration.from_list([], rename='contains.bad.name') with configuration.create('nyah') as cfg: cfg.a.b = Property('nyah.a.b', 1, 'int', '\d', True, True, 'description') self.assertEqual(cfg, configuration.from_list(configuration.to_list(cfg), name='nyah'))
def test_list(self): '''list transformer must return a list of Property tuples''' with configuration.create() as c: c.A = '1' c.a.desc = 'a.1' c.b.x = Property('b.x', 2, 'int', '\d+', True, True, 'b.x.2') c.b.f = 'defined second, alphabetically first' l = configuration.to_list(c) self.assertEqual(3, len(l), 'list must contain exactly 3 Property tuples, but is %s' % l) self.assertEqual(('A', '1', '', '', None, None, 'a.1'), l[0]) self.assertEqual(('b.x', 2, 'int', '\d+', True, True, 'b.x.2'), l[1]) self.assertEqual(('b.f', 'defined second, alphabetically first', '', '', None, None, ''), l[2])
def setOptions(self, c): for k in cfg.to_list(c): value = json.dumps(k.value) key = k.key sel = self.useroptiondb.conn.execute( '''SELECT name, value FROM option WHERE userid = ? AND name = ?''', (self.userid, key)).fetchone() if sel: self.useroptiondb.conn.execute( '''UPDATE option SET value = ? WHERE userid = ? AND name = ?''', (value, self.userid, key)) else: self.useroptiondb.conn.execute( '''INSERT INTO option (userid, name, value) VALUES (?,?,?)''', (self.userid, key, value)) self.useroptiondb.conn.commit()
def setOptions(self, c): for k in cfg.to_list(c): value = json.dumps(k.value) key = k.key sel = self.useroptiondb.conn.execute( """SELECT name, value FROM option WHERE userid = ? AND name = ?""", (self.userid, key), ).fetchone() if sel: self.useroptiondb.conn.execute( """UPDATE option SET value = ? WHERE userid = ? AND name = ?""", (value, self.userid, key), ) else: self.useroptiondb.conn.execute( """INSERT INTO option (userid, name, value) VALUES (?,?,?)""", (self.userid, key, value), ) self.useroptiondb.conn.commit()