Skip to content

Commit

Permalink
WIP: Fix systemd units for Flatpak
Browse files Browse the repository at this point in the history
  • Loading branch information
chase9 committed Dec 4, 2023
1 parent b0599aa commit 841e026
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 10 deletions.
28 changes: 21 additions & 7 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
{
"python.linting.pylintEnabled": true,
"python.linting.enabled": true,
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter"
},
"python.formatting.provider": "none"
}
"python.analysis.autoImportCompletions": true,
"python.analysis.exclude": [
".git",
"**/__pycache__",
"**/node_modules",
"build",
".flatpak-builder"
],
"python.analysis.ignore": [
".flatpak-builder",
"build",
"**/__pycache__",
".git"
],
"pylint.ignorePatterns": [
"**/__pycache__",
".git",
"build",
".flatpak-builder"
]
}
14 changes: 11 additions & 3 deletions tests/test_daemon_handler.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import pathlib
from pathlib import Path
import re
import shutil
import subprocess
import unittest
from datetime import time
from os.path import isfile

from yin_yang import daemon_handler
from yin_yang import daemon_handler, helpers
from yin_yang.config import config
from yin_yang.meta import Modes, ConfigEvent

Expand All @@ -26,9 +27,16 @@ def tearDown(self) -> None:
def setUpClass(cls) -> None:
super().setUpClass()
if not isfile(daemon_handler.TIMER_PATH):
pathlib.Path(daemon_handler.SYSTEMD_PATH).mkdir(parents=True, exist_ok=True)
Path(daemon_handler.SYSTEMD_PATH).mkdir(parents=True, exist_ok=True)
shutil.copyfile('./resources/yin_yang.timer', daemon_handler.TIMER_PATH)
shutil.copyfile('./resources/yin_yang.service', daemon_handler.SERVICE_PATH)
# If we're in a flatpak, the service file needs to be updated
if (helpers.is_flatpak()):
with open(daemon_handler.SERVICE_PATH, 'r') as service:
lines = service.readlines()
with open(daemon_handler.SERVICE_PATH, 'w') as service:
for line in lines:
service.write(re.sub('ExecStart=\/usr\/bin\/yin-yang --systemd', 'ExecStart='+str(Path.home())+'\/.local\/share\/flatpak\/exports\/bin\/sh.oskar.yin-yang --systemd', line))
shutil.copyfile(daemon_handler.TIMER_PATH, daemon_handler.TIMER_PATH.with_suffix('.timer_backup'))

@classmethod
Expand Down
9 changes: 9 additions & 0 deletions yin_yang/daemon_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import subprocess
from enum import Enum, auto
from pathlib import Path
import re

from yin_yang import helpers
from .config import ConfigWatcher, config
Expand All @@ -14,6 +15,7 @@
SERVICE_PATH = SYSTEMD_PATH / 'yin_yang.service'



def create_files():
logger.debug('Creating systemd files')
if not SYSTEMD_PATH.is_dir():
Expand All @@ -22,6 +24,13 @@ def create_files():
shutil.copy('./resources/yin_yang.timer', TIMER_PATH)
if not SERVICE_PATH.is_file():
shutil.copy('./resources/yin_yang.service', SERVICE_PATH)
# TODO: Will this cause an issue switching back from flatpak?
if (helpers.is_flatpak()):
with open(SERVICE_PATH, 'r') as service:
lines = service.readlines()
with open(SERVICE_PATH, 'w') as service:
for line in lines:
service.write(re.sub('ExecStart=\/usr\/bin\/yin-yang --systemd', 'ExecStart='+str(Path.home())+'/.local/share/flatpak/exports/bin/sh.oskar.yin-yang --systemd', line))


def run_command(command, **kwargs):
Expand Down

0 comments on commit 841e026

Please sign in to comment.