def profile(self, profiles):
		profile_name = " ".join(profiles)
		if profile_name == "":
			return False
		try:
			(ret, msg) = self._controller.switch_profile(profile_name)
		except TunedAdminDBusException as e:
			self._error(e)
			if profile_name in profiles_locator(consts.LOAD_DIRECTORIES).get_known_names():
				if self._cmd.write_to_file(consts.ACTIVE_PROFILE_FILE, profile_name):
					print "You need to (re)start the tuned daemon by hand for changes to apply."
					return True
				else:
					self._error("Unable to switch profile, do you have enough permissions?")
					return False
			else:
				self._error("Requested profile '%s' doesn't exist." % profile_name)
				return False
		if ret:
			if not self._controller.is_running() and not self._controller.start():
				self._error("Cannot enable the tuning.")
				ret = False
		else:
			self._error(msg)

		return ret
示例#2
0
文件: admin.py 项目: swipswaps/tuned
 def __init__(self,
              dbus=True,
              debug=False,
              asynco=False,
              timeout=consts.ADMIN_TIMEOUT,
              log_level=logging.ERROR):
     self._dbus = dbus
     self._debug = debug
     self._async = asynco
     self._timeout = timeout
     self._cmd = commands(debug)
     self._profiles_locator = profiles_locator(consts.LOAD_DIRECTORIES)
     self._daemon_action_finished = threading.Event()
     self._daemon_action_profile = ""
     self._daemon_action_result = True
     self._daemon_action_errstr = ""
     self._controller = None
     self._log_token = None
     self._log_level = log_level
     if self._dbus:
         self._controller = tuned.admin.DBusController(
             consts.DBUS_BUS, consts.DBUS_INTERFACE, consts.DBUS_OBJECT,
             debug)
         try:
             self._controller.set_signal_handler(
                 consts.DBUS_SIGNAL_PROFILE_CHANGED,
                 self._signal_profile_changed_cb)
         except TunedAdminDBusException as e:
             self._error(e)
             self._dbus = False
示例#3
0
文件: admin.py 项目: adamBrinek/tuned
	def profile(self, profiles, dbus_warn = True):
		fallback = False
		profile_name = " ".join(profiles)
		if profile_name == "":
			return False
		try:
			ret = self._controller.switch_profile(profile_name)
		except TunedAdminDBusException as e:
			fallback = True
			if dbus_warn:
				print >> sys.stderr, e
			if profile_name in profiles_locator(consts.LOAD_DIRECTORIES).get_known_names():
				ret = tuned.utils.commands.write_to_file(consts.ACTIVE_PROFILE_FILE, profile_name)
			else:
				ret = False
				self._error("Requested profile '%s' doesn't exist." % profile_name)
		if ret:
			if fallback:
				print "You need to (re)start the tuned daemon by hand for changes to apply."
			else:
				if not self._controller.is_running() and not self._controller.start():
					self._error("Cannot enable the tuning.")
					ret = False
		else:
			self._error("Cannot switch the profile.")

		return ret
	def list(self):
		try:
			profile_names = self._controller.profiles()
		except TunedAdminDBusException as e:
			self._error(e)
			profile_names = profiles_locator(consts.LOAD_DIRECTORIES).get_known_names()
		print "Available profiles:"
		for profile in profile_names:
			print "- %s" % profile
		self.active()
示例#5
0
文件: admin.py 项目: adamBrinek/tuned
	def list(self, dbus_warn = True):
		try:
			profile_names = self._controller.profiles()
		except TunedAdminDBusException as e:
			if dbus_warn:
				print >> sys.stderr, e
			profile_names = profiles_locator(consts.LOAD_DIRECTORIES).get_known_names()
		print "Available profiles:"
		for profile in profile_names:
			print "- %s" % profile
		self.active(False)
示例#6
0
 def list(self):
     no_dbus = self._controller is None
     if not no_dbus:
         try:
             profile_names = self._controller.profiles()
         except TunedAdminDBusException as e:
             self._error(e)
             no_dbus = True
     if no_dbus:
         profile_names = profiles_locator(
             consts.LOAD_DIRECTORIES).get_known_names()
     print "Available profiles:"
     for profile in profile_names:
         print "- %s" % profile
     self.active()
示例#7
0
    def profile(self, profiles):
        no_dbus = self._controller is None
        profile_name = " ".join(profiles)
        if profile_name == "":
            return False
        if not no_dbus:
            try:
                (ret, msg) = self._controller.switch_profile(profile_name)
            except TunedAdminDBusException as e:
                self._error(e)
                no_dbus = True
        if no_dbus:
            if profile_name in profiles_locator(
                    consts.LOAD_DIRECTORIES).get_known_names():
                if self._cmd.write_to_file(consts.ACTIVE_PROFILE_FILE,
                                           profile_name):
                    print "Trying to (re)start tuned..."
                    (ret,
                     out) = self._cmd.execute(["service", "tuned", "restart"])
                    if retcode == 0:
                        print "Tuned (re)started, changes applied."
                    else:
                        print "Tuned (re)start failed, you need to (re)start tuned by hand for changes to apply."
                    return True
                else:
                    self._error(
                        "Unable to switch profile, do you have enough permissions?"
                    )
                    return False
            else:
                self._error("Requested profile '%s' doesn't exist." %
                            profile_name)
                return False
        if ret:
            if not self._controller.is_running(
            ) and not self._controller.start():
                self._error("Cannot enable the tuning.")
                ret = False
        else:
            self._error(msg)

        return ret
示例#8
0
import time
import threading


class Admin(object):
    def __init__(self,
                 dbus=True,
                 debug=False,
                 async=False,
                 timeout=consts.ADMIN_TIMEOUT):
        self._dbus = dbus
        self._debug = debug
        self._async = async
        self._timeout = timeout
        self._cmd = commands(debug)
        self._profiles_locator = profiles_locator(consts.LOAD_DIRECTORIES)
        self._daemon_action_finished = threading.Event()
        self._daemon_action_profile = ""
        self._daemon_action_result = True
        self._daemon_action_errstr = ""
        self._controller = None
        if self._dbus:
            self._controller = tuned.admin.DBusController(
                consts.DBUS_BUS, consts.DBUS_INTERFACE, consts.DBUS_OBJECT,
                debug)
            try:
                self._controller.set_signal_handler(
                    consts.DBUS_SIGNAL_PROFILE_CHANGED,
                    self._signal_profile_changed_cb)
            except TunedAdminDBusException as e:
                self._error(e)
示例#9
0
from tuned.utils.commands import commands
from tuned.profiles import Locator as profiles_locator
from exceptions import TunedAdminDBusException
import tuned.consts as consts
import os
import sys
import errno
import threading

class Admin(object):
	def __init__(self, controller, debug = False, async = False):
		self._controller = controller
		self._debug = debug
		self._async = async
		self._cmd = commands(debug)
		self._profiles_locator = profiles_locator(consts.LOAD_DIRECTORIES)
		self._daemon_action_finished = threading.Event()
		self._daemon_action_profile = ""
		self._daemon_action_result = True
		self._daemon_action_errstr = ""
		if self._controller is None:
			self._dbus = False
		else:
			self._dbus = True
			try:
				self._controller.set_signal_handler(consts.DBUS_SIGNAL_PROFILE_CHANGED, self._signal_profile_changed_cb)
			except TunedAdminDBusException as e:
				self._error(e)
				self._dbus = False

	def _error(self, message):