コード例 #1
0
ファイル: users.py プロジェクト: pmisik/buildbot
        def thd(conn, no_recurse=False, identifier=identifier):
            tbl = self.db.model.users
            tbl_info = self.db.model.users_info

            self.checkLength(tbl.c.identifier, identifier)
            self.checkLength(tbl_info.c.attr_type, attr_type)
            self.checkLength(tbl_info.c.attr_data, attr_data)

            # try to find the user
            q = sa.select([tbl_info.c.uid],
                          whereclause=and_(tbl_info.c.attr_type == attr_type,
                                           tbl_info.c.attr_data == attr_data))
            rows = conn.execute(q).fetchall()

            if rows:
                return rows[0].uid

            if _race_hook is not None:
                _race_hook(conn)

            # try to do both of these inserts in a transaction, so that both
            # the new user and the corresponding attributes appear at the same
            # time from the perspective of other masters.
            transaction = conn.begin()
            inserted_user = False
            try:
                r = conn.execute(tbl.insert(), dict(identifier=identifier))
                uid = r.inserted_primary_key[0]
                inserted_user = True

                conn.execute(tbl_info.insert(),
                             dict(uid=uid, attr_type=attr_type,
                                  attr_data=attr_data))

                transaction.commit()
            except (sa.exc.IntegrityError, sa.exc.ProgrammingError):
                transaction.rollback()

                # try it all over again, in case there was an overlapping,
                # identical call to findUserByAttr.  If the identifier
                # collided, we'll try again indefinitely; otherwise, only once.
                if no_recurse:
                    raise

                # if we failed to insert the user, then it's because the
                # identifier wasn't unique
                if not inserted_user:
                    identifier = identifiers.incrementIdentifier(
                        256, identifier)
                else:
                    no_recurse = True

                return thd(conn, no_recurse=no_recurse, identifier=identifier)

            return uid
コード例 #2
0
ファイル: logs.py プロジェクト: zmadi1/buildbot
 def addLog(self, stepid, name, type):
     slug = identifiers.forceIdentifier(50, name)
     while True:
         try:
             logid = yield self.master.db.logs.addLog(
                 stepid=stepid, name=name, slug=slug, type=type)
         except KeyError:
             slug = identifiers.incrementIdentifier(50, slug)
             continue
         self.generateEvent(logid, "new")
         return logid
コード例 #3
0
ファイル: users.py プロジェクト: stuarta/buildbot
        def thd(conn, no_recurse=False, identifier=identifier):
            tbl = self.db.model.users
            tbl_info = self.db.model.users_info

            self.checkLength(tbl.c.identifier, identifier)
            self.checkLength(tbl_info.c.attr_type, attr_type)
            self.checkLength(tbl_info.c.attr_data, attr_data)

            # try to find the user
            q = sa.select([tbl_info.c.uid],
                          whereclause=and_(tbl_info.c.attr_type == attr_type,
                                           tbl_info.c.attr_data == attr_data))
            rows = conn.execute(q).fetchall()

            if rows:
                return rows[0].uid

            _race_hook and _race_hook(conn)

            # try to do both of these inserts in a transaction, so that both
            # the new user and the corresponding attributes appear at the same
            # time from the perspective of other masters.
            transaction = conn.begin()
            inserted_user = False
            try:
                r = conn.execute(tbl.insert(), dict(identifier=identifier))
                uid = r.inserted_primary_key[0]
                inserted_user = True

                conn.execute(tbl_info.insert(),
                             dict(uid=uid, attr_type=attr_type,
                                  attr_data=attr_data))

                transaction.commit()
            except (sa.exc.IntegrityError, sa.exc.ProgrammingError):
                transaction.rollback()

                # try it all over again, in case there was an overlapping,
                # identical call to findUserByAttr.  If the identifier
                # collided, we'll try again indefinitely; otherwise, only once.
                if no_recurse:
                    raise

                # if we failed to insert the user, then it's because the
                # identifier wasn't unique
                if not inserted_user:
                    identifier = identifiers.incrementIdentifier(
                        256, identifier)
                else:
                    no_recurse = True

                return thd(conn, no_recurse=no_recurse, identifier=identifier)

            return uid
コード例 #4
0
ファイル: logs.py プロジェクト: Cray/buildbot
 def addLog(self, stepid, name, type):
     slug = identifiers.forceIdentifier(50, name)
     while True:
         try:
             logid = yield self.master.db.logs.addLog(
                 stepid=stepid, name=name, slug=slug, type=type)
         except KeyError:
             slug = identifiers.incrementIdentifier(50, slug)
             continue
         self.generateEvent(logid, "new")
         defer.returnValue(logid)
コード例 #5
0
 def test_incrementIdentifier_add_digits_too_long(self):
     self.assertEqualUnicode(identifiers.incrementIdentifier(6, u'aaa_99'),
                             u'aa_100')
コード例 #6
0
 def test_incrementIdentifier_single_digit(self):
     self.assertEqualUnicode(identifiers.incrementIdentifier(100, u'aaa_2'),
                             u'aaa_3')
コード例 #7
0
 def test_incrementIdentifier_simple_too_long(self):
     self.assertEqualUnicode(identifiers.incrementIdentifier(4, u'aaa'),
                             u'aa_2')
コード例 #8
0
 def test_incrementIdentifier_simple(self):
     self.assertEqualUnicode(identifiers.incrementIdentifier(100, u'aaa'),
                             u'aaa_2')
コード例 #9
0
 def test_incrementIdentifier_add_digits_out_of_space(self):
     self.assertRaises(
         ValueError, lambda: identifiers.incrementIdentifier(6, u'_99999'))
コード例 #10
0
 def test_incrementIdentifier_add_digits_out_of_space(self):
     with self.assertRaises(ValueError):
         identifiers.incrementIdentifier(6, '_99999')
コード例 #11
0
 def test_incrementIdentifier_add_digits(self):
     self.assertEqualUnicode(identifiers.incrementIdentifier(100, 'aaa_99'),
                             'aaa_100')
コード例 #12
0
 def test_incrementIdentifier_add_digits_too_long(self):
     self.assertEqualUnicode(
         identifiers.incrementIdentifier(6, u'aaa_99'),
         u'aa_100')
コード例 #13
0
 def test_incrementIdentifier_single_digit(self):
     self.assertEqualUnicode(
         identifiers.incrementIdentifier(100, u'aaa_2'),
         u'aaa_3')
コード例 #14
0
 def test_incrementIdentifier_simple_too_long(self):
     self.assertEqualUnicode(
         identifiers.incrementIdentifier(4, u'aaa'),
         u'aa_2')
コード例 #15
0
 def test_incrementIdentifier_simple(self):
     self.assertEqualUnicode(
         identifiers.incrementIdentifier(100, u'aaa'),
         u'aaa_2')
コード例 #16
0
 def test_incrementIdentifier_add_digits_out_of_space(self):
     self.assertRaises(ValueError, lambda:
                       identifiers.incrementIdentifier(6, u'_99999'))