def explore_show_summary(self, list, index=False,
                             expected=None, context=None):
        """Show summary of one capability document.

        Given a capability document or index (in list, index True if it is an
        index), write out a simply textual summary of the document with all
        related documents shown as numbered options (of the form
        [#] ...description...) which will then form a menu for the next
        exploration.

        If expected is not None then it should be a list of expected document
        types. If this is set then a warning will be printed if list is not
        one of these document types.

        Look for certain top-level link types including rel="up".
        """
        num_entries = len(list.resources)
        capability = '(unknown capability)'
        if ('capability' in list.md):
            capability = list.md['capability']
        if (index):
            capability += 'index'
        print(
            "Parsed %s document with %d entries:" %
            (capability, num_entries))
        if (expected is not None and capability not in expected):
            print("WARNING - expected a %s document" % (','.join(expected)))
        if (capability not in ['description', 'descriptionoindex', 'capabilitylist',
                               'resourcelist', 'resourcelistindex', 'changelist', 'changelistindex',
                               'resourcedump', 'resourcedumpindex', 'changedump', 'changedumpindex',
                               'resourcelist-archive', 'resourcedump-archive',
                               'changelist-archive', 'changedump-archive']):
            print("WARNING - unknown %s document type" % (capability))
        to_show = num_entries
        if (num_entries > 21):
            to_show = 20
        # What capability entries are allowed/expected?
        entry_caps = self.allowed_entries(capability)
        options = {}
        n = 0
        # Look for <rs:ln> elements in this document
        ln_describedby = list.link('describedby')
        if (ln_describedby):
            if ('href' in ln_describedby):
                uri = ln_describedby['href']
                print("[%s] rel='describedby' link to %s" % ('d', uri))
                uri = self.expand_relative_uri(context, uri)
                options['d'] = Resource(uri, capability='resource')
            else:
                print("WARNING - describedby link with no href, ignoring")
        ln_up = list.link('up')
        if (ln_up):
            if ('href' in ln_up):
                uri = ln_up['href']
                print("[%s] rel='up' link to %s" % ('u', uri))
                uri = self.expand_relative_uri(context, uri)
                options['u'] = Resource(uri)
            else:
                print("WARNING - up link with no href, ignoring")
        ln_index = list.link('index')
        if (ln_index):
            if ('href' in ln_index):
                uri = ln_index['href']
                print("[%s] rel='index' link to %s" % ('i', uri))
                uri = self.expand_relative_uri(context, uri)
                options['i'] = Resource(uri)
            else:
                print("WARNING - index link with no href, ignoring")
        # Show listed resources as numbered options
        for r in list.resources:
            if (n >= to_show):
                print("(not showing remaining %d entries)" % (num_entries - n))
                break
            n += 1
            options[str(n)] = r
            print("[%d] %s" % (n, r.uri))
            if (self.verbose):
                print("  " + str(r))
            r.uri = self.expand_relative_uri(context, r.uri)
            if (r.capability is not None):
                warning = ''
                if (r.capability not in entry_caps):
                    warning = " (EXPECTED %s)" % (' or '.join(entry_caps))
                print("  %s%s" % (r.capability, warning))
            elif (len(entry_caps) == 1):
                r.capability = entry_caps[0]
                print(
                    "  capability not specified, should be %s" %
                    (r.capability))
        return(options, capability)
def explore_show_summary ( self , list , index = False , expected = None , context = None ) : num_entries = len ( list . resources ) capability = '(unknown capability)' if ( 'capability' in list . md ) : capability = list . md [ 'capability' ] if ( index ) : capability += 'index' print ( "Parsed %s document with %d entries:" % ( capability , num_entries ) ) if ( expected is not None and capability not in expected ) : print ( "WARNING - expected a %s document" % ( ',' . join ( expected ) ) ) if ( capability not in [ 'description' , 'descriptionoindex' , 'capabilitylist' , 'resourcelist' , 'resourcelistindex' , 'changelist' , 'changelistindex' , 'resourcedump' , 'resourcedumpindex' , 'changedump' , 'changedumpindex' , 'resourcelist-archive' , 'resourcedump-archive' , 'changelist-archive' , 'changedump-archive' ] ) : print ( "WARNING - unknown %s document type" % ( capability ) ) to_show = num_entries if ( num_entries > 21 ) : to_show = 20 entry_caps = self . allowed_entries ( capability ) options = { } n = 0 ln_describedby = list . link ( 'describedby' ) if ( ln_describedby ) : if ( 'href' in ln_describedby ) : uri = ln_describedby [ 'href' ] print ( "[%s] rel='describedby' link to %s" % ( 'd' , uri ) ) uri = self . expand_relative_uri ( context , uri ) options [ 'd' ] = Resource ( uri , capability = 'resource' ) else : print ( "WARNING - describedby link with no href, ignoring" ) ln_up = list . link ( 'up' ) if ( ln_up ) : if ( 'href' in ln_up ) : uri = ln_up [ 'href' ] print ( "[%s] rel='up' link to %s" % ( 'u' , uri ) ) uri = self . expand_relative_uri ( context , uri ) options [ 'u' ] = Resource ( uri ) else : print ( "WARNING - up link with no href, ignoring" ) ln_index = list . link ( 'index' ) if ( ln_index ) : if ( 'href' in ln_index ) : uri = ln_index [ 'href' ] print ( "[%s] rel='index' link to %s" % ( 'i' , uri ) ) uri = self . expand_relative_uri ( context , uri ) options [ 'i' ] = Resource ( uri ) else : print ( "WARNING - index link with no href, ignoring" ) for r in list . resources : if ( n >= to_show ) : print ( "(not showing remaining %d entries)" % ( num_entries - n ) ) break n += 1 options [ str ( n ) ] = r print ( "[%d] %s" % ( n , r . uri ) ) if ( self . verbose ) : print ( "  " + str ( r ) ) r . uri = self . expand_relative_uri ( context , r . uri ) if ( r . capability is not None ) : warning = '' if ( r . capability not in entry_caps ) : warning = " (EXPECTED %s)" % ( ' or ' . join ( entry_caps ) ) print ( "  %s%s" % ( r . capability , warning ) ) elif ( len ( entry_caps ) == 1 ) : r . capability = entry_caps [ 0 ] print ( "  capability not specified, should be %s" % ( r . capability ) ) return ( options , capability )
Show summary of one capability document.

        Given a capability document or index (in list, index True if it is an
        index), write out a simply textual summary of the document with all
        related documents shown as numbered options (of the form
        [#] ...description...) which will then form a menu for the next
        exploration.

        If expected is not None then it should be a list of expected document
        types. If this is set then a warning will be printed if list is not
        one of these document types.

        Look for certain top-level link types including rel="up".