예제 #1
0
from flask import (Flask, render_template, redirect, url_for, make_response,
                   Response, flash)
from github3 import GitHub, GitHubError
from os import getenv

gh = GitHub()
gh.set_user_agent('subscribed (https://subscribed.herokuapp.com)')

id, secret = (getenv('GH_ID', ''), getenv('GH_SECRET', ''))
if id and secret:
    gh.set_client_id(id, secret)

app = Flask(__name__)
app.secret_key = getenv('SECRET_KEY', '')


@app.route('/')
def index():
    return render_template('index.html')


# Streaming is necessary for accounts like hcilab
# Taken directly from:
# http://flask.pocoo.org/docs/patterns/streaming/#streaming-from-templates
def stream_template(template_name, **context):
    app.update_template_context(context)
    t = app.jinja_env.get_template(template_name)
    rv = t.stream(**context)
    rv.enable_buffering(30)
    return rv
예제 #2
0
파일: base.py 프로젝트: dlfinst/github-cli
class Command(object):
    __metaclass__ = ABCMeta
    name = None
    usage = None
    repository = ()
    user = ''
    subcommands = {}
    SUCCESS = 0
    FAILURE = 1
    COMMAND_UNKNOWN = 127

    def __init__(self):
        super(Command, self).__init__()
        assert self.name
        commands[self.name] = self
        self.gh = GitHub()
        self.gh.set_user_agent('github-cli/{0} (http://git.io/MEmEmw)'.format(
            __version__
        ))
        self.parser = CustomOptionParser(usage=self.usage)

    @abstractmethod
    def run(self, options, args):
        return self.FAILURE

    def get_repo(self, options):
        self.repo = None
        if self.repository:
            self.repo = self.gh.repository(*self.repository)

        if not (self.repo or options.loc_aware):
            self.parser.error('A repository is required.')

    def get_user(self):
        if not self.user:
            self.login()
            self.user = self.gh.user()

    def login(self):
        # Get the full path to the configuration file
        config = github_config()
        parser = ConfigParser()

        # Check to make sure the file exists and we are allowed to read it
        if os.path.isfile(config) and os.access(config, os.R_OK | os.W_OK):
            parser.readfp(open(config))
            self.gh.login(token=parser.get('github', 'token'))
        else:
        # Either the file didn't exist or we didn't have the correct
        # permissions
            user = ''
            while not user:
                # We will not stop until we are given a username
                user = input('Username: '******''
            while not pw:
                # Nor will we stop until we're given a password
                pw = getpass('Password: '******'user', 'repo', 'gist'], 'github-cli',
                'http://git.io/MEmEmw'
            )
            parser.add_section('github')
            parser.set('github', 'token', auth.token)
            self.gh.login(token=auth.token)
            # Create the file if it doesn't exist. Otherwise completely blank
            # out what was there before. Kind of dangerous and destructive but
            # somewhat necessary
            parser.write(open(config, 'w+'))

    def help(self):
        self.parser.print_help()
        if self.subcommands:
            print('\nSubcommands:')
            for command in sorted(self.subcommands.keys()):
                print('  {0}:\n\t{1}'.format(
                    command, self.subcommands[command]
                ))
        sys.exit(0)
예제 #3
0
from flask import (Flask, render_template, redirect, url_for, make_response,
                   Response, flash)
from github3 import GitHub, GitHubError
from os import getenv


gh = GitHub()
gh.set_user_agent('subscribed (https://subscribed.herokuapp.com)')

id, secret = (getenv('GH_ID', ''), getenv('GH_SECRET', ''))
if id and secret:
    gh.set_client_id(id, secret)

app = Flask(__name__)
app.secret_key = getenv('SECRET_KEY', '')


@app.route('/')
def index():
    return render_template('index.html')


# Streaming is necessary for accounts like hcilab
# Taken directly from:
# http://flask.pocoo.org/docs/patterns/streaming/#streaming-from-templates
def stream_template(template_name, **context):
    app.update_template_context(context)
    t = app.jinja_env.get_template(template_name)
    rv = t.stream(**context)
    rv.enable_buffering(30)
    return rv