16
16
SPDX-FileCopyrightText: 2021 Intevation GmbH <https://intevation.de>
17
17
18
18
"""
19
- from pathlib import Path
20
19
import re
21
20
import subprocess
22
21
import sys
22
+ from pathlib import Path
23
23
24
24
KDIALOG = "/usr/bin/kdialog"
25
25
26
26
SUMMARY_PATTERN = re .compile ("^(SUMMARY:.*)$" , re .MULTILINE )
27
27
28
- def get_summary (icalendar_text :str ):
28
+
29
+ def get_summary (icalendar_text : str ):
29
30
"""Get the first SUMMARY: line from an iCalendar text.
30
31
31
32
Do not care about the line being continued.
@@ -38,30 +39,38 @@ def main(ical1_filename, ical2_filename):
38
39
ical1 = ical1_filename .read_text ()
39
40
ical2 = ical2_filename .read_text ()
40
41
41
- additional_args = ["--yes-label" , "take first" ] # return code == 0
42
- additional_args += ["--no-label" , "take second" ] # return code == 1
43
- additional_args += ["--cancel-label" , "do not resolve" ] # return code == 2
44
-
45
- r = subprocess .run (args = [
46
- KDIALOG ,
47
- "--warningyesnocancel" ,
48
- "There was a sync conflict, do you prefer the first entry: \n " +
49
- get_summary (ical1 ) + "...\n (full contents: " + str (ical1_filename ) +
50
- " )\n \n or the second entry: \n " +
51
- get_summary (ical2 ) + "...\n (full contents: " + str (ical2_filename ) +
52
- " )?"
53
- ] + additional_args )
42
+ additional_args = ["--yes-label" , "take first" ] # return code == 0
43
+ additional_args += ["--no-label" , "take second" ] # return code == 1
44
+ additional_args += ["--cancel-label" , "do not resolve" ] # return code == 2
45
+
46
+ r = subprocess .run (
47
+ args = [
48
+ KDIALOG ,
49
+ "--warningyesnocancel" ,
50
+ "There was a sync conflict, do you prefer the first entry: \n "
51
+ + get_summary (ical1 )
52
+ + "...\n (full contents: "
53
+ + str (ical1_filename )
54
+ + " )\n \n or the second entry: \n "
55
+ + get_summary (ical2 )
56
+ + "...\n (full contents: "
57
+ + str (ical2_filename )
58
+ + " )?" ,
59
+ ]
60
+ + additional_args
61
+ )
54
62
55
63
if r .returncode == 2 :
56
64
# cancel was pressed
57
- return # shall lead to items not changed, because not copied
65
+ return # shall lead to items not changed, because not copied
58
66
59
67
if r .returncode == 0 :
60
68
# we want to take the first item, so overwrite the second
61
69
ical2_filename .write_text (ical1 )
62
- else : # r.returncode == 1, we want the second item, so overwrite the first
70
+ else : # r.returncode == 1, we want the second item, so overwrite the first
63
71
ical1_filename .write_text (ical2 )
64
72
73
+
65
74
if len (sys .argv ) != 3 :
66
75
sys .stdout .write (__doc__ )
67
76
else :
0 commit comments