Example #1
0
def run_deploy(folder, major):
    config = load_json_file_to_dict('../connection.conf')
    sftp = SFTPConnection(config)
    sftp.download('PyDeploy/deployments.json', os.getcwd() + '/deployments.json')

    with open('deployments.json') as jsfile:
        remote_config = json.loads(jsfile.read())
        jsfile.close()

    found = False
    deployments = remote_config['deployments']
    for deployment in deployments:
        if folder in deployment['name']:
            deployments.remove(deployment)
            curr_v, new_v = suggest_new_version(deployment, major)
            curr_path = deployment['location']
            name = deployment['name']
            curr_date = ''
            found = True
            break

    if found:
        new_name = '%s-v%s-%s' % (name, curr_v, curr_date)
        destination_path = '%s/PyDeploy/past_deployments/%s' & (config['root'], new_name)
        sftp.move(curr_path, destination_path)

    local_path = os.getcwd() + '/' + folder
    remote_path = config['root'] + '/python/' + folder
    sftp.upload(local_path, remote_path)

    new_config = dict()
    new_config['version'] = new_v
    new_config['location'] = curr_path
    new_config['name'] = name
    deployments.append(new_config)

    with open('../deployments.json', 'w+') as json_config:
        json_config.write(json.dumps(deployments))
        json_config.close()

    sftp.upload('../deployments.json', config['root'] + '/PyDeploy/deployments.json')