コード例 #1
0
    def _get_next_oid(self, oid):
        """
        Returns the next oid after passed oid.
        
        Note: for some reason unknown to me, gtk.TreeView or
        perhaps the GenericTreeModel finds it neccessary to
        iterate through every iter from the root node through
        n_children. Because of this, we will fetch row ids in
        sets of 1024 and cache them to speed things up.
        
        Parameters:
            oid -- the current oid.
        """
        #first call is when oid=None
        if not oid:
            oid = -1

        if GenericDBListStore.OID_CACHE:
            try:
                index = self.oidcache.index(oid)
                return self.oidcache[index + 1]
            except (ValueError, IndexError):
                sql = "SELECT oid FROM %s WHERE oid >= %d LIMIT 1024" % (
                    self.table, oid)
                oids = [oid for (oid, ) in self.db.select(sql)]
                self.oidcache.extend(oids)
                self.oidcache = Utils.unique_list(self.oidcache)
            #if we can only get one result, we must be the last oid
            if len(oids) > 1:
                oid = oids[1]
            else:
                oid = None
        else:
            try:
                (oid, ) = self.db.select_one(
                    "SELECT oid FROM %s WHERE oid > %d LIMIT 1" %
                    (self.table, oid))
            except TypeError:
                oid = None

        return oid
コード例 #2
0
ファイル: Database.py プロジェクト: arsfeld/conduit
    def _get_next_oid(self, oid):
        """
        Returns the next oid after passed oid.
        
        Note: for some reason unknown to me, gtk.TreeView or
        perhaps the GenericTreeModel finds it neccessary to
        iterate through every iter from the root node through
        n_children. Because of this, we will fetch row ids in
        sets of 1024 and cache them to speed things up.
        
        Parameters:
            oid -- the current oid.
        """
        #first call is when oid=None
        if not oid:
            oid = -1
            
        if GenericDBListStore.OID_CACHE:
            try:
                index = self.oidcache.index(oid)
                return self.oidcache[index+1]
            except (ValueError, IndexError):
                sql = "SELECT oid FROM %s WHERE oid >= %d LIMIT 1024" % (self.table, oid)
                oids = [oid for (oid,) in self.db.select(sql)]
                self.oidcache.extend(oids)
                self.oidcache = Utils.unique_list(self.oidcache)
            #if we can only get one result, we must be the last oid
            if len(oids) > 1:
                oid = oids[1] 
            else:
                oid = None        
        else:
            try:
                (oid,) = self.db.select_one("SELECT oid FROM %s WHERE oid > %d LIMIT 1" % (self.table, oid))
            except TypeError:
                oid = None

        return oid
コード例 #3
0
ファイル: TestCoreUtil.py プロジェクト: ProfSteve/conduit
ok("Resized Image in both dimension OK", w==2000 and h==1000)
w,h = Utils.get_proportional_resize(2000,100,200,100)
ok("Resized Image in both dimension OK", w==2000 and h==1000)
w,h = Utils.get_proportional_resize(10,5,200,100)
ok("Resized Image in both dimension OK", w==10 and h==5)
ok("Resized Image returns integers", type(w)==int and type(h)==int)

ok("Test program installed finds sh", Utils.program_installed('sh'))
ok("Test program installed doesnt find foobar", Utils.program_installed('foobar') == False)

fileuri = Utils.new_tempfile("bla").get_local_uri()
ok("New tempfile: %s" % fileuri, os.path.isfile(fileuri))
tmpdiruri = Utils.new_tempdir()
ok("New tempdir: %s" % tmpdiruri, os.path.isdir(tmpdiruri))

ok("Unique list keep order", Utils.unique_list([1,1,2,2,3,3,5,5,4,4]) == [1,2,3,5,4])

s = Utils.random_string()
ok("Random string: %s" % s, len(s) > 0 and type(s) == str)
s = Utils.md5_string('Foo')
ok("md5 string: %s" % s, len(s) > 0 and type(s) == str)
s = Utils.uuid_string()
ok("uuid string: %s" % s, len(s) > 0 and type(s) == str)
s = Utils.get_user_string()
ok("user string: %s" % s, len(s) > 0 and type(s) == str)

#test command line processing
ok("Cmd executed", len(Utils.exec_command_and_return_result("ls",".")) > 0)
ok("Cmd with wrong args", Utils.exec_command_and_return_result("ls","does-not-exist") == None) 
ok("Cmd that doesnt exist", Utils.exec_command_and_return_result("cmd-does-not-exist",".") == None)