euscan: euscan_path_metadata diff using difflib
Signed-off-by: volpino <fox91@anche.no>
This commit is contained in:
parent
21c6a9107d
commit
36e1aa6d12
@ -9,7 +9,7 @@ import tarfile
|
|||||||
import gzip
|
import gzip
|
||||||
import logging
|
import logging
|
||||||
import shutil
|
import shutil
|
||||||
import subprocess
|
from difflib import unified_diff
|
||||||
|
|
||||||
from portage.exception import AmbiguousPackageName
|
from portage.exception import AmbiguousPackageName
|
||||||
from gentoolkit.query import Query
|
from gentoolkit.query import Query
|
||||||
@ -133,9 +133,11 @@ def get_deb_url(name):
|
|||||||
return deb_url, deb_type
|
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")
|
logger.info(" Patching metadata file")
|
||||||
|
|
||||||
|
metadata_path = package.metadata.metadata_path
|
||||||
|
|
||||||
with open(metadata_path) as fp:
|
with open(metadata_path) as fp:
|
||||||
original = fp.read()
|
original = fp.read()
|
||||||
rindent, indent = guess_indent_values(original)
|
rindent, indent = guess_indent_values(original)
|
||||||
@ -203,14 +205,17 @@ def patch_metadata(metadata_path, watch_data, diff=False):
|
|||||||
if not diff:
|
if not diff:
|
||||||
return data
|
return data
|
||||||
else:
|
else:
|
||||||
_, data_path = mkstemp()
|
# Generate clean a/category/package/metadata.xml path
|
||||||
with open(data_path, "w") as f:
|
n = metadata_path.find(package.category)
|
||||||
f.write(data)
|
if n != -1:
|
||||||
sub = subprocess.Popen(["diff", metadata_path, data_path],
|
metadata_path = metadata_path[n:]
|
||||||
stdout=subprocess.PIPE)
|
res = unified_diff(
|
||||||
content = sub.stdout.read()
|
original.splitlines(True),
|
||||||
os.unlink(data_path)
|
data.splitlines(True),
|
||||||
return content
|
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):
|
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:
|
if '9999' in package.version and len(matches) > 0:
|
||||||
package = matches.pop()
|
package = matches.pop()
|
||||||
|
|
||||||
metadata_path = package.metadata.metadata_path
|
|
||||||
watch_data = get_watch_data(package)
|
watch_data = get_watch_data(package)
|
||||||
if watch_data is None:
|
if watch_data is None:
|
||||||
logger.error(" No watch file found")
|
logger.error(" No watch file found")
|
||||||
else:
|
else:
|
||||||
return patch_metadata(metadata_path, watch_data, diff=diff)
|
return patch_metadata(package, watch_data, diff=diff)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
@ -261,7 +265,7 @@ def main():
|
|||||||
logger.info("Processing %s..." % package)
|
logger.info("Processing %s..." % package)
|
||||||
result = process_package(package, opts.diff)
|
result = process_package(package, opts.diff)
|
||||||
if result:
|
if result:
|
||||||
print result
|
sys.stdout.write(result)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
Loading…
Reference in New Issue
Block a user