Browse Source

Step interpolation: Build interpolation dictionary only once

pull/113/head
Louis 9 years ago
parent
commit
23ddb1beb5
  1. 11
      patacrep/build.py

11
patacrep/build.py

@ -154,6 +154,9 @@ class SongbookBuilder(object):
"""Run function if it has not been run yet. """Run function if it has not been run yet.
If it as, return the previous return value. If it as, return the previous return value.
Warning: several function calls with different arguments return the
same value.
""" """
if function not in self._called_functions: if function not in self._called_functions:
self._called_functions[function] = function(*args, **kwargs) self._called_functions[function] = function(*args, **kwargs)
@ -263,8 +266,7 @@ class SongbookBuilder(object):
with codecs.open(sxd_file[:-3] + "sbx", "w", "utf-8") as index_file: with codecs.open(sxd_file[:-3] + "sbx", "w", "utf-8") as index_file:
index_file.write(idx.entries_to_str()) index_file.write(idx.entries_to_str())
def build_custom(self, command): def _set_interpolation(self, command):
"""Run a shell command"""
interpolation = { interpolation = {
"basename": self.basename, "basename": self.basename,
} }
@ -277,6 +279,11 @@ class SongbookBuilder(object):
extension: '{}.{}'.format(self.basename, extension) extension: '{}.{}'.format(self.basename, extension)
for extension in ["aux", "log", "out", "pdf", "sxc", "tex"] for extension in ["aux", "log", "out", "pdf", "sxc", "tex"]
}) })
return interpolation
def build_custom(self, command):
"""Run a shell command"""
interpolation = self._run_once(self._set_interpolation, command)
try: try:
formatted_command = command.format(**interpolation) formatted_command = command.format(**interpolation)
except KeyError as error: except KeyError as error:

Loading…
Cancel
Save