-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdiff_interface.py
More file actions
54 lines (41 loc) · 1.94 KB
/
Copy pathdiff_interface.py
File metadata and controls
54 lines (41 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
"""
###########################################################################
File: diff_interface.py
Author:
Description: Python interface for the longest common subsequence executable.
Copyright (C) PyMerge Team 2019
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
###########################################################################
"""
import subprocess
from xml.etree import ElementTree as ET
import longest_common_subseq
def lcs_c_if(left_file: str, right_file: str, outp_file: str) -> list:
"""
Creates a subprocess calling the LCS executable, passing the left and right files as arguments.
The function then parses the XML output and pads the lines using the function in longest_common_subseq.py
"""
ret_obj = subprocess.run(["LCS_C/build/LCS", left_file, right_file, outp_file], stdout=subprocess.PIPE)
raw_matches: list = [[], []]
tree = ET.parse(outp_file)
root = tree.getroot()
for row in root.iter("match"):
try:
raw_matches[0].append(int(row.attrib["left"]))
raw_matches[1].append(int(row.attrib["right"]))
except (TypeError, ValueError) as err:
print("Type error in diff interface!")
raw_matches.append([-1, -1])
raw_matches[0] = raw_matches[0][:-1]
raw_matches[1] = raw_matches[1][:-1]
outp: str = longest_common_subseq.pad_raw_line_matches(raw_matches, -1)
return outp