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')
def run_setup(): config = dict() config['host'] = raw_input('Please enter the address for the remote host: ') config['port'] = raw_input('Please enter the port for the remote host: ') config['username'] = raw_input('Enter the username for the remote host: ') config['password'] = raw_input('Enter the password for the remote host: ') config['root'] = raw_input('Enter the path to the root folder at the remote host: ') print 'All parameters entered, testing connection...' sftp = SFTPConnection(config) if sftp.test_connection(): print 'Connection tested successfully, writing config to file.' with open('../connection.conf', 'w+') as conn: conn.write(json.dumps(config)) conn.close() sftp.open_connection() sftp.mkdir(config['root'] + '/past_deployments') else: print 'Connection with the given parameters failed, try again please.' sys.exit(0)