Skip to content

Commit 9fcc50d

Browse files
authored
Merge pull request #57 from aboutcode-org/add-sunos
Add sunos
2 parents 42311f2 + da3b8dd commit 9fcc50d

3 files changed

Lines changed: 43 additions & 19 deletions

File tree

  • builtins
    • extractcode_7z_system_provided/src/extractcode_7z
    • extractcode_libarchive_system_provided/src/extractcode_libarchive
    • typecode_libmagic_system_provided/src/typecode_libmagic

builtins/extractcode_7z_system_provided/src/extractcode_7z/__init__.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def get_locations(self):
3030
"""
3131
Return a mapping of {location key: location} providing the installation
3232
locations of the 7zip exe and shared libraries as installed on various
33-
Linux distros or on FreeBSD.
33+
Linux distros, FreeBSD, macOS, and other POSIX.
3434
"""
3535
lib_dir = None
3636
lib_7z = environ.get('EXTRACTCODE_7Z_PATH')
@@ -62,6 +62,12 @@ def get_locations(self):
6262
# This assumes that 7zip was installed using Homebrew
6363
lib_dir = '/opt/homebrew/bin'
6464
lib_7z = path.join(lib_dir, '7zz')
65+
elif mainstream_system == 'sunos':
66+
lib_dir = '/usr/bin'
67+
lib_7z = path.join(lib_dir, '7z')
68+
elif mainstream_system == 'haiku':
69+
lib_dir = '/bin'
70+
lib_7z = path.join(lib_dir, '7z')
6571
else:
6672
lib_dir = path.dirname(lib_7z)
6773

builtins/extractcode_libarchive_system_provided/src/extractcode_libarchive/__init__.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,13 @@ def get_locations(self):
2828
"""
2929
Return a mapping of {location key: location} providing the installation
3030
locations of the libarchive shared library as installed on various Linux
31-
distros or on FreeBSD.
31+
distros, FreeBSD, macOS, and other POSIX.
3232
"""
3333
lib_archive = environ.get('EXTRACTCODE_LIBARCHIVE_PATH')
3434
if not lib_archive:
35-
system_arch = platform.machine()
3635
mainstream_system = platform.system().lower()
36+
system_arch = platform.machine()
37+
system_arch_bit_width = platform.architecture()[0]
3738

3839
if mainstream_system == 'linux':
3940
distribution = self.get_like_distro()
@@ -42,16 +43,14 @@ def get_locations(self):
4243

4344
if any(dist in debian_based_distro for dist in distribution):
4445
lib_dir = (
45-
'/usr/lib' if platform.architecture()[0] == '32bit'
46+
'/usr/lib' if system_arch_bit_width == '32bit'
4647
else f'/usr/lib/{system_arch}-linux-gnu'
4748
)
48-
4949
elif any(dist in rpm_based_distro for dist in distribution):
5050
lib_dir = (
51-
'/usr/lib' if platform.architecture()[0] == '32bit'
51+
'/usr/lib' if system_arch_bit_width == '32bit'
5252
else '/usr/lib64'
5353
)
54-
5554
else:
5655
raise Exception(
5756
'Unsupported system: {}'.format(distribution))
@@ -68,6 +67,14 @@ def get_locations(self):
6867
# This assumes that libarchive was installed using Homebrew
6968
lib_dir = '/opt/homebrew/opt/libarchive/lib'
7069
lib_archive = path.join(lib_dir, 'libarchive.dylib')
70+
elif mainstream_system == 'sunos':
71+
lib_dir = '/usr/lib'
72+
if system_arch == 'i86pc' and system_arch_bit_width == '64bit':
73+
lib_dir = path.join(lib_dir, 'amd64')
74+
lib_archive = path.join(lib_dir, 'libarchive.so')
75+
elif mainstream_system == 'haiku':
76+
lib_dir = '/system/lib'
77+
lib_archive = path.join(lib_dir, 'libarchive.so.13')
7178
else:
7279
lib_dir = path.dirname(lib_archive)
7380

builtins/typecode_libmagic_system_provided/src/typecode_libmagic/__init__.py

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,48 +42,59 @@ def get_locations(self):
4242
"""
4343
Return a mapping of {location key: location} providing the installation
4444
locations of the libmagic shared library as installed on various Linux
45-
distros or on FreeBSD.
45+
distros, FreeBSD, macOS, and other POSIX.
4646
"""
4747
mainstream_system = platform.system().lower()
48+
system_arch = platform.machine()
49+
system_arch_bit_width = platform.architecture()[0]
50+
4851
if mainstream_system == 'linux':
4952
distribution = self.get_like_distro()
5053
debian_based_distro = ['ubuntu', 'mint', 'debian']
5154
rpm_based_distro = ['fedora', 'rhel']
52-
system_arch = platform.machine()
5355

5456
if any(dist in debian_based_distro for dist in distribution):
5557
db_dir = '/usr/lib/file'
5658
lib_dir = (
57-
'/usr/lib' if platform.architecture()[0] == '32bit'
59+
'/usr/lib' if system_arch_bit_width == '32bit'
5860
else f'/usr/lib/{system_arch}-linux-gnu'
5961
)
60-
6162
elif any(dist in rpm_based_distro for dist in distribution):
6263
db_dir = '/usr/share/misc'
6364
lib_dir = (
64-
'/usr/lib' if platform.architecture()[0] == '32bit'
65+
'/usr/lib' if system_arch_bit_width == '32bit'
6566
else '/usr/lib64'
6667
)
67-
6868
else:
6969
raise Exception('Unsupported system: {}'.format(distribution))
7070

7171
dll_loc = path.join(lib_dir, 'libmagic.so.1')
7272
elif mainstream_system == 'freebsd':
7373
dll_loc = ''
7474
db_dir = ''
75-
for lib_dir in ('/usr/local/', '/usr'):
76-
possible_dll_loc = path.join(lib_dir, 'lib/libmagic.so')
77-
possible_db_loc = path.join(lib_dir, 'share/misc/magic.mgc')
75+
for usr_dir in ('/usr/local', '/usr'):
76+
lib_dir = path.join(usr_dir, 'lib')
77+
possible_dll_loc = path.join(lib_dir, 'libmagic.so')
78+
possible_db_loc = path.join(usr_dir, 'share/misc/magic.mgc')
7879
if path.exists(possible_dll_loc) and path.exists(possible_db_loc):
7980
dll_loc = possible_dll_loc
8081
db_dir = path.dirname(possible_db_loc)
8182
break
8283
elif mainstream_system == 'darwin':
8384
# This assumes that libmagic was installed using Homebrew
84-
lib_dir = '/opt/homebrew'
85-
dll_loc = path.join(lib_dir, 'lib/libmagic.dylib')
86-
db_dir = path.join(lib_dir, 'share/misc')
85+
lib_dir = '/opt/homebrew/lib'
86+
dll_loc = path.join(lib_dir, 'libmagic.dylib')
87+
db_dir = '/opt/homebrew/share/misc'
88+
elif mainstream_system == 'sunos':
89+
lib_dir = '/usr/lib'
90+
if system_arch == 'i86pc' and system_arch_bit_width == '64bit':
91+
lib_dir = path.join(lib_dir, 'amd64')
92+
dll_loc = path.join(lib_dir, 'libmagic.so')
93+
db_dir = '/usr/share/misc'
94+
elif mainstream_system == 'haiku':
95+
lib_dir = '/system/lib'
96+
dll_loc = path.join(lib_dir, 'libmagic.so.1')
97+
db_dir = '/system/data/misc'
8798

8899
magicdb_loc = path.join(db_dir, 'magic.mgc')
89100

0 commit comments

Comments
 (0)