Ejemplo n.º 1
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.")
Ejemplo n.º 2
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.")
Ejemplo n.º 3
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.")
Ejemplo n.º 4
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.")
Ejemplo n.º 5
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.") 
Ejemplo 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.")
Ejemplo n.º 7
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.")
Ejemplo n.º 8
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.")
Ejemplo n.º 9
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.")
Ejemplo n.º 10
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.")
Ejemplo 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.")
Ejemplo n.º 12
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.")
Ejemplo n.º 13
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.")
Ejemplo n.º 14
0
    def verify(self):

        prompt_str = "\nRefresh subscriptions for " + Style.bright + \
            self.ptask.spec + Style.reset + " version " + Style.bright + \
            self.ptask_version.number_padded + Style.reset + "\n"
        if not Output.prompt_yes_no(prompt_str):
            raise ActionAborted("User chose not to proceed.")
Ejemplo n.º 15
0
    def verify(self):

        if (not self.publish and not self.unpublish and not self.deprecate and
            not self.undeprecate and not self.official and not self.noofficial):
            raise ActionAborted("No updates to perform.")

        print "\nProduct: {b}{s}{n}\n".format(
            b=Style.bright,
            s=self.product.spec,
            n=Style.normal,
        )

        if self.publish:
            self._version_table(self.publish, title="Publish")
        if self.unpublish:
            self._version_table(self.unpublish, title="Un-publish")
        if self.deprecate:
            self._version_table(self.deprecate, title="Deprecate")
        if self.undeprecate:
            self._version_table(self.undeprecate, title="Un-deprecate")
        if self.official:
            self._version_table([self.official], title="Official")
        if self.noofficial:
            print "{o}: {b}{m}{n}\n".format(
                o="No official",
                b=Style.bright,
                m="This product will have no official versions.",
                n=Style.normal,
            )

        if not Output.prompt_yes_no(Style.bright + "Update" + Style.reset):
            raise ActionAborted("User chose not to proceed.")
Ejemplo n.º 16
0
    def verify(self):

        prompt_str = "\nRefresh subscriptions for " + Style.bright + \
            self.ptask.spec + Style.reset + " version " + Style.bright + \
            self.ptask_version.number_padded + Style.reset + "\n"
        if not Output.prompt_yes_no(prompt_str):
            raise ActionAborted("User chose not to proceed.")
Ejemplo n.º 17
0
    def verify(self):

        if (not self.publish and not self.unpublish and not self.deprecate and
            not self.undeprecate and not self.official and not self.noofficial):
            raise ActionAborted("No updates to perform.")

        print "\nProduct: {b}{s}{n}\n".format(
            b=Style.bright,
            s=self.product.spec,
            n=Style.normal,
        )

        if self.publish:
            self._version_table(self.publish, title="Publish")
        if self.unpublish:
            self._version_table(self.unpublish, title="Un-publish")
        if self.deprecate:
            self._version_table(self.deprecate, title="Deprecate")
        if self.undeprecate:
            self._version_table(self.undeprecate, title="Un-deprecate")
        if self.official:
            self._version_table([self.official], title="Official")
        if self.noofficial:
            print "{o}: {b}{m}{n}\n".format(
                o="No official",
                b=Style.bright,
                m="This product will have no official versions.",
                n=Style.normal,
            )

        if not Output.prompt_yes_no(Style.bright + "Update" + Style.reset):
            raise ActionAborted("User chose not to proceed.")
Ejemplo n.º 18
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()
Ejemplo n.º 19
0
    def verify(self):

        if self._lock:
            self._sub_table(self._lock, title="Lock")
        if self._unlock:
            self._sub_table(self._unlock, title="Unlock")

        if not Output.prompt_yes_no(Style.bright + "Edit" + Style.reset):
            raise ActionAborted("User chose not to proceed.")
Ejemplo n.º 20
0
    def prompt(self):

        # get the description
        if not self.description:
            self._description = Output.prompt(
                "\n Please describe the work done in this version:\n    ",
                blank=False,
                separator=">>>"
            )
Ejemplo n.º 21
0
    def verify(self):

        if self._lock:
            self._sub_table(self._lock, title="Lock")
        if self._unlock:
            self._sub_table(self._unlock, title="Unlock")

        if not Output.prompt_yes_no(Style.bright + "Edit" + Style.reset):
            raise ActionAborted("User chose not to proceed.")
Ejemplo n.º 22
0
    def prompt(self):

        if self._message is None:
            self._message = Output.prompt_text_block(
                Style.bright + \
                "\nEnter OOTO message" + \
                Style.normal,
                blank=False,
                help_str="OOTO message can't be blank.",
            )
Ejemplo n.º 23
0
    def prompt(self):

        if self._message is None:
            self._message = Output.prompt_text_block(
                Style.bright + \
                "\nEnter OOTO message" + \
                Style.normal,
                blank=False,
                help_str="OOTO message can't be blank.",
            )
Ejemplo n.º 24
0
    def prompt(self):

        print ""

        product_display = " [{b}{p}{r}]".format(
            b=Style.bright,
            p=self._product,
            r=Style.reset,
        )

        # category menu
        if not self._category:
            self._category = Output.prompt_menu(
                "Product categories",
                "{pd} category".format(pd=product_display),
                zip(*[Product.category_names()] * 2),
            )
       
        # description
        if not self._description:
            self._description = Output.prompt(
                '{pd} description'.format(pd=product_display),
                blank=False,
            )
        
        # file type
        if not self._file_type:
            if not self._file_type:
                self._file_type = Output.prompt(
                    "{pd} file type".format(pd=product_display),
                    blank=False,
                )

        # resolution
        if not self._resolution:
            self._resolution = Output.prompt(
                "{pd} resolution (Return if none)".format(pd=product_display),
                blank=True,
            )
            if not self._resolution:
                self._resolution = 'none'
Ejemplo n.º 25
0
    def prompt(self):

        # ---- prompt for missing fields

        if not self.code or not self.server:
            print "\nPlease enter the following information:"

        if not self.code:
            print "\nThe db code for this location:"
            self._code = Output.prompt(
                "  " + Style.bright + "Location code" + Style.reset,
                blank=False,
            )

        if not self.server:
            print "\nThe address of the data server this location will " + \
                  "connect to:"
            self._server = Output.prompt(
                "  " + Style.bright + "Data server address" + Style.reset,
                blank=False,
            )
Ejemplo n.º 26
0
    def prompt(self):

        if self._subject is None:
            self._subject = Output.prompt(
                Style.bright + \
                "\nEnter a one line description of the problem" + \
                Style.normal,
                blank=False,
                help_str="Subject line can't be blank.",
                separator = ":\n"
            )

        if self._message is None:
            self._message = Output.prompt_text_block(
                Style.bright + \
                "\nEnter a detailed description of the problem.\n" + \
                Style.normal + \
                " Include steps to replicate, errors, etc below.\n" + \
                " You can copy/paste below as well.\n",
                blank=False,
                help_str="Message can't be blank.",
            )
Ejemplo 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()
Ejemplo n.º 28
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.")
Ejemplo 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()
Ejemplo n.º 30
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()
Ejemplo n.º 31
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()
Ejemplo n.º 32
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()
Ejemplo n.º 33
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()
Ejemplo 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()
Ejemplo n.º 35
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 ""
Ejemplo n.º 36
0
    def prompt(self):

        parent_spec = PTaskSpec.parent(self.spec)
        template_options = []

        if parent_spec:
            par_ptask = PTask.get(parent_spec)
            par_ptask_type = par_ptask.ptask_type
        else:
            par_ptask_type = 'none'

        ptask_area = PTaskArea(parent_spec, validate=False)
        master_config = ptask_area.config(
            PROJECT_MASTER_CONFIG_PATH,
            composite_ancestors=True,
        )

        if not master_config or not hasattr(master_config, 'hierarchy'):
            raise ActionError("Unable to find project master config.")

        if not self.ptask_type in master_config.hierarchy[par_ptask_type]:
            raise ActionError(
                "Cannot create '{t}' ptask inside '{p}' ptask".format(
                    t=self.ptask_type,
                    p=par_ptask_type,
                ))

        # ---- prompt for missing fields
        if not self.source and self.ptask_type in master_config.templates:
            for template_spec in master_config.templates[self.ptask_type]:
                trimmed_spec = re.sub("^templates?=",
                                      "",
                                      template_spec,
                                      flags=re.IGNORECASE)
                template_options.append(
                    (re.sub("[=_-]+", " ",
                            trimmed_spec).title(), template_spec))

            self._source = Output.prompt_menu(
                "Select a template to source",
                prompt_str="Selection",
                options=template_options,
                help_str="Please choose from the templates listed.",
                none_option=True,
                custom_prompt="Custom Source",
                custom_blank=False)

        # see if the ptask already exists
        if not self.ptask:
            try:
                self._ptask = PTask.get(self.spec)
            except PTaskError:
                pass
            else:
                if not self.force:
                    raise ActionAborted("PTask already exists.")
                else:
                    if not self._description:
                        self._description = self.ptask.description
                    if not self._start_date:
                        self._start_date = self.ptask.start_date
                    if not self._due_date:
                        self._due_date = self.ptask.due_date

        if (not self.description or not self.start_date or not self.due_date):

            if self.force:
                raise ActionError(
                    "Cannot force creation without required fields.")
            else:
                print "\nPlease enter information about this new {b}{t}{r}:".\
                    format(
                        b=Style.bright,
                        t=self.ptask_type,
                        r=Style.reset,
                    )

        ptask_display = " [{pt}] {b}{s}{r}".format(
            pt=self.ptask_type,
            b=Style.bright,
            s=self.spec,
            r=Style.reset,
        )

        if not self.description:
            self._description = Output.prompt(
                '{pd} description'.format(pd=ptask_display),
                blank=False,
            )

        if not self.start_date:
            self._start_date = Output.prompt_date(
                '{pd} start date'.format(pd=ptask_display),
                blank=False,
            )

        if not self.due_date:
            self._due_date = Output.prompt_date(
                '{pd} due date'.format(pd=ptask_display),
                blank=False,
            )
Ejemplo n.º 37
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')
Ejemplo n.º 38
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')
Ejemplo n.º 39
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')
Ejemplo n.º 40
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.")
Ejemplo n.º 41
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')
Ejemplo n.º 42
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 ""
Ejemplo n.º 43
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 ""
Ejemplo n.º 44
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 ""
Ejemplo n.º 45
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 ""
Ejemplo n.º 46
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')
Ejemplo n.º 47
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')
Ejemplo n.º 48
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')
Ejemplo n.º 49
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 ""
Ejemplo n.º 50
0
    def execute(self):

        MODE = 0770

        # ensure filesystem root exists
        fs_root = self.location.filesystem_root 
        if not os.path.isdir(fs_root):
            try:
                os.makedirs(fs_root, MODE)
            except error as e:
                raise ActionError(
                    "Unable to create filesystem root directory: " + fs_root + \
                    "\n  " + str(e)
                )

        # remember the directories created below
        dir_lookup = {}

        # create standard directories ('projects', 'bash', 'config', etc.)
        for dir_name in ['bash', 'projects', 'config', '.logs', 'plugins']:
            dir_path = os.path.join(fs_root, dir_name)
            dir_lookup[dir_name] = dir_path
            if not os.path.isdir(dir_path):
                try:
                    os.makedirs(dir_path, MODE)
                except error as e:
                    raise ActionError(
                        "Unable to create root subdirectory: " + dir_path + \
                        "\n  " + str(e)
                    )
                    
        # locate the install location to find the bash template
        install_pkg_dir = os.path.dirname(os.path.abspath(dpa.__file__))

        # ---- bash template

        # the file to read from 
        bash_template_file = os.path.join(
            install_pkg_dir, 'data', 'bash', BASH_ACTIVATE_TEMPLATE
        )
        if not os.path.exists(bash_template_file):
            raise ActionError("Unable to locate LOCATION template bash script.")

        # the file to write to
        bash_activate_file = os.path.join(
            dir_lookup['bash'], BASH_ACTIVATE_TEMPLATE
        )

        # ---- readme file

        # readme file
        bash_readme_template_file = os.path.join(
            install_pkg_dir, 'data', 'bash', BASH_README_TEMPLATE
        )
        if not os.path.exists(bash_readme_template_file):
            raise ActionError("Unable to locate README template file.")

        # the file to write to
        bash_readme_file = os.path.join(
            dir_lookup['bash'], BASH_README_TEMPLATE
        )

        # ---- format template files

        file_pairs = [
            (bash_template_file, bash_activate_file),
            (bash_readme_template_file, bash_readme_file),
        ]

        replacements = (
            ("__DPA_LOCATION_CODE__", self.location.code),
            ("__DPA_DATA_SERVER__", self.server),
            ("__DPA_FILESYSTEM_ROOT__", self.location.filesystem_root),
        )

        # handle the file formatting and writing
        for in_file_path, out_file_path in file_pairs:
            with open(in_file_path) as in_file:
                with open(out_file_path, 'w') as out_file:
                    text = in_file.read()

                    for in_str, out_str in replacements:
                        text = text.replace(in_str, out_str)

                    # write new text to bash file in config dir
                    out_file.write(text)

        # print info to user about bash file to source 
        Output.text(
            "\nA bash script has been created to activate the pipeline in " + \
            "this location. The path to the bash script is: \n\n" + \
            "  " + Style.bright + bash_activate_file + Style.reset + "\n\n" + \
            "See the README in the same directory for instructions on how " + \
            "to reference the script.\n",
            margin=4,
        )
Ejemplo n.º 51
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')