Commits

Antoine Albertelli  committed 297a850

Implements reverting of files (issue #2)

  • Participants
  • Parent commits 31db459

Comments (0)

Files changed (1)

File copy_files.py

 
 import os.path
 import shutil
+import argparse
 
 
 def getDestinationName(path):
     shutil.copy(getAbsolutePath(path), getDestinationName(path))
 
 
+def revertFile(path):
+    """Copies a file from the backup directory."""
+    shutil.copy(getDestinationName(path), getAbsolutePath(path))
+
+
 
 def main():
     fileList = []
     # Files to backup
 
     fileList.append("/etc/fstab")
-    fileList.append("~/.bashrc")
+    fileList.append("/home/antoine/.bashrc")
     fileList.append("/etc/mkinitcpio.conf")
-    fileList.append("~/.vimrc")
-    fileList.append("~/.hgrc") # Mercurial configuration file
+    fileList.append("/home/antoine/.vimrc")
+    fileList.append("/home/antoine/.hgrc") # Mercurial configuration file
     fileList.append("/etc/pacman.conf") # Pacman configuration file
     fileList.append("/etc/locale.gen")
     fileList.append("/etc/locale.conf")
     fileList.append("/boot/syslinux/splash.png") # Background image for syslinux
     fileList.append("/etc/out.icc") # Display calibration
 
-    for f in fileList:
-        print("Copying "+getDestinationName(f)+"...")
-        backupFile(f)
+    parser = argparse.ArgumentParser("Backups or reverts configuration files.")
+    parser.add_argument("--revert", dest="action", action="store_const", const=1, default=0,
+                        help="Reverts all files (default : backup)")
+
+    args = parser.parse_args()
+    if args.action == 0: # Backup files
+        for f in fileList:
+            print("Copying "+getDestinationName(f)+"...")
+            backupFile(f)
+
+    else:
+        for f in fileList:
+            print("Reverting "+getDestinationName(f)+"...")
+            revertFile(f)
 
 if __name__=="__main__":
     main()