Esempio n. 1
0
def run(histries, filename, desc, execute=False, noop=True, private=False):
    """Build contents and post it to gist."""
    commands = []

    for cmd in histries:
        output = util.capture_output(cmd)['output'] if execute else ''
        commands.append({
                'command': cmd,
                'output': output,
                })

    body = util.build_body(commands)

    if noop:
        print body
        return

    gist = Gist()
    if not gist.check_token():
        (username, password) = util.prompt_username_and_password(
            'Token not found so attempt to create.')
        gist.authorize(username, password)

    res = gist.create(filename, desc, body, public=not private)

    if res:
        print 'created on %s' % res['html_url']
    else:
        sys.stderr.write('failed to create\n')
Esempio n. 2
0
    def upload_gist(self, commands):
        username = self.conf['github'].get('username')
        api_key = self.conf['github'].get('api_key')
        public = self.conf['github'].get('public', True)

        gist = Gist(username = username, api_key = api_key, public = public)
        gist.description = self.title

        for filename in self.files:
            path = os.path.join(self.bugdir, filename)
            with open(path) as f:
                content = f.read()

            gist.add_file(filename, content)

        for (filename, content) in commands.items():
            gist.add_file(filename, content)

        return gist.create()