version = 0.1
+def screenwidth():
+ "Return the current width of the terminal window."
+ with popen_or_die(b'stty size', b"rb") as tp:
+ return int(tp.read().split()[1])
+
def rfc3339(t):
"RFC3339 string from Unix time."
return time.strftime(b"%Y-%m-%dT%H:%M:%SZ", time.gmtime(t))
sys.stderr.write("src: " + msg + "\n")
sys.exit(1)
-debug = 1
+debug = 0
DEBUG_COMMANDS = 1 # Show commands as they are executed
def do_or_die(dcmd, legend=b""):
% (self.command, self.legend, oe))
def __exit__(self, extype, value, traceback_unused):
if extype:
- if verbose:
- complain(b"fatal exception in popen_or_die.")
+ complain(b"fatal exception in popen_or_die.")
raise extype(value)
if self.fp.close() is not None:
complain(b"%s%s returned error." % (self.command, self.legend))
return False
def log_capture(fn):
- return popen_or_die("cd .src >/dev/null; rlog %s; cd ..>/dev/null" % fn)
+ "Capture and parse the metadata for a specified file."
+ with popen_or_die("cd .src >/dev/null; rlog %s; cd ..>/dev/null" % fn) as fp:
+ revlist = []
+ maxrevno = 0
+ state = "initial"
+ for line in fp:
+ if line.startswith("----------------------------"):
+ state = "logheader"
+ revlist.append(RCSRevisionItem(maxrevno))
+ maxrevno += 1
+ elif state == "logheader" and line.startswith("revision"):
+ fields = line.split()
+ revlist[-1].revision = fields[1]
+ elif state == "logheader" and line.startswith("date"):
+ fields = line.split()
+ date = fields[1] + " " + fields[2]
+ if date.endswith(";"):
+ date = date[:-1]
+ date = date.replace("/", "-").replace(" ", "T") + "Z"
+ revlist[-1].date = date
+ elif line.startswith("======================="):
+ if not revlist[-1].log.endswith("\n"):
+ revlist[-1].log += "\n"
+ break
+ elif revlist:
+ revlist[-1].log += line
+ for item in revlist:
+ item.revno = maxrevno - item.revno
+ return revlist
def help_method(*args):
"Summarize src commands, or (with argument) show help for a single command."
do_or_die("mv .src/{0},v . && ci -l {0} && mv {0},v .src".format(arg))
announce("%s %d" % (arg, revcount(arg)))
+class RCSRevisionItem:
+ "Capture the state of an RCS revision item in the log."
+ def __init__(self, revno):
+ self.revno = revno;
+ self.revision = None
+ self.log = ""
+ self.date = None
+
def log_method(*args):
args = preamble("log", args)
+ width = screenwidth()
for arg in args:
- sys.stdout.write("%s:\n" % arg)
- with log_capture(arg) as fp:
- revno = 0
- for line in fp:
- if line.startswith("----------------------------"):
- revno += 1
- print "%d\n" % revno
+ sys.stdout.write("= %s %s\n" % (arg, ((width - len(arg) - 5) * "=")))
+ for item in log_capture(arg):
+ sys.stdout.write("%d | %s\n%s" % (item.revno, item.date, item.log))
+ sys.stdout.write(("-" * (width - 1)) + "\n")
dispatch = {
"help": help_method,