Пример #1
0
def list(terse=False, show_command=False, regex=None):
    Namespace = pymod.module.Namespace
    loaded_modules = pymod.mc.get_loaded_modules()
    if not loaded_modules:
        return "No loaded modules\n"

    sio = StringIO()
    loaded_module_names = []
    for loaded in loaded_modules:
        fullname = loaded.fullname
        if loaded.opts:
            fullname += " " + Namespace(**(loaded.opts)).joined(" ")
        loaded_module_names.append(fullname)

    if terse:
        sio.write("\n".join(loaded_module_names))
    elif show_command:
        for module in loaded_module_names:
            sio.write("module load {0}\n".format(module))
    else:
        sio.write("Currently loaded modules\n")
        loaded = [
            "{0}) {1}".format(i + 1, m)
            for (i, m) in enumerate(loaded_module_names)
        ]
        _, width = terminal_size()
        sio.write(colified(loaded, indent=4, width=max(100, width)))

    s = sio.getvalue()
    if regex:
        s = grep_pat_in_string(s, regex, color="G")

    return s
Пример #2
0
 def avail_full(self, regex=None, long_format=False):
     sio = StringIO()
     sio.write("\n")
     _, width = tty.terminal_size()
     # head = lambda x: (" " + x + " ").center(width, "-")
     for path in self:
         directory = path.path
         modules = sorted([m for m in path.modules if m.is_enabled],
                          key=self.sort_key)
         modules = self.filter_modules_by_regex(modules, regex)
         if not os.path.isdir(directory):  # pragma: no cover
             s = colorize("@r{(Directory not readable)}".center(width))
         elif not modules:  # pragma: no cover
             if regex:
                 continue
             s = colorize("@r{(None)}".center(width))
         else:
             modules = [
                 self.colorize(m.format_dl_status()) for m in modules
             ]
             aliases = pymod.alias.get(directory)
             if aliases:  # pragma: no cover
                 for (alias, target) in aliases:
                     i = bisect.bisect_left(modules, alias)
                     insert_key = colorize("@M{%s}@@" % (alias))
                     if long_format:  # pragma: no cover
                         insert_key += " -> %s" % (target)
                     modules.insert(i, insert_key)
             s = colified(modules, width=width)
         directory = directory.replace(os.path.expanduser("~/"), "~/")
         # sio.write(head(directory) + '\n')
         sio.write(colorize("@G{%s}:\n" % (directory)))
         sio.write(s + "\n")
     return sio.getvalue()
Пример #3
0
 def avail(self, terse=False):
     names = sorted([x for x in self.data.keys()])
     if not names:  # pragma: no cover
         return ""
     sio = StringIO()
     if not terse:
         _, width = terminal_size()
         s = colified(names, width=width)
         sio.write("{0}\n{1}\n".format(" Saved clones ".center(width, "-"), s))
     else:
         sio.write("\n".join(c for c in names))
     return sio.getvalue()
Пример #4
0
    def avail(self, terse=False):
        if not self.data:  # pragma: no cover
            return ""

        keys = sorted(list(self.data.keys()))
        fun = lambda key: "{0} -> {1} ({2})".format(
            key,
            self.data[key]["target"],
            colorize("@C{%s}" % self.data[key]["modulepath"]),
        )
        names = [fun(_) for _ in keys]

        sio = StringIO()
        if not terse:
            _, width = terminal_size()
            s = colified(names, width=width)
            sio.write("{0}\n{1}\n".format(" Aliases ".center(width, "-"), s))
        else:
            sio.write("{0}\n".format("\n".join(c for c in names)))
        string = sio.getvalue()
        return string
Пример #5
0
    def avail(self, terse=False, regex=None):
        skip = (pymod.names.default_user_collection, )
        names = sorted([x for x in self.data if x not in skip])

        if regex:
            names = self.filter_collections_by_regex(names, regex)

        if not names:  # pragma: no cover
            return ""

        sio = StringIO()
        if not terse:
            _, width = terminal_size()
            s = colified(names, width=width)
            # sio.write('{0}\n{1}\n'
            #          .format(' Saved collections '.center(width, '-'), s))
            sio.write(colorize("@G{Saved collections}:\n%s\n" % (s)))
        else:
            sio.write("\n".join(c for c in names))
        string = sio.getvalue()
        return string