('bug_comment_entry.tpl','bug_comment_entry')]:
fullpath = os.path.join(self.template, filename)
if os.path.exists(fullpath):
- f = codecs.open(fullpath, "r", self.encoding)
- setattr(self, attr, f.read())
- f.close()
-
- def _write_file(self, tpl, filename ):
- f = codecs.open(os.path.join(self.out_dir, filename), "w", self.encoding)
- f.write(tpl)
+ setattr(self, attr, self._read_file([fullpath]))
+
+ def _make_dir(self, dir_path):
+ dir_path = os.path.abspath(os.path.expanduser(dir_path))
+ if not os.path.exists(dir_path):
+ try:
- os.mkdir(dir_path)
++ os.makedirs(dir_path)
+ except:
+ raise cmdutil.UsageError, "Cannot create output directory '%s'." % dir_path
+ return dir_path
+
+ def _write_file(self, content, path_array, mode='w'):
+ f = codecs.open(os.path.join(*path_array), mode, self.encoding)
+ f.write(content)
+ f.close()
+
+ def _read_file(self, path_array, mode='r'):
+ f = codecs.open(os.path.join(*path_array), mode, self.encoding)
+ content = f.read()
f.close()
-
+ return content
+
+ def write_default_template(self, out_dir):
+ if self.verbose:
+ print "Creating output directories"
+ self.out_dir = self._make_dir(out_dir)
+ if self.verbose:
+ print "Creating css file"
+ self._write_css_file()
+ if self.verbose:
+ print "Creating index_file.tpl file"
+ self._write_file(self.index_file,
+ [self.out_dir, "index_file.tpl"])
+ if self.verbose:
+ print "Creating index_bug_entry.tpl file"
+ self._write_file(self.index_bug_entry,
+ [self.out_dir, "index_bug_entry.tpl"])
+ if self.verbose:
+ print "Creating bug_file.tpl file"
+ self._write_file(self.bug_file,
+ [self.out_dir, "bug_file.tpl"])
+ if self.verbose:
+ print "Creating bug_comment_entry.tpl file"
+ self._write_file(self.bug_comment_entry,
+ [self.out_dir, "bug_comment_entry.tpl"])
+
def _load_default_templates(self):
self.css_file = """
body {