(self, source=None)
return '\n'.join(tip)
Display informations on available sources.
Display informations on available sources.
Display informations on available sources .
def build_status(self, source=None):
        """Display informations on available sources.
        """
        if source is None:
            displayed = sorted(self.sources)
        else:
            if source not in self.sources:
                return 'Source "%s" not in sources.' % source
            displayed = [source]

        missing = '<none>'

        def fmt_keys(l):
            """Nice key_fields formatting."""
            if l is None:
                return missing
            if isinstance(l, (list, tuple, set)):
                return '+'.join(l)
            return str(l)

        def fmt_path(p):
            """Nice path formatting."""
            if isinstance(p, str):
                return str(p)
            if not is_archive(p):
                return p['file']
            return '%s -> %s' % (p['file'], p['extract'])

        tip = [dedent('''
        * Data sources  from %s
        * Configuration from %s
        ''' % (self.sources_dir, self.sources_conf_path))]

        tip.append('-' * 80)
        tip.append('%-20s | %-25s | %s' % ('NAME', 'KEY', 'PATHS (DEFAULT + FAILOVERS)'))
        tip.append('-' * 80)

        for source in displayed:
            config = self.sources[source]

            if config is not None:
                keys  = config.get('key_fields', missing)
                paths = config.get('paths', missing)
                if not paths:
                    paths = missing
            else:
                keys, paths = missing, missing

            if isinstance(paths, (str, dict)):
                paths = [paths]
            tip.append('%-20s | %-25s | %s' % \
                       (source, fmt_keys(keys), '.) %s' % fmt_path(paths[0])))

            for n, path in enumerate(paths[1:], start=1):
                tip.append('%-20s | %-25s | %s' % \
                           ('-', '-', '%s) %s' % (n, fmt_path(path))))

        tip.append('-' * 80)

        return '\n'.join(tip)
def build_status ( self , source = None ) : if source is None : displayed = sorted ( self . sources ) else : if source not in self . sources : return 'Source "%s" not in sources.' % source displayed = [ source ] missing = '<none>' def fmt_keys ( l ) : """Nice key_fields formatting.""" if l is None : return missing if isinstance ( l , ( list , tuple , set ) ) : return '+' . join ( l ) return str ( l ) def fmt_path ( p ) : """Nice path formatting.""" if isinstance ( p , str ) : return str ( p ) if not is_archive ( p ) : return p [ 'file' ] return '%s -> %s' % ( p [ 'file' ] , p [ 'extract' ] ) tip = [ dedent ( '''
        * Data sources  from %s
        * Configuration from %s
        ''' % ( self . sources_dir , self . sources_conf_path ) ) ] tip . append ( '-' * 80 ) tip . append ( '%-20s | %-25s | %s' % ( 'NAME' , 'KEY' , 'PATHS (DEFAULT + FAILOVERS)' ) ) tip . append ( '-' * 80 ) for source in displayed : config = self . sources [ source ] if config is not None : keys = config . get ( 'key_fields' , missing ) paths = config . get ( 'paths' , missing ) if not paths : paths = missing else : keys , paths = missing , missing if isinstance ( paths , ( str , dict ) ) : paths = [ paths ] tip . append ( '%-20s | %-25s | %s' % ( source , fmt_keys ( keys ) , '.) %s' % fmt_path ( paths [ 0 ] ) ) ) for n , path in enumerate ( paths [ 1 : ] , start = 1 ) : tip . append ( '%-20s | %-25s | %s' % ( '-' , '-' , '%s) %s' % ( n , fmt_path ( path ) ) ) ) tip . append ( '-' * 80 ) return '\n' . join ( tip )