Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
def __init__(self, args, config, env):
self.quiet = False
self.api = Api(config.api_url, env.get("USER"), config.install_id)
def upload_command(args, config):
api = Api(config.api_url, os.environ.get("USER"), config.api_token)
return UploadCommand(api, args.filename)
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)
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))