"Fossies" - the Fresh Open Source Software Archive

Member "viewvc-1.2.1/bin/cvsdbadmin" (26 Mar 2020, 5746 Bytes) of package /linux/misc/viewvc-1.2.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "cvsdbadmin": 1.1.28_vs_1.2.1.

    1 #!/usr/bin/env python
    2 # -*-python-*-
    3 #
    4 # Copyright (C) 1999-2020 The ViewCVS Group. All Rights Reserved.
    5 #
    6 # By using this file, you agree to the terms and conditions set forth in
    7 # the LICENSE.html file which can be found at the top level of the ViewVC
    8 # distribution or at http://viewvc.org/license-1.html.
    9 #
   10 # For more information, visit http://viewvc.org/
   11 #
   12 # -----------------------------------------------------------------------
   13 #
   14 # administrative program for CVSdb; this is primarily
   15 # used to add/rebuild CVS repositories to the database
   16 #
   17 # -----------------------------------------------------------------------
   18 #
   19 
   20 #########################################################################
   21 #
   22 # INSTALL-TIME CONFIGURATION
   23 #
   24 # These values will be set during the installation process. During
   25 # development, they will remain None.
   26 #
   27 
   28 LIBRARY_DIR = None
   29 CONF_PATHNAME = None
   30 
   31 # Adjust sys.path to include our library directory
   32 import sys
   33 import os
   34 
   35 if LIBRARY_DIR:
   36   sys.path.insert(0, LIBRARY_DIR)
   37 else:
   38   sys.path.insert(0, os.path.abspath(os.path.join(sys.argv[0], "../../lib")))
   39 
   40 #########################################################################
   41   
   42 import os
   43 import cvsdb
   44 import viewvc
   45 import vclib.ccvs
   46 
   47 
   48 def UpdateFile(db, repository, path, update, quiet_level):
   49     try:
   50         if update:
   51             commit_list = cvsdb.GetUnrecordedCommitList(repository, path, db)
   52         else:
   53             commit_list = cvsdb.GetCommitListFromRCSFile(repository, path)
   54     except cvsdb.error, e:
   55         print '[ERROR] %s' % (e)
   56         return
   57 
   58     file = '/'.join(path)
   59     printing = 0
   60     if update:
   61         if quiet_level < 1 or (quiet_level < 2 and len(commit_list)):
   62             printing = 1
   63             print '[%s [%d new commits]]' % (file, len(commit_list)),
   64     else:
   65         if quiet_level < 2:
   66             printing = 1
   67             print '[%s [%d commits]]' % (file, len(commit_list)),
   68 
   69     ## add the commits into the database
   70     for commit in commit_list:
   71         db.AddCommit(commit)
   72         if printing:
   73             sys.stdout.write('.')
   74         sys.stdout.flush()
   75     if printing:
   76         print
   77 
   78 
   79 def RecurseUpdate(db, repository, directory, update, quiet_level):
   80     for entry in repository.listdir(directory, None, {}):
   81         path = directory + [entry.name]
   82 
   83         if entry.errors:
   84             continue
   85 
   86         if entry.kind is vclib.DIR:
   87             RecurseUpdate(db, repository, path, update, quiet_level)
   88             continue
   89 
   90         if entry.kind is vclib.FILE:
   91             UpdateFile(db, repository, path, update, quiet_level)
   92 
   93 def RootPath(path, quiet_level):
   94     """Break os path into cvs root path and other parts"""
   95     root = os.path.abspath(path)
   96     path_parts = []
   97 
   98     p = root
   99     while 1:
  100         if os.path.exists(os.path.join(p, 'CVSROOT')):
  101             root = p
  102             if quiet_level < 2:
  103                 print "Using repository root `%s'" % root
  104             break
  105 
  106         p, pdir = os.path.split(p)
  107         if not pdir:
  108             del path_parts[:]
  109             if quiet_level < 1:
  110                 print "Using repository root `%s'" % root
  111                 print "Warning: CVSROOT directory not found."
  112             break
  113 
  114         path_parts.append(pdir)
  115 
  116     root = cvsdb.CleanRepository(root)
  117     path_parts.reverse()
  118     return root, path_parts
  119 
  120 def usage():
  121     cmd = os.path.basename(sys.argv[0])
  122     sys.stderr.write(
  123 """Administer the ViewVC checkins database data for the CVS repository
  124 located at REPOS-PATH.
  125 
  126 Usage: 1. %s [[-q] -q] rebuild REPOS-PATH
  127        2. %s [[-q] -q] update REPOS-PATH
  128        3. %s [[-q] -q] purge REPOS-PATH
  129 
  130 1.  Rebuild the commit database information for the repository located
  131     at REPOS-PATH, after first purging information specific to that
  132     repository (if any).
  133 
  134 2.  Update the commit database information for all unrecorded commits
  135     in the repository located at REPOS-PATH.
  136 
  137 3.  Purge information specific to the repository located at REPOS-PATH
  138     from the database.
  139 
  140 Use the -q flag to cause this script to be less verbose; use it twice to
  141 invoke a peaceful state of noiselessness.
  142 
  143 """ % (cmd, cmd, cmd))
  144     sys.exit(1)
  145 
  146 
  147 ## main
  148 if __name__ == '__main__':
  149     args = sys.argv
  150 
  151     # check the quietness level (0 = verbose, 1 = new commits, 2 = silent)
  152     quiet_level = 0
  153     while 1:
  154         try:
  155             index = args.index('-q')
  156             quiet_level = quiet_level + 1
  157             del args[index]
  158         except ValueError:
  159             break
  160 
  161     # validate the command
  162     if len(args) <= 2:
  163         usage()
  164     command = args[1].lower()
  165     if command not in ('rebuild', 'update', 'purge'):
  166         sys.stderr.write('ERROR: unknown command %s\n' % command)
  167         usage()
  168 
  169     # get repository and path, and do the work
  170     root, path_parts = RootPath(args[2], quiet_level)
  171     rootpath = vclib.ccvs.canonicalize_rootpath(root)
  172     try:
  173         cfg = viewvc.load_config(CONF_PATHNAME)
  174         db = cvsdb.ConnectDatabase(cfg)
  175 
  176         if command in ('rebuild', 'purge'):
  177             if quiet_level < 2:
  178                 print "Purging existing data for repository root `%s'" % root
  179             try:
  180                 db.PurgeRepository(root)
  181             except cvsdb.UnknownRepositoryError, e:
  182                 if command == 'purge':
  183                     sys.stderr.write("ERROR: " + str(e) + "\n")
  184                     sys.exit(1)
  185 
  186         if command in ('rebuild', 'update'):
  187             repository = vclib.ccvs.CVSRepository(None, rootpath, None,
  188                                                   cfg.utilities, 0)
  189             RecurseUpdate(db, repository, path_parts,
  190                           command == 'update', quiet_level)
  191     except KeyboardInterrupt:
  192         print
  193         print '** break **'
  194         
  195     sys.exit(0)