From 879fbf59a115a448c134b493479f737e129f4f68 Mon Sep 17 00:00:00 2001
From: "Mads M. Pedersen" <mmpe@dtu.dk>
Date: Wed, 14 Jun 2017 08:24:17 +0200
Subject: [PATCH] striping comments in htcfile to avoid appending tabs during
 open-save procedure

---
 wetb/hawc2/htc_contents.py | 8 ++++----
 wetb/hawc2/htc_file.py     | 1 +
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/wetb/hawc2/htc_contents.py b/wetb/hawc2/htc_contents.py
index 93b58f0..5d60296 100644
--- a/wetb/hawc2/htc_contents.py
+++ b/wetb/hawc2/htc_contents.py
@@ -133,8 +133,8 @@ class HTCSection(HTCContents):
     begin_comments = ""
     def __init__(self, name, begin_comments="", end_comments=""):
         self.name_ = name
-        self.begin_comments = begin_comments
-        self.end_comments = end_comments
+        self.begin_comments = begin_comments.strip(" \t")
+        self.end_comments = end_comments.strip(" \t")
         self.contents = OrderedDict()
 
     @staticmethod
@@ -174,7 +174,7 @@ class HTCLine(HTCContents):
             name = name[:name.index("__")]
         self.name_ = name
         self.values = list(values)
-        self.comments = comments
+        self.comments = comments.strip(" \t")
 
     def __repr__(self):
         return str(self)
@@ -228,7 +228,7 @@ class HTCOutputSection(HTCSection):
 
 
     def line_from_line(self, lines):
-        while lines[0].strip() == "":
+        while len(lines) and lines[0].strip() == "":
             lines.pop(0)
         name = lines[0].split()[0].strip()
         if name in ['filename', 'data_format', 'buffer', 'time']:
diff --git a/wetb/hawc2/htc_file.py b/wetb/hawc2/htc_file.py
index 6445610..287c33b 100644
--- a/wetb/hawc2/htc_file.py
+++ b/wetb/hawc2/htc_file.py
@@ -334,6 +334,7 @@ class HTCFile(HTCContents, HTCDefaults):
                 exe_file = os.path.join(self.modelpath, exe)
             #print (from_unix(getmtime(res_file)), from_unix(getmtime(htc_file)))
             if (isfile(htc_file) and isfile(res_file) and isfile(exe_file) and
+                str(HTCFile(htc_file))==str(self) and
                 getmtime(res_file) > getmtime(htc_file) and getmtime(res_file) > getmtime(exe_file)):
                 if "".join(self.readfilelines(htc_file)) == str(self):
                         return
-- 
GitLab