Beispiel #1
0
def _subs_table(subs):

    sub_id = "Id"
    product_ver = "Product version" 
    locked = "Locked"

    output = Output()
    output.vertical_padding = 0
    output.vertical_separator = None
    output.table_header_separator = '-'
    output.header_names = [
        sub_id,
        product_ver,
        locked,
    ]

    output.set_header_alignment({
        sub_id: "right",
    })

    for sub in sorted(subs, key=lambda s: s.spec):

        output.add_item(
            {
                sub_id: str(sub.id).zfill(5),
                product_ver: sub.product_version_spec,
                locked: sub.locked,
            },
            color_all=Style.bright,
        )

    output.dump(output_format='table')
Beispiel #2
0
    def _sub_table(self, subs, title="Subscriptions"):

        sub_id = "Sub. ID"
        product = "Product"
        subscriber = "Subscriber"

        output = Output()
        output.vertical_padding = 0
        output.vertical_separator = None
        output.table_header_separator="-"
        output.header_names = [
            sub_id,
            product,
            subscriber,
        ]

        output.set_header_alignment({
            sub_id: "right"
        })

        for sub in sorted(subs, key=lambda s: s.spec):
            
            output.add_item(
                {
                    sub_id: str(sub.id).zfill(5),
                    product: sub.product_version_spec,
                    subscriber: sub.ptask_version_spec,
                }
            )

        output.dump(output_format="table")

        print ""
Beispiel #3
0
def _subs_table(subs):

    sub_id = "Id"
    product_ver = "Product version"
    locked = "Locked"

    output = Output()
    output.vertical_padding = 0
    output.vertical_separator = None
    output.table_header_separator = '-'
    output.header_names = [
        sub_id,
        product_ver,
        locked,
    ]

    output.set_header_alignment({
        sub_id: "right",
    })

    for sub in sorted(subs, key=lambda s: s.spec):

        output.add_item(
            {
                sub_id: str(sub.id).zfill(5),
                product_ver: sub.product_version_spec,
                locked: sub.locked,
            },
            color_all=Style.bright,
        )

    output.dump(output_format='table')
Beispiel #4
0
    def _sub_table(self, subs, title="Subscriptions"):

        sub_id = "Sub. ID"
        product = "Product"
        subscriber = "Subscriber"

        output = Output()
        output.vertical_padding = 0
        output.vertical_separator = None
        output.table_header_separator = "-"
        output.header_names = [
            sub_id,
            product,
            subscriber,
        ]

        output.set_header_alignment({sub_id: "right"})

        for sub in sorted(subs, key=lambda s: s.spec):

            output.add_item({
                sub_id: str(sub.id).zfill(5),
                product: sub.product_version_spec,
                subscriber: sub.ptask_version_spec,
            })

        output.dump(output_format="table")

        print ""
Beispiel #5
0
    def _info_versions(self):

        self._versions = self.product.versions

        if len(self._versions) == 0:
            print "Found no versions for product!\n"
            return

        number = "Ver"
        published = "P"
        deprecated = "D"
        note = "Release note"
        reps = "Reps"
        creator = "Creator"
        created = "Created"

        output = Output()
        output.vertical_padding = 0
        output.vertical_separator = None
        output.table_header_separator = "-"
        output.header_names = [published, number, note, reps, creator, created]

        output.set_header_alignment({number: "right", published: "right"})

        for version in sorted(self._versions, key=lambda v: v.number):

            is_official = version.number == self.product.official_version_number
            is_published = version.published
            is_deprecated = version.deprecated

            style = Style.dim
            if is_official or is_published:
                style = Style.normal

            output.add_item(
                {
                    number: version.number_padded,
                    note: version.release_note,
                    published: _published(is_published, is_official),
                    reps: _representations(version),
                    creator: version.creator_username,
                    created: _datetime_format(version.created),
                },
                colors={
                    published: _published_color(is_published, is_official, is_deprecated),
                    number: _published_color(is_published, is_official, is_deprecated),
                    note: style,
                    reps: style,
                    creator: style,
                    created: style,
                },
            )

        output.dump(output_format="table")

        print ""
Beispiel #6
0
    def execute(self):

        products = _get_products(self.wild_spec)

        if len(products) == 0:
            print '\nFound 0 products matching: "{s}"\n'.\
                format(s=self.wild_spec)
            return

        name = "Name"
        category = "Category"
        description = "Description"
        official = "Official"
        spec = "Spec"

        output = Output()
        output.vertical_separator = None
        output.table_cell_separator = '  '
        output.table_header_separator = '-'
        output.header_names = [
            name,
            category,
            description,
            official,
            spec,
        ]

        output.set_header_alignment({
            official: "right" 
        })

        if len(products) == 1:
            output.title = "{s}: 1 match".format(s=self.wild_spec)
        else:
            output.title = "{s}: {n} matches".format(
                s=self.wild_spec, n=len(products))

        for product in sorted(products, key=lambda p: p.name + p.category + p.ptask_spec):
            if self._official_only and not product.official_version_number:
                continue

            output.add_item(
                {
                    name: product.name,
                    category: product.category,
                    description: product.description,
                    official: _official(product),
                    spec: product.spec,
                },
                colors={
                    spec: Style.bright,
                }
            )
            
        output.dump(output_format='table')
Beispiel #7
0
    def _ptask_versions_info(self):

        version_number = "Version"
        description = "Description"
        created = "Created"
        creator = "Creator"
        location = "Location"
        parent = "Source"
        
        output = Output()
        output.vertical_padding = 0
        output.vertical_separator = None
        output.table_header_separator = '-'
        output.header_names = [
            version_number,
            description,
            created,
            creator,
            location,
            parent,
        ]

        output.set_header_alignment({
            version_number: "right",
            parent: "right",
        })

        for version in sorted(self.ptask.versions, key=lambda v: v.number):

            parent_num = version.parent_spec


            if parent_num:
                (parent_ptask_spec, parent_ver) = parent_num.split("@")
                if parent_ptask_spec == self.ptask.spec:
                    parent_num = parent_ver

            output.add_item(
                {
                    version_number: version.number_padded,
                    description: version.description,
                    created: version.created.strftime("%Y/%m/%d %H:%M:%S"),
                    creator: version.creator_username,
                    location: version.location_code,
                    parent: parent_num,
                },
                colors={
                    version_number: Style.bright,
                }
            )

        output.dump(output_format='table')

        print ""
Beispiel #8
0
    def execute(self):

        products = _get_products(self.wild_spec)

        if len(products) == 0:
            print '\nFound 0 products matching: "{s}"\n'.\
                format(s=self.wild_spec)
            return

        name = "Name"
        category = "Category"
        description = "Description"
        official = "Official"
        spec = "Spec"

        output = Output()
        output.vertical_separator = None
        output.table_cell_separator = '  '
        output.table_header_separator = '-'
        output.header_names = [
            name,
            category,
            description,
            official,
            spec,
        ]

        output.set_header_alignment({official: "right"})

        if len(products) == 1:
            output.title = "{s}: 1 match".format(s=self.wild_spec)
        else:
            output.title = "{s}: {n} matches".format(s=self.wild_spec,
                                                     n=len(products))

        for product in sorted(
                products, key=lambda p: p.name + p.category + p.ptask_spec):
            if self._official_only and not product.official_version_number:
                continue

            output.add_item(
                {
                    name: product.name,
                    category: product.category,
                    description: product.description,
                    official: _official(product),
                    spec: product.spec,
                },
                colors={
                    spec: Style.bright,
                })

        output.dump(output_format='table')
Beispiel #9
0
    def _ptask_versions_info(self):

        version_number = "Version"
        description = "Description"
        created = "Created"
        creator = "Creator"
        location = "Location"
        parent = "Source"

        output = Output()
        output.vertical_padding = 0
        output.vertical_separator = None
        output.table_header_separator = '-'
        output.header_names = [
            version_number,
            description,
            created,
            creator,
            location,
            parent,
        ]

        output.set_header_alignment({
            version_number: "right",
            parent: "right",
        })

        for version in sorted(self.ptask.versions, key=lambda v: v.number):

            parent_num = version.parent_spec

            if parent_num:
                (parent_ptask_spec, parent_ver) = parent_num.split("@")
                if parent_ptask_spec == self.ptask.spec:
                    parent_num = parent_ver

            output.add_item(
                {
                    version_number: version.number_padded,
                    description: version.description,
                    created: version.created.strftime("%Y/%m/%d %H:%M:%S"),
                    creator: version.creator_username,
                    location: version.location_code,
                    parent: parent_num,
                },
                colors={
                    version_number: Style.bright,
                })

        output.dump(output_format='table')

        print ""
Beispiel #10
0
    def _version_table(self, versions, title='Versions'):

        number = title
        note = "Release note"
        reps = "Reps"
        creator = "Creator"
        created = "Created"

        output = Output()
        output.vertical_padding = 0
        output.vertical_separator = None
        output.table_header_separator="-"
        output.header_names = [
            number,
            note,
            reps,
            creator,
            created,
        ]

        output.set_header_alignment({
            number: "right",
        })

        output.set_header_colors({
            number: Style.bright,
        })

        for version in sorted(versions, key=lambda v: v.number):

            output.add_item(
                {
                    number: version.number_padded,
                    note: version.release_note,
                    reps: _representations(version),
                    creator: version.creator_username,
                    created: _datetime_format(version.created),
                },
            )

        output.dump(output_format='table')

        print ""
Beispiel #11
0
    def _version_table(self, versions, title='Versions'):

        number = title
        note = "Release note"
        reps = "Reps"
        creator = "Creator"
        created = "Created"

        output = Output()
        output.vertical_padding = 0
        output.vertical_separator = None
        output.table_header_separator="-"
        output.header_names = [
            number,
            note,
            reps,
            creator,
            created,
        ]

        output.set_header_alignment({
            number: "right",
        })

        output.set_header_colors({
            number: Style.bright,
        })

        for version in sorted(versions, key=lambda v: v.number):

            output.add_item(
                {
                    number: version.number_padded,
                    note: version.release_note,
                    reps: _representations(version),
                    creator: version.creator_username,
                    created: _datetime_format(version.created),
                },
            )

        output.dump(output_format='table')

        print ""
Beispiel #12
0
    def execute(self):

        ptasks = []

        # search the ptasks for specs matching the supplied string
        if PTaskSpec.WILDCARD in self.wild_spec:

            search_str = ",".join(
                filter(None,
                       self.wild_spec.strip().split(PTaskSpec.WILDCARD)))

            if not search_str:
                raise ActionError(
                    "Search is too broad. " + \
                    "Please supply a string to search against."
                )

            try:
                # XXX this is inefficient. need better filtering on the backend
                ptasks = PTask.list(search=search_str)
            except PTaskError:
                pass
        else:

            try:
                ptasks.append(PTask.get(self.wild_spec))
            except PTaskError:
                pass

        matching_ptasks = []

        # the rest api's search filter isn't that great. it doesn't maintain any
        # knowledge of order for the supplied filters. So, it will return ptasks
        # that match all of the search terms, but not necessarily in the order
        # supplied. Do one more match against the returned ptasks specs keeping
        # the order of the supplied wildcard spec.

        regex_spec = "^" + \
            self.wild_spec.replace(PTaskSpec.WILDCARD, "([\w=]+)?") + "$"
        regex_spec = re.compile(regex_spec)

        for ptask in ptasks:
            if regex_spec.match(ptask.spec):
                matching_ptasks.append(ptask)

        match_count = len(matching_ptasks)

        if match_count == 0:
            print '\nFound 0 ptasks matching: "{s}"\n'.format(s=self.wild_spec)
            return

        # define the fields names
        spec = "Spec"
        ptask_type = "Type"
        status = "Status"

        # define the look of the output
        output = Output()
        output.vertical_separator = None
        output.table_cell_separator = '  '
        output.table_header_separator = '-'

        if match_count == 1:
            output.title = "{s}: 1 match".format(s=self.wild_spec)
        else:
            output.title = "{s}: {n} matches".format(s=self.wild_spec,
                                                     n=match_count)

        # display order of the information
        output.header_names = [
            spec,
            ptask_type,
            status,
        ]

        for ptask in sorted(matching_ptasks, key=lambda p: p.spec):
            # add all the information
            output.add_item(
                {
                    spec: ptask.spec,
                    ptask_type: ptask.ptask_type,
                    status: ptask.status,
                },
                colors={
                    spec: Style.bright,
                })

        # dump the output as a list of key/value pairs
        output.dump(output_format='table')
Beispiel #13
0
    def _info_versions(self):

        self._versions = self.product.versions

        if len(self._versions) == 0:
            print "Found no versions for product!\n"
            return

        number = "Ver"
        published = "P"
        deprecated = "D"
        note = "Release note"
        reps = "Reps"
        creator = "Creator"
        created = "Created"

        output = Output()
        output.vertical_padding = 0
        output.vertical_separator = None
        output.table_header_separator = "-"
        output.header_names = [
            published,
            number,
            note,
            reps,
            creator,
            created,
        ]

        output.set_header_alignment({
            number: "right",
            published: "right",
        })

        for version in sorted(self._versions, key=lambda v: v.number):

            is_official = version.number == self.product.official_version_number
            is_published = version.published
            is_deprecated = version.deprecated

            style = Style.dim
            if is_official or is_published:
                style = Style.normal

            output.add_item(
                {
                    number: version.number_padded,
                    note: version.release_note,
                    published: _published(is_published, is_official),
                    reps: _representations(version),
                    creator: version.creator_username,
                    created: _datetime_format(version.created),
                },
                colors={
                    published:
                    _published_color(is_published, is_official, is_deprecated),
                    number:
                    _published_color(is_published, is_official, is_deprecated),
                    note:
                    style,
                    reps:
                    style,
                    creator:
                    style,
                    created:
                    style,
                })

        output.dump(output_format='table')

        print ""
Beispiel #14
0
    def execute(self):

        ptasks = []

        # search the ptasks for specs matching the supplied string
        if PTaskSpec.WILDCARD in self.wild_spec:

            search_str = ",".join(
                filter(None,
                    self.wild_spec.strip().split(PTaskSpec.WILDCARD)
                )
            )

            if not search_str:
                raise ActionError(
                    "Search is too broad. " + \
                    "Please supply a string to search against."
                )

            try:
                # XXX this is inefficient. need better filtering on the backend
                ptasks = PTask.list(search=search_str)
            except PTaskError:
                pass
        else:
            
            try:
                ptasks.append(PTask.get(self.wild_spec))
            except PTaskError:
                pass

        matching_ptasks = []

        # the rest api's search filter isn't that great. it doesn't maintain any
        # knowledge of order for the supplied filters. So, it will return ptasks
        # that match all of the search terms, but not necessarily in the order
        # supplied. Do one more match against the returned ptasks specs keeping
        # the order of the supplied wildcard spec. 

        regex_spec = "^" + \
            self.wild_spec.replace(PTaskSpec.WILDCARD, "([\w=]+)?") + "$"
        regex_spec = re.compile(regex_spec)

        for ptask in ptasks:
            if regex_spec.match(ptask.spec):
                matching_ptasks.append(ptask)

        match_count = len(matching_ptasks)

        if match_count == 0:
            print '\nFound 0 ptasks matching: "{s}"\n'.format(s=self.wild_spec)
            return

        # define the fields names
        spec = "Spec"
        ptask_type = "Type"
        status = "Status"

        # define the look of the output
        output = Output()
        output.vertical_separator = None
        output.table_cell_separator = '  '
        output.table_header_separator = '-'

        if match_count == 1:
            output.title = "{s}: 1 match".format(s=self.wild_spec)
        else:
            output.title = "{s}: {n} matches".format(
                s=self.wild_spec, n=match_count)
        
        # display order of the information
        output.header_names = [
            spec, 
            ptask_type, 
            status,
        ]

        for ptask in sorted(matching_ptasks, key=lambda p: p.spec):
            # add all the information 
            output.add_item(
                {
                    spec: ptask.spec,
                    ptask_type: ptask.ptask_type,
                    status: ptask.status,
                },
                colors={
                    spec: Style.bright,
                }
            )

        # dump the output as a list of key/value pairs
        output.dump(output_format='table')