Beispiel #1
0
def upload_asciinema(filename):
    """a wrapper around generation of an asciinema.api.Api to call the 
       upload command given an already existing asciinema file. 

       Parameters
       ==========
       filename: the asciinema file to upload, can be generated with 
                 function record_asciinema in record.py

    """
    if os.path.exists(filename):

        try:
            from asciinema.commands.upload import UploadCommand
            import asciinema.config as aconfig
            from asciinema.api import Api
        except:
            bot.exit(
                "The asciinema module is required to submit "
                "an asciinema recording. Try pip install helpme[asciinema]"
            )

        # Load the API class

        cfg = aconfig.load()
        api = Api(cfg.api_url, os.environ.get("USER"), cfg.install_id)

        # Perform the upload, return the url

        uploader = UploadCommand(api, filename)

        try:
            url, warn = uploader.api.upload_asciicast(filename)
            if warn:
                uploader.print_warning(warn)

            # Extract just the url, if provided (always is https)
            if url:
                match = re.search("https://.+", url)
                if match:
                    url = match.group()
            return url

        except:
            bot.error("Problem with upload, skipping")

    else:
        bot.warning("Cannot find %s, skipping submission." % filename)
Beispiel #2
0
def record_asciinema():
    """a wrapper around generation of an asciinema.api.Api and a custom 
       recorder to pull out the input arguments to the Record from argparse.
       The function generates a filename in advance and a return code
       so we can check the final status. 
    """

    import asciinema.config as aconfig
    from asciinema.api import Api

    # Load the API class

    cfg = aconfig.load()
    api = Api(cfg.api_url, os.environ.get("USER"), cfg.install_id)

    # Create dummy class to pass in as args
    recorder = HelpMeRecord(api)
    code = recorder.execute()

    if code == 0 and os.path.exists(recorder.filename):
        return recorder.filename
    print("Problem generating %s, return code %s" % (recorder.filename, code))
Beispiel #3
0
def auth_command(args, config):
    api = Api(config.api_url, os.environ.get("USER"), config.install_id)
    return AuthCommand(api)
Beispiel #4
0
def upload_command(args, config):
    api = Api(config.api_url, os.environ.get("USER"), config.install_id)
    return UploadCommand(api, args.filename)
Beispiel #5
0
def rec_command(args, config):
    api = Api(config.api_url, os.environ.get("USER"), config.install_id)
    return RecordCommand(api, args)
Beispiel #6
0
def rec_command(args, config):
    api = Api(config.api_url, os.environ.get("USER"), config.api_token)
    return RecordCommand(api, args.filename, args.command, args.title,
                         args.yes, args.quiet, args.max_wait)