Add argument to list packages needed by apps

This commit is contained in:
Sunil Mohan Adapa 2016-09-10 18:05:20 +05:30 committed by James Valleroy
parent 8ce6312190
commit 375f594808
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808
3 changed files with 57 additions and 0 deletions

View File

@ -48,6 +48,10 @@
<option>--setup-no-repeat</option>
<arg choice="opt" rep="repeat">application</arg>
</arg>
<arg>
<option>--list-dependencies</option>
<arg choice="opt" rep="repeat">application</arg>
</arg>
</cmdsynopsis>
</refsynopsisdiv>
@ -151,6 +155,24 @@
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>--list-dependencies</option></term>
<listitem>
<para>
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.
</para>
</listitem>
</varlistentry>
</variablelist>
</refsect1>

View File

@ -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()

View File

@ -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)