Esempio n. 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')
Esempio n. 2
0
    def verify(self):

        ptask_ver = "PTask version"
        product_ver = "Subscribing to"

        output = Output()
        output.title = "Creating subscription:"
        output.header_names = [ptask_ver, product_ver]

        if self.product.official_version_number == self.product_version.number:
            official = Fg.green + "  (official)" + Fg.reset
        else:
            official = ""

        output.add_item(
            {ptask_ver: self.ptask_version.spec, product_ver: self.product_version.spec + official},
            color_all=Style.bright,
        )

        output.dump()

        if self._existing_sub:
            print "Will unsubscribe from existing sub:\n    " + Style.bright + self._existing_sub.product_version.spec + Style.normal + "\n"

        if not Output.prompt_yes_no("Subscribe"):
            raise ActionAborted("User chose not to proceed.")
Esempio n. 3
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 ""
Esempio n. 4
0
    def verify(self):

        code = "Code"
        name = "Name"
        description = "Description"
        server = "Data server"
        filesystem_root = "Filesystem root"

        output = Output()
        output.header_names = [
            code,
            name,
            description,
            server,
            filesystem_root,
        ]

        output.add_item(
            {
                code: self.location.code,
                name: self.location.name,
                description: self.location.description,
                server: self.server,
                filesystem_root: self.location.filesystem_root,
            },
            color_all=Style.bright,
        )

        output.title = "Location summary:"
        output.dump()

        if not Output.prompt_yes_no(
            Style.bright + "Initialize location" + Style.reset
        ):
            raise ActionAborted("User chose not to proceed.") 
Esempio n. 5
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')
Esempio n. 6
0
    def verify(self):

        ptask_field = 'PTask'
        latest_version_field = 'Latest version'
        from_field = 'From'
        to_field = 'To'

        output = Output()
        output.header_names = [
            ptask_field,
            latest_version_field,
            from_field,
            to_field,
        ]

        output.add_item(
            {
                ptask_field: self.ptask.spec,
                latest_version_field: self.ptask_latest_version.number_padded,
                from_field: self.ptask_latest_version.location_code,
                to_field: current_location_code(),
            },
            color_all=Style.bright,
        )

        output.title = "Confirm transfer:"
        output.dump()

        if not Output.prompt_yes_no(Style.bright + "Transfer" + Style.reset):
            raise ActionAborted("User chose not to proceed.")
Esempio n. 7
0
    def _info_product(self):

        # fields:
        name = "Name"
        category = "Category"
        description = "Description"
        official = "Official"
        created = "Created"
        creator = "Creator"
        ptask = "PTask"

        output = Output()
        output.header_names = [name, category, description, official, created, creator, ptask]

        output.add_item(
            {
                name: self.product.name,
                category: self.product.category,
                description: self.product.description,
                official: self.product.official_version_number_padded
                if self.product.official_version_number != 0
                else "None",
                creator: self.product.creator_username,
                created: _datetime_format(self.product.created),
                ptask: self.product.ptask_spec,
            },
            color_all=Style.bright,
        )

        # build the title
        title = " {p.spec} ".format(p=self.product)
        output.title = title

        # dump the output as a list of key/value pairs
        output.dump()
Esempio n. 8
0
    def verify(self):

        ver_range = Frange()
        ver_range.add([v.number for v in self.versions])
        versions_disp = str(ver_range)

        ptask_field = "PTask"
        versions_field = "Version(s)"
        
        output = Output()
        output.header_names = [
            ptask_field,
            versions_field,
        ]

        output.add_item(
            {
                ptask_field: self.ptask.spec,
                versions_field: versions_disp,
            },
            color_all=Style.bright,
        )

        if self.force:
            output.title = "Syncing: "
        else:
            output.title = "Confirm sync:"

        output.dump()

        if not self.force:
            if not Output.prompt_yes_no(Style.bright + "Sync" + Style.reset):
                raise ActionAborted("Sync aborted by user.")
Esempio n. 9
0
    def verify(self):

        next_version = self.ptask.next_version_number_padded

        ptask = "PTask"
        source_version = "Source version"
        description = "v{v} description".format(v=self.latest_version.number)

        output = Output()
        output.header_names = [
            ptask,
            source_version,
            description,
        ]

        output.add_item({
            ptask: Style.bright + str(self.ptask.spec) + Style.reset,
            source_version: \
                Style.bright + \
                str(self.source_version.number_padded) + \
                Style.reset,
            description: Style.bright + str(self.description) + Style.reset,
        })

        output.title = "Confirm version creation: {v}".format(v=next_version)
        output.dump()

        if not Output.prompt_yes_no(Style.bright + "Version up" + Style.reset):
            print "\nAborting!\n"
            raise ActionAborted("User aborted before version attempted.")
Esempio n. 10
0
    def verify(self):

        ptask_type_field = "Type"
        spec_field = "Spec"
        description_field = "Description"
        creator_field = "Creator"
        start_date_field = "Starts"
        due_date_field = "Due"
        source_field = "Source"

        output = Output()
        output.header_names = [
            ptask_type_field,
            spec_field,
            description_field,
            creator_field,
            start_date_field,
            due_date_field,
            source_field,
        ]

        if self.source:
            source_disp = self.source.spec
        else:
            source_disp = "None"

        output.add_item(
            {
                ptask_type_field: self.ptask_type,
                spec_field: self.spec,
                description_field: self.description,
                creator_field: self.creator,
                start_date_field: str(self.start_date),
                due_date_field: str(self.due_date),
                source_field: source_disp,
            },
            color_all=Style.bright,
        )

        if self.force:
            output.title = "Creating:"
        else:
            output.title = "Confirm create:"
        output.dump()

        if not self.force:
            if self.ptask:
                if not Output.prompt_yes_no("This ptask already exists. " + \
                    Style.bright + "Continue anyway" + Style.reset):
                    raise ActionAborted(
                        "PTask already exists. User chose not to continue.")
            else:
                prompt_str = "Create " + Style.bright + self.spec + Style.reset
                if self.source:
                    prompt_str += \
                        " + " + \
                        str(len(self.source.children_recursive)) + \
                        " child ptasks"
                if not Output.prompt_yes_no(prompt_str):
                    raise ActionAborted("User chose not to proceed.")
Esempio n. 11
0
    def verify(self):

        ptask_ver = "PTask version"
        product_ver = "Subscribing to"

        output = Output()
        output.title = "Source subscriptions from: " + self._version.spec
        output.header_names = [
            ptask_ver,
            product_ver,
        ]

        for sub in self.subs_to_source:
            output.add_item(
                {
                    ptask_ver: self.current_ptask_version.spec,
                    product_ver: sub.product_version_spec,
                },
                color_all=Style.bright,
            )

        output.dump(output_format='table')

        if not Output.prompt_yes_no("Source"):
            raise ActionAborted("User chose not to proceed.")
Esempio n. 12
0
    def verify(self):

        ptask_ver = "PTask version"
        product_ver = "Subscribing to"

        output = Output()
        output.title = "Source subscriptions from: " + self._version.spec
        output.header_names = [
            ptask_ver,
            product_ver,
        ]

        for sub in self.subs_to_source:
            output.add_item(
                {
                    ptask_ver: self.current_ptask_version.spec,
                    product_ver: sub.product_version_spec,
                },
                color_all=Style.bright,
            )

        output.dump(output_format='table')

        if not Output.prompt_yes_no("Source"):
            raise ActionAborted("User chose not to proceed.")
Esempio n. 13
0
    def verify(self):

        ver_range = Frange()
        ver_range.add([v.number for v in self.versions])
        versions_disp = str(ver_range)

        ptask_field = "PTask"
        versions_field = "Version(s)"
        
        output = Output()
        output.header_names = [
            ptask_field,
            versions_field,
        ]

        output.add_item(
            {
                ptask_field: self.ptask.spec,
                versions_field: versions_disp,
            },
            color_all=Style.bright,
        )

        if self.force:
            output.title = "Syncing: "
        else:
            output.title = "Confirm sync:"

        output.dump()

        if not self.force:
            if not Output.prompt_yes_no(Style.bright + "Sync" + Style.reset):
                raise ActionAborted("Sync aborted by user.")
Esempio n. 14
0
    def verify(self):

        ptask_field = 'PTask'
        latest_version_field = 'Latest version'
        from_field = 'From'
        to_field = 'To'

        output = Output()
        output.header_names = [
            ptask_field,
            latest_version_field,
            from_field,
            to_field,
        ]

        output.add_item(
            {
                ptask_field: self.ptask.spec,
                latest_version_field: self.ptask_latest_version.number_padded,
                from_field: self.ptask_latest_version.location_code,
                to_field: current_location_code(),
            },
            color_all=Style.bright,
        )

        output.title = "Confirm transfer:"
        output.dump()

        if not Output.prompt_yes_no(Style.bright + "Transfer" + Style.reset):
            raise ActionAborted("User chose not to proceed.")
Esempio n. 15
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 ""
Esempio n. 16
0
    def verify(self):

        ptask_ver = "PTask version"
        product_ver = "Subscribing to"

        output = Output()
        output.title = "Creating subscription:"
        output.header_names = [
            ptask_ver,
            product_ver,
        ]

        if self.product.official_version_number == self.product_version.number:
            official = Fg.green + "  (official)" + Fg.reset
        else:
            official = ""

        output.add_item(
            {
                ptask_ver: self.ptask_version.spec,
                product_ver: self.product_version.spec + official,
            },
            color_all=Style.bright,
        )

        output.dump()

        if self._existing_sub:
            print "Will unsubscribe from existing sub:\n    " + \
                Style.bright + self._existing_sub.product_version.spec + \
                Style.normal + "\n"

        if not Output.prompt_yes_no("Subscribe"):
            raise ActionAborted("User chose not to proceed.")
Esempio n. 17
0
    def verify(self):

        ptask_version = self.subscription.ptask_version
        product_version = self.subscription.product_version
        ptask = ptask_version.ptask
        product = product_version.product

        ptask_ver_header = "PTask version"
        product_ver_header = "Unsubscribing from"

        output = Output()
        output.title = "Removig subscription:"
        output.header_names = [
            ptask_ver_header,
            product_ver_header,
        ]

        if product.official_version_number == product_version.number:
            official = Fg.green + "  (official)" + Fg.reset
        else:
            official = ""

        output.add_item(
            {
                ptask_ver_header: ptask_version.spec,
                product_ver_header: product_version.spec + official,
            },
            color_all=Style.bright,
        )

        output.dump()

        if not Output.prompt_yes_no("Unsubscribe"):        
            raise ActionAborted("User chose not to proceed.")
Esempio n. 18
0
    def verify(self):

        product = "Product"
        source = "From"
        current = "Old"
        new = "New"
        note = "Note"

        output = Output()
        output.title = "Subscriptions to update:"
        output.header_names = [
            source,
            product,
            current,
            new,
            note,
        ]

        output.set_header_alignment({
            current: "right",
            new: "right",
        })

        updates = False

        for sub in sorted(self._subs, key=lambda s: s.spec):
            
            update_map = self._update_map[sub.id]
            cur_ver = update_map['old']
            cur_product = cur_ver.product
            new_ver = update_map['new']
            update_note = update_map['note']

            if new_ver:
                updates = True
                new_ver_disp = new_ver.number_padded
            else:
                new_ver_disp = "----"

            output.add_item(
                {
                    source: cur_product.ptask.spec,
                    product: cur_product.name_spec,
                    current: cur_ver.number_padded,
                    new: new_ver_disp,
                    note: update_note,
                },
            )
            
        output.dump(output_format='table')

        if not updates:
            raise ActionAborted("Nothing to update.")

        if not Output.prompt_yes_no(Style.bright + "Update" + Style.reset):
            raise ActionAborted("User chose not to proceed.")
Esempio n. 19
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 ""
Esempio n. 20
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')
Esempio n. 21
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 ""
Esempio n. 22
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')
Esempio n. 23
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 ""
Esempio n. 24
0
    def verify(self):

        desc = "Description"
        ptask = "PTask"
        version = "Version"
        directory = "Directory"
        path = "Path"
        
        output = Output()
        output.header_names = [
            desc,
            ptask,
            version,
            directory,
        ]

        if self.source_version:
            source_version_disp = self.source_version.number_padded
        else:
            source_version_disp = "Latest"

        if self.destination_version:
            destination_version_disp = self.destination_version.number_padded
        else:
            destination_version_disp = "Latest"

        output.add_item(
            {
                desc: 'Source',
                ptask: self.source.spec,
                version: source_version_disp,
                directory: str(self.source_directory),
            },
            color_all=Style.bright,
        )

        output.add_item(
            {
                desc: 'Destination',
                ptask: self.destination.spec,
                version: destination_version_disp,
                directory: str(self.destination_directory),
            },
            color_all=Style.bright,
        )

        output.title = "Confirm:"
        output.dump()

        if not Output.prompt_yes_no(Style.bright + "Sync" + Style.reset):
            raise ActionAborted("Sync canceled by user.")
Esempio n. 25
0
    def verify(self):

        desc = "Description"
        ptask = "PTask"
        version = "Version"
        directory = "Directory"
        path = "Path"
        
        output = Output()
        output.header_names = [
            desc,
            ptask,
            version,
            directory,
        ]

        if self.source_version:
            source_version_disp = self.source_version.number_padded
        else:
            source_version_disp = "Latest"

        if self.destination_version:
            destination_version_disp = self.destination_version.number_padded
        else:
            destination_version_disp = "Latest"

        output.add_item(
            {
                desc: 'Source',
                ptask: self.source.spec,
                version: source_version_disp,
                directory: str(self.source_directory),
            },
            color_all=Style.bright,
        )

        output.add_item(
            {
                desc: 'Destination',
                ptask: self.destination.spec,
                version: destination_version_disp,
                directory: str(self.destination_directory),
            },
            color_all=Style.bright,
        )

        output.title = "Confirm:"
        output.dump()

        if not Output.prompt_yes_no(Style.bright + "Sync" + Style.reset):
            raise ActionAborted("Sync canceled by user.")
Esempio n. 26
0
    def _ptask_info(self):

        # define the fields names
        version = "Current version"
        description = "Description"
        due_date = "Due date"
        priority = "Priority"
        start_date = "Start date"
        status = "Status"
        ptask_type = "Type"

        # define the look of the output
        output = Output()

        # display order of the information
        output.header_names = [
            ptask_type,
            version,
            description,
            status,
            start_date,
            due_date,
            priority,
        ]

        # add all the information
        output.add_item(
            {
                ptask_type: self.ptask.ptask_type,
                version: self.ptask.latest_version.number_padded,
                description: self.ptask.description,
                status: self.ptask.status,
                start_date: str(self.ptask.start_date),
                due_date: str(self.ptask.due_date),
                priority: str(self.ptask.priority),
            },
            color_all=Style.bright,
        )

        # build the title
        title = " {p.spec}".format(p=self.ptask)
        if not self.ptask.active:
            title += " [INACTIVE]"
        title += " "
        output.title = title

        # dump the output as a list of key/value pairs
        output.dump()
Esempio n. 27
0
    def _ptask_info(self):

        # define the fields names
        version = "Current version"
        description = "Description"
        due_date = "Due date"
        priority = "Priority"
        start_date = "Start date"
        status = "Status"
        ptask_type = "Type"

        # define the look of the output
        output = Output()
        
        # display order of the information
        output.header_names = [
            ptask_type,
            version,
            description,
            status,
            start_date,
            due_date,
            priority,
        ]

        # add all the information 
        output.add_item(
            {
                ptask_type: self.ptask.ptask_type,
                version: self.ptask.latest_version.number_padded,
                description: self.ptask.description,
                status: self.ptask.status,
                start_date: str(self.ptask.start_date),
                due_date: str(self.ptask.due_date),
                priority: str(self.ptask.priority),
            },
            color_all=Style.bright,
        )

        # build the title
        title = " {p.spec}".format(p=self.ptask)
        if not self.ptask.active:
            title += " [INACTIVE]"
        title += " "
        output.title = title

        # dump the output as a list of key/value pairs
        output.dump()
Esempio n. 28
0
    def execute(self):

        # output headers. reused while defining the look of the output
        description = 'Description'
        timezone = 'Timezone'
        lat_long = 'Lat/Long'
        active = 'Active'
        code = 'Code'
        host = 'Host'
        filesystem_root = 'Filesystem root'

        # define the look of the output
        output = Output()
        # defining the data headers
        output.header_names = [
            code,
            description,
            host,
            filesystem_root,
            timezone,
            lat_long,
        ]
        output.add_item(
            {
                code: self.location.code,
                description: self.location.description,
                host: self.location.host,
                filesystem_root: self.location.filesystem_root,
                timezone: self.location.timezone,
                lat_long:
                "{l.latitude}, {l.longitude}".format(l=self.location),
            },
            color_all=Style.bright,
        )

        # build the title
        title = " {l.name} ".format(l=self.location)
        if not self.location.active:
            title += " [INACTIVE]"
        title += " "
        output.title = title

        # dump the output as a list of key/value pairs
        output.dump()
Esempio n. 29
0
    def execute(self):

        # output headers. reused while defining the look of the output
        description = 'Description'
        timezone = 'Timezone'
        lat_long = 'Lat/Long'
        active = 'Active'
        code = 'Code'
        host = 'Host'
        filesystem_root = 'Filesystem root'

        # define the look of the output
        output = Output()
        # defining the data headers
        output.header_names = [
            code,
            description,
            host,
            filesystem_root,
            timezone,
            lat_long,
        ]
        output.add_item(
            {
                code: self.location.code,
                description: self.location.description,
                host: self.location.host,
                filesystem_root: self.location.filesystem_root,
                timezone: self.location.timezone,
                lat_long: "{l.latitude}, {l.longitude}".format(l=self.location),
            },
            color_all=Style.bright,
        )
        
        # build the title
        title = " {l.name} ".format(l=self.location)
        if not self.location.active:
            title += " [INACTIVE]"
        title += " "
        output.title = title

        # dump the output as a list of key/value pairs
        output.dump()
Esempio n. 30
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 ""
Esempio n. 31
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 ""
Esempio n. 32
0
    def verify(self):

        name = "Name"
        category = "Category"
        description = "Description"
        file_type = "File type"
        resolution = "Resolution"
        ptask_ver = "PTask version"
        path = "Path"
        note = "Note"

        output = Output()
        output.header_names = [
            name,
            category,
            description,
            file_type,
            resolution,
            ptask_ver,
            path,
            note,
        ]

        output.add_item(
            {
                name: self._name,
                category: self._category,
                description: self._description,
                file_type: self._file_type,
                resolution: self._resolution,
                ptask_ver: self._ptask_version.spec,
                path: self._path,
                note: self._note,
            },
            color_all=Style.bright,
        )

        output.title = "Confirm create:"
        output.dump()

        if not Output.prompt_yes_no(Style.bright + "Create" + Style.reset):
            raise ActionAborted("User chose not to proceed.")
Esempio n. 33
0
    def _info_product(self):

        # fields:
        name = "Name"
        category = "Category"
        description = "Description"
        official = "Official"
        created = "Created"
        creator = "Creator"
        ptask = "PTask"

        output = Output()
        output.header_names = [
            name,
            category,
            description,
            official,
            created,
            creator,
            ptask,
        ]

        output.add_item(
            {
                name: self.product.name,
                category: self.product.category,
                description: self.product.description,
                official: self.product.official_version_number_padded \
                    if self.product.official_version_number != 0 else 'None',
                creator: self.product.creator_username,
                created: _datetime_format(self.product.created),
                ptask: self.product.ptask_spec,
            },
            color_all=Style.bright,
        )

        # build the title
        title = " {p.spec} ".format(p=self.product)
        output.title = title

        # dump the output as a list of key/value pairs
        output.dump()
Esempio n. 34
0
    def execute(self):

        try:
            user = User.get(self.username)
        except UserError:
            self.logger.error(
                'Could not determine user from: "{u}"'.format(u=self.username)
            )
            raise

        # output headers. reused while defining the look of the output
        username = '******'
        last_name = 'Last'
        first_name = 'First'
        email = 'Email'
        active = 'Active'

        # define the look of the output
        output = Output()
        # defining the data headers
        output.header_names = [username, email]
        output.add_item(
            {
                username: user.username,
                email: user.email,
            },
            color_all=Style.bright,
        )
        
        # build the title
        title = " {u.first_name} {u.last_name}".format(u=user)
        if not user.is_active:
            title += " [INACTIVE]"
        title += " "
        output.title = title

        # dump the output as a list of key/value pairs
        output.dump()
Esempio n. 35
0
    def execute(self):

        try:
            user = User.get(self.username)
        except UserError:
            self.logger.error(
                'Could not determine user from: "{u}"'.format(u=self.username))
            raise

        # output headers. reused while defining the look of the output
        username = '******'
        last_name = 'Last'
        first_name = 'First'
        email = 'Email'
        active = 'Active'

        # define the look of the output
        output = Output()
        # defining the data headers
        output.header_names = [username, email]
        output.add_item(
            {
                username: user.username,
                email: user.email,
            },
            color_all=Style.bright,
        )

        # build the title
        title = " {u.first_name} {u.last_name}".format(u=user)
        if not user.is_active:
            title += " [INACTIVE]"
        title += " "
        output.title = title

        # dump the output as a list of key/value pairs
        output.dump()
Esempio n. 36
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')
Esempio n. 37
0
    def verify(self):

        ptask_type_field = "Type"
        spec_field = "Spec"
        description_field = "Description"
        creator_field = "Creator"
        start_date_field = "Starts"
        due_date_field = "Due"
        source_field = "Source"

        output = Output()
        output.header_names = [
            ptask_type_field,
            spec_field,
            description_field,
            creator_field,
            start_date_field,
            due_date_field,
            source_field,
        ]

        if self.source:
            source_disp = self.source.spec
        else:
            source_disp = "None"

        output.add_item(
            {
                ptask_type_field: self.ptask_type,
                spec_field: self.spec,
                description_field: self.description,
                creator_field: self.creator,
                start_date_field:str(self.start_date),
                due_date_field: str(self.due_date),
                source_field: source_disp,
            },
            color_all=Style.bright,
        )

        if self.force:
            output.title = "Creating:"
        else:
            output.title = "Confirm create:"
        output.dump()

        if not self.force:
            if self.ptask:
                if not Output.prompt_yes_no("This ptask already exists. " + \
                    Style.bright + "Continue anyway" + Style.reset):
                    raise ActionAborted(
                        "PTask already exists. User chose not to continue."
                    )
            else:
                prompt_str = "Create " + Style.bright + self.spec + Style.reset
                if self.source:
                    prompt_str += \
                        " + " + \
                        str(len(self.source.children_recursive)) + \
                        " child ptasks"
                if not Output.prompt_yes_no(prompt_str):
                    raise ActionAborted("User chose not to proceed.")
Esempio n. 38
0
    def _print_product_stats(self):

        total_products = 0
        total_versions = 0
        total_reprs = 0
        total_files = 0

        # category
        # products
        # versions
        # representations
        # files

        cat_name = "Category"
        cat_products = "Products"
        cat_vers = "Versions"
        cat_reprs = "Representatiosn"
        cat_files = "Files"

        cat_out = Output()
        cat_out.title = "Product Totals for : {pt} (by category)".format(
            pt=self._ptask.spec)

        cat_out.header_names = [
            cat_name,
            cat_products,
            cat_vers,
            cat_reprs,
            cat_files,
        ]

        cat_out.set_header_alignment({
            cat_name: "right",
            cat_products: "right",
            cat_vers: "right",
            cat_reprs: "right",
            cat_files: "right",
        })

        for (category,
             category_count) in sorted(self._data.products.iteritems()):

            total_products += category_count

            if category in self._data.product_versions:
                ver_count = self._data.product_versions[category]
                total_versions += ver_count
            else:
                ver_count = 0

            if category in self._data.product_representations:
                repr_count = self._data.product_representations[category]
                total_reprs += repr_count
            else:
                repr_count = 0

            if category in self._data.product_repr_files:
                file_count = self._data.product_repr_files[category]
                total_files += file_count
            else:
                file_count = 0

            cat_out.add_item(
                {
                    cat_name: category,
                    cat_products: category_count,
                    cat_vers: ver_count,
                    cat_reprs: repr_count,
                    cat_files: file_count,
                },
                color_all=Style.bright,
            )

        count = 'Products'
        vers = 'Versions'
        reprs = 'Representations'
        files = 'Files'
        vers_product = "Vers/Product"
        reprs_version = "Reprs/Vers"
        files_repr = "Files/Repr"

        totals_out = Output()
        totals_out.title = "Product Totals for : {pt}".format(
            pt=self._ptask.spec)
        totals_out.header_names = [
            count,
            vers,
            reprs,
            files,
            vers_product,
            reprs_version,
            files_repr,
        ]

        totals_out.set_header_alignment({
            count: "right",
            vers: "right",
            reprs: "right",
            files: "right",
            vers_product: "right",
            reprs_version: "right",
            files_repr: "right",
        })

        if total_products:
            vers_product_val = \
                "%.2f" % (total_versions / float(total_products))
        else:
            vers_product_val = "?"

        if total_versions:
            reprs_version_val = \
                "%.2f" % (total_reprs / float(total_versions))
        else:
            reprs_version_val = "?"

        if total_reprs:
            files_repr_val = \
                "%.2f" % (total_files / float(total_reprs))
        else:
            files_repr_val = "?"

        totals_out.add_item(
            {
                count: total_products,
                vers: total_versions,
                reprs: total_reprs,
                files: total_files,
                vers_product: vers_product_val,
                reprs_version: reprs_version_val,
                files_repr: files_repr_val,
            },
            color_all=Style.bright,
        )

        totals_out.dump(output_format='table')

        file_type_hdr = 'Type'
        count = 'Count'

        types_out = Output()
        types_out.title = "Product Totals for : {pt} (by type)".format(
            pt=self._ptask.spec)

        types_out.header_names = [
            file_type_hdr,
            count,
        ]

        types_out.set_header_alignment({
            file_type_hdr: "right",
            count: "right",
        })

        for (file_type, file_type_count) in \
            sorted(self._data.product_repr_files_by_type.iteritems()):

            types_out.add_item(
                {
                    file_type_hdr: file_type,
                    count: file_type_count,
                },
                color_all=Style.bright,
            )

        cat_out.dump(output_format='table')
        types_out.dump(output_format='table')
Esempio n. 39
0
    def _print_ptask_stats(self):

        total_ptasks = 0
        total_vers = 0
        total_subs = 0
        total_products = 0
        total_product_vers = 0

        type_name = "Type"
        type_total = "Count"
        type_vers = "Versions"
        type_ver_avg = "Vers/PTask"
        type_products = "Products"
        type_prod_avg = "Prods/PTask"
        type_product_vers = "ProductVers"
        type_product_vers_avg1 = "ProductVer/PTaskVer"
        type_product_vers_avg2 = "ProductVer/Product"
        type_subs = "Subs"
        type_subs_avg = "Subs/Ver"

        type_out = Output()
        type_out.title = "PTask Totals for : {pt} (by type)".format(
            pt=self._ptask.spec)

        type_out.header_names = [
            type_name, type_total, type_vers, type_ver_avg, type_products,
            type_prod_avg, type_product_vers, type_product_vers_avg1,
            type_product_vers_avg2, type_subs, type_subs_avg
        ]

        type_out.set_header_alignment({
            type_name: "right",
            type_total: "right",
            type_vers: "right",
            type_ver_avg: "right",
            type_products: "right",
            type_prod_avg: "right",
            type_product_vers: "right",
            type_product_vers_avg1: "right",
            type_product_vers_avg2: "right",
            type_subs: "right",
            type_subs_avg: "right",
        })

        for (ptask_type, ptask_type_count) in \
            sorted(self._data.ptasks.iteritems()):

            total_ptasks += ptask_type_count

            if ptask_type in self._data.ptask_versions:
                ver_count = self._data.ptask_versions[ptask_type]
                total_vers += ver_count
            else:
                ver_count = 0

            if ptask_type in self._data.ptask_products:
                product_count = self._data.ptask_products[ptask_type]
                total_products += product_count
            else:
                product_count = 0

            if ptask_type in self._data.ptask_product_versions:
                product_ver_count = self._data.ptask_product_versions[
                    ptask_type]
                total_product_vers += product_ver_count
            else:
                product_ver_count = 0

            if ptask_type in self._data.ptask_subscriptions:
                subs_count = self._data.ptask_subscriptions[ptask_type]
                total_subs += subs_count
            else:
                subs_count = 0

            if ptask_type_count:
                type_ver_avg_val = \
                    '%.2f' % (ver_count / float(ptask_type_count))
                type_prod_avg_val = \
                    '%.2f' % (product_count / float(ptask_type_count))
            else:
                type_ver_avg_val = "?"
                type_prod_avg_val = "?"

            if ver_count:
                type_product_vers_avg1_val = \
                    "%.2f" % (product_ver_count / float(ver_count))
                type_subs_avg_val = \
                    '%.2f' % (subs_count / float(ver_count))
            else:
                type_product_vers_avg1_val = "?"
                type_subs_avg_val = "?"

            if product_count:
                type_product_vers_avg2_val = \
                    "%.2f" % (product_ver_count / float(product_count))
            else:
                type_product_vers_avg2_val = "?"

            type_out.add_item(
                {
                    type_name: ptask_type,
                    type_total: ptask_type_count,
                    type_vers: ver_count,
                    type_ver_avg: type_ver_avg_val,
                    type_products: product_count,
                    type_prod_avg: type_prod_avg_val,
                    type_product_vers: product_ver_count,
                    type_product_vers_avg1: type_product_vers_avg1_val,
                    type_product_vers_avg2: type_product_vers_avg2_val,
                    type_subs: subs_count,
                    type_subs_avg: type_subs_avg_val,
                },
                color_all=Style.bright,
            )

        count = 'PTasks'
        versions = 'Versions'
        products = 'Products'
        product_vers = "ProductVers"
        subs = 'Subs'

        totals_out = Output()
        totals_out.title = "PTask Totals for : {pt}".format(
            pt=self._ptask.spec)
        totals_out.header_names = [
            count,
            versions,
            subs,
            products,
            product_vers,
        ]

        totals_out.set_header_alignment({
            count: "right",
            versions: "right",
            products: "right",
            product_vers: "right",
            subs: "right",
        })
        totals_out.add_item(
            {
                count: total_ptasks,
                versions: total_vers,
                products: total_products,
                product_vers: total_product_vers,
                subs: total_subs,
            },
            color_all=Style.bright,
        )

        totals_out.dump(output_format='table')
        type_out.dump(output_format='table')
Esempio n. 40
0
    def _print_ptask_stats(self):

        total_ptasks = 0
        total_vers = 0
        total_subs = 0
        total_products = 0
        total_product_vers = 0

        type_name = "Type"
        type_total = "Count"
        type_vers = "Versions"
        type_ver_avg = "Vers/PTask"
        type_products = "Products"
        type_prod_avg = "Prods/PTask"
        type_product_vers = "ProductVers"
        type_product_vers_avg1 = "ProductVer/PTaskVer"
        type_product_vers_avg2= "ProductVer/Product"
        type_subs = "Subs"
        type_subs_avg = "Subs/Ver"

        type_out = Output()
        type_out.title = "PTask Totals for : {pt} (by type)".format(
            pt=self._ptask.spec)

        type_out.header_names = [
            type_name,
            type_total,
            type_vers,
            type_ver_avg,
            type_products,
            type_prod_avg,
            type_product_vers,
            type_product_vers_avg1,
            type_product_vers_avg2,
            type_subs, 
            type_subs_avg
        ]

        type_out.set_header_alignment(
            {
                type_name: "right",
                type_total: "right",
                type_vers: "right",
                type_ver_avg: "right",
                type_products: "right",
                type_prod_avg: "right",
                type_product_vers: "right",
                type_product_vers_avg1: "right",
                type_product_vers_avg2: "right",
                type_subs: "right",
                type_subs_avg: "right",
            })

        for (ptask_type, ptask_type_count) in \
            sorted(self._data.ptasks.iteritems()):

            total_ptasks += ptask_type_count

            if ptask_type in self._data.ptask_versions:
                ver_count = self._data.ptask_versions[ptask_type]
                total_vers += ver_count
            else:
                ver_count = 0

            if ptask_type in self._data.ptask_products:
                product_count = self._data.ptask_products[ptask_type]
                total_products += product_count
            else:
                product_count = 0

            if ptask_type in self._data.ptask_product_versions:
                product_ver_count = self._data.ptask_product_versions[ptask_type]
                total_product_vers += product_ver_count
            else:
                product_ver_count = 0

            if ptask_type in self._data.ptask_subscriptions:
                subs_count = self._data.ptask_subscriptions[ptask_type]
                total_subs += subs_count
            else:
                subs_count = 0

            if ptask_type_count:
                type_ver_avg_val = \
                    '%.2f' % (ver_count / float(ptask_type_count))
                type_prod_avg_val = \
                    '%.2f' % (product_count / float(ptask_type_count))
            else:
                type_ver_avg_val = "?"
                type_prod_avg_val = "?"

            if ver_count:
                type_product_vers_avg1_val = \
                    "%.2f" % (product_ver_count / float(ver_count))
                type_subs_avg_val = \
                    '%.2f' % (subs_count / float(ver_count))
            else:
                type_product_vers_avg1_val = "?"
                type_subs_avg_val = "?"

            if product_count:
                type_product_vers_avg2_val = \
                    "%.2f" % (product_ver_count / float(product_count))
            else:
                type_product_vers_avg2_val = "?"

            type_out.add_item(
                {
                    type_name: ptask_type,
                    type_total: ptask_type_count,
                    type_vers: ver_count,
                    type_ver_avg: type_ver_avg_val,
                    type_products: product_count,
                    type_prod_avg: type_prod_avg_val,
                    type_product_vers: product_ver_count,
                    type_product_vers_avg1: type_product_vers_avg1_val, 
                    type_product_vers_avg2: type_product_vers_avg2_val,
                    type_subs: subs_count,
                    type_subs_avg: type_subs_avg_val,
                },
                color_all=Style.bright,
            )

        count = 'PTasks'
        versions = 'Versions'
        products = 'Products'
        product_vers = "ProductVers"
        subs = 'Subs'

        totals_out = Output()
        totals_out.title = "PTask Totals for : {pt}".format(pt=self._ptask.spec)
        totals_out.header_names = [
            count,
            versions,
            subs,
            products,
            product_vers,
        ]

        totals_out.set_header_alignment(
            {
                count: "right",
                versions: "right",
                products: "right",
                product_vers: "right",
                subs: "right",
            })
        totals_out.add_item(
            {
                count: total_ptasks,
                versions: total_vers,
                products: total_products,
                product_vers: total_product_vers,
                subs: total_subs,
            },
            color_all=Style.bright,
        )
        
        totals_out.dump(output_format='table')
        type_out.dump(output_format='table')
Esempio n. 41
0
    def _print_product_stats(self):

        total_products = 0
        total_versions = 0
        total_reprs = 0
        total_files = 0

            # category
            # products
            # versions
            # representations
            # files

        cat_name = "Category"
        cat_products = "Products"
        cat_vers = "Versions"
        cat_reprs = "Representatiosn"
        cat_files = "Files"

        cat_out = Output()
        cat_out.title = "Product Totals for : {pt} (by category)".format(
            pt=self._ptask.spec)

        cat_out.header_names = [
            cat_name,
            cat_products,
            cat_vers,
            cat_reprs,
            cat_files,
        ]

        cat_out.set_header_alignment(
            {
                cat_name: "right",
                cat_products: "right",
                cat_vers: "right",
                cat_reprs: "right",
                cat_files: "right",
            })

        for (category, category_count) in sorted(self._data.products.iteritems()):

            total_products += category_count

            if category in self._data.product_versions:
                ver_count = self._data.product_versions[category]
                total_versions += ver_count
            else:
                ver_count = 0

            if category in self._data.product_representations:
                repr_count = self._data.product_representations[category]
                total_reprs += repr_count
            else:
                repr_count = 0

            if category in self._data.product_repr_files:
                file_count = self._data.product_repr_files[category] 
                total_files += file_count
            else:
                file_count = 0

            cat_out.add_item(
                {
                    cat_name: category,
                    cat_products: category_count,
                    cat_vers: ver_count,
                    cat_reprs: repr_count,
                    cat_files: file_count,
                },
                color_all=Style.bright,
            )
             
        count = 'Products'
        vers = 'Versions'
        reprs = 'Representations'
        files = 'Files'
        vers_product = "Vers/Product"
        reprs_version = "Reprs/Vers"
        files_repr = "Files/Repr"

        totals_out = Output()
        totals_out.title = "Product Totals for : {pt}".format(pt=self._ptask.spec)
        totals_out.header_names = [
            count,
            vers,
            reprs,
            files,
            vers_product,
            reprs_version,
            files_repr,
        ]

        totals_out.set_header_alignment(
            {
                count: "right",
                vers: "right",
                reprs: "right",
                files: "right",
                vers_product: "right",
                reprs_version: "right",
                files_repr: "right",
            }
        )

        if total_products:
            vers_product_val = \
                "%.2f" % (total_versions / float(total_products))
        else:
            vers_product_val = "?"

        if total_versions:
            reprs_version_val = \
                "%.2f" % (total_reprs / float(total_versions))
        else:
            reprs_version_val = "?"

        if total_reprs:
            files_repr_val = \
                "%.2f" % (total_files / float(total_reprs))
        else:
            files_repr_val = "?"

        totals_out.add_item(
            {
                count: total_products,
                vers: total_versions,
                reprs: total_reprs,
                files: total_files,
                vers_product: vers_product_val,
                reprs_version: reprs_version_val,
                files_repr: files_repr_val,
            },
            color_all=Style.bright,
        )
        
        totals_out.dump(output_format='table')

        file_type_hdr = 'Type'
        count = 'Count'

        types_out = Output()
        types_out.title = "Product Totals for : {pt} (by type)".format(
            pt=self._ptask.spec)

        types_out.header_names = [
            file_type_hdr,
            count,
        ]

        types_out.set_header_alignment(
            {
                file_type_hdr: "right",
                count: "right",
            }
        )

        for (file_type, file_type_count) in \
            sorted(self._data.product_repr_files_by_type.iteritems()):

            types_out.add_item(
                {
                    file_type_hdr: file_type,
                    count: file_type_count,
                },
                color_all=Style.bright,
            )

        cat_out.dump(output_format='table')
        types_out.dump(output_format='table')
Esempio n. 42
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')
Esempio n. 43
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 ""