forked from AppImageCrafters/appimage-builder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
appimage-modules
executable file
·79 lines (62 loc) · 2.97 KB
/
appimage-modules
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env python3
# Copyright 2020 Alexis Lopez Zubieta
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation the
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
# sell copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
import argparse
import logging
import os
import subprocess
from AppImageBuilder.app_dir.bundlers.apt.config import Config as AptConfig
from AppImageBuilder.commands.apt_get import AptGet
from AppImageBuilder.recipe import Recipe
def __main__():
parser = argparse.ArgumentParser(description='AppImage modules analisys tool')
parser.add_argument('--recipe', dest='recipe', default=os.path.join(os.getcwd(), "AppImageBuilder.yml"),
help='recipe file path (default: $PWD/AppImageBuilder.yml)')
parser.add_argument('--log', dest='loglevel', default="INFO", help='logging level (default: INFO)')
parser.add_argument('--generate-apt-graph', dest='apt_graph', action="store_true",
help='Generate apt dependencies graph', default=False)
parser.add_argument('--update-apt-cache', dest='apt_update', action="store_true",
help='Update apt cache', default=False)
args = parser.parse_args()
configure_logging(args)
recipe = Recipe()
recipe.load_file(args.recipe)
if args.apt_graph:
return generate_deb_graph(recipe, args)
def configure_logging(args):
numeric_level = getattr(logging, args.loglevel.upper())
if not isinstance(numeric_level, int):
logging.error('Invalid log level: %s' % args.loglevel)
logging.basicConfig(level=numeric_level)
def generate_deb_graph(recipe, args):
app_dir = os.path.abspath(recipe.get_item('AppDir/path'))
apt_settings = recipe.get_item('AppDir/apt')
apt_config = AptConfig()
apt_config.load(apt_settings)
apt_config.generate()
if args.apt_update:
apt_command = AptGet(apt_config.apt_prefix, apt_config.get_apt_conf_path())
apt_command.update()
output = _run_apt_cache_depends_recursive(apt_config)
file_name = 'apt_graph.dot'
with open(file_name, 'w') as f:
f.write(output)
print("The apt dependencies graph have been written to: %s" % file_name)
def _run_apt_cache_depends_recursive(apt_config):
command = ['apt-cache', '-c', apt_config.get_apt_conf_path(), '-i', '-q', '--recurse', 'dotty']
command.extend(apt_config.apt_include)
print(' '.join(command))
proc = subprocess.run(command, stdout=subprocess.PIPE)
apt_cache_output = proc.stdout.decode('utf-8')
return apt_cache_output
if __name__ == '__main__':
__main__()