- Merged Trevor branch
authorGianluca Montecchi <gian@grys.it>
Thu, 22 Oct 2009 20:20:19 +0000 (22:20 +0200)
committerGianluca Montecchi <gian@grys.it>
Thu, 22 Oct 2009 20:20:19 +0000 (22:20 +0200)
- Reapplied the fix for subdirs

1  2 
becommands/html.py

index 0b28b4ad96056f5097f80a7fa6d10869cfa93c57,d1bd625a99b3cac77563acaa7e21df4aef53291c..b0640da10054103692ed5ccbf82abde504148fe6
@@@ -325,15 -298,52 +298,52 @@@ class HTMLGen (object)
                                ('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 {