mirror of
https://github.com/vitalif/viewvc-4intranet
synced 2019-04-16 04:14:59 +03:00
Compare commits
1 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
99216ae1da |
71
lib/dbi.py
Normal file
71
lib/dbi.py
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
# -*- Mode: python -*-
|
||||||
|
#
|
||||||
|
# Copyright (C) 2000 The ViewCVS Group. All Rights Reserved.
|
||||||
|
#
|
||||||
|
# By using this file, you agree to the terms and conditions set forth in
|
||||||
|
# the LICENSE.html file which can be found at the top level of the ViewCVS
|
||||||
|
# distribution or at http://www.lyra.org/viewcvs/license-1.html.
|
||||||
|
#
|
||||||
|
# Contact information:
|
||||||
|
# Greg Stein, PO Box 760, Palo Alto, CA, 94302
|
||||||
|
# gstein@lyra.org, http://www.lyra.org/viewcvs/
|
||||||
|
#
|
||||||
|
# -----------------------------------------------------------------------
|
||||||
|
#
|
||||||
|
|
||||||
|
import sys
|
||||||
|
import MySQLdb
|
||||||
|
|
||||||
|
|
||||||
|
dbi_error = "dbi error"
|
||||||
|
|
||||||
|
|
||||||
|
## make some checks in MySQLdb
|
||||||
|
_no_datetime = """\
|
||||||
|
ERROR: Your version of MySQLdb requires the mxDateTime module
|
||||||
|
for the Timestamp() and TimestampFromTicks() methods.
|
||||||
|
You will need to install mxDateTime to use the ViewCVS
|
||||||
|
database.
|
||||||
|
"""
|
||||||
|
|
||||||
|
if not hasattr(MySQLdb, "Timestamp") or \
|
||||||
|
not hasattr(MySQLdb, "TimestampFromTicks"):
|
||||||
|
sys.stderr.write(_no_datetime)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
class Cursor:
|
||||||
|
def __init__(self, mysql_cursor):
|
||||||
|
self.__cursor = mysql_cursor
|
||||||
|
|
||||||
|
def execute(self, *args):
|
||||||
|
apply(self.__cursor.execute, args)
|
||||||
|
|
||||||
|
def fetchone(self):
|
||||||
|
try:
|
||||||
|
row = self.__cursor.fetchone()
|
||||||
|
except IndexError:
|
||||||
|
row = None
|
||||||
|
|
||||||
|
return row
|
||||||
|
|
||||||
|
|
||||||
|
class Connection:
|
||||||
|
def __init__(self, host, user, passwd, db):
|
||||||
|
self.__mysql = MySQLdb.connect(
|
||||||
|
host=host, user=user, passwd=passwd, db=db)
|
||||||
|
|
||||||
|
def cursor(self):
|
||||||
|
return Cursor(self.__mysql.cursor())
|
||||||
|
|
||||||
|
|
||||||
|
def Timestamp(year, month, date, hour, minute, second):
|
||||||
|
return MySQLdb.Timestamp(year, month, date, hour, minute, second)
|
||||||
|
|
||||||
|
|
||||||
|
def TimestampFromTicks(ticks):
|
||||||
|
return MySQLdb.TimestampFromTicks(ticks)
|
||||||
|
|
||||||
|
|
||||||
|
def connect(host, user, passwd, db):
|
||||||
|
return Connection(host, user, passwd, db)
|
102
lib/query.py
Normal file
102
lib/query.py
Normal file
@@ -0,0 +1,102 @@
|
|||||||
|
# -*- Mode: python -*-
|
||||||
|
#
|
||||||
|
# Copyright (C) 2000 The ViewCVS Group. All Rights Reserved.
|
||||||
|
#
|
||||||
|
# By using this file, you agree to the terms and conditions set forth in
|
||||||
|
# the LICENSE.html file which can be found at the top level of the ViewCVS
|
||||||
|
# distribution or at http://www.lyra.org/viewcvs/license-1.html.
|
||||||
|
#
|
||||||
|
# Contact information:
|
||||||
|
# Greg Stein, PO Box 760, Palo Alto, CA, 94302
|
||||||
|
# gstein@lyra.org, http://www.lyra.org/viewcvs/
|
||||||
|
#
|
||||||
|
# -----------------------------------------------------------------------
|
||||||
|
#
|
||||||
|
|
||||||
|
import time
|
||||||
|
import dbi
|
||||||
|
|
||||||
|
|
||||||
|
## QueryEntry holds data on one match-type in the SQL database
|
||||||
|
## match is: "exact", "like", or "regex"
|
||||||
|
|
||||||
|
class QueryEntry:
|
||||||
|
def __init__(self, data, match):
|
||||||
|
self.data = data
|
||||||
|
self.match = match
|
||||||
|
|
||||||
|
|
||||||
|
## CheckinDatabaseQueryData is a object which contains the search parameters
|
||||||
|
## for a query to the CheckinDatabase
|
||||||
|
|
||||||
|
class CheckinDatabaseQuery:
|
||||||
|
def __init__(self):
|
||||||
|
## sorting
|
||||||
|
self.sort = "date"
|
||||||
|
|
||||||
|
## repository to query
|
||||||
|
self.repository_list = []
|
||||||
|
self.branch_list = []
|
||||||
|
self.directory_list = []
|
||||||
|
self.file_list = []
|
||||||
|
self.author_list = []
|
||||||
|
|
||||||
|
## date range in DBI 2.0 timedate objects
|
||||||
|
self.from_date = None
|
||||||
|
self.to_date = None
|
||||||
|
|
||||||
|
## list of commits -- filled in by CVS query
|
||||||
|
self.commit_list = []
|
||||||
|
|
||||||
|
## commit_cb provides a callback for commits as they
|
||||||
|
## are added
|
||||||
|
self.commit_cb = None
|
||||||
|
|
||||||
|
def SetRepository(self, repository, match = "exact"):
|
||||||
|
self.repository_list.append(QueryEntry(repository, match))
|
||||||
|
|
||||||
|
def SetBranch(self, branch, match = "exact"):
|
||||||
|
self.branch_list.append(QueryEntry(branch, match))
|
||||||
|
|
||||||
|
def SetDirectory(self, directory, match = "exact"):
|
||||||
|
self.directory_list.append(QueryEntry(directory, match))
|
||||||
|
|
||||||
|
def SetFile(self, file, match = "exact"):
|
||||||
|
self.file_list.append(QueryEntry(file, match))
|
||||||
|
|
||||||
|
def SetAuthor(self, author, match = "exact"):
|
||||||
|
self.author_list.append(QueryEntry(author, match))
|
||||||
|
|
||||||
|
def SetSortMethod(self, sort):
|
||||||
|
self.sort = sort
|
||||||
|
|
||||||
|
def SetFromDateObject(self, ticks):
|
||||||
|
self.from_date = dbi.TimestampFromTicks(ticks)
|
||||||
|
|
||||||
|
def SetToDateObject(self, ticks):
|
||||||
|
self.to_date = dbi.TimestampFromTicks(ticks)
|
||||||
|
|
||||||
|
def SetFromDateHoursAgo(self, hours_ago):
|
||||||
|
ticks = time.time() - (3600 * hours_ago)
|
||||||
|
self.from_date = dbi.TimestampFromTicks(ticks)
|
||||||
|
|
||||||
|
def SetFromDateDaysAgo(self, days_ago):
|
||||||
|
ticks = time.time() - (86400 * days_ago)
|
||||||
|
self.from_date = dbi.TimestampFromTicks(ticks)
|
||||||
|
|
||||||
|
def SetToDateDaysAgo(self, days_ago):
|
||||||
|
ticks = time.time() - (86400 * days_ago)
|
||||||
|
self.to_date = dbi.TimestampFromTicks(ticks)
|
||||||
|
|
||||||
|
def AddCommit(self, commit):
|
||||||
|
self.commit_list.append(commit)
|
||||||
|
if self.commit_cb:
|
||||||
|
self.commit_cb(commit)
|
||||||
|
|
||||||
|
def SetCommitCB(self, callback):
|
||||||
|
self.commit_cb = callback
|
||||||
|
|
||||||
|
|
||||||
|
## entrypoints
|
||||||
|
def CreateCheckinQuery():
|
||||||
|
return CheckinDatabaseQuery()
|
Reference in New Issue
Block a user