#!/usr/bin/python # vim: fileencoding=utf8 foldmethod=marker #{{{ License header: MIT # Copyright (c) 2010 Till Maas # # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies # of the Software, and to permit persons to whom the Software is furnished to do # so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. #}}} """ :author: Till Maas :contact: opensource@till.name :license: MIT """ import sys import re import subprocess as sp import string STATUS_LINE = re.compile("^File: (\S*)\s*Status: (.*)$") STATUS_DIR = re.compile("^cvs status: Examining (.*)$") cvs_status_map = {"?": "?", "Entry Invalid": "!", "Locally Added": "N", "Locally Modified": "M", "Needs Checkout": "D", "Needs Patch": "O", "Up-to-date": "", "Unresolved Conflict": "C", } def print_files(output): files = output.keys() files.sort(key=string.lower) for file in files: sys.stdout.write("%s %s\n" % (output[file], file)) if __name__ == "__main__": cmdline = ["cvs", "status"] extra_opts = sys.argv[1:] if extra_opts: cmdline.extend(extra_opts) cvs_status = sp.Popen(cmdline, stdout=sp.PIPE, stderr=sp.STDOUT) data = cvs_status.communicate()[0] output = {} output_subdir = {} dir_prefix = "" for line in data.splitlines(): line = line.strip() if line.startswith("?"): if "/" in line: output_subdir[line[2:]] = "?" else: output[line[2:]] = "?" else: match = STATUS_DIR.match(line) if match: dir_prefix = "%s/" % match.groups() if dir_prefix == "./": dir_prefix = "" continue match = STATUS_LINE.match(line) if match: file, status = match.groups() status = cvs_status_map[status] if status: if dir_prefix: output_subdir["%s%s" % (dir_prefix, file)] = status else: output["%s%s" % (dir_prefix, file)] = status print_files(output) print_files(output_subdir)