Skip to content

Commit 7af36f4

Browse files
authored
fix a bug with installing Flatpak apps from Bash scripts
1 parent c3390ee commit 7af36f4

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

src/install_flatpak_from_script.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,29 +39,25 @@
3939
installed_flatpaks_files = [f'{DATA_FLATPAK}/installed_flatpaks.sh', f'{DATA_FLATPAK}/installed_user_flatpaks.sh']
4040
system_flatpak_dir = '/var/lib/flatpak/app'
4141
user_flatpak_dir = os.path.expanduser('~/.local/share/flatpak/app')
42-
43-
# load Flatpaks from bash scripts
42+
# Load Flatpaks from bash scripts
4443
installed_flatpaks = set()
4544
for file in installed_flatpaks_files:
4645
if os.path.exists(file):
4746
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'))
5148

52-
# get installed Flatpaks in the system and the home directories
49+
# Get installed Flatpaks in the specified directories
5350
installed_apps = set()
5451
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)))
5854

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
6056
flatpaks_to_install = installed_flatpaks - installed_apps
6157

6258
if flatpaks_to_install:
6359
for app in flatpaks_to_install:
6460
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")
6662
else:
6763
print('All Flatpak apps are installed.')

0 commit comments

Comments
 (0)