Esempio n. 1
0
def show_help(params):
    proj_path = params["proj_path"]
    targets = target.get_all_targets(proj_path)

    if targets and len(targets) > 0:
        l.colored("List of available targets:\n", l.MAGENTA)

        for target_item in targets:
            l.m("  - {0}".format(target_item))
    else:
        l.e("No targets available")
Esempio n. 2
0
def show_help(params):
    l.colored("List of available verb actions:\n", l.MAGENTA)
    l.m("  - generate")
    l.m("  - download")
    l.m("  - upload")
Esempio n. 3
0
def show_help(params):
    l.colored("Available actions:\n", l.MAGENTA)
    l.m("  - format")
Esempio n. 4
0
def show_help(params):
    l.colored("Available actions:\n", l.MAGENTA)
    l.m("  - generate")
    l.m("  - serve")
    l.m("  - publish")
Esempio n. 5
0
def docs_publish(params):
    proj_path = params["proj_path"]

    docs_name = ls.get_arg_list_value(params["args"], "--name")

    if not docs_name:
        docs_name = const.DOCS_DEFAULT_NAME

    docs_path = os.path.join(
        proj_path,
        const.DIR_NAME_FILES,
        const.DIR_NAME_FILES_DOCS,
        docs_name,
    )

    output_path = os.path.join(
        proj_path,
        const.DIR_NAME_BUILD,
        const.DIR_NAME_BUILD_DOCS,
        docs_name,
    )

    ignore_files = [".DS_Store", "Thumbs.db"]

    config_data = config.run(proj_path, params)
    config_data = config_data[docs_name]

    has_tool = check_tool_mkdocs()

    if has_tool:
        params["target_name"] = "docs"

        # prepare data
        version = config_data["version"] if "version" in config_data else None
        append_version = (config_data["append_version"]
                          if "append_version" in config_data else None)
        force = ls.list_has_value(params["args"], "--force")

        aws_key_id = os.getenv(const.AWS_KEY_ID_ENV)
        aws_secret_key = os.getenv(const.AWS_SECRET_KEY_ENV)
        aws_bucket_name = config_data["bucket_name"]
        aws_bucket_path = "{0}".format(config_data["bucket_path"])

        if append_version:
            aws_bucket_path = "{0}/{1}".format(aws_bucket_path, version)

        # generate files
        run_args = [
            "mkdocs",
            "build",
            "--clean",
            "--config-file",
            "mkdocs.yml",
            "-d",
            output_path,
        ]

        r.run(run_args, cwd=docs_path)

        # version
        if append_version:
            if not version or len(version) == 0:
                l.e("You need define version name (parameter: --version)")

            l.i("Version defined: {0}".format(version))

        # prepare to upload
        if not os.path.isdir(docs_path):
            l.e("Documentation output folder not exists: {0}".format(
                docs_path))

        # prepare aws sdk
        l.i("Initializing AWS bucket and SDK...")

        if not aws_key_id or not aws_secret_key:
            l.failed("Your AWS credentials are invalid")

        s3_client = boto3.client(
            service_name="s3",
            aws_secret_access_key=aws_secret_key,
            aws_access_key_id=aws_key_id,
        )

        # checking for existing path
        l.i('Checking if remote path "{0}" exists on AWS...'.format(
            aws_bucket_path, ))

        has_remote_path = a.s3_path_exists(
            s3_client,
            aws_bucket_name,
            aws_bucket_path,
        )

        if has_remote_path:
            if force:
                l.i('The path "{0}" already exists on AWS, removing...'.format(
                    aws_bucket_path))

                a.s3_delete_path(
                    s3_client,
                    aws_bucket_name,
                    aws_bucket_path,
                )
            else:
                l.e('The path "{0}" already exists on AWS'.format(
                    aws_bucket_path))

        # create path folder
        a.s3_create_path(
            s3_client,
            aws_bucket_name,
            aws_bucket_path,
        )

        # upload
        walks = os.walk(output_path)

        for source, dirs, files in walks:
            l.i("Entering directory: {0}".format(source))

            for filename in files:
                if filename in ignore_files:
                    continue

                local_file_path = os.path.join(source, filename)
                relative_path = os.path.relpath(local_file_path, output_path)

                s3_file = os.path.join(aws_bucket_path, relative_path)

                l.i('Uploading file "{0}" to S3 bucket "{1}"...'.format(
                    relative_path, aws_bucket_name))

                extra_args = {}

                if os.path.isdir(local_file_path):
                    extra_args = {
                        "ACL": "public-read",
                    }
                elif os.path.isfile(local_file_path):
                    mime_type = mime.guess_type(local_file_path)

                    extra_args = {
                        "ACL":
                        "public-read",
                        "ContentType":
                        (mime_type[0]
                         if mime_type != None and len(mime_type) > 0
                         and mime_type[0] != None else ""),
                    }

                s3_client.upload_file(
                    local_file_path,
                    aws_bucket_name,
                    s3_file,
                    ExtraArgs=extra_args,
                    Callback=a.ProgressPercentage(local_file_path),
                )

        if append_version:
            l.colored(
                "[DONE] You can access documentation here: {0}/{1}/index.html".
                format(
                    config_data["url"],
                    version,
                ),
                l.BLUE,
            )
        else:
            l.colored(
                "[DONE] You can access documentation here: {0}/index.html".
                format(config_data["url"], ),
                l.BLUE,
            )

        l.ok()
Esempio n. 6
0
def show_help(params):
    l.colored("Available actions:\n", l.MAGENTA)
    l.m("  - setup")
    l.m("  - generate")
    l.m("  - version")
Esempio n. 7
0
def run(params):
    args = params["args"]
    proj_path = params["proj_path"]

    targets = target.get_all_targets(proj_path)

    show_target_list = False

    if len(args) > 0:
        target_item = args[0]
        args.pop(0)

        if target_item in targets:
            target_verbs = target.get_all_target_verbs(proj_path, target_item)
            target_verbs = list(
                ls.filter_list(target_verbs, const.TARGET_VERBS_INTERNAL))

            show_target_verb_list = False

            if len(args) > 0:
                verb_name = args[0]

                if verb_name in target_verbs:
                    l.i('Running "{0}" on target "{1}"...'.format(
                        verb_name, target_item))

                    target_verb_folder = os.path.join(
                        proj_path,
                        const.DIR_NAME_FILES,
                        const.DIR_NAME_FILES_TARGETS,
                        target_item,
                        const.DIR_NAME_FILES_TARGET_VERBS,
                    )

                    params["target_name"] = target_item

                    r.run_external(
                        path=target_verb_folder,
                        module_name=verb_name,
                        command_name="run",
                        command_params=params,
                        show_log=False,
                        show_error_log=True,
                        throw_error=True,
                    )
                else:
                    show_target_verb_list = True
            else:
                show_target_verb_list = True

            if show_target_verb_list:
                if target_verbs and len(target_verbs) > 0:
                    l.colored("List of available target verbs:\n", l.MAGENTA)

                    for target_verb in target_verbs:
                        l.m("  - {0}".format(target_verb))
                else:
                    l.e("No target verbs available")
        else:
            show_target_list = True
    else:
        show_target_list = True

    if show_target_list:
        show_help(params)