示例#1
0
 def pack(self, output_path, verbose=False, workspace_dir=Workspace.DEFAULT_WORKSPACE_DIR):
     """
     Creates a *.son file of this service object.
     First writes the normal project structure to disk (to be used with packaging tool)
     """
     start_time = time.time()
     tmp_path = self._write(output_path)
     pkg_path = os.path.join(output_path, self.pkg_name) + ".son"
     LOG.warning(pkg_path)
     self.metadata["package_disk_path"] = pkg_path
     # be sure the target directory exists
     ensure_dir(output_path)
     # obtain workspace
     # TODO have workspace dir as command line argument
     workspace = Workspace.__create_from_descriptor__(workspace_dir)
     if workspace is None:
         LOG.error("Couldn't initialize workspace: %r. Abort." % workspace_dir)
         exit(1)
     # force verbosity of external tools if required
     workspace.log_level = "DEBUG" if verbose else "INFO"
     # obtain project
     project = Project.__create_from_descriptor__(workspace, tmp_path)
     if project is None:
         LOG.error("Packager couldn't load service project: %r. Abort." % tmp_path)
         exit(1)
     # initialize and run packager
     pck = Packager(workspace, project, dst_path=output_path)
     pck.generate_package(self.pkg_name)
     self.metadata["package_disk_size"] = os.path.getsize(pkg_path)
     self.metadata["package_generation_time"] = time.time() - start_time
     LOG.debug("Packed: {} to {}".format(self, pkg_path))
     return pkg_path
示例#2
0
    def test_generate_package(self, m_zipfile, m_join):
        """
        Ensures that a package file is created with correct name and location
        """
        # First, create a workspace to give to Packager
        workspace = Workspace("ws/root", ws_name="ws_test", log_level='debug')

        # Create project
        project = Project(workspace, 'prj/path')

        # Instantiate a Packager instance
        packager = Packager(workspace=workspace,
                            project=project,
                            generate_pd=False,
                            dst_path="dst/path")

        packager._package_descriptor = True

        # Prepare mocks
        context_manager_mock = Mock()
        m_zipfile.ZipFile.return_value = context_manager_mock
        enter_mock = Mock()
        exit_mock = Mock()
        setattr(context_manager_mock, '__enter__', enter_mock)
        setattr(context_manager_mock, '__exit__', exit_mock)

        # execute
        packager.generate_package("package_name")

        # make assertions
        self.assertEqual(m_join.call_args_list[-1],
                         mock.call('dst/path', 'package_name.son'))
示例#3
0
 def pack(self, output_path):
     """
     Use son-package to pack the given packet.
     :param output_path: resulting packages are placed in output_path
     :return: package path
     """
     start_time = time.time()
     pkg_destination_path = os.path.join(output_path, self.pkg_name())
     # obtain workspace
     # TODO have workspace dir as command line argument
     workspace = Workspace.__create_from_descriptor__(
         Workspace.DEFAULT_WORKSPACE_DIR)
     if workspace is None:
         LOG.error("Couldn't initialize workspace: %r. Abort." %
                   Workspace.DEFAULT_WORKSPACE_DIR)
         exit(1)
     # obtain project
     project = Project.__create_from_descriptor__(workspace,
                                                  self.pkg_service_path)
     if project is None:
         LOG.error("Packager couldn't load service project: %r. Abort." %
                   self.pkg_service_path)
         exit(1)
     # initialize and run packager
     pck = Packager(workspace, project, dst_path=pkg_destination_path)
     pck.generate_package(os.path.join(output_path, self.pkg_name()))
     self.pkg_package_path = os.path.join(output_path,
                                          self.pkg_name()) + ".son"
     self.pkg_file_size = os.path.getsize(self.pkg_package_path)
     self.pack_time = time.time() - start_time
     return self.pkg_package_path
示例#4
0
文件: sonpkg.py 项目: CN-UPB/son-cli
 def pack(self, output_path):
     """
     Use son-package to pack the given packet.
     :param output_path: resulting packages are placed in output_path
     :return: package path
     """
     start_time = time.time()
     pkg_destination_path = os.path.join(output_path, self.pkg_name())
     # obtain workspace
     # TODO have workspace dir as command line argument
     workspace = Workspace.__create_from_descriptor__(Workspace.DEFAULT_WORKSPACE_DIR)
     if workspace is None:
         LOG.error("Couldn't initialize workspace: %r. Abort." % Workspace.DEFAULT_WORKSPACE_DIR)
         exit(1)
     # obtain project
     project = Project.__create_from_descriptor__(workspace, self.pkg_service_path)
     if project is None:
         LOG.error("Packager couldn't load service project: %r. Abort." % self.pkg_service_path)
         exit(1)
     # initialize and run packager
     pck = Packager(workspace, project, dst_path=pkg_destination_path)
     pck.generate_package(os.path.join(output_path, self.pkg_name()))
     self.pkg_package_path = os.path.join(output_path, self.pkg_name()) + ".son"
     self.pkg_file_size = os.path.getsize(self.pkg_package_path)
     self.pack_time = time.time() - start_time
     return self.pkg_package_path
示例#5
0
    def test_generate_package(self, m_zipfile, m_join, m_validator, m_hash):
        """
        Ensures that a package file is created with correct name and location
        """
        # First, create a workspace to give to Packager
        workspace = Workspace("ws/root", ws_name="ws_test", log_level="debug")

        # Create project
        project = Project(workspace, "prj/path")

        # Instantiate a Packager instance
        packager = Packager(workspace=workspace, project=project, generate_pd=False, dst_path="dst/path")

        packager._package_descriptor = True

        # Prepare mocks
        context_manager_mock = Mock()
        m_zipfile.ZipFile.return_value = context_manager_mock
        enter_mock = Mock()
        exit_mock = Mock()
        setattr(context_manager_mock, "__enter__", enter_mock)
        setattr(context_manager_mock, "__exit__", exit_mock)
        m_validator.validate_package.return_value = True
        m_hash.return_value = ""

        # execute
        packager.generate_package("package_name")

        # make assertions
        self.assertEqual(m_join.call_args_list[-1], mock.call("dst/path", "package_name.son"))
示例#6
0
 def pack(self,
          output_path,
          verbose=False,
          workspace_dir=Workspace.DEFAULT_WORKSPACE_DIR):
     """
     Creates a *.son file of this service object.
     First writes the normal project structure to disk (to be used with packaging tool)
     """
     start_time = time.time()
     tmp_path = self._write(output_path)
     pkg_path = os.path.join(output_path, self.pkg_name) + ".son"
     LOG.warning(pkg_path)
     self.metadata["package_disk_path"] = pkg_path
     # be sure the target directory exists
     ensure_dir(output_path)
     # obtain workspace
     # TODO have workspace dir as command line argument
     workspace = Workspace.__create_from_descriptor__(workspace_dir)
     if workspace is None:
         LOG.error("Couldn't initialize workspace: %r. Abort." %
                   workspace_dir)
         exit(1)
     # force verbosity of external tools if required
     workspace.log_level = "DEBUG" if verbose else "INFO"
     # obtain project
     project = Project.__create_from_descriptor__(workspace, tmp_path)
     if project is None:
         LOG.error("Packager couldn't load service project: %r. Abort." %
                   tmp_path)
         exit(1)
     # initialize and run packager
     pck = Packager(workspace, project, dst_path=output_path)
     pck.generate_package(self.pkg_name)
     self.metadata["package_disk_size"] = os.path.getsize(pkg_path)
     self.metadata["package_generation_time"] = time.time() - start_time
     LOG.debug("Packed: {} to {}".format(self, pkg_path))
     return pkg_path