commit 6a5b194814c0e9490a1e8c0fa4e741ecbc25b054 Author: askiiart Date: Fri Nov 25 20:11:37 2022 -0600 Initial commit diff --git a/README b/README new file mode 100644 index 0000000..0f0add8 --- /dev/null +++ b/README @@ -0,0 +1,3 @@ +# nbdime helper + +This is just a helper to make the use of nbdime easier. \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..407316b --- /dev/null +++ b/main.py @@ -0,0 +1,39 @@ +from tkinter import filedialog +from os import system, remove + +path = filedialog.askopenfilename() +filename = path[:path.find('.ipynb')] +local_path = filename + '-local.tmp' +remote_path = filename + '-remote.tmp' + + +def separate_versions(base, local, remote): + notebook_file = open(base, 'rt') + local_file = open(local, 'wt') + remote_file = open(remote, 'wt') + + conflict_state = 'none' + + for line in notebook_file.readlines(): + if conflict_state == 'none': + if '<<<<<<< local' in line: + conflict_state = 'local' + else: + local_file.write(line) + remote_file.write(line) + else: + if '=======' in line: + conflict_state = 'remote' + elif '>>>>>>> remote' in line: + conflict_state = 'none' + elif conflict_state == 'local': + local_file.write(line) + elif conflict_state == 'remote': + remote_file.write(line) + + +separate_versions(path, local_path, remote_path) +system(f'nbdime merge {path} {local_path} {remote_path}') + +remove(local_path) +remove(remote_path)