Beispiel #1
0
    def _get_password_from_user(self, parent, profile_id = None, mode = None, pw_id = 1, prompt = None):
        """
        ask user for password. This does even work when run as cronjob
        and user is logged in.
        """
        if prompt is None:
            prompt = _('Profile \'%(profile)s\': Enter password for %(mode)s: ') % {'profile': self.config.get_profile_name(profile_id), 'mode': self.config.SNAPSHOT_MODES[mode][pw_id + 1]}

        tools.register_backintime_path('qt4')

        x_server = tools.check_x_server()
        import_successful = False
        if x_server:
            try:
                import messagebox
                import_successful = True
            except ImportError:
                pass

        if not import_successful or not x_server:
            import getpass
            alarm = tools.Alarm()
            alarm.start(300)
            try:
                password = getpass.getpass(prompt)
                alarm.stop()
            except Timeout:
                password = ''
            return password

        password = messagebox.ask_password_dialog(parent, self.config.APP_NAME,
                    prompt = prompt,
                    timeout = 300)
        return password
Beispiel #2
0
    def load_plugins(self, snapshots=None, cfg=None, force=False):
        if self.plugins_loaded and not force:
            return

        if snapshots is None:
            import snapshots as snapshots_
            snapshots = snapshots_.Snapshots(cfg)

        self.plugins_loaded = True
        self.plugins = []
        self.has_gui_plugins_ = False

        loadedPlugins = []
        for path in ('plugins', 'common/plugins', 'qt4/plugins'):
            fullPath = tools.get_backintime_path(path)
            if os.path.isdir(fullPath):
                logger.debug('Register plugin path %s' % fullPath, self)
                tools.register_backintime_path(path)
                for f in os.listdir(fullPath):
                    if f not in loadedPlugins and f.endswith(
                            '.py') and not f.startswith('__'):
                        try:
                            module = __import__(f[:-3])
                            module_dict = module.__dict__

                            for key, value in list(module_dict.items()):
                                if key.startswith('__'):
                                    continue

                                if type(value) is type:
                                    if issubclass(value, Plugin):
                                        plugin = value()
                                        if plugin.init(snapshots):
                                            logger.debug(
                                                'Add plugin %s' % f, self)
                                            if plugin.is_gui():
                                                self.has_gui_plugins_ = True
                                                self.plugins.insert(0, plugin)
                                            else:
                                                self.plugins.append(plugin)
                            loadedPlugins.append(f)
                        except BaseException as e:
                            logger.error(
                                'Failed to load plugin %s: %s' % (f, str(e)),
                                self)
Beispiel #3
0
    def load_plugins(self, snapshots=None, cfg=None, force=False):
        if self.plugins_loaded and not force:
            return

        if snapshots is None:
            import snapshots as snapshots_

            snapshots = snapshots_.Snapshots(cfg)

        self.plugins_loaded = True
        self.plugins = []
        self.has_gui_plugins_ = False

        loadedPlugins = []
        for path in ("plugins", "common/plugins", "qt4/plugins"):
            fullPath = tools.get_backintime_path(path)
            if os.path.isdir(fullPath):
                logger.debug("Register plugin path %s" % fullPath, self)
                tools.register_backintime_path(path)
                for f in os.listdir(fullPath):
                    if f not in loadedPlugins and f.endswith(".py") and not f.startswith("__"):
                        try:
                            module = __import__(f[:-3])
                            module_dict = module.__dict__

                            for key, value in list(module_dict.items()):
                                if key.startswith("__"):
                                    continue

                                if type(value) is type:
                                    if issubclass(value, Plugin):
                                        plugin = value()
                                        if plugin.init(snapshots):
                                            logger.debug("Add plugin %s" % f, self)
                                            if plugin.is_gui():
                                                self.has_gui_plugins_ = True
                                                self.plugins.insert(0, plugin)
                                            else:
                                                self.plugins.append(plugin)
                            loadedPlugins.append(f)
                        except BaseException as e:
                            logger.error("Failed to load plugin %s: %s" % (f, str(e)), self)
Beispiel #4
0
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License along
#    with this program; if not, write to the Free Software Foundation, Inc.,
#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.


import os
import sys
import tools

tools.register_backintime_path("common")
tools.register_backintime_path("plugins")

import logger
from exceptions import StopException


class Plugin:
    def __init__(self):
        return

    def init(self, snapshots):
        return True

    def is_gui(self):
        return False
Beispiel #5
0
 def test_register_backintime_path(self):
     path = tools.get_backintime_path('foo')
     tools.register_backintime_path('foo')
     self.assertIn(path, sys.path)
     sys.path.remove(path)
Beispiel #6
0
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License along
#    with this program; if not, write to the Free Software Foundation, Inc.,
#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

import os
import sys
import tools

tools.register_backintime_path('common')
tools.register_backintime_path('plugins')

import logger
from exceptions import StopException


class Plugin:
    def __init__(self):
        return

    def init(self, snapshots):
        return True

    def is_gui(self):
        return False