From 375f5948084084bd8b076b782d3dd1193d6eea62 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Sat, 10 Sep 2016 18:05:20 +0530 Subject: [PATCH] Add argument to list packages needed by apps --- doc/plinth.xml | 22 ++++++++++++++++++++++ plinth/__main__.py | 21 +++++++++++++++++++++ plinth/setup.py | 14 ++++++++++++++ 3 files changed, 57 insertions(+) diff --git a/doc/plinth.xml b/doc/plinth.xml index 4563c2940..a95a6eefb 100644 --- a/doc/plinth.xml +++ b/doc/plinth.xml @@ -48,6 +48,10 @@ application + + + application + @@ -151,6 +155,24 @@ + + + + + For the list of provided applications, print the list of + packages needed by the applications. If no application is + provided as additional argument, then print list of + packages needed by all essential applications. If '*' is + provided in the list of the applications, then list of + packages needed by all applications will be printed. + Although, packages are installed when the application is + first accessed, this list will be useful for adding list + of dependencies to a Debian package and to get a list of + all interesting packages. Other output may be printed on + stderr and should be ignored. + + + diff --git a/plinth/__main__.py b/plinth/__main__.py index 494c0a4d0..bb2849870 100644 --- a/plinth/__main__.py +++ b/plinth/__main__.py @@ -60,6 +60,9 @@ def parse_arguments(): parser.add_argument( '--diagnose', action='store_true', default=False, help='run diagnostic tests and exit') + parser.add_argument( + '--list-dependencies', default=False, nargs='*', + help='list package dependencies for essential modules') global arguments arguments = parser.parse_args() @@ -267,6 +270,21 @@ def run_setup_and_exit(module_list, allow_install=True): sys.exit(error_code) +def list_dependencies(module_list): + """List dependencies for all essential modules and exit.""" + error_code = 0 + try: + if module_list: + setup.list_dependencies(module_list=module_list) + else: + setup.list_dependencies(essential=True) + except Exception as exception: + logger.error('Error listing dependencies - %s', exception) + error_code = 1 + + sys.exit(error_code) + + def run_diagnostics_and_exit(): """Run diagostics on all modules and exit.""" module = importlib.import_module('plinth.modules.diagnostics.diagnostics') @@ -309,6 +327,9 @@ def main(): if arguments.setup_no_install is not False: run_setup_and_exit(arguments.setup_no_install, allow_install=False) + if arguments.list_dependencies is not False: + list_dependencies(arguments.list_dependencies) + if arguments.diagnose: run_diagnostics_and_exit() diff --git a/plinth/setup.py b/plinth/setup.py index e6479ed35..7ea4f1985 100644 --- a/plinth/setup.py +++ b/plinth/setup.py @@ -175,3 +175,17 @@ def setup_modules(module_list=None, essential=False, allow_install=True): continue module.setup_helper.run(allow_install=allow_install) + + +def list_dependencies(module_list=None, essential=False): + """Print list of packages required by selected or essential modules.""" + for module_name, module in plinth.module_loader.loaded_modules.items(): + if essential and not getattr(module, 'is_essential', False): + continue + + if module_list and module_name not in module_list and \ + '*' not in module_list: + continue + + for package_name in getattr(module, 'managed_packages', []): + print(package_name)