Skip to content

Make SevenzipPaths.get_locations() more robust #54

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,29 @@ def get_locations(self):
debian_based_distro = ['ubuntu', 'mint', 'debian']
rpm_based_distro = ['fedora', 'rhel']

dir_candidates = ("/usr/bin", "/usr/libexec/p7zip")
bin_candidates = ("7z", "7zz", "7za")

if any(dist in debian_based_distro for dist in distribution):
lib_dir = '/usr/bin'
for bin_name in ('7z', '7zz'):
lib_7z = path.join(lib_dir, bin_name)
# take the defaults
pass
elif any(dist in rpm_based_distro for dist in distribution):
# Fedora >= 43 has 7zip proper, in /usr/bin
dir_candidates = ("/usr/libexec/p7zip", "/usr/bin")
bin_candidates = ("7za", "7z", "7zz")

found = False
for lib_dir in dir_candidates:
for bin_candidate in bin_candidates:
lib_7z = path.join(lib_dir, bin_candidate)
if path.exists(lib_7z):
found = True
break
elif any(dist in rpm_based_distro for dist in distribution):
# 7zip proper is not available on dnf
lib_dir = '/usr/libexec/p7zip'
lib_7z = path.join(lib_dir, '7za')
else:
raise Exception(
'Unsupported system: {}'.format(distribution))
if found:
break

# If none is found here, lib_7z won’t be found below either.

elif mainstream_system == 'freebsd':
lib_dir = '/usr/local/bin'
lib_7z = path.join(lib_dir, '7z')
Expand Down