示例#1
0
    def save_profile(self, profile):
        path = tuned.consts.LOAD_DIRECTORIES[1] + '/' + profile.name
        config = configobj.ConfigObj()
        config.filename = path + '/' + tuned.consts.PROFILE_FILE
        config.initial_comment = ('#', 'tuned configuration', '#')

        try:
            config['main'] = profile.options
        except KeyError:
            config['main'] = ''

            # profile dont have main section

            pass
        for (name, unit) in profile.units.items():
            config[name] = unit.options
        if not os.path.exists(path):
            os.makedirs(path)
        else:

            #             you cant rewrite profile!

            raise managerException.ManagerException('Profile with name ' +
                                                    profile.name +
                                                    'exists already')
        config.write()
        self._refresh_profiles()
示例#2
0
    def update_profile(
        self,
        old_profile_name,
        profile,
        is_admin,
    ):

        if old_profile_name not in self.get_names():
            raise managerException.ManagerException('Profile: ' +
                                                    old_profile_name +
                                                    ' is not in profiles')

        path = tuned.consts.LOAD_DIRECTORIES[1] + '/' + profile.name

        if old_profile_name != profile.name:
            self.remove_profile(old_profile_name, is_admin=is_admin)

        config = configobj.ConfigObj(list_values=False, interpolation=False)
        config.filename = path + '/' + tuned.consts.PROFILE_FILE
        config.initial_comment = ('#', 'tuned configuration', '#')
        try:
            config['main'] = profile.options
        except KeyError:

            # profile dont have main section

            pass
        for (name, unit) in list(profile.units.items()):
            config[name] = unit.options

        self._save_profile(config)

        self._refresh_profiles()
示例#3
0
    def set_raw_profile(self, profile_name, config):

        profilePath = self._locate_profile_path(profile_name)

        if profilePath == tuned.consts.LOAD_DIRECTORIES[1]:
            file_path = profilePath + '/' + profile_name + '/' + tuned.consts.PROFILE_FILE
            config_parser = ConfigParser(delimiters=('='), inline_comment_prefixes=('#'))
            config_parser.optionxform = str
            config_parser.read_string(config)

            config_obj = {
                'main': collections.OrderedDict(),
                'filename': file_path,
                'initial_comment': ('#', '# tuned configuration', '#')
            }
            for s in config_parser.sections():
                config_obj['main'][s] = collections.OrderedDict()
                for o in config_parser.options(s):
                    config_obj['main'][s][o] = config_parser.get(s, o, raw=True)
            self._save_profile(config_obj)
            self._refresh_profiles()
        else:
            raise managerException.ManagerException(profile_name
                    + ' profile is stored in ' + profilePath
                    + ' and can not be storet do this location')
示例#4
0
    def update_profile(
        self,
        old_profile_name,
        profile,
        is_admin,
        ):

        if old_profile_name not in self.get_names():
            raise managerException.ManagerException('Profile: '
                    + old_profile_name + ' is not in profiles')

        path = tuned.consts.LOAD_DIRECTORIES[1] + '/' + profile.name

        if old_profile_name != profile.name:
            self.remove_profile(old_profile_name, is_admin=is_admin)

        config = {
            'main': collections.OrderedDict(),
            'filename': path + '/' + tuned.consts.PROFILE_FILE,
            'initial_comment': ('#', '# tuned configuration', '#')
        }
        try:
            config['main']['main'] = profile.options
        except KeyError:

            # profile dont have main section

            pass
        for (name, unit) in list(profile.units.items()):
            config['main'][name] = unit.options

        self._save_profile(config)

        self._refresh_profiles()
示例#5
0
 def _delete_profile(self, profile_name):
     ec = subprocess.call([
         'pkexec', sys.executable, tuned.gtk.gui_profile_deleter.__file__,
         profile_name
     ])
     if (ec != 0):
         raise managerException.ManagerException(
             'Error while deleting profile "%s"' % (profile_name))
示例#6
0
 def _save_profile(self, config):
     ec = subprocess.call([
         'pkexec', sys.executable, tuned.gtk.gui_profile_saver.__file__,
         json.dumps(config.__dict__)
     ])
     if (ec != 0):
         raise managerException.ManagerException(
             'Error while saving profile file "%s"' % (config.filename))
示例#7
0
    def remove_profile(self, profile_name, is_admin):
        profile_path = self._locate_profile_path(profile_name)

        if self.is_profile_removable(profile_name):
            self._delete_profile(profile_name)
            self._load_all_profiles()
        else:
            raise managerException.ManagerException(profile_name
                    + ' profile is stored in ' + profile_path)
示例#8
0
    def set_raw_profile(self, profile_name, config):

        profilePath = self._locate_profile_path(profile_name)

        if profilePath == tuned.consts.LOAD_DIRECTORIES[1]:
            file = profilePath + '/' + profile_name + '/' + tuned.consts.PROFILE_FILE
            with open(file, 'w') as f:
                f.write(config)
        else:
            raise managerException.ManagerException(
                profile_name + ' profile is stored in ' + profilePath +
                ' and can not be storet do this location')
    def set_raw_profile(self, profile_name, config):

        profilePath = self._locate_profile_path(profile_name)

        config_lines = config.split('\n')

        if profilePath == tuned.consts.LOAD_DIRECTORIES[1]:
            file_path = profilePath + '/' + profile_name + '/' + tuned.consts.PROFILE_FILE

            config_obj = configobj.ConfigObj(infile=config_lines,list_values = False, interpolation = False)
            config_obj.filename = file_path
            config_obj.initial_comment = ('#', 'tuned configuration', '#')
            self._save_profile(config_obj)
            self._refresh_profiles()
        else:
            raise managerException.ManagerException(profile_name
                    + ' profile is stored in ' + profilePath
                    + ' and can not be storet do this location')
示例#10
0
    def update_profile(
        self,
        old_profile_name,
        profile,
        is_admin,
    ):

        if old_profile_name not in self.get_names():
            raise managerException.ManagerException('Profile: ' +
                                                    old_profile_name +
                                                    ' is not in profiles')
        if self.is_profile_factory(old_profile_name):
            path = tuned.consts.LOAD_DIRECTORIES[0] + '/' + profile.name
        else:
            path = tuned.consts.LOAD_DIRECTORIES[1] + '/' + profile.name

        if old_profile_name != profile.name:
            self.remove_profile(old_profile_name, is_admin=is_admin)

        config = configobj.ConfigObj()
        config.filename = path + '/' + tuned.consts.PROFILE_FILE
        config.initial_comment = ('#', 'tuned configuration', '#')
        try:
            config['main'] = profile.options
        except KeyError:

            # profile dont have main section

            pass
        for (name, unit) in profile.units.items():
            config[name] = unit.options

        if not os.path.exists(path):
            os.makedirs(path)
        config.write()
        self._refresh_profiles()