Skip to content

Commit

Permalink
Add log_system_info function to log some basic system info
Browse files Browse the repository at this point in the history
Should help with bug reports as all debug logs will have this.
  • Loading branch information
infirit committed Oct 17, 2024
1 parent b8a7cbd commit d05fd33
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 4 deletions.
3 changes: 2 additions & 1 deletion blueman/Constants.py.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__all__ = ["VERSION", "PACKAGE", "WEBSITE", "ICON_PATH", "PIXMAP_PATH", "UI_PATH", "BIN_DIR"]
__all__ = ["VERSION", "PACKAGE", "WEBSITE", "ICON_PATH", "PIXMAP_PATH", "UI_PATH", "BIN_DIR", "BLUETOOTHD_PATH"]

VERSION = "@VERSION@"
PACKAGE = "@PACKAGE@"
Expand All @@ -8,6 +8,7 @@ BIN_DIR = "@BINDIR@"
LOCALEDIR = "@LOCALEDIR@"
ICON_PATH = "@icondir@"
PIXMAP_PATH = "@pkgdatadir@/pixmaps"
BLUETOOTHD_PATH = "@bluetoothd_path@"
UI_PATH = "@pkgdatadir@/ui"
DHCP_CONFIG_FILE = "@dhconfig@"
POLKIT = @POLKIT@
Expand Down
56 changes: 53 additions & 3 deletions blueman/Functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
from time import sleep
from pathlib import Path
from typing import Optional, Dict, Tuple, List, Callable, Iterable, Union, Any
import re
import os
Expand All @@ -33,11 +34,11 @@
import socket
import array
import time

import subprocess
import cairo

from blueman.main.DBusProxies import AppletService, DBusProxyFailed
from blueman.Constants import BIN_DIR, ICON_PATH
from blueman.Constants import BIN_DIR, ICON_PATH, BLUETOOTHD_PATH

import gi
gi.require_version("Gtk", "3.0")
Expand All @@ -49,7 +50,7 @@

__all__ = ["check_bluetooth_status", "launch", "setup_icon_path", "adapter_path_to_name", "e_", "bmexit",
"format_bytes", "create_menuitem", "have", "set_proc_title", "create_logger", "create_parser", "open_rfcomm",
"get_local_interfaces"]
"get_local_interfaces", "log_system_info"]


def check_bluetooth_status(message: str, exitfunc: Callable[[], Any]) -> None:
Expand Down Expand Up @@ -334,3 +335,52 @@ def get_local_interfaces() -> Dict[str, Tuple[str, Optional[str]]]:

def bmexit(msg: Optional[Union[str, int]] = None) -> None:
raise SystemExit(msg)


def log_system_info() -> None:
def parse_os_release(path: Path) -> Dict[str, str]:
release_dict = {}
try:
with path.open() as f:
for line in f:
try:
key, val = line.strip().split("=")
release_dict[key] = val.strip("\"")
except ValueError:
logging.error(f"Unable to parse line: {line}")
except OSError:
logging.error(f"Could not read {path.as_uri()}")
return release_dict

try:
complete = subprocess.run(
[BLUETOOTHD_PATH, "-v"],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
text=True,
timeout=2
)
except OSError as err:
complete = None
logging.info(f"Failed to run bluetoothd {err.strerror}")
except subprocess.TimeoutExpired:
complete = None
logging.info("Timeout running bluetoothd")
bluez_version = complete.stdout.strip() if complete else "Unknown"
logging.info(f"BlueZ version: {bluez_version}")

etc_os_release = Path("/etc/os-release")
lib_os_release = Path("/usr/lib/os-release")
if etc_os_release.exists():
os_release = parse_os_release(etc_os_release)
elif lib_os_release.exists():
os_release = parse_os_release(lib_os_release)
else:
os_release = {}

version = os_release.get("VERSION", "version not provided")
logging.info(f"Distribution: {os_release['NAME']} - {version}")

desktop = os.environ.get("XDG_CURRENT_DESKTOP", "Unknown")
session_type = os.environ.get("XDG_SESSION_TYPE", "Unknown")
logging.info(f"Running: {desktop} on {session_type}")
5 changes: 5 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ AC_SUBST([dhconfig])

dnl ---------------------------------

AC_ARG_WITH([bluetoothd_path],
AS_HELP_STRING([--with-bluetoothd-path=PATH], [Set bluetooth daemon path]),
[bluetoothd_path="$withval"], [bluetoothd_path='/usr/libexec/bluetoothd'])
AC_SUBST([bluetoothd_path])

AC_ARG_ENABLE([polkit],
AS_HELP_STRING([--enable-polkit], [Enable policykit support]),
Expand Down Expand Up @@ -354,6 +358,7 @@ echo Nemo sendto: $have_nemo_python
echo Nautilus sendto: $have_nautilus_python
echo Settings menu integration enabled: $have_settings
echo Dhcpd 3 configuration file: $dhconfig
echo Bluetooth daemon path: $bluetoothd_path
echo PulseAudio support: $use_pulseaudio
echo Systemd system unit dir: ${systemd_system_unit_dir}
echo Systemd user unit dir: ${systemd_user_unit_dir}
Expand Down
1 change: 1 addition & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ conf_data.set('pkgdatadir', join_paths(prefix, pkgdatadir))
conf_data.set('LOCALEDIR', join_paths(prefix, get_option('localedir')))
conf_data.set('icondir', join_paths(prefix, datadir, 'icons'))
conf_data.set('dhconfig', get_option('dhcp-config-path'))
conf_data.set('bluetoothd_path', get_option('bluetoothd-path'))
conf_data.set('POLKIT', have_polkit)
conf_data.set('GETTEXT_PACKAGE', package_name)
conf_data.set('PYTHON', pyinstall.full_path())
Expand Down
1 change: 1 addition & 0 deletions meson_options.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
option('runtime_deps_check', type: 'boolean', value: true, description: 'Disable runtime dependency check (for package maintainers)')
option('dhcp-config-path', type: 'string', value: '/etc/dhcp3/dhcpd.conf', description: 'Set dhcp3 server configuration path')
option('bluetoothd-path', type: 'string', value: '/usr/libexec/bluetoothd', description: 'Set bluetooth daemon path')
option('policykit', type: 'boolean', value: true, description: 'Enable policykit support')
option('pulseaudio', type: 'boolean', value: true, description: 'Enable PulseAudio support')
option('systemdsystemunitdir', type: 'string', description: 'Path to systemd system unit dir relative to ${prefix}')
Expand Down

0 comments on commit d05fd33

Please sign in to comment.