Ejemplo n.º 1
0
    def unpack_package(package_path, target_dir):
        """
        Unpacks a Nordic DFU package.

        :param str package_path: Path to the package
        :param str target_dir: Target directory to unpack the package to
        :return: Manifest Manifest: Returns a manifest back to the user. The manifest is a parse datamodel
        of the manifest found in the Nordic DFU package.
        """

        if not os.path.isfile(package_path):
            raise NordicSemiException("Package {0} not found.".format(package_path))

        target_dir = os.path.abspath(target_dir)
        target_base_path = os.path.dirname(target_dir)

        if not os.path.exists(target_base_path):
            raise NordicSemiException("Base path to target directory {0} does not exist.".format(target_base_path))

        if not os.path.isdir(target_base_path):
            raise NordicSemiException("Base path to target directory {0} is not a directory.".format(target_base_path))

        if os.path.exists(target_dir):
            raise NordicSemiException(
                "Target directory {0} exists, not able to unpack to that directory.",
                target_dir)

        with ZipFile(package_path, 'r') as pkg:
            pkg.extractall(target_dir)

            with open(os.path.join(target_dir, Package.MANIFEST_FILENAME), 'r') as f:
                _json = f.read()
                """:type :str """

                return Manifest.from_json(_json)
Ejemplo n.º 2
0
    def unpack_package(package_path, target_dir):
        """
        Unpacks a Nordic DFU package.

        :param str package_path: Path to the package
        :param str target_dir: Target directory to unpack the package to
        :return: Manifest Manifest: Returns a manifest back to the user. The manifest is a parse datamodel
        of the manifest found in the Nordic DFU package.
        """

        if not os.path.isfile(package_path):
            raise NordicSemiException("Package {0} not found.".format(package_path))

        target_dir = os.path.abspath(target_dir)
        target_base_path = os.path.dirname(target_dir)

        if not os.path.exists(target_base_path):
            raise NordicSemiException("Base path to target directory {0} does not exist.".format(target_base_path))

        if not os.path.isdir(target_base_path):
            raise NordicSemiException("Base path to target directory {0} is not a directory.".format(target_base_path))

        if os.path.exists(target_dir):
            raise NordicSemiException("Target directory {0} exists, not able to unpack to that directory.", target_dir)

        with ZipFile(package_path, "r") as pkg:
            pkg.extractall(target_dir)

            with open(os.path.join(target_dir, Package.MANIFEST_FILENAME), "r") as f:
                _json = f.read()
                """:type :str """

                return Manifest.from_json(_json)
Ejemplo n.º 3
0
 def test_manifest_c(self):
     r = ManifestGenerator(self.firmwares_data_c)
     m = Manifest.from_json(r.generate_manifest())
     self.assertIsNotNone(m)
     self.assertIsNone(m.application)
     self.assertIsNone(m.bootloader)
     self.assertIsNotNone(m.softdevice)
     self.assertEqual('softdevice_fw.bin', m.softdevice.bin_file)
     self.assertEqual('softdevice_fw.dat', m.softdevice.dat_file)
     self.assertIsNone(m.softdevice_bootloader)
 def test_manifest_c(self):
     r = ManifestGenerator(self.firmwares_data_c)
     m = Manifest.from_json(r.generate_manifest())
     self.assertIsNotNone(m)
     self.assertIsNone(m.application)
     self.assertIsNone(m.bootloader)
     self.assertIsNotNone(m.softdevice)
     self.assertEqual('softdevice_fw.bin', m.softdevice.bin_file)
     self.assertEqual('softdevice_fw.dat', m.softdevice.dat_file)
     self.assertIsNone(m.softdevice_bootloader)
Ejemplo n.º 5
0
 def test_manifest_b(self):
     r = ManifestGenerator(self.firmwares_data_b)
     m = Manifest.from_json(r.generate_manifest())
     self.assertIsNotNone(m)
     self.assertIsNotNone(m.application)
     self.assertEqual("app_fw.bin", m.application.bin_file)
     self.assertEqual("app_fw.dat", m.application.dat_file)
     self.assertIsNotNone(m.bootloader)
     self.assertEqual("bootloader_fw.bin", m.bootloader.bin_file)
     self.assertEqual("bootloader_fw.dat", m.bootloader.dat_file)
     self.assertIsNone(m.softdevice)
     self.assertIsNone(m.softdevice_bootloader)
 def test_manifest_b(self):
     r = ManifestGenerator(self.firmwares_data_b)
     m = Manifest.from_json(r.generate_manifest())
     self.assertIsNotNone(m)
     self.assertIsNotNone(m.application)
     self.assertEqual("app_fw.bin", m.application.bin_file)
     self.assertEqual("app_fw.dat", m.application.dat_file)
     self.assertIsNotNone(m.bootloader)
     self.assertEqual("bootloader_fw.bin", m.bootloader.bin_file)
     self.assertEqual("bootloader_fw.dat", m.bootloader.dat_file)
     self.assertIsNone(m.softdevice)
     self.assertIsNone(m.softdevice_bootloader)
Ejemplo n.º 7
0
 def test_manifest_a(self):
     r = ManifestGenerator(0.5, self.firmwares_data_a)
     m = Manifest.from_json(r.generate_manifest())
     self.assertIsNotNone(m)
     self.assertIsNotNone(m.application)
     self.assertEqual("app_fw.bin", m.application.bin_file)
     self.assertEqual("app_fw.dat", m.application.dat_file)
     self.assertIsNone(m.bootloader)
     self.assertIsNone(m.softdevice)
     self.assertIsNotNone(m.softdevice_bootloader)
     self.assertEqual(90, m.softdevice_bootloader.sd_size)
     self.assertEqual(50, m.softdevice_bootloader.bl_size)
     self.assertEqual("sd_bl_fw.bin", m.softdevice_bootloader.bin_file)
     self.assertEqual("sd_bl_fw.dat", m.softdevice_bootloader.dat_file)