本文整理汇总了Python中paella.db.midlevel.StatementCursor.select方法的典型用法代码示例。如果您正苦于以下问题:Python StatementCursor.select方法的具体用法?Python StatementCursor.select怎么用?Python StatementCursor.select使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类paella.db.midlevel.StatementCursor
的用法示例。
在下文中一共展示了StatementCursor.select方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: PaellaProfiles
# 需要导入模块: from paella.db.midlevel import StatementCursor [as 别名]
# 或者: from paella.db.midlevel.StatementCursor import select [as 别名]
class PaellaProfiles(Element):
def __init__(self, conn):
Element.__init__(self, 'profiles')
self.conn = conn
self.stmt = StatementCursor(self.conn)
self.env = ProfileEnvironment(self.conn)
self.profiletraits = ProfileTrait(self.conn)
self._profiles = {}
for row in self.stmt.select(table='profiles', order='profile'):
self._append_profile(row.profile, row.suite)
def _append_profile(self, profile, suite):
element = self.export_profile(profile, suite)
self._profiles[profile] = element
self.appendChild(self._profiles[profile])
def export_profile(self, profile, suite=None):
if suite is None:
row = self.stmt.select_row(table='profiles',clause=Eq('profile', profile))
suite = row['suite']
suite = str(suite)
profile = str(profile)
self.env.set_profile(profile)
element = ProfileElement(profile, suite)
element.append_traits(self.profiletraits.trait_rows(profile))
element.append_variables(self.env.get_rows())
return element
def insert_profile(self, profile):
idata = {'profile' : profile.name,
'suite' : profile.suite}
self.stmt.insert(table='profiles', data=idata)
idata = {'profile' : profile.name,
'trait' : None,
'ord' : 0}
for trait, ord in profile.traits:
print trait, ord
idata['trait'] = trait
idata['ord'] = ord #str(ord)
self.stmt.insert(table='profile_trait', data=idata)
idata = {'profile' : profile.name,
'trait' : None,
'name' : None,
'value': None}
for trait, name, value in profile.vars:
idata['trait'] = trait
idata['name'] = name
idata['value'] = value
self.stmt.insert(table='profile_variables', data=idata)
def export_profiles(self, path):
rows = self.stmt.select(fields='profile', table='profiles', clause=None)
for row in rows:
self.write_profile(row.profile, path)
def write_profile(self, profile, path):
xmlfile = file(join(path, '%s.xml' % profile), 'w')
data = self.export_profile(profile)
data.writexml(xmlfile, indent='\t', newl='\n', addindent='\t')
xmlfile.close()
示例2: TableEditor
# 需要导入模块: from paella.db.midlevel import StatementCursor [as 别名]
# 或者: from paella.db.midlevel.StatementCursor import select [as 别名]
class TableEditor(ListWin):
def __init__(self, conn, table, pkey=None, fields=[],
command_data=dict(new='new entry', edit='edit entry')):
ListWin.__init__(self)
self.conn = conn
self.cursor = StatementCursor(self.conn)
self.cursor.set_table(table)
self._cdata = command_data
self.tbar.add_button('new', self._cdata['new'], self.toolbar_button_pressed)
self.tbar.add_button('edit', self._cdata['edit'], self.toolbar_button_pressed)
if pkey is None:
print get_pkey_info(StatementCursor(conn), table)
self._pkey = pkey
self.reset_rows()
self._fields = fields
self.fields = [pkey] + self._fields
self.dialogs = {}.fromkeys(self._cdata.keys())
def reset_rows(self):
self.set_rows(self.cursor.select(order=self._pkey))
def toolbar_button_pressed(self, button, data):
row = None
if data == 'new':
if self.dialogs['new'] is None:
row = self.cursor.select()[0]
self._make_dialog('new', row, self.add_new_record)
elif data == 'edit':
if self.dialogs['edit'] is None:
row = get_single_row(self.listbox, self._pkey)
if row is not None:
self._make_dialog('edit', row, self.edit_record, row[self._pkey])
def _make_dialog(self, name, row, okfun, pkey=None):
if name == 'edit':
fields = self._fields
else:
fields = self.fields
make_record_dialog(self, name, row, okfun, pkey, fields, self._cdata)
def add_new_record(self, *args):
dialog = self.dialogs['new']
self.cursor.insert(data=dict(dialog.items()))
self.destroy_dialog(dialog)
self.reset_rows()
def edit_record(self, *args):
dialog = self.dialogs['edit']
clause = Eq(self._pkey, dialog.pkey)
data = dict(dialog.items())
self.cursor.update(data=data, clause=clause)
self.destroy_dialog(dialog)
self.reset_rows()
示例3: BaseDiffer
# 需要导入模块: from paella.db.midlevel import StatementCursor [as 别名]
# 或者: from paella.db.midlevel.StatementCursor import select [as 别名]
class BaseDiffer(VBox):
def __init__(self, conn, name='BaseDiffer'):
VBox.__init__(self)
self.set_name(name)
self.conn = conn
self.view = TwinScrollCList(name=name)
self.cursor = StatementCursor(self.conn)
suites = [r.suite for r in self.cursor.select(table='suites', order='suite')]
self.suite_bar = SuiteBar(suites, name=name)
self.trait_bar = TraitBar(name=name)
self.pack_end(self.suite_bar, 0, 0, 0)
self.pack_end(self.trait_bar, 0, 0, 0)
self.add(self.view)
self.suite_bar.show()
self.show()
def update_lists(self, fields, suffix):
self.lsuite = self.suite_bar.lcombo.get()
self.rsuite = self.suite_bar.rcombo.get()
self.cursor.set_fields(fields)
clause = None
ltrait = self.trait_bar.lcombo.get()
if ltrait:
clause = Eq('trait', ltrait)
table = '%s_%s' % (self.lsuite, suffix)
rows = self.cursor.select(table=table, clause=clause, order=fields)
self.view.lbox.set_rows(rows)
clause = None
rtrait = self.trait_bar.rcombo.get()
if rtrait:
clause = Eq('trait', rtrait)
table = '%s_%s' % (self.rsuite, suffix)
rows = self.cursor.select(table=table, clause=clause, order=fields)
self.view.rbox.set_rows(rows)
fields = ['trait']
self.cursor.set_fields(fields)
rows = self.cursor.select(table='%s_traits' % self.lsuite, order=fields)
ltraits = [r.trait for r in rows]
rows = self.cursor.select(table='%s_traits' % self.rsuite, order=fields)
rtraits = [r.trait for r in rows]
self.trait_bar.lcombo.fill(ltraits)
self.trait_bar.rcombo.fill(rtraits)
if ltrait and ltrait in ltraits:
self.trait_bar.lcombo.set(ltrait)
else:
self.trait_bar.lcombo.set('')
if rtrait and rtrait in rtraits:
self.trait_bar.rcombo.set(rtrait)
else:
self.trait_bar.rcombo.set('')
示例4: __init__
# 需要导入模块: from paella.db.midlevel import StatementCursor [as 别名]
# 或者: from paella.db.midlevel.StatementCursor import select [as 别名]
def __init__(self, name='Manager'):
CommandBoxWindow.__init__(self)
self.cfg = PaellaConfig('database')
self.dialogs = {}.fromkeys(['dbname', 'suitemanager'])
apps = ['profiles', 'families', 'suitemanager', 'traitmanager', 'machines',
'traits', 'tdiff', 'sdiff', 'fdiff', 'default_environment', 'clients']
self.workspace = {}.fromkeys(apps)
self.add_menu(dbcommands, 'database', self.database_command)
self.add_menu(self.workspace.keys(), 'edit', self.edit_command)
self.set_size_request(150,200)
self.conn = None
self.dbname = None
self.dblist = ScrollCList()
self.vbox.add(self.dblist)
conn = PaellaConnection(self.cfg)
cursor = StatementCursor(conn, 'quicky')
self.dblist.set_rows(cursor.select(table='pg_database'))
cursor.close()
conn.close()
self.tbar.add_button('profiles', 'profile manager', self.run_tbar)
self.tbar.add_button('families', 'family manager', self.run_tbar)
self.tbar.add_button('machines', 'machine manager', self.run_tbar)
self.tbar.add_button('traits', 'trait manager', self.run_tbar)
self.tbar.add_button('tdiff', 'template differ', self.run_tbar)
self.tbar.add_button('sdiff', 'script differ', self.run_tbar)
self.tbar.add_button('fdiff', 'family differ', self.run_tbar)
示例5: Family
# 需要导入模块: from paella.db.midlevel import StatementCursor [as 别名]
# 或者: from paella.db.midlevel.StatementCursor import select [as 别名]
class Family(object):
def __init__(self, conn):
object.__init__(self)
self.conn = conn
self.cursor = StatementCursor(self.conn)
self.current = None
self.parent = SimpleRelation(self.conn, 'family_parent', 'family')
self.env = Environment(self.conn, 'family_environment', 'family')
def set_family(self, family):
self.current = family
self.parent.set_current(family)
self.env.set_main(family)
def add_family(self, family, type='general'):
pass
def get_families(self, families=[]):
rows = self.cursor.select(table='family_parent')
graph = kjGraph([(r.family, r.parent) for r in rows])
dfamilies = Set()
for fam in families:
dfamilies |= Set([fam]) | Set(graph.reachable(fam).items())
return dfamilies
def parents(self, family=None):
if family is None:
family = self.current
self.parent.set_clause(family)
rows = self.parent.cmd.select(fields=['parent'], order='parent')
self.parent.reset_clause()
return [x.parent for x in rows]
示例6: DisksElement
# 需要导入模块: from paella.db.midlevel import StatementCursor [as 别名]
# 或者: from paella.db.midlevel.StatementCursor import select [as 别名]
class DisksElement(Element):
def __init__(self, conn):
Element.__init__(self, 'disks')
self.conn = conn
self.cursor = StatementCursor(self.conn)
disks = [r.diskname for r in self.cursor.select(table='disks', order='diskname')]
self.disks = []
for diskname in disks:
disk_element = DiskElement(diskname)
clause = Eq('diskname', diskname)
partitions = self.cursor.select(table='partitions',
clause=clause, order='partition')
for p in partitions:
disk_element.append_partition(p.partition, p.start, p.size, p.id)
self.disks.append(disk_element)
self.appendChild(disk_element)
示例7: MachinesElement
# 需要导入模块: from paella.db.midlevel import StatementCursor [as 别名]
# 或者: from paella.db.midlevel.StatementCursor import select [as 别名]
class MachinesElement(Element):
def __init__(self, conn, machines=None):
Element.__init__(self, 'machines')
self.conn = conn
self.cursor = StatementCursor(self.conn)
self.machines = []
if machines is None:
machines = self.cursor.select(table='machines', order='machine')
else:
clause = In('machine', machines)
machines = self.cursor.select(table='machines', clause=clause, order='machine')
for m in machines:
machine_element = MachineElement(m.machine, m.machine_type,
m.kernel, m.profile, m.filesystem)
self.machines.append(machine_element)
self.appendChild(machine_element)
示例8: MachineTypesElement
# 需要导入模块: from paella.db.midlevel import StatementCursor [as 别名]
# 或者: from paella.db.midlevel.StatementCursor import select [as 别名]
class MachineTypesElement(Element):
def __init__(self, conn):
Element.__init__(self, 'machine_types')
self.conn = conn
self.cursor = StatementCursor(self.conn)
rows = self.cursor.select(table='machine_types', order='machine_type')
mtypes = [r.machine_type for r in rows]
self.machine_types = []
for mtype in mtypes:
mtype_element = MachineTypeElement(mtype)
clause = Eq('machine_type', mtype)
mdisks = self.cursor.select(table='machine_disks', clause=clause,
order='device')
for m in mdisks:
mtype_element.append_device(m.diskname, m.device)
self.machine_types.append(mtype_element)
self.appendChild(mtype_element)
示例9: TraitsWindow
# 需要导入模块: from paella.db.midlevel import StatementCursor [as 别名]
# 或者: from paella.db.midlevel.StatementCursor import select [as 别名]
class TraitsWindow(DragListWindow):
def __init__(self, conn, suite, name='TraitsWindow'):
self.cmd = StatementCursor(conn, name=name)
self.cmd.set_table(ujoin(suite, 'traits'))
rows = self.cmd.select()
packer = lambda x : rowpacker('trait', x)
DragListWindow.__init__(self, '%s traits' % suite, packer, rows,
TARGETS.get('trait', suite), name=name)
self.set_size_request(400, 300)
示例10: EnvironmentList
# 需要导入模块: from paella.db.midlevel import StatementCursor [as 别名]
# 或者: from paella.db.midlevel.StatementCursor import select [as 别名]
class EnvironmentList(KListView):
def __init__(self, app, parent, etype='default', name='EnvironmentList'):
KListView.__init__(self, parent, name)
dbwidget(self, app)
self.etype = etype
self.environ = ETYPE[self.etype](self.conn)
self.cursor = StatementCursor(self.conn)
self.cursor.set_table('%s_environment' % self.etype)
self.setRootIsDecorated(True)
for field in ['section', 'option', 'value']:
self.addColumn(field)
def refreshlistView(self):
self.clear()
if self.etype == 'default':
fields = ['section', 'option', 'value']
rows = self.cursor.select(fields=fields, order=['section', 'option'])
if self.etype == 'current':
fields = ['hostname', 'name', 'value']
rows = self.cursor.select(fields=fields, order=['hostname', 'name'])
for row in rows:
KListViewItem(self, *row)
def file_selected(self, filesel):
filename = str(filesel.selectedFile())
print filename, filesel.actiontype
action = filesel.actiontype
if action == 'save':
self.environ.write(file(filename, 'w'))
elif action == 'load':
newcfg = RawConfigParser()
newcfg.read(filename)
self._update_environ(newcfg)
def _update_environ(self, newcfg):
self.environ.update(newcfg)
self.environ = ETYPE[self.etype] (self.conn)
self.refreshlistView()
def slotEdit(self):
newcfg = self.environ.edit()
self._update_environ(newcfg)
示例11: KernelsElement
# 需要导入模块: from paella.db.midlevel import StatementCursor [as 别名]
# 或者: from paella.db.midlevel.StatementCursor import select [as 别名]
class KernelsElement(Element):
def __init__(self, conn):
Element.__init__(self, 'kernels')
self.conn = conn
self.cursor = StatementCursor(self.conn)
self.kernels = []
kernels = [r.kernel for r in self.cursor.select(table='kernels', order='kernel')]
for k in kernels:
k_element = KernelElement(k)
self.kernels.append(k_element)
self.appendChild(k_element)
示例12: Select
# 需要导入模块: from paella.db.midlevel import StatementCursor [as 别名]
# 或者: from paella.db.midlevel.StatementCursor import select [as 别名]
class Select(object):
def __init__(self, conn):
self.conn = conn
self.win = MenuWindow()
self.scroll = ScrollCList()
self.win.vbox.add(self.scroll)
self.s = StatementCursor(self.conn)
def select(self, *args, **kw):
rows = self.s.select(*args, **kw)
self.scroll.set_rows(rows)
示例13: PaellaDatabase
# 需要导入模块: from paella.db.midlevel import StatementCursor [as 别名]
# 或者: from paella.db.midlevel.StatementCursor import select [as 别名]
class PaellaDatabase(Element):
def __init__(self, conn, path='/'):
Element.__init__(self, 'paelladatabase')
self.conn = conn
self.stmt = StatementCursor(self.conn)
self._profile_traits_ = ProfileTrait(self.conn)
self.path = path
self.suites = SuitesElement()
self.appendChild(self.suites)
for row in self._suite_rows():
args = map(str, [row.suite, row.nonus, row.updates, row.local, row.common])
element = SuiteElement(*args)
self.suites.appendChild(element)
self.profiles = PaellaProfiles(self.conn)
self.family = Family(self.conn)
suites = [x.suite for x in self._suite_rows()]
for suite in suites:
self.appendChild(TraitsElement(self.conn, suite))
def _suite_rows(self):
return self.stmt.select(table='suites', order='suite')
def write(self, filename):
path = join(self.path, filename)
xmlfile = file(path, 'w')
self.writexml(xmlfile, indent='\t', newl='\n', addindent='\t')
def backup(self, path=None):
if path is None:
path = self.path
if not isdir(path):
raise Error, '%s not a directory' % path
dbfile = file(join(path, 'database.xml'), 'w')
self.writexml(dbfile, indent='\t', newl='\n', addindent='\t')
dbfile.close()
self.backup_profiles(path)
self.backup_families(path)
suites = [x.suite for x in self._suite_rows()]
for suite in suites:
makepaths(join(path, suite))
trait = Trait(self.conn, suite)
for t in trait.get_trait_list():
trait.set_trait(t)
trait.backup_trait(join(path, suite))
def backup_profiles(self, path=None):
profiles_dir = join(path, 'profiles')
makepaths(profiles_dir)
self.profiles.export_profiles(profiles_dir)
def backup_families(self, path=None):
fpath = join(path, 'families')
makepaths(fpath)
self.family.export_families(fpath)
示例14: MachinesElement
# 需要导入模块: from paella.db.midlevel import StatementCursor [as 别名]
# 或者: from paella.db.midlevel.StatementCursor import select [as 别名]
class MachinesElement(Element):
def __init__(self, conn):
Element.__init__(self, 'machines')
self.conn = conn
self.cursor = StatementCursor(self.conn)
self.machines = []
machines = self.cursor.select(table='machines', order='machine')
for m in machines:
machine_element = MachineElement(m.machine, m.machine_type,
m.kernel, m.profile, m.filesystem)
self.machines.append(machine_element)
self.appendChild(machine_element)
示例15: FilesystemsElement
# 需要导入模块: from paella.db.midlevel import StatementCursor [as 别名]
# 或者: from paella.db.midlevel.StatementCursor import select [as 别名]
class FilesystemsElement(Element):
def __init__(self, conn):
Element.__init__(self, 'filesystems')
self.conn = conn
self.cursor = StatementCursor(self.conn)
filesystems = [r.filesystem for r in self.cursor.select(table='filesystems',
order='filesystem')]
self.filesystems = []
for filesystem in filesystems:
fs_element = FilesystemElement(self.conn, filesystem)
self.filesystems.append(fs_element)
self.appendChild(fs_element)