<commit_before>#!/usr/bin/env python

import pprint
import json
import time


try:
    import requests
except ImportError, e:
    print "Missing requests module.  Install with: sudo pip install requests"
    print "If you don't have pip, do this first: sudo easy_install pip"
    exit(2)


class spinnaker():

    def __init__(self, spinnaker_address, spinnaker_port, gate_port):
        print "init, baby!"

        self.spinnaker_address = spinnaker_address
        self.spinnaker_port = spinnaker_port
        self.gate_port = gate_port

        self.pp = pprint.PrettyPrinter(indent=4)
        self.retries = 5
        self.retry_interval = 2  # in seconds...
        self.error_response = None

    

    '''
    curl 'http://localhost:8084/pipelines' 
        -H 'Origin: http://localhost:8080' 
        -H 'Accept-Encoding: gzip, deflate' 
        -H 'Accept-Language: en-US,en;q=0.8' 
        -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.80 Safari/537.36' 
        -H 'Content-Type: application/json;charset=UTF-8' 
        -H 'Accept: application/json, text/plain, */*' 
        -H 'Referer: http://localhost:8080/' 
        -H 'Cookie: PLAY_SESSION=01d09ca7710d8ea9c16349e16d578065c86f7677-sessionid=b140299f82252baeca13b5e4b40308c21199303dec55c4e909e08a9415e17df99412aeb84cadb4397e3dc5e2c4cba38d' 
        -H 'Connection: keep-alive' 
        -H 'DNT: 1' 
        --data-binary '{"index":0,"name":"appnamepipeline","stageCounter":0,"triggers":[{"enabled":true,"type":"jenkins","master":"Jenkins","job":"Package_example_app"}],"application":"appname","stages":[],"parallel":true,"id":"9bfb3400-88ce-11e5-bf5b-9d3eb09d9db6"}' --compressed
    
    curl 'http://localhost:8084/pipelines' -X OPTIONS -H 'Access-Control-Request-Method: POST' -H 'Origin: http://localhost:8080' -H 'Accept-Encoding: gzip, deflate, sdch' -H 'Accept-Language: en-US,en;q=0.8' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.80 Safari/537.36' -H 'Accept: */*' -H 'Referer: http://localhost:8080/' -H 'Connection: keep-alive' -H 'DNT: 1' -H 'Access-Control-Request-Headers: accept, content-type' --compressed
    '''
    '''
    {
    "index": 0,
    "name": "appnamepipeline",
    "stageCounter": 0,
    "triggers": [
        {
            "enabled": true,
            "type": "jenkins",
            "master": "Jenkins",
            "job": "Package_example_app"
        }
    ],
    "application": "appname",
    "stages": [],
    "parallel": true,
    "id": "9bfb3400-88ce-11e5-bf5b-9d3eb09d9db6"
    }
    '''
    def create_trigger(self,trigger):
        print "Creating Trigger"

        '''
        This returns nothing in the response, just headers, so don't go looking for nothing if it's not in the headers
        '''
        url = 'http://' + self.spinnaker_address + ':' + self.gate_port + \
            '/pipelines'

        try:
            r = requests.post(url, json=trigger)
        except requests.exceptions.RequestException, e:
            print e
            return False

    '''
    curl 'http://192.168.127.12/gate/pipelines' 
    -H 'Origin: http://192.168.127.12' 
    -H 'Accept-Encoding: gzip, deflate' 
    -H 'Accept-Language: en-US,en;q=0.8' 
    -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.80 Safari/537.36' 
    -H 'Content-Type: application/json;charset=UTF-8' 
    -H 'Accept: application/json, text/plain, */*' 
    -H 'Referer: http://192.168.127.12/' 
    -H 'Connection: keep-alive' -H 'DNT: 1' 
    --data-binary '{"name":"pipeline-name","stages":[],"triggers":[],"application":"jpancoast.test.script","stageCounter":0,"parallel":true,"index":0}' --compressed
    '''
    def create_pipeline(self, pipeline):
        print "Creating pipeline: " + pipeline['name']

        '''
        This returns nothing in the response, just headers, so don't go looking for nothing if it's not in the headers
        '''
        url = 'http://' + self.spinnaker_address + ':' + self.gate_port + \
            '/pipelines'

        try:
            r = requests.post(url, json=pipeline)
        except requests.exceptions.RequestException, e:
            self.error_response = r
            print e
            return False

        return True

    '''<commit_msg>removed reference to my name.<commit_after>#!/usr/bin/env python

import pprint
import json
import time


try:
    import requests
except ImportError, e:
    print "Missing requests module.  Install with: sudo pip install requests"
    print "If you don't have pip, do this first: sudo easy_install pip"
    exit(2)


class spinnaker():

    def __init__(self, spinnaker_address, spinnaker_port, gate_port):
        print "init, baby!"

        self.spinnaker_address = spinnaker_address
        self.spinnaker_port = spinnaker_port
        self.gate_port = gate_port

        self.pp = pprint.PrettyPrinter(indent=4)
        self.retries = 5
        self.retry_interval = 2  # in seconds...
        self.error_response = None

    

    '''
    curl 'http://localhost:8084/pipelines' 
        -H 'Origin: http://localhost:8080' 
        -H 'Accept-Encoding: gzip, deflate' 
        -H 'Accept-Language: en-US,en;q=0.8' 
        -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.80 Safari/537.36' 
        -H 'Content-Type: application/json;charset=UTF-8' 
        -H 'Accept: application/json, text/plain, */*' 
        -H 'Referer: http://localhost:8080/' 
        -H 'Cookie: PLAY_SESSION=01d09ca7710d8ea9c16349e16d578065c86f7677-sessionid=b140299f82252baeca13b5e4b40308c21199303dec55c4e909e08a9415e17df99412aeb84cadb4397e3dc5e2c4cba38d' 
        -H 'Connection: keep-alive' 
        -H 'DNT: 1' 
        --data-binary '{"index":0,"name":"appnamepipeline","stageCounter":0,"triggers":[{"enabled":true,"type":"jenkins","master":"Jenkins","job":"Package_example_app"}],"application":"appname","stages":[],"parallel":true,"id":"9bfb3400-88ce-11e5-bf5b-9d3eb09d9db6"}' --compressed
    
    curl 'http://localhost:8084/pipelines' -X OPTIONS -H 'Access-Control-Request-Method: POST' -H 'Origin: http://localhost:8080' -H 'Accept-Encoding: gzip, deflate, sdch' -H 'Accept-Language: en-US,en;q=0.8' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.80 Safari/537.36' -H 'Accept: */*' -H 'Referer: http://localhost:8080/' -H 'Connection: keep-alive' -H 'DNT: 1' -H 'Access-Control-Request-Headers: accept, content-type' --compressed
    '''
    '''
    {
    "index": 0,
    "name": "appnamepipeline",
    "stageCounter": 0,
    "triggers": [
        {
            "enabled": true,
            "type": "jenkins",
            "master": "Jenkins",
            "job": "Package_example_app"
        }
    ],
    "application": "appname",
    "stages": [],
    "parallel": true,
    "id": "9bfb3400-88ce-11e5-bf5b-9d3eb09d9db6"
    }
    '''
    def create_trigger(self,trigger):
        print "Creating Trigger"

        '''
        This returns nothing in the response, just headers, so don't go looking for nothing if it's not in the headers
        '''
        url = 'http://' + self.spinnaker_address + ':' + self.gate_port + \
            '/pipelines'

        try:
            r = requests.post(url, json=trigger)
        except requests.exceptions.RequestException, e:
            print e
            return False

    '''
    curl 'http://52.26.81.34/gate/pipelines' 
    -H 'Origin: http://52.26.81.34' 
    -H 'Accept-Encoding: gzip, deflate' 
    -H 'Accept-Language: en-US,en;q=0.8' 
    -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.80 Safari/537.36' 
    -H 'Content-Type: application/json;charset=UTF-8' 
    -H 'Accept: application/json, text/plain, */*' 
    -H 'Referer: http://5172.16.58.3/' 
    -H 'Connection: keep-alive' -H 'DNT: 1' 
    --data-binary '{"name":"pipeline-name","stages":[],"triggers":[],"application":"kenzan.test.script","stageCounter":0,"parallel":true,"index":0}' --compressed
    '''
    def create_pipeline(self, pipeline):
        print "Creating pipeline: " + pipeline['name']

        '''
        This returns nothing in the response, just headers, so don't go looking for nothing if it's not in the headers
        '''
        url = 'http://' + self.spinnaker_address + ':' + self.gate_port + \
            '/pipelines'

        try:
            r = requests.post(url, json=pipeline)
        except requests.exceptions.RequestException, e:
            self.error_response = r
            print e
            return False

        return True

    '''
{'fraction_non_alphanumeric': 0.15077832064538121, 'fraction_numerical': 0.062265651630496535, 'mean_word_length': 2.6736227045075127, 'pattern_counts': {'":': 62, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 6, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5590776', 'n_tokens_mistral': 3378, 'n_tokens_neox': 2989, 'n_words': 638}