Skip to content

Instantly share code, notes, and snippets.

@elextr
Created November 9, 2014 22:32
Show Gist options
  • Save elextr/7f17f3d777af311d050a to your computer and use it in GitHub Desktop.
Save elextr/7f17f3d777af311d050a to your computer and use it in GitHub Desktop.
# Extended formatter
class Fmt(string.Formatter):
def __init__(self, builddir, sourcedir, cachedir):
self.bd = builddir
self.sd = sourcedir
self.cd = cachedir
def get_field(self, name, args, kwargs):
if len(name) > 1 and ( name[0] == '"' or name[0] == "'" ):
return (name[1:-1], name)
else:
return super().get_field(name, args, kwargs)
def convert_field(self, value, conversion):
if conversion == 'B':
base = self.bd
elif conversion == 'S':
base = self.sd
elif conversion == 'C':
base = self.cd
else:
return super().convert_field(value, conversion)
if isinstance(value, str):
return os.path.join(base, value)
else:
return os.path.join(base, *value)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment