Found a few bugs ...
------------
#!/usr/bin/python
import sys
import os
import os.path
import subprocess
from optparse import OptionParser
DUMMY_FILENAME = "__dummy_non_existing_file"
def get_files(paths):
if not paths:
paths = ["."]
files = []
for p in paths:
_files = execute(["svn", "list", "--recursive", p],
split_lines=True)
if os.path.isdir(p):
_files = [os.path.join(p, file) for file in _files]
_files = [os.path.abspath(f) for f in _files]
for f in _files:
if os.path.isfile(f):
files.append(f)
# return sorted list of files. convert to set and back to list to
remove duplicates
return sort_and_remove_duplicates(files)
def sort_and_remove_duplicates(a):
a.sort()
last = a[-1]
for i in range(len(a)-2, -1, -1):
if last == a[i]:
del a[i]
else:
last = a[i]
return a
def create_file_diff(file):
diff = execute(["diff", "-u", "--new-file", DUMMY_FILENAME, file],
split_lines=True, ignore_errors=True)
if not diff:
return ""
info = execute(["svn", "info", file], split_lines=True)
for l in info:
if l.lower().startswith("url"):
url = l.split(":",1)[1].strip()
if l.lower().startswith("repository root"):
repos_root = l.split(":",1)[1].strip()
if l.lower().startswith("revision"):
rev = l.split(":",1)[1].strip()
if not url or not repos_root or not rev:
raise Exception("Failed to get svn info for " + file)
url = url.replace(repos_root, "")
diff.insert(0, "Index: " + url)
diff.insert(1,
"===================================================================")
diff[2] = "--- " + url + "\t(revision 0)"
diff[3] = "+++ " + url + "\t(revision %s)" % (rev)
return "\n".join(diff)
def execute(command, env=None, split_lines=False, ignore_errors=False,
extra_ignore_errors=()):
if env:
env.update(os.environ)
else:
env = os.environ.copy()
env['LC_ALL'] = 'en_US.UTF-8'
env['LANGUAGE'] = 'en_US.UTF-8'
if sys.platform.startswith('win'):
p = subprocess.Popen(command,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
shell=False,
universal_newlines=True,
env=env)
else:
p = subprocess.Popen(command,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
shell=False,
close_fds=True,
universal_newlines=True,
env=env)
if split_lines:
data = [line.rstrip("\n") for line in p.stdout.readlines()]
else:
data = p.stdout.read()
rc = p.wait()
if rc and not ignore_errors and rc not in extra_ignore_errors:
raise Exception('Failed to execute command: %s\n%s' %
(command, data))
return data
def parse_options(args):
parser = OptionParser()
(globals()["options"], args) = parser.parse_args(args)
return args
def main(args):
args = parse_options(args)
files = get_files(args)
diff = '\n'.join([create_file_diff(file) for file in files])
print diff
if __name__ == "__main__":
main(sys.argv[1:])
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"reviewboard" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/reviewboard?hl=en
-~----------~----~----~----~------~----~------~--~---