Exemplo n.º 1
0
    def to_dict(self) -> Dict[str, Any]:
        """Returns and ordered dictonary with the transformed app entry."""

        app_dict = deepcopy(self._app_properties)

        for command_name, command in self.commands.items():
            app_dict[command_name] = command.command

        if self.prepend_command_chain or self.command_chain:
            app_dict["command-chain"] = self.prepend_command_chain + self.command_chain

        # Adjust socket values to formats snap.yaml accepts
        sockets = app_dict.get("sockets", dict())
        for socket in sockets.values():
            mode = socket.get("socket-mode")
            if mode is not None:
                socket["socket-mode"] = yaml_utils.OctInt(mode)

        # Strip keys.
        for key in ["adapter", "desktop"]:
            if key in app_dict:
                app_dict.pop(key)

        # Apply passthrough keys.
        app_dict.update(self.passthrough)
        return app_dict
Exemplo n.º 2
0
 def _render_socket_modes(self, apps: Dict[str, Any]) -> None:
     for app in apps.values():
         sockets = app.get("sockets", {})
         for socket in sockets.values():
             mode = socket.get("socket-mode")
             if mode is not None:
                 socket["socket-mode"] = yaml_utils.OctInt(mode)
Exemplo n.º 3
0
 def _fix_sockets(self) -> None:
     # Adjust socket values to formats snap.yaml accepts
     sockets = self._app_properties.get("sockets", dict())
     for socket in sockets.values():
         mode = socket.get("socket-mode")
         if mode is not None:
             socket["socket-mode"] = yaml_utils.OctInt(mode)
Exemplo n.º 4
0
    def test_octint_dump(self):
        output = io.StringIO()
        yaml_utils.dump(dict(number=yaml_utils.OctInt(8)), stream=output)
        output.seek(0)

        self.assertThat(output.read().strip(), Equals("number: 0010"))
Exemplo n.º 5
0
def test_dump_octint(tmp_path):
    output = io.StringIO()
    yaml_utils.dump(dict(number=yaml_utils.OctInt(8)), stream=output)
    output.seek(0)

    assert output.read().strip() == "number: 0010"