flowcraft/generator/engine.py
def fetch_docker_tags(self):
        """
        Export all dockerhub tags associated with each component given by
        the -t flag.
        """

        # dict to store the already parsed components (useful when forks are
        # given to the pipeline string via -t flag
        dict_of_parsed = {}

        # fetches terminal width and subtracts 3 because we always add a
        # new line character and we want a space at the beggining and at the end
        # of each line
        terminal_width = shutil.get_terminal_size().columns - 3

        # first header
        center_string = " Selected container tags "

        # starts a list with the headers
        tags_list = [
            [
                "=" * int(terminal_width / 4),
                "{0}{1}{0}".format(
                    "=" * int(((terminal_width/2 - len(center_string)) / 2)),
                    center_string)
                ,
                "{}\n".format("=" * int(terminal_width / 4))
            ],
            ["component", "container", "tags"],
            [
                "=" * int(terminal_width / 4),
                "=" * int(terminal_width / 2),
                "=" * int(terminal_width / 4)
            ]
        ]

        # Skip first init process and iterate through the others
        for p in self.processes[1:]:
            template = p.template
            # if component has already been printed then skip and don't print
            # again
            if template in dict_of_parsed:
                continue

            # starts a list of  containers for the current process in
            # dict_of_parsed, in which each containers will be added to this
            # list once it gets parsed
            dict_of_parsed[template] = {
                "container": []
            }

            # fetch repo name from directives of each component.
            for directives in p.directives.values():
                try:
                    repo = directives["container"]
                    default_version = directives["version"]
                except KeyError:
                    # adds the default container if container key isn't present
                    # this happens for instance in integrity_coverage
                    repo = "flowcraft/flowcraft_base"
                    default_version = "1.0.0-1"
                # checks if repo_version already exists in list of the
                # containers for the current component being queried
                repo_version = repo + default_version
                if repo_version not in dict_of_parsed[template]["container"]:
                    # make the request to docker hub
                    r = requests.get(
                        "https://hub.docker.com/v2/repositories/{}/tags/"
                        .format(repo)
                    )
                    # checks the status code of the request, if it is 200 then
                    # parses docker hub entry, otherwise retrieve no tags but
                    # alerts the user
                    if r.status_code != 404:
                        # parse response content to dict and fetch results key
                        r_content = json.loads(r.content)["results"]
                        for version in r_content:
                            printed_version = (version["name"] + "*") \
                                if version["name"] == default_version \
                                else version["name"]
                            tags_list.append([template, repo, printed_version])
                    else:
                        tags_list.append([template, repo, "No DockerHub tags"])

                dict_of_parsed[template]["container"].append(repo_version)

        # iterate through each entry in tags_list and print the list of tags
        # for each component. Each entry (excluding the headers) contains
        # 3 elements (component name, container and tag version)
        for x, entry in enumerate(tags_list):
            # adds different color to the header in the first list and
            # if row is pair add one color and if is even add another (different
            # background)
            color = "blue_bold" if x < 3 else \
                ("white" if x % 2 != 0 else "0;37;40m")
            # generates a small list with the terminal width for each column,
            # this will be given to string formatting as the 3, 4 and 5 element
            final_width = [
                int(terminal_width/4),
                int(terminal_width/2),
                int(terminal_width/4)
            ]
            # writes the string to the stdout
            sys.stdout.write(
                colored_print("\n {0: <{3}} {1: ^{4}} {2: >{5}}".format(
                    *entry, *final_width), color)
            )
        # assures that the entire line gets the same color
        sys.stdout.write("\n{0: >{1}}\n".format("(* = default)",
                                                terminal_width + 3))
def fetch_docker_tags(self):
        # dict to store the already parsed components (useful when forks are
        # given to the pipeline string via -t flag
        dict_of_parsed = {}

        # fetches terminal width and subtracts 3 because we always add a
        # new line character and we want a space at the beggining and at the end
        # of each line
        terminal_width = shutil.get_terminal_size().columns - 3

        # first header
        center_string = " Selected container tags "

        # starts a list with the headers
        tags_list = [
            [
                "=" * int(terminal_width / 4),
                "{0}{1}{0}".format(
                    "=" * int(((terminal_width/2 - len(center_string)) / 2)),
                    center_string)
                ,
                "{}\n".format("=" * int(terminal_width / 4))
            ],
            ["component", "container", "tags"],
            [
                "=" * int(terminal_width / 4),
                "=" * int(terminal_width / 2),
                "=" * int(terminal_width / 4)
            ]
        ]

        # Skip first init process and iterate through the others
        for p in self.processes[1:]:
            template = p.template
            # if component has already been printed then skip and don't print
            # again
            if template in dict_of_parsed:
                continue

            # starts a list of  containers for the current process in
            # dict_of_parsed, in which each containers will be added to this
            # list once it gets parsed
            dict_of_parsed[template] = {
                "container": []
            }

            # fetch repo name from directives of each component.
            for directives in p.directives.values():
                try:
                    repo = directives["container"]
                    default_version = directives["version"]
                except KeyError:
                    # adds the default container if container key isn't present
                    # this happens for instance in integrity_coverage
                    repo = "flowcraft/flowcraft_base"
                    default_version = "1.0.0-1"
                # checks if repo_version already exists in list of the
                # containers for the current component being queried
                repo_version = repo + default_version
                if repo_version not in dict_of_parsed[template]["container"]:
                    # make the request to docker hub
                    r = requests.get(
                        "https://hub.docker.com/v2/repositories/{}/tags/"
                        .format(repo)
                    )
                    # checks the status code of the request, if it is 200 then
                    # parses docker hub entry, otherwise retrieve no tags but
                    # alerts the user
                    if r.status_code != 404:
                        # parse response content to dict and fetch results key
                        r_content = json.loads(r.content)["results"]
                        for version in r_content:
                            printed_version = (version["name"] + "*") \
                                if version["name"] == default_version \
                                else version["name"]
                            tags_list.append([template, repo, printed_version])
                    else:
                        tags_list.append([template, repo, "No DockerHub tags"])

                dict_of_parsed[template]["container"].append(repo_version)

        # iterate through each entry in tags_list and print the list of tags
        # for each component. Each entry (excluding the headers) contains
        # 3 elements (component name, container and tag version)
        for x, entry in enumerate(tags_list):
            # adds different color to the header in the first list and
            # if row is pair add one color and if is even add another (different
            # background)
            color = "blue_bold" if x < 3 else \
                ("white" if x % 2 != 0 else "0;37;40m")
            # generates a small list with the terminal width for each column,
            # this will be given to string formatting as the 3, 4 and 5 element
            final_width = [
                int(terminal_width/4),
                int(terminal_width/2),
                int(terminal_width/4)
            ]
            # writes the string to the stdout
            sys.stdout.write(
                colored_print("\n {0: <{3}} {1: ^{4}} {2: >{5}}".format(
                    *entry, *final_width), color)
            )
        # assures that the entire line gets the same color
        sys.stdout.write("\n{0: >{1}}\n".format("(* = default)",
                                                terminal_width + 3))
def fetch_docker_tags ( self ) : # dict to store the already parsed components (useful when forks are # given to the pipeline string via -t flag dict_of_parsed = { } # fetches terminal width and subtracts 3 because we always add a # new line character and we want a space at the beggining and at the end # of each line terminal_width = shutil . get_terminal_size ( ) . columns - 3 # first header center_string = " Selected container tags " # starts a list with the headers tags_list = [ [ "=" * int ( terminal_width / 4 ) , "{0}{1}{0}" . format ( "=" * int ( ( ( terminal_width / 2 - len ( center_string ) ) / 2 ) ) , center_string ) , "{}\n" . format ( "=" * int ( terminal_width / 4 ) ) ] , [ "component" , "container" , "tags" ] , [ "=" * int ( terminal_width / 4 ) , "=" * int ( terminal_width / 2 ) , "=" * int ( terminal_width / 4 ) ] ] # Skip first init process and iterate through the others for p in self . processes [ 1 : ] : template = p . template # if component has already been printed then skip and don't print # again if template in dict_of_parsed : continue # starts a list of  containers for the current process in # dict_of_parsed, in which each containers will be added to this # list once it gets parsed dict_of_parsed [ template ] = { "container" : [ ] } # fetch repo name from directives of each component. for directives in p . directives . values ( ) : try : repo = directives [ "container" ] default_version = directives [ "version" ] except KeyError : # adds the default container if container key isn't present # this happens for instance in integrity_coverage repo = "flowcraft/flowcraft_base" default_version = "1.0.0-1" # checks if repo_version already exists in list of the # containers for the current component being queried repo_version = repo + default_version if repo_version not in dict_of_parsed [ template ] [ "container" ] : # make the request to docker hub r = requests . get ( "https://hub.docker.com/v2/repositories/{}/tags/" . format ( repo ) ) # checks the status code of the request, if it is 200 then # parses docker hub entry, otherwise retrieve no tags but # alerts the user if r . status_code != 404 : # parse response content to dict and fetch results key r_content = json . loads ( r . content ) [ "results" ] for version in r_content : printed_version = ( version [ "name" ] + "*" ) if version [ "name" ] == default_version else version [ "name" ] tags_list . append ( [ template , repo , printed_version ] ) else : tags_list . append ( [ template , repo , "No DockerHub tags" ] ) dict_of_parsed [ template ] [ "container" ] . append ( repo_version ) # iterate through each entry in tags_list and print the list of tags # for each component. Each entry (excluding the headers) contains # 3 elements (component name, container and tag version) for x , entry in enumerate ( tags_list ) : # adds different color to the header in the first list and # if row is pair add one color and if is even add another (different # background) color = "blue_bold" if x < 3 else ( "white" if x % 2 != 0 else "0;37;40m" ) # generates a small list with the terminal width for each column, # this will be given to string formatting as the 3, 4 and 5 element final_width = [ int ( terminal_width / 4 ) , int ( terminal_width / 2 ) , int ( terminal_width / 4 ) ] # writes the string to the stdout sys . stdout . write ( colored_print ( "\n {0: <{3}} {1: ^{4}} {2: >{5}}" . format ( * entry , * final_width ) , color ) ) # assures that the entire line gets the same color sys . stdout . write ( "\n{0: >{1}}\n" . format ( "(* = default)" , terminal_width + 3 ) )
Export all dockerhub tags associated with each component given by
        the -t flag.
Export all dockerhub tags associated with each component given by the - t flag .