示例#1
0
文件: pippel.py 项目: ocodo/.emacs.d
 def get_installed_packages(self):
     final = []
     get_list = ListCommand()
     options,args = get_list.parse_args(["--outdated"])
     for package in get_installed_distributions():
         name = str(package).split(" ")[0]
         if name == "team": continue
         for pkg in get_list.iter_packages_latest_infos([package], options):
             latest = str(pkg.latest_version)
         for attributes in search_packages_info([name]):   
             result = {"name": attributes["name"],
                       "version": attributes["version"],
                       "latest": latest,
                       "summary": attributes["summary"],
                       "home-page": attributes["home-page"]}
         final.append(result)
     return final
示例#2
0
 def get_installed_packages(self):
     final = []
     get_list = ListCommand()
     options,args = get_list.parse_args(["--outdated"])
     for package in get_installed_distributions():
         name = str(package).split(" ")[0]
         if name == "team": continue
         for pkg in get_list.iter_packages_latest_infos([package], options):
             latest = str(pkg.latest_version)
         for attributes in search_packages_info([name]):   
             result = {"name": attributes["name"],
                       "version": attributes["version"],
                       "latest": latest,
                       "summary": attributes["summary"],
                       "home-page": attributes["home-page"]}
         final.append(result)
     return final
示例#3
0
 def get_installed_packages(self):
     # type: () -> List[Dict[str, str]]
     try:
         get_list = ListCommand()
     except TypeError:
         get_list = ListCommand("Pippel",
                                "Backend server for the Pippel service.")
     options, args = get_list.parse_args(["--outdated"])
     packages = [
         package for package in get_installed_distributions()
         if package.key != "team"
     ]
     final = [
         {
             "name": attributes.get("name"),
             "version": attributes.get("version"),
             "latest": str(getattr(package, "latest_version")),
             "summary": attributes.get("summary"),
             "home-page": attributes.get("home-page")
         } for package in get_list.iter_packages_latest_infos(
             packages, options)
         for attributes in search_packages_info([package.key])  # noqa
     ]
     # TODO: To profile performance speed of snippet above and below.
     # final = [
     #     {"name": attributes.get("name"),
     #      "version": attributes.get("version"),
     #      "latest": str(getattr(latest_info, "latest_version")),
     #      "summary": attributes.get("summary"),
     #      "home-page": attributes.get("home-page")
     #     }
     #     for latest_info, attributes in zip(
     #             [get_list.iter_packages_latest_infos(packages, options),
     #              search_packages_info([getattr(package, "key")
     #                                    for package in packages])]
     #     )
     # ]
     return final
    data, header = format_for_columns(packages, opts)
    data.insert(0, header)
    pkg_str, sizes = tabulate(data)
    pkg_str.insert(1, " ".join(map(lambda x: '-' * x, sizes)))
    pkg_str.append(
        f'\nThere are {len(packages)} packages to be upgraded.'
        if len(packages) > 1 else '\nThere is one package to be upgraded.')
    print('\n'.join(pkg_str))


if __name__ == '__main__':
    main_opts = parse_args()
    list_cmd = ListCommand()
    list_opts = list_cmd.parse_args(['--outdated'])[0]
    distributions = [
        d for d in list_cmd.iter_packages_latest_infos(
            get_installed_distributions(), list_opts)
        if d.latest_version > d.parsed_version
    ]
    distributions = sorted(distributions, key=lambda p: p.project_name.lower())
    if not distributions:
        print('There are no packages to be upgraded.')
        exit(0)
    print_distributions(distributions, list_opts)
    if main_opts.show_upgradeable:
        exit(0)
    if main_opts.filter:
        filters = [string.lower() for string in main_opts.filter]
        excluded = []
        for package in distributions:
            if package.project_name.lower() in filters:
                excluded.append(