def read(self, filename):
"""Read configuration from file"""
+ if not os.path.isfile(filename):
+ raise Config.ReadException("No file '" + filename + "'.")
config = configparser.RawConfigParser()
config.read(filename)
shutil.rmtree(os.path.join(basedir, d))
+def printUsage():
+ """Print --help text"""
+
+ print("shbackup - a simple backup solution.")
+ print("")
+ print("Usage:")
+ print(" " + sys.argv[0] + " [-C <configfile>")
+ print(" " + sys.argv[0] + " --help")
+ print("")
+ print("Options:")
+ print(" -C <configfile> default: /etc/shbackup.conf")
+
+
if __name__ == "__main__":
- conffn = "shbackup.conf"
- if len(sys.argv) > 1:
- conffn = sys.argv[1]
+ conffn = "/etc/shbackup.conf"
+
+ i=0
+ while i < len(sys.argv)-1:
+ i += 1
+ opt = sys.argv[i]
+
+ if opt in ["-h", "--help"]:
+ printUsage()
+ exit(0)
+
+ elif opt in ["-C", "--config"]:
+ i += 1
+ conffn = sys.argv[i]
+ continue
+
+ else:
+ print("Unknown option: " + opt)
+ exit(1)
+
+ try:
+ man = BackupManager(conffn)
+ man.backup()
+ man.prune()
- man = BackupManager(conffn)
- man.backup()
- man.prune()
+ except Config.ReadException as e:
+ print("Error reading config file: ", end="")
+ for a in e.args:
+ print(a, end=" ")
+ print()