1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
|
#!/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):
try:
commit_list = cvsdb.GetUnrecordedCommitList(repository, os.path.normcase(path))
except cvsdb.error, e:
print '[ERROR] %s' % (e)
return
print '[%s[%d new commits]]' % (path, 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):
for path in os.listdir(directory):
path = os.path.join(directory, path)
if os.path.islink(path):
continue
if os.path.isdir(path):
RecurseUpdate(db, repository, path)
continue
if os.path.isfile(path):
if path[-2:] == ',v':
UpdateFile(db, repository, path)
def CommandUpdate():
## connect to the database we are updating
db = cvsdb.ConnectDatabase()
repository = vclib.bincvs.BinCVSRepository \
(None, os.path.normcase(sys.argv[2]), cvsdb.cfg.general)
RecurseUpdate(db, repository, repository.rootpath)
def RebuildFile(db, repository, path):
try:
commit_list = cvsdb.GetCommitListFromRCSFile(repository, os.path.normcase(path))
except cvsdb.error, e:
print '[ERROR] %s' % (e)
return
print '[%s[%d commits]]' % (path, 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 RecurseRebuild(db, repository, directory):
for path in os.listdir(directory):
path = os.path.join(directory, path)
if os.path.islink(path):
continue
if os.path.isdir(path):
RecurseRebuild(db, repository, path)
continue
if os.path.isfile(path):
if path[-2:] == ',v':
RebuildFile(db, repository, path)
def CommandRebuild():
## connect to the database we are updating
db = cvsdb.ConnectDatabase()
repository = vclib.bincvs.BinCVSRepository \
(None, os.path.normcase(sys.argv[2]), cvsdb.cfg.general)
RecurseRebuild(db, repository, repository.rootpath)
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':
commandFunction = CommandRebuild
elif string.lower(command) == 'update':
commandFunction = CommandUpdate
else:
print 'ERROR: unknown command %s' % (command)
usage()
## run command
try:
commandFunction()
except KeyboardInterrupt:
print
print '** break **'
sys.exit(0)
|