Пример #1
0
    def setUp(self):
        LogFactory.getLogger(level = 10)

        self.snappath_new = os.path.join(_TestSnapshotPaths.get_snp_path(), self.snp_new_name)
        self.in_path_abs = _TestSnapshotPaths.get_docinput_path()
#        print "SNAPPATH NEW: '%s'"\ % (self.snappath_new)
        self.__clean_dir()
Пример #2
0
    def logsome(self):
        l = LogFactory.getLogger("TestLogger", "sbackup.log")

        l.info("Hello World")
        l.debug("Argh")

        l = LogFactory.getLogger("TestLogger1", "sbackup.log")

        l.info("Hello World Log 1")
        l.error("Argh")
Пример #3
0
    def __init__(self, indicator_hdl):
        if not isinstance(indicator_hdl, SBackupdIndicatorHandler):
            raise TypeError(
                "Parameter of type `SBackupdIndicatorHandler` expected.")
        self.logger = LogFactory.getLogger()
        INotifyMixin.__init__(self,
                              logger=self.logger,
                              iconfile=None,
                              trayicon=None)

        self._indicator_hdl = indicator_hdl
        self._mainloop = gobject.MainLoop()

        self._indicator = None

        self._exit = False
        #TODO: Collect required named dialogs in dictionary.
        self._targetnotfound_dialog = None
        self._cancel_dialog = None
        self._current_dialogs = []
        self._menu = gtk.Menu()
        self._menuitems = {}

        self._connect_dbus_signal_handlers()
        self._init_dbus_check_timer()
        self._init_autoexitcheck_timer()
Пример #4
0
    def _compare_snar_files(self, snapshot, snarfile):
        """Compares the snar file of the given `snapshot` and the given
        (result) `snarfile`.
        
        The header of the snar files (i.e. the tar version, time of backup)
        is not compared. Any following records (mtime, inode, filenames) are
        compared and must be identical to pass the comparison.        
        """
        # only for debugging
        if LogFactory.getLogger().isEnabledFor(10):
            debug_print_snarfile(snapshot.getSnarFile())
            debug_print_snarfile(snarfile)
        # end of debug output

        _snar1 = debug_snarfile_to_list(snapshot.getSnarFile())
        _snar2 = debug_snarfile_to_list(snarfile)

        self.assertEqual(len(_snar1), len(_snar2))
        for idx in range(0, len(_snar1)):
            _record1 = _snar1[idx]
            _record2 = _snar2[idx]
            self.assertEqual(len(_record1), len(_record2))
            for idx2 in range(0, len(_record1) - 1):
                self.assertEqual(_record1[idx2], _record2[idx2])

            _content1 = _record1[-1]
            _content2 = _record2[-1]
            self.assertEqual(len(_content1), len(_content2))
            for idx2 in range(0, len(_content1)):
                self.assertEqual(_content1[idx2].getFilename(),
                                 _content2[idx2].getFilename())
                self.assertEqual(_content1[idx2].getControl(),
                                 _content2[idx2].getControl())
Пример #5
0
class TestTarUtilsArchiveType(unittest.TestCase) :
    """Test case for function 'getArchiveType' defined in module 'tar'.
    """

    LogFactory.getLogger(level = 10)

    def test_get_archive_type(self):
        """Test determination of archive types using mime types
        """
        rel_dir = "archivetype"

        input_data = [{ "file" : "test-tar.tar", "type" : "tar" },
                      { "file" : "test-tar.tar.gz", "type" : "gzip" },
                      { "file" : "test-tar.tar.bz2", "type" : "bzip2" },
                      { "file" : "test-tar.archive", "type" : "tar" },
                      { "file" : "test-tar.tar.zip", "type" : "gzip" },
                      { "file" : "test-tar.archive.lzma", "type" : "bzip2" },
                      { "file" : "test-tar.fake.tar", "type" : None },
                      { "file" : "test-tar.fake.tar.gz", "type" : None },
                      { "file" : "test-tar.fake.tar.bz2", "type" : None }
                     ]
        for _data in input_data:
            _res = getArchiveType(_TestTarPaths.get_path(rel_dir +
                                                         os.path.sep +
                                                         _data["file"]))
            self.assertEqual(_res, _data["type"])
Пример #6
0
    def __init__(self, backup_dbus_obj, options):
        if not isinstance(backup_dbus_obj, dbus_support.DBusClientFacade):
            raise TypeError(
                "Given backup_dbus_obj of type `DBusClientFacade` expected.")

        self.logger = LogFactory.getLogger()
        self.__options = options

        self._backup_dbus_obj = backup_dbus_obj

        self._space_required = constants.SPACE_REQUIRED_UNKNOWN
        self._target = constants.TARGET_UNKNOWN
        self._profile = constants.PROFILE_UNKNOWN

        self.__error_present = False
        self.__warning_present = False

        self._menuitem_status_tmpl = {
            "profile": _("Profile: %s"),
            "size_of_backup": _("Size of backup: %s"),
            "progress": _("%.1f%% processed"),
            "remaining_time": _("Remaining time: %s")
        }

        self._targetnotfound_run_timer = False
        self._targetnotfound_clock = 0
        self._starttime_backup = None
        self._time_est_total = 0
Пример #7
0
class TestTarUtilsAppendTar(unittest.TestCase) :
    """Test case for functions 'appendToTar..' defined in module 'tar'.
    """

    LogFactory.getLogger(level = 10)

    def test_append_to_tar(self):
#        rel_dir = "archivetype"
#        
#        input_data = [{ "file" : "test-tar.tar", "type" : "tar" },
#                      { "file" : "test-tar.tar.gz", "type" : "gzip" },
#                      { "file" : "test-tar.tar.bz2", "type" : "bzip2" },
#                      { "file" : "test-tar.archive", "type" : "tar" },
#                      { "file" : "test-tar.tar.zip", "type" : "gzip" },
#                      { "file" : "test-tar.archive.lzma", "type" : "bzip2" },
#                      { "file" : "test-tar.fake.tar", "type" : None },
#                      { "file" : "test-tar.fake.tar.gz", "type" : None },
#                      { "file" : "test-tar.fake.tar.bz2", "type" : None } 
#                     ]
#        for _data in input_data:
#            _res = getArchiveType(_TestTarPaths.get_path(rel_dir +
#                                                         os.path.sep +
#                                                         _data["file"]))

        raise NotImplementedError
Пример #8
0
    def setUp(self):
        LogFactory.getLogger(level = 10)

        self.snappath_ful = os.path.join(_TestSnapshotPaths.get_snp_path(), self.snp_ful_name)
        self.snappath_inc = os.path.join(_TestSnapshotPaths.get_snp_path(), self.snp_inc_name)

        self.in_path_abs = _TestSnapshotPaths.get_docinput_path()

#        print "ABSPATH TESTDIR: '%s'\nSNAPPATH FUL: '%s'\nSNAPPATH INC: '%s'"\
#              "\nSNAPPATH NEW: '%s'"\
#                % (self.abspath_testdir, self.snappath_ful,
#                   self.snappath_inc, self.snappath_new)

        self.__clean_dir()
        self.__untar_snapshots()

        # creation of snapshots
        self.snapshot_ful = snapshot.Snapshot(self.snappath_ful)
        self.snapshot_inc = snapshot.Snapshot(self.snappath_inc)
Пример #9
0
    def setUp(self):
        """Common setup method: creates required directories, extracts the
        test data and retrieves the names of input and result snapshots.
        """
        LogFactory.getLogger(level=LOGLEVEL)

        # sorting order is important!
        self.snpname = []
        self.res_snpname = []
        self.snppath = []
        self.res_snppath = []

        self._clean_dirs()
        self._make_dirs()
        self._untar()
        self._setup_snppaths()
        self._copy_result_snar()

        # create SnapshotManager
        self.snpman = SnapshotManager(self._path_class.get_path_working_dir())
Пример #10
0
    def __init__(self, parent=None):
        GladeWindow.__init__(self,
                             gladefile=Util.get_resource_file(
                                 gtk_rsrc.RESTOREGUI_GLADEFILE),
                             widget_list=gtk_rsrc.get_restoregui_widgets(),
                             handlers=gtk_rsrc.get_restoregui_handlers(),
                             root=gtk_rsrc.RESTOREGUI_TOPWINDOW,
                             parent=parent,
                             pull_down_dict=None)
        self.set_top_window(self.widgets[gtk_rsrc.RESTOREGUI_TOPWINDOW])
        Gtk.Window.set_default_icon_from_file(
            Util.get_resource_file(constants.RESTORE_ICON_FILENAME))

        # setup progress bar
        ProgressbarMixin.__init__(self, self.widgets['progressbar'])
        self._init_pulse()

        self.logger = LogFactory.getLogger(level=10)
        self.config = self.__get_configuration()
        self.__default_destination_path = self.config.get_destination_path()

        self.currentSnp = None
        self.currentsbdict = None
        self.currSnpFilesInfos = None
        self.restoreman = None
        self.snpman = None
        self.target = None
        self.__fam_target_hdl = fam.get_fam_target_handler_facade_instance()
        self.__fop = fam.get_file_operations_facade_instance()

        # tree stores
        self.snplisttreestore = Gtk.TreeStore(str, str)
        self.flisttreestore = Gtk.TreeStore(str, str)
        self.flisttreesort = Gtk.TreeModelSort(self.flisttreestore)
        self.historylisttreestore = Gtk.TreeStore(str)
        self.__init_treeviews()

        self.widgets['snpdetails'].set_sensitive(False)

        self.__context_id = None
        self.__init_statusbar()

        # firstly initialize destination with target of default profile
        self._defaultdest_active = True
        self.widgets['defaultradiob'].set_active(True)
        self._apply_defaultradiob_state()
        self.widgets['defaultfolderlabel'].set_text(_("n.a."))
        self._defaultdest_active = True
        GObject.idle_add(self.__set_destination,
                         self.__default_destination_path)

        self.__restore_dialog = RestoreDialog(parent=self)
Пример #11
0
    def _untar(self):
        """Extracts the archives defined in the according class `paths`.
        """
        LogFactory.getLogger().info("\nPrepare test: now un-tar input")
        tarcmd = [
            'tar', '--extract', '--lzma',
            '--directory=%s' % self._path_class.get_path_working_dir(),
            '--file=%s' % self._path_class.get_path_input_tar()
        ]
        LogFactory.getLogger().debug("  tar command: %s" % tarcmd)
        subprocess.call(tarcmd)

        LogFactory.getLogger().info("Prepare test: now un-tar results")
        if self._path_class.has_result_tar():
            tarcmd = [
                'tar', '--extract', '--lzma',
                '--directory=%s' % self._path_class.get_path_result_dir(),
                '--file=%s' % self._path_class.get_path_result_tar()
            ]
            LogFactory.getLogger().debug("  tar command: %s" % tarcmd)
            subprocess.call(tarcmd)
        else:
            LogFactory.getLogger().info("No results defined")
Пример #12
0
    def __init__(self, indicator_hdl):
        if not isinstance(indicator_hdl, SBackupdIndicatorHandler):
            raise TypeError(
                "Parameter of type `SBackupdIndicatorHandler` expected.")

        SBackupdIndicatorBase.__init__(self, indicator_hdl)

        self.logger = LogFactory.getLogger()
        self._indicator = gtk.StatusIcon()

        PyNotifyMixin.__init__(self,
                               logger=self.logger,
                               iconfile=util.get_resource_file(
                                   constants.NOTIFICATION_ICON_FILENAME),
                               trayicon=self._indicator)

        self.__init_ctrls()
Пример #13
0
    def __init__(self, indicator_hdl):
        if not isinstance(indicator_hdl, SBackupdIndicatorHandler):
            raise TypeError(
                "Parameter of type `SBackupdIndicatorHandler` expected.")

        SBackupdIndicatorBase.__init__(self, indicator_hdl)

        self.logger = LogFactory.getLogger()
        self._indicator = appindicator.Indicator(
            constants.INDICATORAPP_NAME, constants.INDICATOR_ACTIVE_ICON,
            appindicator.CATEGORY_APPLICATION_STATUS)

        PyNotifyMixin.__init__(self,
                               logger=self.logger,
                               iconfile=util.get_resource_file(
                                   constants.NOTIFICATION_ICON_FILENAME),
                               trayicon=None)

        self.__init_ctrls()
Пример #14
0
    def _compare_tar_archives(self, snapshot_path, result_path):
        """Compares the content of the `files.tar.gz` archive that are
        stored in the given locations (`snapshot_path` and `result_path`).
        
        The archives are not extracted. The content of the archives using
        the tar option `--list` is compared. The content must be completely
        identical (same file owners, same dates, same files) to pass
        the comparison.
        """
        wd_tar = os.path.join(snapshot_path, "files.tar.gz")
        cmd = "tar"
        opts = ["--list", "--verbose", "--file=%s" % wd_tar]
        stdo_wd, stde_wd, exc_wd = util.launch(cmd=cmd, opts=opts)

        res_tar = os.path.join(result_path, "files.tar.gz")
        cmd = "tar"
        opts = ["--list", "--verbose", "--file=%s" % res_tar]
        stdo_res, stde_res, exc_res = util.launch(cmd=cmd, opts=opts)

        self.assertEqual(exc_wd, 0)
        self.assertEqual(exc_res, 0)

        stdo_wd = stdo_wd.split("\n")
        stdo_res = stdo_res.split("\n")

        stdo_wd.sort()
        stdo_res.sort()

        stdo_wd = "\n".join(stdo_wd)
        stdo_res = "\n".join(stdo_res)

        # only for debugging
        if LogFactory.getLogger().isEnabledFor(10):
            print "\nworking dir:"
            print stdo_wd
            print "\ntarget result:"
            print stdo_res
        # end of debug output

        self.assertEqual(stdo_wd, stdo_res)
Пример #15
0
    def __init__(self, destination):
        """Default constructor. Takes the path to the target backup
        directory as parameter.
        """
        if not isinstance(destination, str):
            raise TypeError("Destination path of type string expected. Got %s instead"\
                            % type(destination))

        self.logger = LogFactory.getLogger()

        self._fop = fam.get_file_operations_facade_instance()
        # This is the current directory used by this SnapshotManager
        self.__dest_path = destination

        # The list of the snapshots is stored the first time it's used,
        # so we don't have to re-get it later
        self.__snapshots = None

        # helper variables for displaying status messages
        self.statusMessage = None
        self.substatusMessage = None
        self.statusNumber = None
Пример #16
0
 def _setup_workingdir_paths(self):
     """Retrieves names of existing snapshots in the working directory.
     In order to reduce maintenance effort this is done automatically.
     
     :attention: The retrieval is done in a brute and dumb way! Take
                 care what files/directories are present in the working
                 directory when calling this method.
                 
     :result: The object variable `snpname` and `snppath` are updated.  
     """
     self.snpname = []
     self.snppath = []
     _dir = self._path_class.get_path_working_dir()
     listing = os.listdir(_dir)
     listing.sort(reverse=True)
     for name in listing:
         self.snpname.append(name)
         self.snppath.append(os.path.join(_dir, name))
     # debug output
     if LogFactory.getLogger().isEnabledFor(10):
         print "Paths to snapshots to proceed:"
         for _path in self.snppath:
             print "   %s" % _path
Пример #17
0
class TestTarUtilsGetDumpdir(unittest.TestCase) :
    """Test case for function 'get_dumpdir_from_list' defined in module 'tar'.
    """

    LogFactory.getLogger(level = 10)

    def test_getdumpdirfromlist_nolist(self):
        """Get dumpdir from list with invalid list parameter
        """
        input_data = [ ("test", "test"),
                       {"test" : "test"},
                       "test",
                       1200
                     ]
        for _data in input_data:
            self.assertRaises(TypeError, get_dumpdir_from_list, _data, "test")

    def test_getdumpdirfromlist_nodumpdir(self):
        """Get dumpdir from list with invalid elements in list
        """
        input_data = [ ["test", "test"],
                       [{"test" : "test"}],
                       ["test"],
                       [1200]
                     ]
        for _data in input_data:
            self.assertRaises(TypeError, get_dumpdir_from_list, _data, "test")

    def test_getdumpdirfromlist_notfound(self):
        """Get dumpdir from list but filename not found
        """
        input_data = [ [ Dumpdir("Ytestname"), Dumpdir("Nsome file"),
                         Dumpdir("NSome File"), Dumpdir("Ytestname~") ]
                     ]
        for _data in input_data:
            self.assertRaises(SBException, get_dumpdir_from_list, _data, "test")

    def test_get_dumpdir_from_list(self):
        """Test get dumpdir from list with valid parameters
        """
        input_data = [ { "list" : [ Dumpdir("Ytestname"),
                                    Dumpdir("Nsome file"),
                                    Dumpdir("NSome File"),
                                    Dumpdir("Ytestname~") ],
                         "name" : "testname",
                         "result" : 0
                       },
                       { "list" : [ Dumpdir("Ytestname"),
                                    Dumpdir("Nsome file"),
                                    Dumpdir("NSome File"),
                                    Dumpdir("Ytestname~") ],
                         "name" : "some file",
                         "result" : 1
                       },
                       { "list" : [ Dumpdir("Ytestname"),
                                    Dumpdir("Nsome file"),
                                    Dumpdir("NSome File"),
                                    Dumpdir("Ytestname~") ],
                         "name" : "Some File",
                         "result" : 2
                       },
                       { "list" : [ Dumpdir("Ytestname"),
                                    Dumpdir("Nsome file"),
                                    Dumpdir("NSome File"),
                                    Dumpdir("Ytestname~") ],
                         "name" : "testname~",
                         "result" : 3
                       }
                     ]
        for _data in input_data:
            _res = get_dumpdir_from_list(_data["list"], _data["name"])
            self.assertTrue(_res is _data["list"][_data["result"]])
Пример #18
0
 def setUp(self):
     """Set-up the test to be run.
     """
     LogFactory.getLogger(level=LOGLEVEL)
Пример #19
0
 def setUp(self):
     LogFactory.getLogger("Test", level = 10)
     self.rvtman = RestoreManager()
     self.snpman = SnapshotManager(os.path.abspath("test-datas/backupdir"))
Пример #20
0
 def setUp(self):
     LogFactory.getLogger(level=LOGLEVEL)
Пример #21
0
 def setUp(self):
     LogFactory.getLogger(level = 10)
     self.__clean_dir()