Skip to content

Instantly share code, notes, and snippets.

@Mego Mego/tio_do_pull.py

Last active Mar 17, 2017
Embed
What would you like to do?
#!/usr/bin/env python3
from flask import Flask, request, make_response
import json
import subprocess
import os
app = Flask(__name__)
with open('secrets') as secrets_file:
secrets = json.load(secrets_file)
def check_secret(user, secret):
global secrets
return secret == secrets[user]
@app.route('/tio_pull', methods=['POST'])
def do_pull():
user, repo, secret = request.form["user"], request.form["repo"], request.form["secret"]
if not check_secret(user, secret):
return make_response("Authorization failed", 401)
cwd = os.getcwd()
try:
os.chdir(user+'_'+repo)
except FileNotFoundError:
try:
subprocess.check_call(['git', 'clone', "https://github.com/{}/{}.git".format(user, repo), user+'_'+repo])
return make_response("Success", 200)
except subprocess.CalledProcessError:
print("Error cloning {}/{}".format(user, repo))
return make_response("Error cloning {}/{}".format(user, repo), 500)
try:
subprocess.check_call(['git', 'pull'])
except:
print("Error pulling {}/{}".format(user, repo))
return make_response("Error pulling {}/{}".format(user, repo), 500)
finally:
os.chdir(cwd)
return make_response("Success", 200)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.