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


Python StatementCursor.select_row方法代码示例

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


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

示例1: TextFileManager

# 需要导入模块: from useless.db.midlevel import StatementCursor [as 别名]
# 或者: from useless.db.midlevel.StatementCursor import select_row [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

示例2: find_missing_packages

# 需要导入模块: from useless.db.midlevel import StatementCursor [as 别名]
# 或者: from useless.db.midlevel.StatementCursor import select_row [as 别名]
 def find_missing_packages(self, traitxml):
     all_packages = []
     missing = []
     cursor = StatementCursor(self.conn)
     suite = traitxml.suite
     ptable = '%s_packages' % suite
     for package, action in traitxml.packages:
         if package not in all_packages:
             all_packages.append(package)
     for package in all_packages:
         try:
             row = cursor.select_row(table=ptable, clause=Eq('package', package))
         except NoExistError:
             missing.append(package)
     return missing
开发者ID:BackupTheBerlios,项目名称:paella-svn,代码行数:17,代码来源:main.py

示例3: PaellaProfiles

# 需要导入模块: from useless.db.midlevel import StatementCursor [as 别名]
# 或者: from useless.db.midlevel.StatementCursor import select_row [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 = {}
        self._profile = Profile(self.conn)
        
        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_families(self._profile.family_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}
        idata = dict(profile=profile.name)
        for family in profile.families:
            idata['family'] = family
            self.stmt.insert(table='profile_family', data=idata)
        idata = dict(profile=profile.name)
        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()
开发者ID:BackupTheBerlios,项目名称:paella-svn,代码行数:70,代码来源:xmlgen.py

示例4: MachineElement

# 需要导入模块: from useless.db.midlevel import StatementCursor [as 别名]
# 或者: from useless.db.midlevel.StatementCursor import select_row [as 别名]
class MachineElement(Element):
    def __init__(self, conn, name):
        Element.__init__(self, 'machine')
        self.conn = conn
        self.cursor = StatementCursor(self.conn)
        self.setAttribute('name', name)
        self.scripts = []
        self.families = []
        self.variables = []
        self.machine = name
        clause = Eq('machine', name)
        self.set_attributes(clause)
        self._append_scripts(clause)
        self._append_families(clause)
        self._append_variables(clause)

    def set_attributes(self, clause):
        self.set_parent(clause)
        row = self.cursor.select_row(table='machines',
                                     clause=clause)
        if row.diskconfig is not None:
            self.setAttribute('diskconfig', row.diskconfig)
        if row.kernel is not None:
            self.setAttribute('kernel', row.kernel)
        if row.profile is not None:
            self.setAttribute('profile', row.profile)
            
    def set_parent(self, clause):
        try:
            row = self.cursor.select_row(table='machine_parent',
                                         clause=clause)
            parent = row.parent
        except NoExistError:
            parent = None
        if parent is not None:
            self.setAttribute('parent', parent)
            
    def append_family(self, family):
        fam_element = MachineFamilyElement(family)
        self.families.append(fam_element)
        self.appendChild(fam_element)

    def _append_families(self, clause):
        table = 'machine_family'
        fams = self.cursor.select(table=table, clause=clause, order='family')
        for row in fams:
            self.append_family(row.family)
        
    def append_script(self, name):
        script_element = MachineScriptElement(name)
        self.scripts.append(script_element)
        self.appendChild(script_element)

    def _append_scripts(self, clause):
        table = 'machine_scripts'
        scripts = self.cursor.select(table=table, clause=clause, order='script')
        for row in scripts:
            self.append_script(row.script)
    
    def append_variable(self, trait, name, value):
        variable_element = MachineVariableElement(trait, name, value)
        self.variables.append(variable_element)
        self.appendChild(variable_element)

    def _append_variables(self, clause):
        table = 'machine_variables'
        vlist = self.cursor.select(table=table, clause=clause, order=['name'])
        for row in vlist:
            self.append_variable(row.trait, row.name, row.value)

    def export_directory(self, machinetopdir):
        machine = self.getAttribute('name')
        dirname = path(machinetopdir) / machine
        return dirname

    def export(self, machinetopdir):
        dirname = self.export_directory(machinetopdir)
        makepaths(dirname)
        xmlfile = dirname / 'machine.xml'
        xmlfile.write_text(self.toprettyxml())
开发者ID:joelsefus,项目名称:paella,代码行数:82,代码来源:xmlgen.py

示例5: Family

# 需要导入模块: from useless.db.midlevel import StatementCursor [as 别名]
# 或者: from useless.db.midlevel.StatementCursor import select_row [as 别名]

#.........这里部分代码省略.........
        # by the profile and the machine.  In this
        # case, the families argument will always
        # be a list, empty or not.
        # I can't think of any other circumstance
        # where this method would be called outside
        # of the installer, or a script, and the script
        # should be using either a profile or machine
        # to get the list of families anyway, make the
        # point moot.  I will probably remove this part
        # of the code in the near future, once I'm sure
        # that there's no reason to pass None to the
        # families argument.
        if families is None:
            families = [self.current]
        all = self.make_familylist(families)
        superdict = {}
        for f in all:
            superdict.update(self.env.make_tagdict(f, sep=sep))
        return superdict
            
        
            
    def make_familylist(self, families):
        deps = families
        all = list(self.get_related_families(families))
        setfun = self.set_family
        parfun = self.parents
        return make_deplist(deps, all, setfun, parfun)

    def export_family(self, family=None):
        if family is None:
            family = self.current
        # row isn't used, except to determine that the family exists
        row = self.cursor.select_row(table='families', clause=Eq('family', family))
        element = FamilyElement(family)
        element.append_parents(self.parents(family))
        element.append_variables(self.environment_rows(family))
        return element

    def write_family(self, family, path):
        fxml = file(join(path, '%s.xml' % family), 'w')
        data = self.export_family(family)
        data.writexml(fxml, indent='\t', newl='\n', addindent='\t')
        fxml.close()
        
    def export_families(self, path):
        families = self.all_families()
        self.report_total_families(len(families))
        for f in families:
            self.write_family(f, path)
            self.report_family_exported(f, path)

    def import_family(self, element):
        parsed = FamilyParser(element)
        print 'inserting family', parsed.name
        all = self.all_families()
        for p in parsed.parents:
            if p not in all:
                print 'insertion failed for', parsed.name
                raise UnbornError
        self.create_family(parsed.name)
        self.set_family(parsed.name)
        self.insert_parents(parsed.parents)
        row = dict(family=parsed.name)
        for var in parsed.environ:
            row.update(var)
开发者ID:umeboshi2,项目名称:paella,代码行数:70,代码来源:main.py

示例6: BaseDatabase

# 需要导入模块: from useless.db.midlevel import StatementCursor [as 别名]
# 或者: from useless.db.midlevel.StatementCursor import select_row [as 别名]
class BaseDatabase(QSqlDatabase):
    def __init__(self, dsn, name, parent=None, objname=None):
        deprecated('useless.kdedb.BaseDatabase is deprecated')
        QSqlDatabase.__init__(self, 'QPSQL7', name, parent, objname)
        if hasattr(dsn, 'items'): #if dsn is dictionary
            self.conn = BasicConnection(**dsn)
            self.setDatabaseName(dsn['dbname'])
            self.setHostName(dsn['host'])
            self.dbuser = dsn['user']
        else: #else a conn was passed as dsn
            self.conn = dsn
            self.setDatabaseName(self.conn.conn.db)
            self.setHostName(self.conn.conn.host)
            self.dbuser = self.conn.conn.user
        self.setUserName(self.dbuser)
        self.stmt = Statement()
        self.mcursor = StatementCursor(self.conn)
        
    def set_table(self, table):
        self.stmt.table = table

    def set_clause(self, items, cmp='=', join='and'):
        self.stmt.set_clause(items, cmp=cmp, join=join)

    def set_data(self, data):
        self.stmt.set(data)

    def set_fields(self, fields):
        self.stmt.fields = fields

    def qdelete(self, table=None, clause=None):
        query = self.stmt.delete(table=table, clause=clause)
        return self.execStatement(query)

    def qinsert(self, table=None, data=None):
        query = self.stmt.insert(table=table, data=data)
        return self.execStatement(query)

    def qupdate(self, table=None, data=None, clause=None):
        query = self.stmt.update(table=table, data=data, clause=clause)
        return self.execStatement(query)

    def qselect(self, fields=None, table=None, clause=None,
               group=None, having=None, order=None):
        query = self.stmt.select(fields=fields, table=table, clause=clause,
                                 group=group, having=having, order=order)
        return self.execStatement(query)

    def delete(self, table=None, clause=None):
        query = self.stmt.delete(table=table, clause=clause)
        return self.mcursor.execute(query)

    def insert(self, table=None, data=None):
        query = self.stmt.insert(table=table, data=data)
        return self.mcursor.execute(query)

    def update(self, table=None, data=None, clause=None):
        query = self.stmt.update(table=table, data=data, clause=clause)
        return self.mcursor.execute(query)

    def select(self, fields=None, table=None, clause=None,
               group=None, having=None, order=None):
        query = self.stmt.select(fields=fields, table=table, clause=clause,
                                 group=group, having=having, order=order)
        self.mcursor.execute(query)
        return self.mcursor.fetchall()

    def select_row(self, fields=None, table=None, clause=None,
               group=None, having=None, order=None):
        query = self.stmt.select(fields=fields, table=table, clause=clause,
                                 group=group, having=having, order=order)
        self.mcursor.execute(query)
        rows = len(self.mcursor)
        if rows == 1:
            return self.mcursor.next()
        elif rows == 0:
            raise NoExistError
        else:
            raise RuntimeError, 'bad row count %s' % rows

    def clear(self, **args):
        self.stmt.clear(**args)

    def stdclause(self, data):
        return reduce(and_, [Eq(k, v) for k,v in data.items()])

    def insertData(self, idcol, table, data, commit=True):
        clause = self.stdclause(data)
        try:
            self.mcursor.select_row(fields=[idcol], table=table, clause=clause)
        except NoExistError:
            self.mcursor.insert(table=table, data=data)
            if commit:
                self.conn.commit()
            
    def identifyData(self, idcol, table, data, commit=True):
        clause = self.stdclause(data)
        self.insertData(idcol, table, data, commit=commit)
        return self.mcursor.select_row(fields=['*'], table=table, clause=clause)
开发者ID:BackupTheBerlios,项目名称:useless-svn,代码行数:101,代码来源:__init__.py

示例7: BaseDatabase

# 需要导入模块: from useless.db.midlevel import StatementCursor [as 别名]
# 或者: from useless.db.midlevel.StatementCursor import select_row [as 别名]
class BaseDatabase(object):
    def __init__(self, conn=None):
        if conn is None:
            self.conn = KonsultantConnection()
        else:
            self.conn = conn
        self.stmt = Statement()
        self.mcursor = StatementCursor(self.conn)
        
    def set_table(self, table):
        self.stmt.table = table

    def set_clause(self, items, cmp='=', join='and'):
        self.stmt.set_clause(items, cmp=cmp, join=join)

    def set_data(self, data):
        self.stmt.set(data)

    def set_fields(self, fields):
        self.stmt.fields = fields

    def delete(self, table=None, clause=None):
        query = self.stmt.delete(table=table, clause=clause)
        return self.mcursor.execute(query)

    def insert(self, table=None, data=None):
        query = self.stmt.insert(table=table, data=data)
        return self.mcursor.execute(query)

    def update(self, table=None, data=None, clause=None):
        query = self.stmt.update(table=table, data=data, clause=clause)
        return self.mcursor.execute(query)

    def select(self, fields=None, table=None, clause=None,
               group=None, having=None, order=None):
        query = self.stmt.select(fields=fields, table=table, clause=clause,
                                 group=group, having=having, order=order)
        self.mcursor.execute(query)
        return self.mcursor.fetchall()

    def select_row(self, fields=None, table=None, clause=None,
               group=None, having=None, order=None):
        query = self.stmt.select(fields=fields, table=table, clause=clause,
                                 group=group, having=having, order=order)
        self.mcursor.execute(query)
        rows = len(self.mcursor)
        if rows == 1:
            return self.mcursor.next()
        elif rows == 0:
            raise NoExistError
        else:
            raise Error, 'bad row count %s' % rows

    def clear(self, **args):
        self.stmt.clear(**args)

    def stdclause(self, data):
        return reduce(and_, [Eq(k, v) for k,v in data.items()])

    def insertData(self, idcol, table, data, commit=True):
        clause = self.stdclause(data)
        try:
            self.mcursor.select_row(fields=[idcol], table=table, clause=clause)
        except NoExistError:
            self.mcursor.insert(table=table, data=data)
            if commit:
                self.conn.commit()
            
    def identifyData(self, idcol, table, data, commit=True):
        clause = self.stdclause(data)
        self.insertData(idcol, table, data, commit=commit)
        return self.mcursor.select_row(fields=['*'], table=table, clause=clause)
开发者ID:BackupTheBerlios,项目名称:konsultant-svn,代码行数:74,代码来源:__init__.py


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