[snap] snapd checking routine refactored

This commit is contained in:
Vinícius Moreira
2020-01-13 16:27:54 -03:00
parent 8b6580ec51
commit 2a00b01f14
2 changed files with 17 additions and 16 deletions

View File

@@ -19,6 +19,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- the application name tooltip now displays the installation level. e.g: **gedit ( system )** - the application name tooltip now displays the installation level. e.g: **gedit ( system )**
- info window displaying the installation level - info window displaying the installation level
- "remote not set" warning dropped in favor of the new behavior: automatically adds Flathub as the default remote at the user level - "remote not set" warning dropped in favor of the new behavior: automatically adds Flathub as the default remote at the user level
- Snap:
- snapd checking routine refactored
- Web: - Web:
- not using HTTP sessions anymore to perform the searches. It seems to avoid URLs not being found after an internet drop event. - not using HTTP sessions anymore to perform the searches. It seems to avoid URLs not being found after an internet drop event.
- supporting JPEG images as custom icons - supporting JPEG images as custom icons

View File

@@ -9,7 +9,7 @@ from bauh.gems.snap.model import SnapApplication
BASE_CMD = 'snap' BASE_CMD = 'snap'
RE_SNAPD_STATUS = re.compile('\s+') RE_SNAPD_STATUS = re.compile('\s+')
SNAPD_RUNNING_STATUS = {'listening', 'running'} RE_SNAPD_SERVICES = re.compile(r'snapd\.\w+.+')
def is_installed(): def is_installed():
@@ -18,24 +18,23 @@ def is_installed():
def is_snapd_running() -> bool: def is_snapd_running() -> bool:
services = new_subprocess(['systemctl', 'list-units']) output = run_cmd('systemctl list-units')
service, service_running = False, False snapd_services = RE_SNAPD_SERVICES.findall(output)
socket, socket_running = False, False
for o in new_subprocess(['grep', '-Eo', 'snapd.+'], stdin=services.stdout).stdout:
if o:
line = o.decode().strip()
if line: socket, socket_running, service, service_running = False, False, False, False
line_split = RE_SNAPD_STATUS.split(line) if snapd_services:
running = line_split[3] in SNAPD_RUNNING_STATUS for service_line in snapd_services:
line_split = RE_SNAPD_STATUS.split(service_line)
if line_split[0] == 'snapd.service': running = line_split[3] in {'listening', 'running'}
service = True
service_running = running if line_split[0] == 'snapd.service':
elif line_split[0] == 'snapd.socket': service = True
socket = True service_running = running
socket_running = running elif line_split[0] == 'snapd.socket':
socket = True
socket_running = running
return socket and socket_running and (not service or service_running) return socket and socket_running and (not service or service_running)