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.
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:
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:
index_file.write(idx.entries_to_str())
def build_custom(self, command):
"""Run a shell command"""
def _set_interpolation(self, command):
interpolation = {
"basename": self.basename,
}
@ -277,6 +279,11 @@ class SongbookBuilder(object):
extension: '{}.{}'.format(self.basename, extension)
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:
formatted_command = command.format(**interpolation)
except KeyError as error:

Loading…
Cancel
Save