Mercurial > repos > bcclaywell > argo_navis
comparison venv/lib/python2.7/site-packages/planemo/shed/diff.py @ 0:d67268158946 draft
planemo upload commit a3f181f5f126803c654b3a66dd4e83a48f7e203b
author | bcclaywell |
---|---|
date | Mon, 12 Oct 2015 17:43:33 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:d67268158946 |
---|---|
1 from __future__ import print_function | |
2 | |
3 import os | |
4 import sys | |
5 from xml.etree import ElementTree | |
6 | |
7 from planemo.xml import diff | |
8 | |
9 | |
10 def diff_and_remove(working, label_a, label_b, f): | |
11 assert label_a != label_b | |
12 special = ["tool_dependencies.xml", "repository_dependencies.xml"] | |
13 deps_diff = 0 | |
14 # Could walk either A or B; will only compare if in same relative location | |
15 for dirpath, dirnames, filenames in os.walk(os.path.join(working, label_a)): | |
16 for filename in filenames: | |
17 if filename in special: | |
18 a = os.path.join(dirpath, filename) | |
19 b = os.path.join(working, label_b, os.path.relpath(a, os.path.join(working, label_a))) | |
20 if os.path.exists(a) and os.path.exists(b): | |
21 deps_diff &= _shed_diff(a, b, f) | |
22 os.remove(a) | |
23 os.remove(b) | |
24 return deps_diff | |
25 | |
26 | |
27 def _shed_diff(file_a, file_b, f=sys.stdout): | |
28 xml_a = ElementTree.parse(file_a).getroot() | |
29 xml_b = ElementTree.parse(file_b).getroot() | |
30 _strip_shed_attributes(xml_a) | |
31 _strip_shed_attributes(xml_b) | |
32 return diff.diff(xml_a, xml_b, reporter=f.write) | |
33 | |
34 | |
35 def _strip_shed_attributes(xml_element): | |
36 if xml_element.tag == "repository": | |
37 _remove_attribs(xml_element) | |
38 children = xml_element.getchildren() | |
39 if len(children) > 0: | |
40 for child in children: | |
41 _strip_shed_attributes(child) | |
42 | |
43 | |
44 def _remove_attribs(xml_element): | |
45 for attrib in ["changeset_revision", "toolshed"]: | |
46 if attrib in xml_element.attrib: | |
47 del xml_element.attrib[attrib] |