Exemplo n.º 1
0
 def do_multable(self, subcmd, opts, number=10, times=25):
     """${cmd_name}: Print multiplication table
     
     To demonstrate `colprint` feature
     
     ${cmd_usage}
     ${cmd_option_list}
     """
     with self.bootstrapped():
         textui.colprint([[str(x * y) for y in range(1, 1 + int(times))]
                          for x in range(1, 1 + int(number))])
Exemplo n.º 2
0
 def do_multable(self, subcmd, opts, number=10, times=25):
     """${cmd_name}: Print multiplication table
     
     To demonstrate `colprint` feature
     
     ${cmd_usage}
     ${cmd_option_list}
     """
     with self.bootstrapped():
         textui.colprint([
             [str(x*y) for y in range(1, 1+int(times))]
             for x in range(1, 1+int(number))
         ])
Exemplo n.º 3
0
    def do_list(self, subcmd, opts):
        """${cmd_name}: List the currently installed packages

        As of now, PyPM only lists packages installed via PyPM
        itself. Eventually, the plan is to list every packages installed by all
        package managers.
        
        ${cmd_usage}
        ${cmd_option_list}
        """
        with self.bootstrapped():
            l = list(self.pypmenv.installed_store.find_all_packages())
            l = list(sorted(l, key=attrgetter('name'))) # sort by name
            if opts.short:
                for ipkg in l: print(ipkg.name)
            else:
                textui.colprint([
                    [ipkg.name, ipkg.printable_version, ipkg.summary or '']
                    for ipkg in l])
            return l
Exemplo n.º 4
0
def test_colprint():
    sample_table = [
        ['python-daemon', '4.5.7.7.3-1', 'blah foo meh yuck'],
        ['foo',           '6.1', ('some very loooooooooong string here .. I '
                                  'suggest we make it even longer .. so longer '
                                  ' that normal terminal widths should entail '
                                  'colprint to trim the string')]]
    textui.colprint(sample_table)

    # try with empty inputs
    textui.colprint(None)
    textui.colprint([])
Exemplo n.º 5
0
            ).save()
        log.debug('playlist items count: %s', PlaylistItems.objects.count())

if __name__ == '__main__':
    from applib.textui import colprint

    logging.basicConfig(level=logging.DEBUG, format='%(message)s')

    db = setup_eve_mongoengine()

    # reduce votes to per-player, per-map
    vr = VoteReduce()
    vr.vote_reduce()

    # get all valid maps
    pl = Playlister()
    pl.generate_playlist()

    x = list()
    x.append(["Map", "Type", "Score", "Modifiers", "Votes"])

    playlistitems = list(PlaylistItems.objects.order_by('score'))
    for pli in playlistitems:
        x.append([
            pli.gamemap.name, str(pli.gametype), str(pli.score),
            ", ".join(['{name}:{factor}'.format(**m) for m in pli.modifiers]),
            ", ".join(['{0.player.name}:{0.vote}'.format(v) for v in pli.votes])
        ])
    x.append(["Map", "Type", "Score", "Modifiers", "Votes"])
    colprint(x)
Exemplo n.º 6
0
    def do_search(self, subcmd, opts, *keywords):
        """${cmd_name}: Search for a package by name or description

        In the search results, the first column (if available) may show the
        package status marker: 'i' means the package is installed; 'u' means a
        newer version of that package is available.

        If no KEYWORDS are given, all available packages are listed.
        
        ${cmd_usage}
        ${cmd_option_list}
        """
        u = 'http://code.activestate.com/pypm/search:{0}/'.format('+'.join(keywords))
        with self.bootstrapped():
            if opts.web:
                import webbrowser
                webbrowser.open(u)
            else:
                self._autosync()
                
                results = list(self.pypmenv.repo_store.search(*keywords))
                
                # Find the list of installed packages; useful to mark the
                # search results later
                installed = {}
                for pkg in self.pypmenv.installed_store.find_all_packages():
                    installed[pkg.name] = pkg

                # prune duplicates
                verlists = collections.defaultdict(list)
                for pkg in results:
                    verlists[pkg.name].append(pkg)
                for k, verlist in verlists.items():
                    verlist.sort(key=attrgetter('version_key'), reverse=True)
                    
                # prepare what needs to be printed
                output_table = []
                is_be_user = licensing.user_has_be_license()
                print_be_warning = False
                for (name, verlist) in sorted(verlists.items()):
                    pkg = verlist[0] # pick the latest version
                    mark = []
                    
                    # BE mark
                    if pkg.requires_be_license and not is_be_user:
                        mark.append('[BE]')
                        print_be_warning = True
                        
                    # Status mark (installed, upgrade)
                    if pkg.name in installed:
                        available_key = pkg.version_key
                        installed_key = installed[pkg.name].version_key
                        if available_key > installed_key:
                            mark.append('u')
                        else:
                            mark.append('i')
                    
                    output_table.append([
                        ' '.join(mark), name, pkg.summary or ''])
                    
                # If the user is not a BE user and there are BE-only packages
                # in the search results, show the standard BE warning message.
                if print_be_warning:
                    sys.stderr.write((
                        '*** Packages marked [BE] below require a valid \n'
                        '*** Business Edition license to install. Please visit\n'
                        '*** {0} for more details.\n\n').format(
                            licensing.BE_HOME_PAGE))

                if output_table:
                    textui.colprint(output_table)
                else:
                    LOG.warn("no matches found for `%s`; try PyPM Index:\n  %s",
                             ' '.join(keywords), u)
                
                return results