viewvc-4intranet/tools/cvsdbadmin

134 lines
3.6 KiB
Python
Executable File

#!/usr/bin/env python
# -*- 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/
#
# -----------------------------------------------------------------------
#
# administrative program for CVSdb; this is primarily
# used to add/rebuild CVS repositories to the database
#
# -----------------------------------------------------------------------
#
#########################################################################
#
# INSTALL-TIME CONFIGURATION
#
# These values will be set during the installation process. During
# development, they will remain None.
#
LIBRARY_DIR = None
CONF_PATHNAME = None
# Adjust sys.path to include our library directory
import sys
if LIBRARY_DIR:
sys.path.insert(0, LIBRARY_DIR)
else:
sys.path[:0] = ['../lib'] # any other places to look?
#########################################################################
import os
import string
import cvsdb
import vclib.bincvs
def UpdateFile(db, repository, path, update):
try:
if update:
commit_list = cvsdb.GetUnrecordedCommitList(repository, path)
else:
commit_list = cvsdb.GetCommitListFromRCSFile(repository, path)
except cvsdb.error, e:
print '[ERROR] %s' % (e)
return
file = string.join(path, "/")
if update:
print '[%s [%d new commits]]' % (file, len(commit_list)),
else:
print '[%s [%d commits]]' % (file, len(commit_list)),
## add the commits into the database
for commit in commit_list:
db.AddCommit(commit)
sys.stdout.write('.')
sys.stdout.flush()
print
def RecurseUpdate(db, repository, directory, update):
for entry in repository.listdir(directory, {}):
path = directory + [entry.name]
if entry.errors:
continue
if entry.kind is vclib.DIR:
RecurseUpdate(db, repository, path, update)
continue
if entry.kind is vclib.FILE:
UpdateFile(db, repository, path, update)
def usage():
print 'Usage: %s <command> [arguments]' % (sys.argv[0])
print 'Preforms administrative functions for the CVSdb database'
print 'Commands:'
print ' rebuild <repository> rebuilds the CVSdb database'
print ' for all files in the repository'
print ' update <repository> updates the CVSdb database for'
print ' all unrecorded commits'
print
sys.exit(1)
## main
if __name__ == '__main__':
## check that a command was given
if len(sys.argv) < 2:
usage()
## set the handler function for the command
command = sys.argv[1]
if string.lower(command) == 'rebuild':
update = 0
elif string.lower(command) == 'update':
update = 1
else:
print 'ERROR: unknown command %s' % (command)
usage()
# get repository path
path = cvsdb.CleanRepository(os.path.abspath(sys.argv[2]))
## run command
try:
## connect to the database we are updating
db = cvsdb.ConnectDatabase()
repository = vclib.bincvs.BinCVSRepository \
(None, path, cvsdb.cfg.general)
RecurseUpdate(db, repository, [], update)
except KeyboardInterrupt:
print
print '** break **'
sys.exit(0)