# encoding=utf-8

from flask import Flask
from flask import request
import requests
import subprocess
import sys

reload(sys)
sys.setdefaultencoding('utf-8')

app = Flask(__name__)
app.debug = True
app.use_debugger = True

@app.route("/")
def index():
    req = requests.get('http://git.xici.com/api/v3/projects/chekun%2fflask-dances-with-gitlab/repository/branches?private_token=xxx')
    result = req.json()
    options = [u'<option value="%s">%s</option>' % (branch['name'], branch['name']) for branch in result]
    return u'''
    <!DOCTYPE html>
    <html>
        <head>
            <meta charset="utf-8">
            <title>Preview 分支管理</title>
        </head>
        <body>
            <h3>Preview 分支管理</h3>
            <form method="post" action="/checkout" charset="utf-8">
                <p>
Example #2
0
  operation = site.get_operation(op_name)
  set_verbose(verbose_opt)
  if dry_run_opt:
    msgs.append("Dry run for operation {} on site {}".format(operation.name, site.name))
  else:
    std_str = StringIO.StringIO()
    with stdout_redirector(std_str):
      operation.do_cmd()
      msg = cgi.escape(std_str.getvalue()).replace("\n", "<br>")
      msg = Markup("<code>"+msg+"</code>")
      msgs.append(msg)
      std_str.close()
  return {'msgs': msgs}

if __name__ == '__main__':
  try:
    config_file = file('config.yaml', 'r')
    config = yaml.load(config_file)
    if config['FLASK']['DEBUG']:
      app.debug = True
      use_debugger = True
      try:
        use_debugger = not(config['FLASK']['DEBUG_WITH_ECLIPSE'])
        app.use_debugger = use_debugger
        app.use_reloader = use_debugger
      except:
        pass
  except:
    print "Problem openning config.yaml"
  print app
  app.run(host='0.0.0.0')
Example #3
0
from flask import Flask
from flask import request
import requests
from flask import jsonify

app = Flask(__name__)

DEBUG = True
app.debug = DEBUG
app.use_debugger = DEBUG

TOKEN = '064968cdbc6a496571d814dd2769aa1d2ae137d2'

REPO_OWNER = 'dotgc'
REPO_NAME = 'git-email'

@app.route("/email_hook", methods=['GET', 'POST'])
def email_hook():
    req_data = request.get_json()
    try:
        head_commit = req_data['head_commit']
    except Exception as e:
        head_commit = {}
    head_commit_id = head_commit['id']
    commit_url = 'https://api.github.com/repos/%s/%s/git/commits/%s'
    diff_url = commit_url % (REPO_OWNER, REPO_NAME, head_commit_id)
    return jsonify({'diff': diff_url, 'token': TOKEN})

def fetch_url(url):
    resp = requests.get(url)