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
|
#!/usr/bin/env python
#
# $Source$
# $Id: xxcvs.old 762 2004-02-14 18:23:26Z blais $
#
# Copyright (c) 2002, Martin Blais. All rights reserved.
#
"""Interface to CVS and xxdiff.
This script is also used as a test for the CVS python library.
Usage:
------------------------------
xxcvs [<global options>] <subcmd> [<subcmd options>] <args> ...
"""
__version__ = "$Revision: 762 $"
__author__ = "Martin Blais <blais@furius.ca>"
#===============================================================================
# EXTERNAL DECLARATIONS
#===============================================================================
import os, shutil
import string
from os.path import isfile
import cvs
from pprint import PrettyPrinter
pprint = PrettyPrinter().pprint
#===============================================================================
# LOCAL DECLARATIONS
#===============================================================================
#===============================================================================
# CLASS Error
#===============================================================================
class Error:
"""Exception class for this module."""
def __init__(self, msg):
self.msg = msg
def __repr__(self):
return repr(self.msg)
def __str__(self):
return str(self.msg)
#===============================================================================
# CLASS CmdStatus
#===============================================================================
class CmdStatus:
name = ['status']
def addopts(self, parser):
parser.add_option('-v', '--tags', action='store_true',
help="Include tags")
parser.add_option('-R', '--recursive', action='store_true',
help="Recursive")
def __init__(self):
self.fmt = "%-50s %-12s %-16s %s"
def execute(self, subargs):
if len(subargs) > 1 or ( len(subargs) == 1 and os.path.isdir(subargs[0]) ):
mstatii = cvs.MultipleStatii(subargs,
self.opts.tags,
self.opts.recursive)
while 1:
status = mstatii.next()
if not status:
break
print self.fmt % (status.filename, status.workingRev(), \
status.stickyTag(), status.statusStr())
elif len(subargs) == 1:
status = cvs.Status(subargs[0], self.opts.tags)
print self.fmt % (status.filename, status.workingRev(), \
status.stickyTag(), status.statusStr())
#===============================================================================
# CLASS CmdLog
#===============================================================================
class CmdLog:
name = ['log']
def execute(self, subargs):
for f in subargs:
log = cvs.Log(f)
print f
print "------------------------------"
print log
#===============================================================================
# CLASS CmdRootPath
#===============================================================================
class CmdRootPath:
name = ['rootpath']
def execute(self, subargs):
print cvs.getRootPath()
#===============================================================================
# MAIN
#===============================================================================
try:
import optparse
parser = optparse.OptionParser(__doc__.strip(), version=__version__)
parser.add_option('-V', '--verbose', action='store_true',
help="Verbose mode (useful for debugging).")
parser.add_option('--debug', action='store_true',
help="Full-on debug mode, including CVS commands.")
# Declare subcommands
subcmds = [
CmdStatus(),
CmdLog(),
CmdRootPath()
]
gopts, sc, opts, args = parse_subcommands(parser, subcmds)
if gopts.debug:
gopts.verbose = 1
cvs.trace = 1
sc.execute(args)
except Error, e:
print 'Error:', e
except cvs.Error, e:
print 'CVS Error:', e
if gopts.debug:
raise
|