4:26
  "   lamJq@pOlJbѿh      4:7
     	h      	disabled
  	   0  7   lamJq@q\jbѿ0aamJq@q\jbѿ  	   0     h      4096
  #   lm_JJh Ȯ2o߿ (N    """RCS interface module.

Defines the class RCS, which represents a directory with rcs version
files and (possibly) corresponding work files.

"""


import fnmatch
import os
import re
import string
import tempfile


class RCS:

    """RCS interface class (local filesystem version).

    An instance of this class represents a directory with rcs version
    files and (possible) corresponding work files.

    Methods provide access to most rcs operations such as
    checkin/checkout, access to the rcs metadata (revisions, logs,
    branches etc.) as well as some filesystem operations such as
    listing all rcs version files.

    XXX BUGS / PROBLEMS

    - The instance always represents the current directory so it's not
    very useful to have more than one instance around simultaneously

    """

    # Characters allowed in work file names
    okchars = string.ascii_letters + string.digits + '-_=+'

    def __init__(self):
        """Constructor."""
        pass

    def __del__(self):
        """Destructor."""
        pass

    # --- Informational methods about a single file/revision ---

    def log(self, name_rev, otherflags = ''):
        """Return the full log text for NAME_REV as a string.

        Optional OTHERFLAGS are passed to rlog.

        """
        f = self._open(name_rev, 'rlog ' + otherflags)
        data = f.read()
        status = self._closepipe(f)
        if status:
            data = data + "%s: %s" % status
        elif data[-1] == '\n':
            data = data[:-1]
        return data

    def head(self, name_rev):
        """Return the head revision for NAME_REV"""
        dict = self.info(name_rev)
        return dict['head']

    def info(self, name_rev):
        """Return a dictionary of info (from rlog -h) for NAME_REV

        The dictionary's keys are the keywords that rlog prints
        (e.g. 'head' and its values are the corresponding data
        (e.g. '1.3').

        XXX symbolic names and locks are not returned

        """
        f = self._open(name_rev, 'rlog -h')
        dict = {}
        while 1:
            line = f.readline()
            if not line: break
            if line[0] == '\t':
                # XXX could be a lock or symbolic name
                # Anything else?
                continue
            i = string.find(line, ':')
            if i > 0:
                key, value = line[:i], string.strip(line[i+1:])
                dict[key] = value
        status = self._closepipe(f)
        if status:
            raise IOError, status
        return dict

    # --- Methods that change files ---

    def lock(self, name_rev):
        """Set an rcs lock on NAME_REV."""
        name, rev = self.checkfile(name_rev)
        cmd = "rcs -l%s %s" % (rev, name)
        return self._system(cmd)

    def unlock(self, name_rev):
        """Clear an rcs lock on NAME_REV."""
        name, rev = self.checkfile(name_rev)
        cmd = "rcs -u%s %s" % (rev, name)
        return self._system(cmd)

    def checkout(self, name_rev, withlock=0, otherflags=""):
        """Check out NAME_REV to its work file.

        If optional WITHLOCK is set, check out locked, else unlocked.

        The optional OTHERFLAGS is passed to co without
        interpretation.

        Any output from co goes to directly to stdout.

        """
        name, rev = self.checkfile(name_rev)
        if withlock: lockflag = "-l"
        else: lockflag = "-u"
        cmd = 'co %s%s %s %s' % (lockflag, rev, otherflags, name)
        return self._system(cmd)

    def checkin(self, name_rev, message=None, otherflags=""):
        """Check in NAME_REV from its work file.

        The optional MESSAGE argument becomes the checkin message
        (default "<none>" if None); or the file description if this is
        a new file.

        The o