refactor
This commit is contained in:
+20
-30
@@ -1,22 +1,22 @@
|
||||
import configparser
|
||||
import os
|
||||
import sys
|
||||
import dbus
|
||||
# import dbus
|
||||
from tools.helper import run
|
||||
from tools.logger import Logger
|
||||
|
||||
def DBusContainerService(object_path="/ContainerManager", intf="id.waydro.ContainerManager"):
|
||||
return dbus.Interface(dbus.SystemBus().get_object("id.waydro.Container", object_path), intf)
|
||||
# def DBusContainerService(object_path="/ContainerManager", intf="id.waydro.ContainerManager"):
|
||||
# return dbus.Interface(dbus.SystemBus().get_object("id.waydro.Container", object_path), intf)
|
||||
|
||||
def DBusSessionService(object_path="/SessionManager", intf="id.waydro.SessionManager"):
|
||||
return dbus.Interface(dbus.SessionBus().get_object("id.waydro.Session", object_path), intf)
|
||||
# def DBusSessionService(object_path="/SessionManager", intf="id.waydro.SessionManager"):
|
||||
# return dbus.Interface(dbus.SessionBus().get_object("id.waydro.Session", object_path), intf)
|
||||
|
||||
def use_dbus():
|
||||
try:
|
||||
DBusContainerService()
|
||||
except:
|
||||
return False
|
||||
return True
|
||||
# def use_dbus():
|
||||
# try:
|
||||
# DBusContainerService()
|
||||
# except:
|
||||
# return False
|
||||
# return True
|
||||
|
||||
def use_overlayfs():
|
||||
cfg = configparser.ConfigParser()
|
||||
@@ -34,30 +34,20 @@ def use_overlayfs():
|
||||
return False
|
||||
|
||||
|
||||
def get_session():
|
||||
return DBusContainerService().GetSession()
|
||||
# def get_session():
|
||||
# return DBusContainerService().GetSession()
|
||||
|
||||
def stop():
|
||||
if use_dbus():
|
||||
session = DBusContainerService().GetSession()
|
||||
if session:
|
||||
DBusContainerService().Stop(False)
|
||||
else:
|
||||
# if use_dbus():
|
||||
# session = DBusContainerService().GetSession()
|
||||
# if session:
|
||||
# DBusContainerService().Stop(False)
|
||||
# else:
|
||||
run(["waydroid", "container", "stop"])
|
||||
|
||||
def start(*session):
|
||||
if use_dbus() and session:
|
||||
DBusContainerService().Start(session[0])
|
||||
else:
|
||||
run(["systemctl", "restart", "waydroid-container.service"])
|
||||
|
||||
def is_running():
|
||||
if use_dbus():
|
||||
if DBusContainerService().GetSession():
|
||||
return True
|
||||
return False
|
||||
else:
|
||||
return "Session:\tRUNNING" in run(["waydroid", "status"]).stdout.decode()
|
||||
|
||||
|
||||
|
||||
def upgrade():
|
||||
run(["waydroid", "upgrade", "-o"], ignore=r"\[.*\] Stopping container\n\[.*\] Starting container")
|
||||
@@ -131,6 +131,3 @@ def check_root():
|
||||
if os.geteuid() != 0:
|
||||
Logger.error("This script must be run as root. Aborting.")
|
||||
sys.exit(1)
|
||||
|
||||
def upgrade():
|
||||
run(["waydroid", "upgrade", "-o"], ignore=r"\[.*\] Stopping container\n\[.*\] Starting container")
|
||||
Reference in New Issue
Block a user