path: root/templatefile.py
diff options
authorPeter Seebach <peter.seebach@windriver.com>2011-03-25 12:38:43 -0500
committerPeter Seebach <peter.seebach@windriver.com>2011-03-25 12:38:43 -0500
commit29e8b8a4cd8f7383c3d851b6255272f1c2a5d286 (patch)
treec9619032a670d06124ef45c392484f4a04f7d0f0 /templatefile.py
parent96d8e7ce8b483e5cafd0449b9735e4714f41f20b (diff)
Merge in ports work
This is a spiffied-up rebase of a bunch of intermediate changes, presented as a whole because it is, surprisingly, less confusing that way. The basic idea is to separate the guts code into categories ranging from generic stuff that can be the same everywhere and specific variants. The big scary one is the Darwin support, which actually seems to run okay on 64-bit OS X 10.6. (No other variants were tested.) The other example given is support for the old clone() syscall on RHEL 4, which affects some wrlinux use cases. There's a few minor cleanup bits here, such as a function with inconsistent calling conventions, but nothing really exciting.
Diffstat (limited to 'templatefile.py')
1 files changed, 19 insertions, 7 deletions
diff --git a/templatefile.py b/templatefile.py
index e08bc64..11e002c 100644
--- a/templatefile.py
+++ b/templatefile.py
@@ -16,6 +16,8 @@ class TemplateFile:
# empty footer if none specified:
self.sections['footer'] = []
+ # empty per-port if none specified:
+ self.sections['port'] = []
# lines appended to body by default
self.sections['body'] = []
@@ -45,7 +47,10 @@ class TemplateFile:
for section, data in self.sections.items():
- self.sections[section] = Template("\n".join(data))
+ if len(data) > 0:
+ self.sections[section] = Template("\n".join(data))
+ else:
+ self.sections[section] = None
# You need a file if this isn't a file-per-item
if not self.file_per_item:
@@ -68,8 +73,7 @@ class TemplateFile:
return "\n".join(strings)
- def emit(self, template, item=None):
- """Emit a template, with optional interpolation of an item."""
+ def get_file(self, item):
if self.file_per_item:
if not item:
@@ -84,16 +88,24 @@ class TemplateFile:
(path, self.path, template)
+ def emit(self, template, item=None):
+ """Emit a template, with optional interpolation of an item."""
if template == "copyright":
# hey, at least it's not a global variable, amirite?
- self.file.write(TemplateFile.copyright)
+ self.get_file(item)
+ if self.file:
+ self.file.write(TemplateFile.copyright)
elif template in self.sections:
templ = self.sections[template]
- self.file.write(templ.safe_substitute(item))
- self.file.write("\n")
+ if templ:
+ self.get_file(item)
+ if self.file:
+ self.file.write(templ.safe_substitute(item))
+ self.file.write("\n")
print "Warning: Unknown template '%s'." % template
if self.file_per_item:
- self.file.close()
+ if self.file:
+ self.file.close()
self.file = None