+ ", tarbin: " + self.tarbin + \
+ ", excludes: " + repr(self.excludes) + \
+ ", epochs: " + repr(self.epochs) + \
+ ", sets: " + repr(self.sets) + "]"
+
+ def getRealEpochsSorted(self):
+ """Return all epochs with have a non-None unit, sorted by
+ Epoch.getTimeDelta(), starting with the longest dela."""
+ epochs = self.epochs
+ realepochs = [ e for e in epochs.keys() if epochs[e].unit != None ]
+ deltakey = lambda e: epochs[e].getTimeDelta()
+ realepochs.sort(key=deltakey, reverse=True)
+ return realepochs
+
+
+ def _read_global(self, config, sec):
+ for opt in config.options(sec):
+ if opt=="backupdir":
+ self.backupdir = config.get(sec, opt)
+ if not os.path.isdir(self.backupdir):
+ raise Config.ReadError("Backupdir '{0}' does not exist.".format(self.backupdir))
+ elif opt=="format":
+ self.format = config.get(sec, opt)
+ if not self.format in Config.formats:
+ raise Config.ReadError("Invalid 'format' given.")
+ elif opt=="tarbin":
+ self.tarbin = config.get(sec, opt)
+ if not os.path.isfile(self.tarbin):
+ raise Config.ReadError("Tar binary '{0}' does not exist.".format(self.tarbin))
+ elif opt.startswith("exclude"):
+ self.excludes += [ config.get(sec, opt) ]
+ else:
+ raise Config.ReadError("Unknown option '{0}'.".format(opt))
+
+
+ def _read_epoch(self, config, sec):
+ name = sec[6:].strip()
+ e = Epoch()
+ if name in self.epochs:
+ raise Config.ReadError("Epoch '{0}' already defined.".format(name))
+ if name in Epoch.units:
+ e.unit = name
+
+ for opt in config.options(sec):
+ if opt=="numkeeps":
+ try:
+ e.numkeeps = int(config.getint(sec, opt))
+ except ValueError:
+ raise Config.ReadError("Invalid integer given for '{0}'.".format(opt))
+ if e.numkeeps <= 0:
+ raise Config.ReadError("Non-positive numkeeps '{0}' given.".format(e.numkeeps))
+
+ elif opt=="mode":
+ e.mode = config.get(sec, opt)
+ if not e.mode in Modes:
+ raise Config.ReadError("Invalid mode '{0}'.".format(e.mode))
+
+ elif opt=="timespan":
+ if name in Epoch.units:
+ raise Config.ReadError("The time delta of a standard epoch " + \
+ "is not supposed to be redefined. ")
+ td = config.get(sec,opt)
+ try:
+ mult, unit = Epoch.parseTimedelta(td)
+ e.unit = unit
+ e.mult = mult
+ except ValueError as e:
+ raise Config.ReadError("Invalid timespan '{0}': {1}".format(td, str(e)))
+
+ elif opt.startswith("exclude"):
+ e.excludes += [config.get(sec, opt)]
+
+ else:
+ raise Config.ReadError("Unknown option '" + opt + "'.")
+
+ if e.numkeeps == None:
+ raise Config.ReadError("No numkeeps set for epoch '{0}'.".format(name))
+
+ self.epochs[name] = e
+
+
+ def _read_set(self, config, sec):
+ name = sec[4:].strip()
+ dirs = []
+ excludes = []
+
+ for opt in config.options(sec):
+ if opt.startswith("dir"):
+ dirs += [config.get(sec, opt)]
+ elif opt.startswith("exclude"):
+ excludes += [config.get(sec,opt)]
+ else:
+ raise Config.ReadError("Unknown option '" + opt + "'.")
+
+ self.sets += [FileSet(name, dirs, excludes)]
+