예제 #1
0
    def test_metadata_get_exception(self):
        """verify get checks for invalid keys"""
        json_str = """{"backup-today": "", "latest-complete": ""}"""
        metadata = MetaData(self.log, self.comms, self.settings, json_str)
        with self.assertRaises(CrashPlanError) as cpe:
            metadata.get("test")

        self.assertIsInstance(cpe.exception, CrashPlanError)
        self.assertEqual(repr(cpe.exception.value),
                         "'(get) Invalid meta data key - test'")

        self.assertEqual(self.log.getVal('info'), '')
예제 #2
0
 def test_metadata_set_success(self):
     """verify successful setting of key,val pair"""
     json_str = """{"backup-today": "2019-01-02", "latest-complete": "2019-01-02-012345"}"""
     metadata = MetaData(self.log, self.comms, self.settings, json_str)
     metadata.set('backup-today', "2019-12-12")
     self.assertEqual(metadata.get("backup-today"), "2019-12-12")
     self.assertEqual(self.log.getVal('info'), '')
예제 #3
0
    def set_loading(self, path):

        from MetaData import MetaData

        try:
            meta = MetaData(path)
            preview = meta.get(meta.KEY_PREVIEW)
        except Exception:
            preview = ""

        dirname = os.path.dirname(path)
        icon = os.path.join(dirname, preview)

        self.__label.set_markup("<big><b>Loading:</b>\n%s</big>" % path)

        self.__icon.hide()
        if preview:
            try:
                # for him who loves small try blocks: you don't gain anything
                # from splitting up this block except for badly readable code ;)
                from utils import vfs

                data = vfs.read_entire_file(icon)
                loader = gtk.gdk.PixbufLoader()
                loader.write(data, len(data))
                loader.close()
                pbuf = loader.get_pixbuf()

                # scale icon down while preserving aspect ratio
                width = pbuf.get_width()
                height = pbuf.get_height()
                scale = 48 / float(height)
                width *= scale
                if width > 96:
                    width = 96

                if abs(scale - 1.0) > 0.001:
                    pbuf = pbuf.scale_simple(int(width), 48, 3)

                self.__icon.set_from_pixbuf(pbuf)
                self.__icon.show()

            except Exception:
                pass

        # end if

        self.resize(10, 10)
        self.set_size_request(-1, -1)