1#!/usr/bin/env python 2# -*- coding: utf-8 -*- 3 4"""HelpDev - Extracts information about the Python environment easily. 5 6Authors: 7 - Daniel Cosmo Pizetta <daniel.pizetta@usp.br> 8 9Since: 10 2019/04/16 11 12License: 13 MIT 14 15""" 16 17 18import argparse 19import sys 20 21import helpdev 22 23 24def parse_args(): 25 """Parse arguments. 26 27 Returns: 28 argparse.Namespace: parsed arguments. 29 """ 30 parser = argparse.ArgumentParser( 31 description=__doc__.split("\n")[0], 32 add_help=False, 33 formatter_class=argparse.RawTextHelpFormatter) 34 35 parser.add_argument('--hardware', action='store_true', 36 help="CPU, memory and architecture (PEI)\n\n") 37 38 parser.add_argument('--os', action='store_true', 39 help="Operating system (PEI)\n\n") 40 41 parser.add_argument('--thread', action='store_true', 42 help="Thread specification in the system (PEI)\n\n") 43 44 parser.add_argument('--distributions', action='store_true', 45 help="All options for distributions below (PED)") 46 parser.add_argument('--python', action='store_true', 47 help="Python distribution (PED)") 48 parser.add_argument('--conda', action='store_true', 49 help="Conda/Anaconda Python distribution (PED)\n\n") 50 51 parser.add_argument('--packages', nargs='?', const="", default=None, type=str, 52 help="All options for packages below, except '-e' (PED).\n" 53 "Filter PACKAGE(s) to show. Accepts regex, separator is ','") 54 parser.add_argument('--packages-pip', action='store_true', 55 help="PIP installed packages + PIP check (PED)") 56 parser.add_argument('--packages-pip-e', action='store_true', 57 help="PIP locally installed packages + PIP check (PED)") 58 parser.add_argument('--packages-conda', action='store_true', 59 help="CONDA installed packages (PED)") 60 parser.add_argument('--packages-conda-e', action='store_true', 61 help="CONDA locally installed packages (PED)\n\n") 62 63 parser.add_argument('--qt', action='store_true', 64 help="All options for Qt below (PEAD)") 65 parser.add_argument('--qt-bindings', action='store_true', 66 help="Available Qt bindings (PyQt/Pyside) (PEAD)") 67 parser.add_argument('--qt-abstractions', action='store_true', 68 help="Available Qt abstractions (QtPy/Qt.Py/PyQtGraph)(PEAD)\n\n") 69 70 parser.add_argument('--numbers', action='store_true', 71 help="All options for numbers below (PEI)") 72 parser.add_argument('--float', action='store_true', 73 help="Float representation in the system (PEI)") 74 parser.add_argument('--int', action='store_true', 75 help="Integer representation in the system (PEI)\n\n") 76 77 parser.add_argument('--network', nargs='?', const=5, default=None, type=int, 78 help="Network information, DNS and load for usual sites (PEI). \n" 79 "NETWORK timeout defaults to 5s. 0 is disabled\n\n") 80 81 parser.add_argument('--personal', action='store_true', 82 help="All options for personal information below (PEAD)") 83 parser.add_argument('--path', action='store_true', 84 help="Show Python current paths i.e. 'sys.path' (PEAD)") 85 parser.add_argument('--scope', action='store_true', 86 help="Show Python current scope i.e. 'dir()' (PEAD)\n\n") 87 88 parser.add_argument('--all', action='store_true', 89 help="Run all options above, except 'personal' (PEAD)") 90 parser.add_argument('--all-for-sure', action='store_true', 91 help="Run all options above, INCLUDING 'PERSONAL' (PEAD)\n\n") 92 93 parser.add_argument('--report', default=None, type=str, 94 help="Apply a custom filter from REPORT package.\n" 95 "The filter is given by REPORT.custom_helpdev(version)\n\n") 96 97 parser.add_argument('--help', '-h', action='help', 98 help="Show the program's help") 99 parser.add_argument('--version', '-v', action='version', 100 version='v{}'.format(helpdev.__version__), 101 help="Show the program's version") 102 103 arguments = parser.parse_args() 104 105 return arguments 106 107 108def main(): # noqa:R701,R0912 109 """Main function.""" 110 args = parse_args() 111 112 info = {} 113 114 # To not repeat the test 115 if args.all_for_sure: 116 args.all = True 117 118 no_args = len(sys.argv) <= 1 119 120 # Commom hardware, OS and Thread info 121 if args.hardware or args.all or no_args: 122 info.update(helpdev.check_hardware()) 123 if args.os or args.all or no_args: 124 info.update(helpdev.check_os()) 125 if args.thread or args.all or no_args: 126 info.update(helpdev.check_thread()) 127 128 # Distribution info 129 if args.python or args.all or no_args or args.distributions: 130 info.update(helpdev.check_python()) 131 if args.conda or args.all or no_args or args.distributions: 132 info.update(helpdev.check_conda()) 133 134 # Packages, PIP and Conda info 135 if args.packages_pip or args.all or args.packages or args.packages == '': 136 info.update(helpdev.check_python_packages(packages=args.packages)) 137 if args.packages_pip_e: 138 info.update(helpdev.check_python_packages(edit_mode=True, packages=args.packages)) 139 if args.packages_conda or args.all or args.packages or args.packages == '': 140 info.update(helpdev.check_conda_packages(packages=args.packages)) 141 if args.packages_conda_e or args.all: 142 info.update(helpdev.check_conda_packages(edit_mode=True, packages=args.packages)) 143 144 # Qt, binding and abstraction info 145 if args.qt_bindings or args.qt or args.all or no_args: 146 info.update(helpdev.check_qt_bindings()) 147 if args.qt_abstractions or args.qt or args.all or no_args: 148 info.update(helpdev.check_qt_abstractions()) 149 150 # Numbers info 151 if args.float or args.all or args.numbers: 152 info.update(helpdev.check_float()) 153 if args.int or args.all or args.numbers: 154 info.update(helpdev.check_int()) 155 156 # Network info 157 if args.network: 158 info.update(helpdev.check_network(args.network)) 159 160 # Personal info for self-check, not executed when --all is passed 161 # Needs to use all-for-sure to be listed 162 # This may contains personal folder adresses, be carefull sharing 163 if args.path or args.all_for_sure or args.personal: 164 info.update(helpdev.check_path()) 165 if args.scope or args.all_for_sure or args.personal: 166 info.update(helpdev.check_scope()) 167 168 if args.report: 169 info.update(helpdev.customize(package=args.report)) 170 elif args.report == '': 171 print("You must pass a package name to report [--report PACKAGE_NAME]") 172 173 helpdev.print_output(info) 174