diff options
author | 2012-07-25 13:49:47 +0200 | |
---|---|---|
committer | 2012-07-25 13:49:47 +0200 | |
commit | 36e1aa6d12b0f2816e0446c03d2de7dc92750d1c (patch) | |
tree | 50b7697dde4468eb4a909e24fd524d7005d19a7b /bin | |
parent | euscan: generic handler fixes (diff) | |
download | euscan-36e1aa6d12b0f2816e0446c03d2de7dc92750d1c.tar.gz euscan-36e1aa6d12b0f2816e0446c03d2de7dc92750d1c.tar.bz2 euscan-36e1aa6d12b0f2816e0446c03d2de7dc92750d1c.zip |
euscan: euscan_path_metadata diff using difflib
Signed-off-by: volpino <fox91@anche.no>
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/euscan_patch_metadata | 30 |
1 files changed, 17 insertions, 13 deletions
diff --git a/bin/euscan_patch_metadata b/bin/euscan_patch_metadata index 642b639..617ca3b 100755 --- a/bin/euscan_patch_metadata +++ b/bin/euscan_patch_metadata @@ -9,7 +9,7 @@ import tarfile import gzip import logging import shutil -import subprocess +from difflib import unified_diff from portage.exception import AmbiguousPackageName from gentoolkit.query import Query @@ -133,9 +133,11 @@ def get_deb_url(name): return deb_url, deb_type -def patch_metadata(metadata_path, watch_data, diff=False): +def patch_metadata(package, watch_data, diff=False): logger.info(" Patching metadata file") + metadata_path = package.metadata.metadata_path + with open(metadata_path) as fp: original = fp.read() rindent, indent = guess_indent_values(original) @@ -203,14 +205,17 @@ def patch_metadata(metadata_path, watch_data, diff=False): if not diff: return data else: - _, data_path = mkstemp() - with open(data_path, "w") as f: - f.write(data) - sub = subprocess.Popen(["diff", metadata_path, data_path], - stdout=subprocess.PIPE) - content = sub.stdout.read() - os.unlink(data_path) - return content + # Generate clean a/category/package/metadata.xml path + n = metadata_path.find(package.category) + if n != -1: + metadata_path = metadata_path[n:] + res = unified_diff( + original.splitlines(True), + data.splitlines(True), + fromfile=os.path.join('a/', metadata_path), + tofile=os.path.join('b/', metadata_path), + ) + return "".join([x for x in res]) def process_package(query, diff=False): @@ -236,12 +241,11 @@ def process_package(query, diff=False): if '9999' in package.version and len(matches) > 0: package = matches.pop() - metadata_path = package.metadata.metadata_path watch_data = get_watch_data(package) if watch_data is None: logger.error(" No watch file found") else: - return patch_metadata(metadata_path, watch_data, diff=diff) + return patch_metadata(package, watch_data, diff=diff) def main(): @@ -261,7 +265,7 @@ def main(): logger.info("Processing %s..." % package) result = process_package(package, opts.diff) if result: - print result + sys.stdout.write(result) if __name__ == "__main__": main() |