|
39 | 39 | installed_flatpaks_files = [f'{DATA_FLATPAK}/installed_flatpaks.sh', f'{DATA_FLATPAK}/installed_user_flatpaks.sh'] |
40 | 40 | system_flatpak_dir = '/var/lib/flatpak/app' |
41 | 41 | user_flatpak_dir = os.path.expanduser('~/.local/share/flatpak/app') |
42 | | - |
43 | | -# load Flatpaks from bash scripts |
| 42 | +# Load Flatpaks from bash scripts |
44 | 43 | installed_flatpaks = set() |
45 | 44 | for file in installed_flatpaks_files: |
46 | 45 | if os.path.exists(file): |
47 | 46 | with open(file, 'r') as f: |
48 | | - for line in f: |
49 | | - if line.startswith('flatpak install'): |
50 | | - installed_flatpaks.add(line.split()[3]) |
| 47 | + installed_flatpaks.update(line.split()[3] for line in f if line.startswith('flatpak install')) |
51 | 48 |
|
52 | | -# get installed Flatpaks in the system and the home directories |
| 49 | +# Get installed Flatpaks in the specified directories |
53 | 50 | installed_apps = set() |
54 | 51 | for directory in [system_flatpak_dir, user_flatpak_dir]: |
55 | | - for app in os.listdir(directory): |
56 | | - if os.path.isdir(os.path.join(directory, app)): |
57 | | - installed_apps.add(app) |
| 52 | + if os.path.exists(directory): |
| 53 | + installed_apps.update(app for app in os.listdir(directory) if os.path.isdir(os.path.join(directory, app))) |
58 | 54 |
|
59 | | -# compare Flatpaks listed in the Bash scripts with the Flatpaks installed in the system |
| 55 | +# Compare Flatpaks listed in the Bash scripts with the installed ones |
60 | 56 | flatpaks_to_install = installed_flatpaks - installed_apps |
61 | 57 |
|
62 | 58 | if flatpaks_to_install: |
63 | 59 | for app in flatpaks_to_install: |
64 | 60 | subprocess.run(['flatpak', 'install', '--user', app, '-y']) |
65 | | - os.system(f"rm -rf {DATA_FLATPAK}/*.sh") |
| 61 | + os.system(f"rm -rf {DATA_FLATPAK}/*.sh") |
66 | 62 | else: |
67 | 63 | print('All Flatpak apps are installed.') |
0 commit comments