Skip to content

Commit

Permalink
Merge branch 'object-oriented' into urs
Browse files Browse the repository at this point in the history
  • Loading branch information
uliska committed Feb 26, 2017
2 parents d150667 + 535d2b2 commit 723145d
Show file tree
Hide file tree
Showing 6 changed files with 532 additions and 334 deletions.
104 changes: 39 additions & 65 deletions lydiff.py
Original file line number Diff line number Diff line change
@@ -1,93 +1,67 @@
#!/usr/bin/env python3
"""
Program `lydiff`
© 2017 Joram Berger
© 2017 Joram Berger, Urs Liska
License: GPL3+
Usage examples:
1 .ly, 2 bin
lydiff file.ly -l lilypond /my/other/lilypond -o diff_file.png
1 .ly, 2 versionen, viele bins
lydiff file.ly
lydiff file.ly -v 2.18.0 2.19.50 [--convert] -i /my/paths -o diff_file_2-18-0_2-19-50.png
2 .ly, 1 bin/1 version
lydiff file1.ly file2.ly -l lilypond
3 .ly, -g commit1 commit2 -l lilypond
lydiff file.ly -g a677be ffe523
Visually compares two LilyPond scores.
Use cases:
a)
1 .ly file, two LilyPond versions:
- fromfile (default)
- latest (default)
- specific version
b)
2 .ly files, one or two LilyPond versions
c)
2 versions of 1 .ly file (not implemented yet)
"""
import os
import subprocess

import lydiff
from lydiff.lyversions import Versions
from lydiff import cliopts

def main():

try:
cli_opts = lydiff.cliopts.cli_options()
cli_opts.available_versions = Versions(cli_opts.path)
lyDiff = lydiff.LyDiff(lydiff.cliopts.CliOptions())
except Exception as e:
print()
print(e)
exit(1)

opt = lydiff.configure(cli_opts)

quiet = opt['quiet']
dryrun = opt['dryrun']
show_output = opt['show_output']

if lydiff.check_empty_comparison(opt):
print()
print("Warning: Equal input_files won't generate differences. Aborting.")
print()
exit()
lydiff.check_available_versions(opt)

if not quiet:
lydiff.print_report(opt)
if dryrun or show_output:
print()

lydiff.purge_dirs(opt)
lydiff.runconvert(opt)
lydiff.runlily(opt)

if show_output:
exit("\n{}\n".format(e))

if not lyDiff.options.quiet:
print('\n - '.join(lyDiff.task_list))

vm = lyDiff.check_version_mismatch()
if not lyDiff.options.quiet:
for v in vm:
print(v)

purge = lyDiff.purge_dirs()
if not lyDiff.options.quiet:
print('\n'.join(purge))

lyDiff.run_convert()
lyDiff.run_lily()

if lyDiff.options.show_output:
print('-'*48)

try:
ret = lydiff.compare(opt)
ret = lyDiff.compare()
except FileNotFoundError as e:
print("\n", e)
print("Temporary files are *not* purged, please inspect. Aborting")
exit(1)
exit("\n{}\nTemporary files are *not* purged, please inspect. Aborting".format(e))

if not quiet:
if not lyDiff.options.quiet:
print('done')

print('Outputs', ['differ', 'are identical'][int(ret)])

# optionally perform a textual diff
lydiff.do_diff(opt)
lyDiff.do_diff()

if not opt['keep_intermediate_files']:
lydiff.purge_temporary_files(opt)
if not lyDiff.options.keep_intermediate_files:
lyDiff.purge_temporary_files()

return not ret


if __name__ == "__main__":
exit(main())
vv = Versions("/usr/bin ~/Technik/sw/ly/*/bin")
#print(vv)
#print(vv.get("2.18.0"))
#print(vv.get("2.18.5"))
#print(vv.get("2.19.53"))
#print(vv.get("2.20.0"))
#comp = ['compare', '-metric', 'AE', 'tmp-test3-2.18.2.png', 'tmp-test3-2.19.53.png', 'null:']
#subprocess.call(comp)
#import subprocess
main()
Loading

1 comment on commit 723145d

@uliska
Copy link
Collaborator Author

@uliska uliska commented on 723145d Feb 26, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This merge changes the program's structure pretty thoroughly, going to an
object oriented design. Of course this isn't the original KISS approach anymore,
but I'm pretty sure this will make the code much more extendable in the future.

One part is not fully completed, namely the fact that in the lydiff module's files
there are still a number of explicit print() statements, which should eventually
be removed as soon as we intend to make the lydiff module available to any
other clients.

Please sign in to comment.