vg, lv, pv code had the same function for handling command execution.
Move to utility function and abstract the difference.
from .automatedproperties import AutomatedProperties
from . import utils
-from .utils import vg_obj_path_generate, log_error
+from .utils import vg_obj_path_generate, log_error, _handle_execute
import dbus
from . import cmdhandler
from . import cfg
@staticmethod
def handle_execute(rc, out, err):
- if rc == 0:
- cfg.load()
- else:
- # Need to work on error handling, need consistent
- raise dbus.exceptions.DBusException(
- LV_INTERFACE,
- 'Exit code %s, stderr = %s' % (str(rc), err))
+ _handle_execute(rc, out, err, LV_INTERFACE)
@staticmethod
def validate_dbus_object(lv_uuid, lv_name):
from .cfg import PV_INTERFACE
from . import cmdhandler
from .utils import vg_obj_path_generate, n, pv_obj_path_generate, \
- lv_object_path_method
+ lv_object_path_method, _handle_execute
from .loader import common
from .request import RequestEntry
from .state import State
@staticmethod
def handle_execute(rc, out, err):
- if rc == 0:
- cfg.load()
- else:
- # Need to work on error handling, need consistent
- raise dbus.exceptions.DBusException(
- PV_INTERFACE,
- 'Exit code %s, stderr = %s' % (str(rc), err))
+ return _handle_execute(rc, out, err, PV_INTERFACE)
@staticmethod
def validate_dbus_object(pv_uuid, pv_name):
STDOUT_TTY = os.isatty(sys.stdout.fileno())
+def _handle_execute(rc, out, err, interface):
+ if rc == 0:
+ cfg.load()
+ else:
+ # Need to work on error handling, need consistent
+ raise dbus.exceptions.DBusException(
+ interface, 'Exit code %s, stderr = %s' % (str(rc), err))
+
+
def rtype(dbus_type):
"""
Decorator making sure that the decorated function returns a value of
from .automatedproperties import AutomatedProperties
from . import utils
-from .utils import pv_obj_path_generate, vg_obj_path_generate, n
+from .utils import pv_obj_path_generate, vg_obj_path_generate, n, \
+ _handle_execute
import dbus
from . import cfg
from .cfg import VG_INTERFACE
@staticmethod
def handle_execute(rc, out, err):
- if rc == 0:
- cfg.load()
- else:
- # Need to work on error handling, need consistent
- raise dbus.exceptions.DBusException(
- VG_INTERFACE,
- 'Exit code %s, stderr = %s' % (str(rc), err))
+ return _handle_execute(rc, out, err, VG_INTERFACE)
@staticmethod
def validate_dbus_object(vg_uuid, vg_name):