瀏覽代碼

fix tempalte loading with relative / absolute path

nico 8 年之前
父節點
當前提交
c950c66955
共有 1 個文件被更改,包括 9 次插入1 次删除
  1. 9 1
      core/NeuronModule.py

+ 9 - 1
core/NeuronModule.py

@@ -157,7 +157,15 @@ class NeuronModule(object):
             sys.setdefaultencoding('utf-8')
             # the user choose a file_template option
             if self.file_template is not None:  # the user choose a file_template option
-                real_file_template_path = "templates/%s" % self.file_template
+                if not os.path.isabs(self.file_template):  # os.path.isabs returns True if the path is absolute
+                    # here we are
+                    dir_we_are = os.path.dirname(os.path.realpath(__file__))
+                    # root directory
+                    root_dir = os.path.normpath(dir_we_are + os.sep + os.pardir)
+                    # real path of the template
+                    real_file_template_path = os.path.join(root_dir, self.file_template)
+                else:
+                    real_file_template_path = self.file_template
                 if os.path.isfile(real_file_template_path):
                     # load the content of the file as template
                     t = Template(self._get_content_of_file(real_file_template_path))