<repo_name>erodriguezv/LocalScripts<file_sep>/deploy.py
#!/usr/bin/python
import sys
import os.path
import os

# ######################################################################
# we define the environments
environments = {
    "dev": {
        "host": "switch.zion",
        "user": "zato",
        "pickup": "/zato/dev/server1/pickup-dir/"
    },
    "qa": {
        "host": "dillard.zion",
        "user": "zato",
        "pickup": "/zato/qa/server1/pickup-dir/"
    }
}
environments['d'] = environments['dev']
environments['q'] = environments['qa']

# ######################################################################
# utility functions


def display_syntax():
    print '''
Usage:
deploy <env> <file1> <file2> .. <filen>


'''


def deploy(env, file_list):
    print "Deploying"
    command = "scp {0} {1}@{2}:{3}".format(
        ' '.join(file_list),
        environments[env]['user'],
        environments[env]['host'],
        environments[env]['pickup']
    )
    print command
    os.system(command)


# ######################################################################
# validations

if len(sys.argv) < 3:
    print "\nPlease specify at least one file"
    display_syntax()
    sys.exit(-1)

env = sys.argv[1].lower()

if env not in ['dev', 'd', 'qa', 'q']:
    print "\nNot a valid environment."
    display_syntax()
    sys.exit(-1)

file_list = []
missing_file = False
for arg in sys.argv[2:]:
    arg = arg.replace('./', '')
    if '/' in arg:
        print "The script only works for files in the current directory"
        missing_file = True
    else:
        if not os.path.exists(arg):
            missing_file = True
            print 'File does not exist: {0}'.format(arg)
        else:
            file_list.append(arg)

if missing_file:
    print "Exiting"
    sys.exit(-1)


# ######################################################################
# now we deploy

deploy(env, file_list)
