Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- posix=True
- try:
- from os import getuid
- except ImportError:
- posix=False
- print "You must be on a POSIX compliant platform!"
- from sys import exit
- from shutil import copytree, rmtree
- import argparse
- def sudo():
- if posix:
- if getuid() != 0:
- print ("You need to run this program as sudo!")
- exit(0)
- def remove(path=None):
- if not path: path="//var//www/"
- try:
- rmtree(path)
- except:
- print "Error!"
- def copy(src=None):
- if not src:
- src = "//home//luis//site"
- dst="//var//www/"
- try:
- copytree(src,dst)
- except:
- print "Error - '/var/www/' exists."
- print "Would you like to delete it and proceed?"
- ask = raw_input("(y/n):\t")
- if ask.lower() == 'y':
- remove()
- def parse_args():
- parser = argparse.ArgumentParser(
- description="Purpose: To update naranjogomez.com, after pushing changes via FTP",
- epilog="Developed by Luis Naranjo."
- )
- parser.add_argument('-u','--update',help="Move and replace the -u files to /var/www/",dest="update")
- parser.add_argument('-r','--remove',help="Remove '/var/www/site'",action='store_true',dest="remove")
- args = parser.parse_args()
- return {'update':args.update,'remove':args.remove}
- args = parse_args()
- if args['remove']:
- remove()
- exit(0)
- if args['update']:
- copy(src=args['update'])
- exit(0)
- sudo()
- copy()
Advertisement
Add Comment
Please, Sign In to add comment