def _installed_versions(): if parse_version(pip.__version__) >= parse_version('10.0.0'): installed_dists = get_installed_distributions(local_only=False) else: installed_dists = get_installed_distributions() return {d.project_name: d for d in installed_dists}
def exception_message(): """Creates a message describing an unhandled exception.""" def get_os_release(): """Returns detailed OS release.""" if platform.linux_distribution()[0]: return " ".join(platform.linux_distribution()) elif platform.mac_ver()[0]: return "%s %s" % (platform.mac_ver()[0], platform.mac_ver()[2]) else: return "Unknown" msg = ( "Oops! Cuckoo failed in an unhandled exception!\nSometimes bugs are " "already fixed in the development release, it is therefore " "recommended to retry with the latest development release available " "%s\nIf the error persists please open a new issue at %s\n\n" % (GITHUB_URL, ISSUES_PAGE_URL)) msg += "=== Exception details ===\n" msg += "Cuckoo version: %s\n" % version msg += "OS version: %s\n" % os.name msg += "OS release: %s\n" % get_os_release() msg += "Python version: %s\n" % platform.python_version() msg += "Python implementation: %s\n" % platform.python_implementation() msg += "Machine arch: %s\n" % platform.machine() try: import pip._internal as pip except ImportError: import pip msg += "Modules: %s\n\n" % " ".join( sorted("%s:%s" % (package.key, package.version) for package in pip.get_installed_distributions())) return msg
def main(): parser = get_parser() args = parser.parse_args() pkgs = get_installed_distributions(local_only=args.local_only, user_only=args.user_only) dist_index = build_dist_index(pkgs) tree = construct_tree(dist_index) if args.json: print(render_json(tree, indent=4)) return 0 elif args.json_tree: print(render_json_tree(tree, indent=4)) return 0 elif args.output_format: output = dump_graphviz(tree, output_format=args.output_format) print_graphviz(output) return 0 return_code = 0 # show warnings about possibly conflicting deps if found and # warnings are enabled if args.warn != 'silence': conflicting = conflicting_deps(tree) if conflicting: print('Warning!!! Possibly conflicting dependencies found:', file=sys.stderr) for p, reqs in conflicting.items(): pkg = p.render_as_root(False) print('* {}'.format(pkg), file=sys.stderr) for req in reqs: req_str = req.render_as_branch(False) print(' - {}'.format(req_str), file=sys.stderr) print('-' * 72, file=sys.stderr) cyclic = cyclic_deps(tree) if cyclic: print('Warning!! Cyclic dependencies found:', file=sys.stderr) for a, b, c in cyclic: print('* {0} => {1} => {2}'.format(a.project_name, b.project_name, c.project_name), file=sys.stderr) print('-' * 72, file=sys.stderr) if args.warn == 'fail' and (conflicting or cyclic): return_code = 1 show_only = set(args.packages.split(',')) if args.packages else None tree = render_tree(tree if not args.reverse else reverse_tree(tree), list_all=args.all, show_only=show_only, frozen=args.freeze) print(tree) return return_code
def installed_packages(): """Iterate on all packages installed in the current python environment. return: (iter of str) """ pip.utils.pkg_resources = imp.reload(pip.utils.pkg_resources) for pjt in get_installed_distributions(): yield pjt.project_name
def get_pip_list(): string = "" ignore_packages = ["setuptools", "pip", "python", "mirage", "console"] packages = get_installed_distributions(local_only = True, skip = ignore_packages) for package in packages: string += "+ " + package.project_name + " " + package.version + " \n" return string
def exception_message(): """Creates a message describing an unhandled exception.""" def get_os_release(): """Returns detailed OS release.""" if platform.linux_distribution()[0]: return " ".join(platform.linux_distribution()) elif platform.mac_ver()[0]: return "%s %s" % (platform.mac_ver()[0], platform.mac_ver()[2]) else: return "Unknown" msg = ( "Oops! Cuckoo failed in an unhandled exception!\nSometimes bugs are " "already fixed in the development release, it is therefore " "recommended to retry with the latest development release available " "%s\nIf the error persists please open a new issue at %s\n\n" % (GITHUB_URL, ISSUES_PAGE_URL) ) msg += "=== Exception details ===\n" msg += "Cuckoo version: %s\n" % version msg += "OS version: %s\n" % os.name msg += "OS release: %s\n" % get_os_release() msg += "Python version: %s\n" % platform.python_version() msg += "Python implementation: %s\n" % platform.python_implementation() msg += "Machine arch: %s\n" % platform.machine() try: import pip._internal as pip except ImportError: import pip msg += "Modules: %s\n\n" % " ".join(sorted( "%s:%s" % (package.key, package.version) for package in pip.get_installed_distributions() )) return msg
#!/usr/bin/env python # Prints when python packages were installed from datetime import datetime import os from pip._internal import get_installed_distributions if __name__ == "__main__": packages = [] for package in get_installed_distributions(): package_name_version = f"{package.project_name}=={package._version}" try: module_dir = next(package._get_metadata('top_level.txt')) package_location = os.path.join(package.location, module_dir) os.stat(package_location) except (StopIteration, OSError): try: package_location = os.path.join(package.location, package.key) os.stat(package_location) except: package_location = package.location modification_time = os.path.getctime(package_location) modification_time = datetime.fromtimestamp(modification_time) packages.append([modification_time, package_name_version]) for modification_time, package_name_version in sorted(packages): print("{0} - {1}".format(modification_time, package_name_version))
def check_pymongo(): for package in get_installed_distributions(): if package.project_name == 'pymongo': return True return False
from os import listdir from pip._internal import main from pip._internal import get_installed_distributions dist_list = get_installed_distributions() dist_names = [dist.project_name for dist in dist_list] #print(dist_names); main(["install", "pygubu"]) import os.path import sys, glob, codecs, pygubu, xml import xml.etree.ElementTree as ET from difflib import SequenceMatcher #Load correct tk try: import tkinter as tk # for python 3 except: import Tkinter as tk # for python 2 #switch to utf8 sys.stdout = codecs.getwriter("utf-8")(sys.stdout.detach()) #Finds all xml files starting with GTIP def findGTIPXML(scanDir): matchingFiles = [] for root, dirs, files in os.walk(scanDir): for file in files: if file.endswith(".xml") and file.startswith('GTIP'): fPath = os.path.join(root, file) matchingFiles.append(fPath) print(str(len(matchingFiles)))
#!/usr/bin/env python3 from pip._internal import get_installed_distributions from subprocess import call for dist in get_installed_distributions(): call('pip3 install --upgrade ' + dist.project_name, shell=True)
def get_installed_packages(): installed = pip.get_installed_distributions() installed_packages = [package.project_name for package in installed] return installed_packages
import pip._internal as pip print([i.key for i in pip.get_installed_distributions()]) # or pip.main(['freeze'])
def main(): default_skip = ['setuptools', 'pip', 'python', 'distribute'] skip = default_skip + ['pipdeptree'] pkgs = pip.get_installed_distributions(local_only=True, skip=skip) pickle.dump(pkgs, sys.stdout) return 0