1
0
mirror of https://github.com/openSUSE/osc.git synced 2025-01-14 09:36:21 +01:00

Merge branch 'linux-platform-detection' of https://github.com/tomaskrizek/osc

Use the distro module (if available) for guessing the linux distribution.
In case of python < 3.8, use the platform.linux_distribution() fallback if
no distro module is available.
Rationale: platform.linux_distribution() was dropped in python3.8
This commit is contained in:
Marcus Huewe 2019-12-05 21:25:03 +01:00
commit 7621e79ddf

View File

@ -23,8 +23,14 @@ import socket
import errno
import shlex
import hashlib
import platform
try:
import distro
except ImportError:
distro = None
try:
from urllib.parse import urlsplit, urlunsplit, urlparse, quote_plus, urlencode, unquote
from urllib.error import HTTPError
@ -4016,17 +4022,20 @@ def read_meta_from_spec(specfile, *args):
return spec_data
def _get_linux_distro():
if distro is not None:
return distro.id()
elif sys.version_info >= (3, 8):
return None
# compatibility for Python 2.6 to 3.7
return platform.linux_distribution()[0]
def get_default_editor():
import platform
system = platform.system()
if system == 'Windows':
return 'notepad'
if system == 'Linux':
try:
# Python 2.6
dist = platform.linux_distribution()[0]
except AttributeError:
dist = platform.dist()[0]
dist = _get_linux_distro()
if dist == 'debian':
return 'editor'
elif dist == 'fedora':
@ -4035,16 +4044,11 @@ def get_default_editor():
return 'vi'
def get_default_pager():
import platform
system = platform.system()
if system == 'Windows':
return 'less'
if system == 'Linux':
try:
# Python 2.6
dist = platform.linux_distribution()[0]
except AttributeError:
dist = platform.dist()[0]
dist = _get_linux_distro()
if dist == 'debian':
return 'pager'
return 'less'