Example #1
0
def execute(args, exit_on_error=True):
    try:
        args.func(args)
    except McmdError as e:
        _handle_error(str(e), args.write_to_history, args.arg_string, exit_on_error)
    except configparser.Error as e:
        message = 'Error reading or writing mcmd.properties: %s' % str(e)
        _handle_error(message, args.write_to_history, args.arg_string, exit_on_error)
    else:
        if args.write_to_history:
            history.write(args.arg_string, success=True)
        io.succeed()
def _add_host():
    url = io.input_("Enter the URL of the host", required=True)
    if config.host_exists(url):
        raise McmdError("A host with URL {} already exists.".format(url))

    username = io.input_(
        "Enter the username of the superuser (Default: admin)")
    password = io.password(
        "Enter the password of the superuser (Default: admin)")

    username = '******' if len(username) == 0 else username
    password = '******' if len(password) == 0 else password

    io.start("Adding host {}".format(highlight(url)))
    config.add_host(url, username, password)
    io.succeed()
    return url
Example #3
0
def _download_attachment(attachment, issue_num):
    issue_folder = get_issues_folder().joinpath(issue_num)
    issue_folder.mkdir(parents=True, exist_ok=True)
    file_path = issue_folder.joinpath(attachment.name)

    if file_path.exists():
        overwrite = io.confirm('File %s already exists. Re-download?' % file_path.name)
        if not overwrite:
            return file_path

    io.start('Downloading %s from GitHub issue %s' % (highlight(attachment.name), highlight('#' + issue_num)))
    try:
        r = requests.get(attachment.url)
        r.raise_for_status()
        with file_path.open('wb') as f:
            f.write(r.content)
    except (OSError, requests.RequestException, requests.HTTPError) as e:
        raise McmdError('Error downloading GitHub attachment: %s' % str(e))
    io.succeed()
    return file_path