How to use the dbutils.Database.forSystem function in DBUtils

To help you get started, we’ve selected a few DBUtils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jensl / critic / src / maintenance / check-branches.py View on Github external
parser.add_argument("--include", action="append", help="include (only) repository")
parser.add_argument("--dry-run", "-n", action="store_true", help="don't touch the database or repositories")
parser.add_argument("--force", "-f", action="store_true", help="update the database and/or repositories")

arguments = parser.parse_args()

if not arguments.dry_run and not arguments.force:
    print "One of --dry-run/-n and --force/-f must be specified."
    sys.exit(1)
elif arguments.dry_run and arguments.force:
    print "Only one of --dry-run/-n and --force/-f can be specified."
    sys.exit(1)

force = arguments.force

db = dbutils.Database.forSystem()
cursor = db.cursor()

def getBranchCommits(repository, branch_id):
    cursor = db.cursor()
    cursor.execute("SELECT sha1 FROM commits JOIN reachable ON (commit=id) WHERE branch=%s", (branch_id,))

    return log.commitset.CommitSet(gitutils.Commit.fromSHA1(db, repository, sha1) for (sha1,) in cursor)

def getReview(branch_id):
    cursor = db.cursor()
    cursor.execute("SELECT id FROM reviews WHERE branch=%s", (branch_id,))
    return cursor.fetchone()[0]

def getReviewCommits(repository, review_id):
    review_id = getReview(branch_id)
github jensl / critic / src / background / changeset.py View on Github external
def perform_job():
        soft_limit, hard_limit = getrlimit(RLIMIT_RSS)
        rss_limit = configuration.services.CHANGESET["rss_limit"]
        if soft_limit < rss_limit:
            setrlimit(RLIMIT_RSS, (rss_limit, hard_limit))

        from changeset.create import createChangeset

        request = json_decode(sys.stdin.read())

        try:
            db = dbutils.Database.forSystem()

            createChangeset(db, request)

            db.close()

            sys.stdout.write(json_encode(request))
        except:
            print "Request:"
            print json_encode(request, indent=2)
            print

            print_exc(file=sys.stdout)
github jensl / critic / src / maintenance / check-commits.py View on Github external
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
# License for the specific language governing permissions and limitations under
# the License.

import sys
import os
import cPickle

sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(sys.argv[0]), "..")))

import dbutils
import gitutils
import progress

db = dbutils.Database.forSystem()
cursor = db.cursor()

commits = {}
pending_commits = set()

cursor.execute("SELECT COUNT(*) FROM commits")

print

progress.start(cursor.fetchone()[0], prefix="Fetching commits ...")

cursor.execute("SELECT id, sha1 FROM commits")

for commit_id, commit_sha1 in cursor:
    commits[commit_id] = commit_sha1
    pending_commits.add(commit_id)
github jensl / critic / src / background / branchtrackerhook.py View on Github external
try: data = json_decode(data)
                except ValueError: return

                message = "connection from %s:%d:" % self.__peeraddress
                message += "\n  repository: %s" % data["repository"]

                if data.has_key("timeout"):
                    message += "\n  timeout:    %d" % data["timeout"]
                if data["branches"]:
                    message += "\n  branches:   %s" % ", ".join(data["branches"])
                if data["tags"]:
                    message += "\n  tags:       %s" % ", ".join(data["tags"])

                self.server.info(message)

                db = dbutils.Database.forSystem()

                try:
                    cursor = db.cursor()
                    notify_tracker = False
                    wait_for_reply = False

                    # Make sure the 'knownremotes' table has this remote listed
                    # as "pushing" since it obviously is.

                    cursor.execute("""SELECT pushing
                                        FROM knownremotes
                                       WHERE url=%s""",
                                   (data["repository"],))

                    row = cursor.fetchone()
github jensl / critic / src / maintenance / criticctl.py View on Github external
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
# License for the specific language governing permissions and limitations under
# the License.

import sys
import argparse

import auth
import configuration
import dbutils
import inpututils

db = dbutils.Database.forSystem()

cursor = db.cursor()
cursor.execute("SELECT name FROM roles")

roles = [role for (role,) in cursor]

def valid_user(name):
    try:
        dbutils.User.fromName(db, name)
    except dbutils.NoSuchUser:
        return "no such user"

def valid_role(role):
    if role not in roles:
        return "invalid role; must be one of %s" % ", ".join(roles)
github jensl / critic / src / background / extensiontasks.py View on Github external
def run(self):
        if not configuration.extensions.ENABLED:
            self.info("service stopping: extension support not enabled")
            return

        failed_events = set()

        while not self.terminated:
            self.interrupted = False

            with dbutils.Database.forSystem() as db:
                cursor = db.cursor()
                cursor.execute("""SELECT id
                                    FROM extensionfilterhookevents
                                ORDER BY id ASC""")

                finished_events = []

                for (event_id,) in cursor:
                    if event_id not in failed_events:
                        try:
                            extensions.role.filterhook.processFilterHookEvent(
                                db, event_id, self.debug)
                        except Exception:
                            self.exception()
                            failed_events.add(event_id)
                        else: