mirror of
ssh://git.janware.com/janware/proj/jw-pkg
synced 2026-04-24 09:13:37 +02:00
App.os_cascade: Don't use platform.system()
Python's platform.system() outputs 'Linux', and to use it is tempting. Sadly, that's wrong, because it reflects the host's idea of the target system, not the execution context's, so replace it with straight 'linux' if the distro is known, or, failing that, the output of uname -s. Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
parent
b2e1e411f1
commit
4393ca21fc
1 changed files with 32 additions and 10 deletions
|
|
@ -300,15 +300,31 @@ class App(Base):
|
|||
@property
|
||||
def os_release(self) -> str:
|
||||
if self.__os_release is None:
|
||||
result = self.call_async(
|
||||
self.exec_context.run(
|
||||
['/usr/bin/cat', '/etc/os-release'],
|
||||
throw=True,
|
||||
cmd_input=InputMode.NonInteractive
|
||||
release_file = '/etc/os-release'
|
||||
try:
|
||||
result = self.call_async(
|
||||
self.exec_context.run(
|
||||
['/usr/bin/cat', release_file],
|
||||
throw=True,
|
||||
cmd_input=InputMode.NonInteractive
|
||||
)
|
||||
)
|
||||
)
|
||||
assert result.status == 0
|
||||
self.__os_release = result.decode().stdout.strip()
|
||||
self.__os_release = result.decode().stdout.strip()
|
||||
except Exception as e:
|
||||
result = self.call_async(
|
||||
self.exec_context.run(
|
||||
['uname', '-s'],
|
||||
throw=False,
|
||||
cmd_input=InputMode.NonInteractive
|
||||
)
|
||||
)
|
||||
if result.status != 0:
|
||||
log(ERR, f'/etc/os-release and uname both failed, the latter with exit status {result.status}')
|
||||
raise
|
||||
log(INFO, f'Failed to read {release_file} ({str(e)}), falling back to uname')
|
||||
uname = result.decode().stdout.strip().lower()
|
||||
self.__os_release = f'ID={uname}\nVERSION_CODENAME=unknown'
|
||||
|
||||
return self.__os_release
|
||||
|
||||
def os_release_field(self, key: str, throw: bool=False) -> str:
|
||||
|
|
@ -422,32 +438,38 @@ class App(Base):
|
|||
def __append(entry: str):
|
||||
if not entry in ret:
|
||||
ret.append(entry)
|
||||
import platform
|
||||
if self.__os_cascade is None:
|
||||
ret = [ 'os', platform.system().lower() ]
|
||||
ret = [ 'os' ]
|
||||
match self.distro_id:
|
||||
case 'centos':
|
||||
__append('linux')
|
||||
__append('pkg-rpm')
|
||||
__append('pm-yum')
|
||||
__append('redhat')
|
||||
__append('rhel')
|
||||
case 'fedora' | 'rhel':
|
||||
__append('linux')
|
||||
__append('pkg-rpm')
|
||||
__append('pm-yum')
|
||||
__append('redhat')
|
||||
case 'suse':
|
||||
__append('linux')
|
||||
__append('pkg-rpm')
|
||||
__append('pm-zypper')
|
||||
case 'kali' | 'raspbian':
|
||||
__append('linux')
|
||||
__append('pkg-debian')
|
||||
__append('pm-apt')
|
||||
__append('debian')
|
||||
case 'ubuntu':
|
||||
__append('linux')
|
||||
__append('pkg-debian')
|
||||
__append('pm-apt')
|
||||
case 'archlinux':
|
||||
__append('linux')
|
||||
__append('pkg-pm')
|
||||
__append('pm-pacman')
|
||||
|
||||
os = self.__opt_os if self.__opt_os is not None else self.get_os()
|
||||
name = re.sub(r'-.*', '', os)
|
||||
series = os
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue