def load_file (self, filename): """Load new items from the file 'filename'.""" f = open (filename, "r") for orig_line in f.readlines(): if orig_line[-1] == '\n': orig_line = orig_line[:-1] line = string.strip (orig_line) if not line: # empty line continue if line[0] == '#': # a comment continue m = re.match (r"([-+]?\d+):([-+]):(.*)", line) if not m: error ("ExclusionList: Cannot parse line: %s\n" % orig_line) else: prio = int (m.group (1)) action = m.group (2) == '+' regexp = m.group (3) new_item = (action, regexp) if self._items.has_key (prio): self._items[prio].append (new_item) else: self._items[prio] = [new_item]
def load_file(self, filename): """Load new items from the file 'filename'.""" f = open(filename, "r") for orig_line in f.readlines(): if orig_line[-1] == '\n': orig_line = orig_line[:-1] line = string.strip(orig_line) if not line: # empty line continue if line[0] == '#': # a comment continue m = re.match(r"([-+]?\d+):([-+]):(.*)", line) if not m: error("ExclusionList: Cannot parse line: %s\n" % orig_line) else: prio = int(m.group(1)) action = m.group(2) == '+' regexp = m.group(3) new_item = (action, regexp) if self._items.has_key(prio): self._items[prio].append(new_item) else: self._items[prio] = [new_item]
def add_entry (self, entry): """Add an explict entry""" m = re.match (r"([-+]?\d+):([-+]):(.*)", entry) if not m: error ("ExclusionList: Cannot parse line: %s\n" % orig_line) else: prio = int (m.group (1)) action = m.group (2) == '+' regexp = m.group (3) new_item = (action, regexp) if self._items.has_key (prio): self._items[prio].append (new_item) else: self._items[prio] = [new_item]
def write (self, verbose, alias_list): cachedir = os.path.expandvars (self._cachedir) cachedir = os.path.expanduser (cachedir) if not os.path.exists (cachedir): error("%s does not exists!" % cachedir) return if not os.path.isdir (cachedir): error("%s is not a directory" % cachedir) return # clear the cache directory for name in os.listdir (cachedir): fname = os.path.join (cachedir, name) if os.path.isfile (fname): os.unlink (fname) # Now call the super class to do the actual work return Writer.write (self, verbose, alias_list=alias_list)