本文整理汇总了Python中useless.db.midlevel.StatementCursor.select方法的典型用法代码示例。如果您正苦于以下问题:Python StatementCursor.select方法的具体用法?Python StatementCursor.select怎么用?Python StatementCursor.select使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类useless.db.midlevel.StatementCursor
的用法示例。
在下文中一共展示了StatementCursor.select方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TableEditor
# 需要导入模块: from useless.db.midlevel import StatementCursor [as 别名]
# 或者: from useless.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()
示例2: BaseDiffer
# 需要导入模块: from useless.db.midlevel import StatementCursor [as 别名]
# 或者: from useless.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('')
示例3: MachinesElement
# 需要导入模块: from useless.db.midlevel import StatementCursor [as 别名]
# 或者: from useless.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)
示例4: TraitAssigner
# 需要导入模块: from useless.db.midlevel import StatementCursor [as 别名]
# 或者: from useless.db.midlevel.StatementCursor import select [as 别名]
class TraitAssigner(BaseAssigner):
def __init__(self, app, parent, profile):
self.profile = Profile(app.conn)
self.profile.set_profile(profile)
BaseAssigner.__init__(self, app, parent,
name='TraitAssigner', udbuttons=True)
self.connect(self, SIGNAL('okClicked()'), self.slotLaughAtMe)
def initView(self):
app = self.app
self.db = app.db
self.suite = self.profile.current.suite
self.traits = StatementCursor(app.conn)
self.traits.set_table('%s_traits' % self.suite)
ptrows = self.profile.get_trait_rows()
pt = [r.trait for r in ptrows]
all_trows = self.traits.select(fields=['trait'], order=['trait'])
trows = [r for r in all_trows if r.trait not in pt]
abox = self.listBox.availableListBox()
sbox = self.listBox.selectedListBox()
for row in ptrows:
r = QListBoxText(sbox, row.trait)
r.trait = row.trait
for row in trows:
r = QListBoxText(abox, row.trait)
r.trait = row.trait
def slotLaughAtMe(self):
sbox = self.listBox.selectedListBox()
traits = [sbox.item(n).trait for n in range(sbox.numRows())]
print 'laughing out loud', traits
示例5: __init__
# 需要导入模块: from useless.db.midlevel import StatementCursor [as 别名]
# 或者: from useless.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',
'browser']
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)
示例6: ScriptNameComboBox
# 需要导入模块: from useless.db.midlevel import StatementCursor [as 别名]
# 或者: from useless.db.midlevel.StatementCursor import select [as 别名]
class ScriptNameComboBox(KComboBox):
def __init__(self, parent, name='ScriptNameComboBox'):
KComboBox.__init__(self, parent, name)
self.app = get_application_pointer()
self.cursor = StatementCursor(self.app.conn)
self.scriptnames = [row.script for row in self.cursor.select(table='scriptnames')]
self.insertStrList(self.scriptnames)
示例7: DisksElement
# 需要导入模块: from useless.db.midlevel import StatementCursor [as 别名]
# 或者: from useless.db.midlevel.StatementCursor import select [as 别名]
class DisksElement(Element):
def __init__(self, conn, disks=None):
Element.__init__(self, "disks")
self.conn = conn
self.cursor = StatementCursor(self.conn)
if disks is None:
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)
示例8: TraitsWindow
# 需要导入模块: from useless.db.midlevel import StatementCursor [as 别名]
# 或者: from useless.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)
示例9: EnvironmentList
# 需要导入模块: from useless.db.midlevel import StatementCursor [as 别名]
# 或者: from useless.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)
示例10: ScriptNameComboBox
# 需要导入模块: from useless.db.midlevel import StatementCursor [as 别名]
# 或者: from useless.db.midlevel.StatementCursor import select [as 别名]
class ScriptNameComboBox(KComboBox):
def __init__(self, parent, type, name='ScriptNameComboBox'):
KComboBox.__init__(self, parent, name)
self.app = get_application_pointer()
self.cursor = StatementCursor(self.app.conn)
clause=In('type', ['both', type])
rows = self.cursor.select(table='scriptnames', clause=clause)
#self.scriptnames = [row.script for row in self.cursor.select(table='scriptnames')]
self.scriptnames = [row.script for row in rows]
self.insertStrList(self.scriptnames)
示例11: Select
# 需要导入模块: from useless.db.midlevel import StatementCursor [as 别名]
# 或者: from useless.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)
示例12: PaellaDatabase
# 需要导入模块: from useless.db.midlevel import StatementCursor [as 别名]
# 或者: from useless.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)
示例13: FilesystemsElement
# 需要导入模块: from useless.db.midlevel import StatementCursor [as 别名]
# 或者: from useless.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)
示例14: KernelsElement
# 需要导入模块: from useless.db.midlevel import StatementCursor [as 别名]
# 或者: from useless.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)
示例15: ScriptBrowser
# 需要导入模块: from useless.db.midlevel import StatementCursor [as 别名]
# 或者: from useless.db.midlevel.StatementCursor import select [as 别名]
class ScriptBrowser(ListNoteBook):
def __init__(self, conn, suite, trait):
self.conn = conn
self.suite = suite
self.trait = trait
self.cursor = StatementCursor(self.conn)
self._scriptnames =[r.script for r in self.cursor.select(table='scriptnames')]
self.cursor.set_table('%s_scripts' % self.suite)
self.edit_menu = make_menu(self._scriptnames, self.modify_trait, name='edit')
self.diff_menu = make_menu(self._scriptnames, self.modify_trait, name='diff')
self.menu = make_menu(['edit', 'diff'], self.modify_trait)
self.menu['edit'].set_submenu(self.edit_menu)
self.menu['diff'].set_submenu(self.diff_menu)
self.menu.set_name('main')
ListNoteBook.__init__(self)
self.reset_rows()
def reset_rows(self):
rows = self.cursor.select(fields=['script'], clause=self._trait_clause())
self.set_rows(rows)
self.set_row_select(self.script_selected)
def modify_trait(self, menuitem, action):
parent = menuitem.get_parent().get_name()
if parent == '_none_':
print 'ack ack ack'
elif parent != 'main':
print parent, action
def _trait_clause(self):
return Eq('trait', self.trait)
def script_selected(self, listbox, row, column, event):
script = listbox.get_selected_data()[0].script
self.select_script(script)
def select_script(self, script):
if script not in self.pages:
newpage = ScriptText(self.conn, self.suite, self.trait, script)
self.append_page(newpage, script)
self.set_current_page(script)