Ejemplo n.º 1
0
    def save_configuration(self, filepath):

        # Create empty config
        config = configobj.ConfigObj(indent_type='    ')

        # Update with default config if specified
        if self.application.preferences_controller.preferences.save_defaults:
            config.update(self.session.session_config_manager.defaults())

        # Update with UI values
        config.update(self.get_view_configuration())

        # Remove option having the same value as the default if specified
        if not self.application.preferences_controller.preferences.save_defaults:
            self.logger.verbose('Removing defaults')
            remove_defaults(config)

        # Remove comments
        if not self.application.preferences_controller.preferences.save_comments:
            self.logger.verbose('Removing comments')
            config.walk(_walker_remove_all_comments_, call_on_sections=True)

        self.notice('Saving configuration to %r', filepath)
        try:
            rollover(
                filepath, self.application.preferences_controller.preferences.
                backup_count)
        except Exception, e:
            self.exception('Rollover of file %r failed: %s', filepath, e)
Ejemplo n.º 2
0
    def save_preferences(self):
        path = self.application.get_preferences_file()
        self.notice('Saving preferences to %r', path)
        self.verbose('Preferences:\n%s', self.preferences.to_xml_str())

        try:
            rollover(path, self.preferences.backup_count)
        except Exception, e:
            self.exception('Rollover of file %r failed: %s', path, e)
Ejemplo n.º 3
0
    def save_sessions(self):
        path = self.application.get_sessions_file()
        self.notice('Saving sessions to %r', path)
        self.verbose('Sessions:\n%s', self.sessions.to_xml_str())

        try:
            rollover(path, self.application.preferences_controller.preferences.backup_count)
        except Exception as e:
            self.exception('Rollover of file %r failed: %s', path, e)

        mkfdirs(path)
        self.sessions.to_xml_file(path)
Ejemplo n.º 4
0
    def save_configuration(self, filepath):

        # Create empty config
        config = configobj.ConfigObj(indent_type='    ')

        # Update with default config if specified
        if self.application.preferences_controller.preferences.save_defaults:
            config.update(self.session.session_config_manager.defaults())

        # Update with UI values
        config.update(self.get_view_configuration())

        # Remove option having the same value as the default if specified
        if not self.application.preferences_controller.preferences.save_defaults:
            self.logger.verbose('Removing defaults')
            remove_defaults(config)

        # Remove comments
        if not self.application.preferences_controller.preferences.save_comments:
            self.logger.verbose('Removing comments')
            config.walk(_walker_remove_all_comments_, call_on_sections=True)

        self.notice('Saving configuration to %r', filepath)
        try:
            rollover(filepath, self.application.preferences_controller.preferences.backup_count)
        except Exception as e:
            self.exception('Rollover of file %r failed: %s', filepath, e)
        with file(filepath, 'w') as f:
            config.write(f)

        self.info('Configuration:\n%s', self.pformat(config.dict()))
        self.session.configuration_file = filepath
        self.session.session_config = config
        self.main_window.set_configuration(
            self.session.session_config_manager,
            self.session.session_config,
            self.session.session_config_raw
        )
        self.main_window.update_session_status()
Ejemplo n.º 5
0
from shutil import rmtree
from tempfile import mkdtemp
from os.path import join

import vacumm.misc.file as F

tmpdir = mkdtemp(dir='.')

afile = join(tmpdir, 'afile')
count = 2
suffix = '.backup%d'

try:

    F.rollover(afile, count=count, suffix=suffix)
    # nothing done, afile does not exists
    with file(afile, 'w') as f: f.write('0')
    # we created afile
    # afile contains 0
    F.rollover(afile, count=count, suffix=suffix)
    # did a copy of afile to afile.backup1
    with file(afile, 'w') as f: f.write('1')
    # afile contains 1
    # afile.backup1 contains 0
    F.rollover(afile, count=count, suffix=suffix)
    # did a copy of afile.backup1 to afile.backup2, and a copy of afile to afile.backup2
    with file(afile, 'w') as f: f.write('2')
    # afile contains 2
    # afile.backup1 contains 1
    # afile.backup2 contains 0