当前位置: 首页>>代码示例>>Python>>正文


Python StatementCursor.set_table方法代码示例

本文整理汇总了Python中useless.db.midlevel.StatementCursor.set_table方法的典型用法代码示例。如果您正苦于以下问题:Python StatementCursor.set_table方法的具体用法?Python StatementCursor.set_table怎么用?Python StatementCursor.set_table使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在useless.db.midlevel.StatementCursor的用法示例。


在下文中一共展示了StatementCursor.set_table方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TraitAssigner

# 需要导入模块: from useless.db.midlevel import StatementCursor [as 别名]
# 或者: from useless.db.midlevel.StatementCursor import set_table [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
开发者ID:BackupTheBerlios,项目名称:paella-svn,代码行数:34,代码来源:profile.py

示例2: TraitsWindow

# 需要导入模块: from useless.db.midlevel import StatementCursor [as 别名]
# 或者: from useless.db.midlevel.StatementCursor import set_table [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)
开发者ID:BackupTheBerlios,项目名称:paella-svn,代码行数:11,代码来源:traitgen.py

示例3: TableEditor

# 需要导入模块: from useless.db.midlevel import StatementCursor [as 别名]
# 或者: from useless.db.midlevel.StatementCursor import set_table [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()
开发者ID:BackupTheBerlios,项目名称:paella-svn,代码行数:57,代码来源:base.py

示例4: TextFileBrowser

# 需要导入模块: from useless.db.midlevel import StatementCursor [as 别名]
# 或者: from useless.db.midlevel.StatementCursor import set_table [as 别名]
class TextFileBrowser(ListTextView):
    def __init__(self, conn, name='TextFileBrowser'):
        ListTextView.__init__(self, name=name)
        self.conn = conn
        self.cursor = StatementCursor(self.conn)
        self.cursor.set_table('textfiles')

    def reset_rows(self):
        self.set_rows(self.cursor.select(fields=['fileid']))
        self.set_row_select(self.fileid_selected)

    def fileid_selected(self, listbox, row, column, event):
        pass
开发者ID:BackupTheBerlios,项目名称:paella-svn,代码行数:15,代码来源:database.py

示例5: MountsElement

# 需要导入模块: from useless.db.midlevel import StatementCursor [as 别名]
# 或者: from useless.db.midlevel.StatementCursor import set_table [as 别名]
class MountsElement(Element):
    def __init__(self, conn):
        Element.__init__(self, "mounts")
        self.conn = conn
        self.cursor = StatementCursor(self.conn)
        self.cursor.set_table("mounts")
        self.mounts = []
        rows = self.cursor.select(order="mnt_name")
        for r in rows:
            self.append_mount(r.mnt_name, r.mnt_point, r.fstype, r.mnt_opts, r.dump, r["pass"])

    def append_mount(self, mnt_name, mnt_point, fstype, mnt_opts, dump, pass_):
        mnt_element = MountElement(mnt_name, mnt_point, fstype, mnt_opts, dump, pass_)
        self.mounts.append(mnt_element)
        self.appendChild(mnt_element)
开发者ID:BackupTheBerlios,项目名称:paella-svn,代码行数:17,代码来源:xmlgen.py

示例6: BaseRelationalBrowser

# 需要导入模块: from useless.db.midlevel import StatementCursor [as 别名]
# 或者: from useless.db.midlevel.StatementCursor import set_table [as 别名]
class BaseRelationalBrowser(ListNoteBook, HasDialogs):
    def __init__(self, conn, maintable, pkey):
        self.menu = make_menu(['insert', 'update', 'done'], self.pkey_command)
        ListNoteBook.__init__(self)
        self.conn = conn
        self.main = StatementCursor(self.conn)
        self.main.set_table(maintable)
        self.pkey = pkey
        self.dialogs = {}.fromkeys(['insert', 'update', 'delete'])
        self.relations = {}
        
    def reset_rows(self):
        self.set_rows(self.main.select(order=self.pkey))
        self.set_row_select(self.pkey_selected)

    def pkey_selected(self, listbox, row, column, event):
        print listbox.get_selected_data()[0][0]
        
    def pkey_command(self, menuitem, command):
        if command == 'insert':
            if self.dialogs['insert'] is None:
                dialog = dialogs.Entry('insert a %s' % self.pkey, name='insert')
                dialog.set_ok(self.pkey_insert_ok)
                dialog.set_cancel(self.destroy_dialog)
                self.dialogs['insert'] = dialog
        elif command == 'update':
            dialogs.Message('need to set update to cascade in db')
        elif command == 'done':
            value = None
            try:
                value = self.listbox.get_selected_data()[0][0]
            except IndexError:
                dialogs.Message('need to select %s first' % self.pkey)
            if value is not None:
                dialogs.Message('ok, i am done.')

    def append_relation(self, table, fields=[], fkeyname=None):
        if table not in self.relations:
            if not fields:
                if fkeyname is None:
                    fkeyname = self.pkey
                fields = [f for f in self.main.fields(table) if f != fkeyname]
            if fkeyname is None:
                fkeyname = self.pkey
            self.relations[table] = fkeyname, fields
        else:
            raise Error, "relation already exists %s" % table
开发者ID:BackupTheBerlios,项目名称:paella-svn,代码行数:49,代码来源:base.py

示例7: FilesystemElement

# 需要导入模块: from useless.db.midlevel import StatementCursor [as 别名]
# 或者: from useless.db.midlevel.StatementCursor import set_table [as 别名]
class FilesystemElement(Element):
    def __init__(self, conn, filesystem):
        Element.__init__(self, "filesystem")
        self.conn = conn
        self.cursor = StatementCursor(self.conn)
        self.cursor.set_table("filesystem_mounts")
        self.setAttribute("name", filesystem)
        self.mounts = []
        self.filesystem = filesystem
        clause = Eq("filesystem", filesystem)
        rows = self.cursor.select(clause=clause, order="mnt_name")
        for r in rows:
            self.append_fs_mount(r.mnt_name, r.ord, r.partition, r.size)

    def append_fs_mount(self, mnt_name, ord, partition, size):
        fs_mount_element = FilesystemMountElement(mnt_name, str(ord), str(partition), str(size))
        self.mounts.append(fs_mount_element)
        self.appendChild(fs_mount_element)
开发者ID:BackupTheBerlios,项目名称:paella-svn,代码行数:20,代码来源:xmlgen.py

示例8: EnvironmentList

# 需要导入模块: from useless.db.midlevel import StatementCursor [as 别名]
# 或者: from useless.db.midlevel.StatementCursor import set_table [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)
开发者ID:BackupTheBerlios,项目名称:paella-svn,代码行数:45,代码来源:environ.py

示例9: PackageDoc

# 需要导入模块: from useless.db.midlevel import StatementCursor [as 别名]
# 或者: from useless.db.midlevel.StatementCursor import set_table [as 别名]
class PackageDoc(BaseDocument):
    def __init__(self, app, **atts):
        BaseDocument.__init__(self, app, **atts)
        self.suite = None
        self.cursor = StatementCursor(self.conn)

    def set_suite(self, suite):
        self.suite = suite
        self.cursor.set_table("%s_packages" % self.suite)

    def set_clause(self, clause):
        print "clause---->", clause, type(clause)
        self.cursor.clause = clause
        self.clear_body()
        title = SimpleTitleElement("%s Packages" % self.suite, bgcolor="IndianRed", width="100%")
        self.body.appendChild(title)
        for row in self.cursor.select(clause=clause):
            self.body.appendChild(PackageFieldTable(row, bgcolor="MistyRose2"))
            self.body.appendChild(HR())
开发者ID:BackupTheBerlios,项目名称:paella-svn,代码行数:21,代码来源:main.py

示例10: TraitsElement

# 需要导入模块: from useless.db.midlevel import StatementCursor [as 别名]
# 或者: from useless.db.midlevel.StatementCursor import set_table [as 别名]
class TraitsElement(Element):
    def __init__(self, conn, suite):
        Element.__init__(self, 'traits')
        self.conn = conn
        self.suite = suite
        self.setAttribute('suite', self.suite)
        self._traits_ = StatementCursor(self.conn, 'Traits')
        self._traits_.set_table(ujoin(self.suite, 'traits'))
        self.traitnames = [row.trait for row in self._traits_.select(order='trait')]
        for t in self.traitnames:
            t_element = Element('trait')
            t_element.setAttribute('name', t)
            self.appendChild(t_element)
            

    def make_trait(self, trait):
        t_element = TraitElement(self.conn, self.suite)
        t_element.set(trait)
        return t_element
开发者ID:BackupTheBerlios,项目名称:paella-svn,代码行数:21,代码来源:main.py

示例11: DefEnvEditor

# 需要导入模块: from useless.db.midlevel import StatementCursor [as 别名]
# 或者: from useless.db.midlevel.StatementCursor import set_table [as 别名]
class DefEnvEditor(CommandBoxWindow):
    def __init__(self, conn):
        CommandBoxWindow.__init__(self)
        self.conn = conn
        self.defenv = DefaultEnvironment(self.conn)
        self.add_menu(['load', 'edit', 'save'], 'main', self.main_menu_selected)
        self.cursor = StatementCursor(self.conn)
        self.cursor.set_table('default_environment')
        self.view = ScrollCList()
        self.vbox.add(self.view)
        self.reset_rows()
        
    def reset_rows(self):
        self.view.set_rows(self.cursor.select(order=['section', 'option']))

    def main_menu_selected(self, menuitem, name):
        if name == 'edit':
            newcfg = self.defenv.edit()
            self._update_dfenv(newcfg)
        elif name in ['load', 'save']:
            filesel = FileSelection(title='%s Default Environment' % name)
            filesel.cancel_button.connect('clicked',
                                          lambda x: filesel.destroy())
            filesel.show()
            filesel.ok_button.connect('clicked', self.ok_filesel, filesel)
            filesel.set_data('action', name)

    def ok_filesel(self, button, filesel):
        path = filesel.get_filename()
        action = filesel.get_data('action')
        filesel.destroy()
        if action == 'save':
            self.defenv.write(file(path, 'w'))
        elif action == 'load':
            newcfg = RawConfigParser()
            newcfg.read(path)
            self._update_dfenv(newcfg)

    def _update_dfenv(self, newcfg):
            self.defenv.update(newcfg)
            self.defenv = DefaultEnvironment(self.conn)
            self.reset_rows()
开发者ID:BackupTheBerlios,项目名称:paella-svn,代码行数:44,代码来源:management.py

示例12: TextFileManager

# 需要导入模块: from useless.db.midlevel import StatementCursor [as 别名]
# 或者: from useless.db.midlevel.StatementCursor import set_table [as 别名]
class TextFileManager(object):
    def __init__(self, conn):
        object.__init__(self)
        self.conn = conn
        self.cursor = StatementCursor(self.conn)
        self.cursor.set_table('textfiles')

    def insert_file(self, datafile):
        md5 = self._md5sum(datafile)
        data = datafile.read()
        md5size = '_'.join([md5, str(len(data))])
        return self._insert_data(md5size, data)

    def insert_data(self, data):
        md5 = md5sum(strfile(data))
        md5size = '_'.join([md5, str(len(data))])
        return self._insert_data(md5size, data)
    
    def _insert_data(self, md5size, data):
        clause=Eq('md5size', md5size)
        try:
            row = self.cursor.select_row(clause=clause)
        except NoExistError:
            row = None
        if not row:
            self.cursor.insert(data={'md5size' : md5size, 'data' : data})
            row = self.cursor.select_row(clause=clause)
        return row.fileid

    def get_data(self, id):
        row = self.cursor.select_row(clause=Eq('fileid', id))
        return row.data

    def get_strfile(self, id):
        return strfile(self.get_data(id))

    def _md5sum(self, datafile):
        datafile.seek(0)
        md5 = md5sum(datafile)
        datafile.seek(0)
        return md5
开发者ID:BackupTheBerlios,项目名称:paella-svn,代码行数:43,代码来源:objects.py

示例13: ScriptBrowser

# 需要导入模块: from useless.db.midlevel import StatementCursor [as 别名]
# 或者: from useless.db.midlevel.StatementCursor import set_table [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)
开发者ID:BackupTheBerlios,项目名称:paella-svn,代码行数:43,代码来源:scriptomatic.py

示例14: PackagesWindow

# 需要导入模块: from useless.db.midlevel import StatementCursor [as 别名]
# 或者: from useless.db.midlevel.StatementCursor import set_table [as 别名]
class PackagesWindow(DragListWindow):
    def __init__(self, conn, suite, name='PackagesWindow'):
        self.cmd = StatementCursor(conn, name=name)
        table = ujoin(suite, 'packages')
        self.cmd.set_table(table)
        section_query ='select distinct section from %s' % table
        sections = [x.section for x in self.cmd.get(section_query)]
        self.section_combo = MyCombo(sections)
        self.section_combo.set(sections[0])
        rows = self.cmd.select(clause="section = '%s'" % sections[0])
        packer = lambda x : rowpacker('package', x)
        DragListWindow.__init__(self, '%s packages' % suite, packer, rows,
                        TARGETS.get('package', suite), name=name)
        self.vbox.pack_start(self.section_combo,0,0,0)
        self.set_size_request(400, 300)
        self.set_ok(self.set_packages)
        
    def set_packages(self, *args):
        section = self.section_combo.get()
        fields = ['package', 'priority', 'version', 'installedsize',
                  'maintainer', 'size']
        rows = self.cmd.select(fields=fields, clause=Eq('section', section))
        self.set_rows(rows)
        self.set_select_mode('multi')
开发者ID:BackupTheBerlios,项目名称:paella-svn,代码行数:26,代码来源:traitgen.py

示例15: TraitAssignerOrig

# 需要导入模块: from useless.db.midlevel import StatementCursor [as 别名]
# 或者: from useless.db.midlevel.StatementCursor import set_table [as 别名]
class TraitAssignerOrig(KMainWindow):
    def __init__(self, app, parent, profile):
        KMainWindow.__init__(self, parent, 'TraitAssigner')
        self.page = QFrame(self)
        self.vbox = QVBoxLayout(self.page, 5, 7)
        self.listBox = KActionSelector(self.page)
        self.listBox.setShowUpDownButtons(True)
        self.setCentralWidget(self.page)
        self.vbox.addWidget(self.listBox)
        hbox = QHBoxLayout(self.page, 5, 7)
        self.vbox.addLayout(hbox)
        self.ok_button = KPushButton('ok', self.page)
        self.cancel_button = KPushButton('cancel', self.page)
        hbox.addWidget(self.ok_button)
        hbox.addWidget(self.cancel_button)
        self.app = app
        self.db = app.db
        self.profile = Profile(app.conn)
        self.profile.set_profile(profile)
        self.suite = self.profile.current.suite
        self.traits = StatementCursor(app.conn)
        self.traits.set_table('%s_traits'  % self.suite)
        self.initlistView()
        self.show()

    def initlistView(self):
        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:
            QListBoxText(sbox, row.trait)
        for row in trows:
            QListBoxText(abox, row.trait)
开发者ID:BackupTheBerlios,项目名称:paella-svn,代码行数:38,代码来源:profile.py


注:本文中的useless.db.midlevel.StatementCursor.set_table方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。