Skip to content

Instantly share code, notes, and snippets.

@rodolfofadino
Created September 6, 2015 17:06
Show Gist options
  • Save rodolfofadino/2cc3f23638577c89c417 to your computer and use it in GitHub Desktop.
Save rodolfofadino/2cc3f23638577c89c417 to your computer and use it in GitHub Desktop.
webserver in Python to run PowerShell scripts
from flask import Flask
from flask import request
import requests
import subprocess
import json
import time
payload_url = 'https://url-que-notificaremos-quando-o-deploy-terminar/'
app = Flask(__name__)
@app.route("/deploy", methods=['POST'])
def index():
execute_script("deploy-exemplo-em-powershell")
notify("deploy realizado")
return ""
def notify(message):
payload = {'text' : message}
r = requests.post(payload_url, data=json.dumps(payload))
def execute_script(script):
cmd = ["powershell","-ExecutionPolicy", "Bypass", "C:\\deploy\\{0}.ps1".format(script)]
p = subprocess.Popen(cmd, stdout = subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
out,err = p.communicate()
if(err):
raise Exception('Error: ' + str(err))
return out
if __name__ == "__main__":
app.run(port=7500, host='0.0.0.0', debug=True, threaded=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment