Skip to content

Commit

Permalink
More fixes
Browse files Browse the repository at this point in the history
 * don't run convert.ly on windows.  The process fails for an
   unknown reason.

 * remove some windows references

 * tmpPath does not store the path from the last time ly2video was
   run.  Since the temporary directory name is random, there's no
   point in deleting 'old temporary files'.

 * tmpPath was using RUNDIR for some strange reason.  Though at
   execution time, it's "" which leaves just the temporary
   directory and the desired subdirectory name to join.
  • Loading branch information
jstma committed Dec 10, 2023
1 parent 9d7ce7a commit c3f9fea
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 22 deletions.
45 changes: 26 additions & 19 deletions ly2video/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,19 +119,31 @@ def getAbsolutePitch(self):

return pitch, token

def runConvertLy(lilypond, lyFile, newLyFile):
if sys.platform.startswith("win"):
# rc = os.system("python %sconvert-ly.py '%s' >> '%s'"
# % (lilypond, lyFile, newLyFile))

def preprocessLyFile(lyFile, lilypondVersion):
rc = 1 # for now error out so that converted.ly is created by copy
else:
rc = os.system("convert-ly '%s' >> '%s'" % (lyFile, newLyFile))

if rc:
warn("Convert of input file has failed. " +
"This could cause some problems.")

return rc

def preprocessLyFile(lilypond, lyFile, lilypondVersion):
version = getLyVersion(lyFile)
progress("Version in %s: %s" %
(lyFile, version if version else "unspecified"))
if version and version != lilypondVersion:
progress("Will convert to: %s" % lilypondVersion)
newLyFile = tmpPath('converted.ly')
if os.system("convert-ly '%s' >> '%s'" % (lyFile, newLyFile)) == 0:
if runConvertLy(lilypond, lyFile, newLyFile) == 0:
print('convertly success')
return newLyFile
else:
warn("Convert of input file has failed. " +
"This could cause some problems.")

newLyFile = tmpPath('unconverted.ly')

Expand Down Expand Up @@ -922,19 +934,19 @@ def parseOptions():
group_os = parser.add_argument_group(title='External programs')

group_os.add_argument(
"--windows-lilypond", dest="winLilypond",
help='(for Windows users) folder with lilypond.exe '
"--lilypond", dest="lilypond",
help='folder with lilypond executable '
'(e.g. "C:\\lilypond\\bin\\")',
metavar="PATH", default="")
group_os.add_argument(
"--windows-ffmpeg", dest="winFfmpeg",
help='(for Windows users) folder with ffpeg.exe '
"--ffmpeg", dest="ffmpeg",
help='folder with ffmpeg executable '
'(e.g. "C:\\ffmpeg\\bin\\")',
metavar="PATH", default="")
group_os.add_argument(
"--windows-timidity", dest="winTimidity",
help='(for Windows users) folder with '
'timidity.exe (e.g. "C:\\timidity\\")',
"--timidity", dest="timidity",
help='folder with timidity executable'
' (e.g. "C:\\timidity\\")',
metavar="PATH", default="")

group_debug = parser.add_argument_group(title='Debug')
Expand Down Expand Up @@ -1565,19 +1577,14 @@ def main():
# we'll have somewhere nice to save state.
global runDir
runDir = os.getcwd()
setRunDir(runDir)

# Delete old temporary files.
if os.path.isdir(tmpPath()):
shutil.rmtree(tmpPath())
os.mkdir(tmpPath())
setRunDir(runDir) # runDir is needed for lilypond includes

# .ly input file from user (string)
lyFile = options.input

# If the input .ly doesn't match the currently installed LilyPond
# version, try to convert it
lyFile = preprocessLyFile(lyFile, lilypondVersion)
lyFile = preprocessLyFile(options.lilypond, lyFile, lilypondVersion)

# https://pillow.readthedocs.io/en/5.1.x/releasenotes/5.0.0.html#decompression-bombs-now-raise-exceptions
Image.MAX_IMAGE_PIXELS = None
Expand Down
4 changes: 1 addition & 3 deletions ly2video/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,7 @@ def tmpPath(*dirs):
if not TMPDIR:
TMPDIR = tempfile.mkdtemp(prefix='ly2video')

segments = [ TMPDIR ]
segments.extend(dirs)
return os.path.join(RUNDIR, *segments)
return os.path.join(TMPDIR, *dirs)


class Observable:
Expand Down

0 comments on commit c3f9fea

Please sign in to comment.