def run(self, cmdln_class): """Run the application using the given cmdln processor. This method also ensures configuration of logging handlers for console """ assert issubclass(cmdln_class, Cmdln) l = logging.getLogger('') log.setup_trace(l, self.locations.log_file_path) cmdln_class(install_console=True).main()
def main(arguments=None): """Invoke the client command `arguments` is the list of arguments to PyPM; eg:: >>> from pypm.client.command import main >>> ret = main(['install', 'ipython']) [... installs ipython ...] >>> Note that the sub-commands are designed to return the Python objects for further use; `main()` returns them as-it-is:: >>> installed_packages = main(['ls']) The PyPM script invokes `main()` without any arguments - therby using sys.argv (expected. """ l = logging.getLogger('') log.setup_trace(l, application.locations.log_file_path) api_use = arguments is not None if api_use: assert isinstance(arguments, list), ( 'invalid type for `arguments` -- ' 'expected a list, got %s' % type(arguments)) argv = ['pypm'] + arguments else: argv = sys.argv if len(argv) < 2: # The user has just typed 'pypm'; likely he is a newbie # We should not intimidate him with our huge help text. concise_help = r"""PyPM {0} (Python Package Manager) brief help: Type "pypm install PACKAGE" to install a package. Type "pypm search KEYWORDS" to search for packages. Type "pypm upgrade" to upgrade installed packages. Type "pypm help" to show full help.""" print(concise_help.format(pypm.__version__)) else: if P.exists(CONF_FILE_LOCAL): LOG.debug('using local config file: %s', CONF_FILE_LOCAL) conf_file = CONF_FILE_LOCAL else: conf_file = CONF_FILE_GLOBAL ret = Commands( install_console=True, default_configfile=conf_file, ).main(argv=argv) # Do not return objects returned by do_* when invoked for setuptools' # entry points, which treat the return values as stuff to be passed to # sys.exit (madness!) if api_use: return ret
def main(): l = logging.getLogger('') log.setup_trace(l, application.locations.log_file_path) if len(sys.argv) < 2: # The user has just typed 'pypm'; likely he is a newbie # We should not intimidate him with our huge help text. concise_help = r"""PyPM {0} (Python Package Manager) brief help: Type "pypm install PACKAGE" to install a package. Type "pypm search KEYWORDS" to search for packages. Type "pypm upgrade" to upgrade installed packages. Type "pypm help" to show full help.""" print(concise_help.format(pypm.__version__)) else: if exists(CONF_FILE_LOCAL): LOG.debug('using local config file: %s', CONF_FILE_LOCAL) conf_file = CONF_FILE_LOCAL else: conf_file = CONF_FILE_GLOBAL Commands( install_console=True, default_configfile=conf_file, ).main()