luisnaranjo733

Update

Mar 5th, 2012
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.49 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. posix=True
  4.  
  5. try:
  6.     from os import getuid
  7. except ImportError:
  8.     posix=False
  9.     print "You must be on a POSIX compliant platform!"
  10.  
  11. from sys import exit
  12. from shutil import copytree, rmtree
  13. import argparse
  14.  
  15. def sudo():
  16.     if posix:
  17.         if getuid() != 0:
  18.             print ("You need to run this program as sudo!")
  19.             exit(0)
  20.  
  21. def remove(path=None):
  22.     if not path: path="//var//www/"
  23.     try:
  24.         rmtree(path)
  25.     except:
  26.         print "Error!"
  27.  
  28.  
  29. def copy(src=None):
  30.     if not src:
  31.         src = "//home//luis//site"
  32.     dst="//var//www/"
  33.     try:
  34.         copytree(src,dst)
  35.     except:
  36.         print "Error - '/var/www/' exists."
  37.         print "Would you like to delete it and proceed?"
  38.         ask = raw_input("(y/n):\t")
  39.         if ask.lower() == 'y':
  40.             remove()
  41.  
  42. def parse_args():
  43.     parser = argparse.ArgumentParser(
  44.         description="Purpose: To update naranjogomez.com, after pushing changes via FTP",
  45.         epilog="Developed by Luis Naranjo."
  46.     )
  47.  
  48.     parser.add_argument('-u','--update',help="Move and replace the -u files to /var/www/",dest="update")
  49.     parser.add_argument('-r','--remove',help="Remove '/var/www/site'",action='store_true',dest="remove")
  50.     args = parser.parse_args()
  51.     return {'update':args.update,'remove':args.remove}
  52.  
  53.  
  54. args = parse_args()
  55.  
  56. if args['remove']:
  57.     remove()
  58.     exit(0)
  59.    
  60. if args['update']:
  61.     copy(src=args['update'])
  62.     exit(0)
  63.  
  64. sudo()
  65. copy()
Advertisement
Add Comment
Please, Sign In to add comment