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')