+#!/usr/bin/python
+#shuber, 2008-06-09
+
+__author__ = "shuber"
+
+
+
+import re
+import string
+
+import StatusWindow
+
+class Configuration:
+
+ def __init__(self):
+ self.breakpoints = []
+ self.watches = []
+
+
+ def load(self, filename):
+ try:
+ cnt = 0
+ #Parse all lines
+ for line in file(filename).readlines():
+ cnt += 1
+
+ #Get command and tail
+ cmd = string.split(line)[0]
+ tail = string.join(string.split(line)[1:])
+
+ if cmd == "break":
+ self.parseBreak(tail)
+ elif cmd == "watch":
+ self.parseWatch(tail)
+ else:
+ cnt -= 1
+ print "Unkown command", cmd
+ return cnt
+ except IOError:
+ return None
+
+ def store(self, filename):
+
+ f = file(filename, "w")
+
+ for b in self.breakpoints:
+ self.__writeBreak(f, b)
+
+ for w in self.watches:
+ self.__writeWatch(f, w)
+
+
+ def parseBreak(self, tail):
+
+ tail = tail.strip()
+ rx = re.compile("^[\w\._\-]+:\d+(\s+if\s+\S+.*)?$")
+
+ if not rx.search(tail):
+ print "Wrong breakpoint format:", tail
+ return
+
+ preif = string.split(tail, "if")[0].strip()
+ postif = string.join( string.split(tail, "if")[1:], "if").strip()
+
+ [file,lineno] = string.split(preif, ":")
+ lineno = int(lineno)
+
+ cond = None
+ if postif != "":
+ cond = postif
+
+ self.addBreak(file, lineno, cond)
+
+
+ def parseWatch(self, tail):
+ self.addWatch(tail)
+
+
+ def __writeBreak(self, f, b):
+ if b["cond"] != None:
+ f.write("break %(file)s:%(lineno)d if %(cond)s\n" % b)
+ else:
+ f.write("break %(file)s:%(lineno)d\n" % b)
+
+ def __writeWatch(self, f, w):
+ f.write("watch %(expr)s\n" % w)
+
+
+ def addBreak(self, file, lineno, cond=None):
+ self.breakpoints += [ {"file" : file, "lineno" : lineno, "cond" : cond} ]
+
+ def addWatch(self, expr):
+ self.watches += [ {"expr" : expr.strip() } ]
+
+ def __str__(self):
+ return "breakpoints=" + str(self.breakpoints) + ", watches=" + str(self.watches)
+
+
+