Ejemplo n.º 1
0
    def test_to_dict_is_a_copy(self):
        metadata = ExtractedMetadata(summary="summary")
        metadata_dict = metadata.to_dict()
        metadata_dict["summary"] = "edited summary"

        # Ensure the metadata cannot be edited with its dict
        self.assertThat(metadata.get_summary(), Equals("summary"))
Ejemplo n.º 2
0
def _adopt_keys(config_data: Dict[str, Any],
                extracted_metadata: _metadata.ExtractedMetadata) -> Set[str]:
    ignored_keys = set()
    metadata_dict = extracted_metadata.to_dict()

    # desktop_file_paths and common_ids are special cases that will be handled
    # after all the top level snapcraft.yaml keys.
    ignore = ('desktop_file_paths', 'common_id')
    overrides = ((k, v) for k, v in metadata_dict.items() if k not in ignore)

    for key, value in overrides:
        if key not in config_data:
            if key == 'icon':
                if _icon_file_exists() or not os.path.exists(str(value)):
                    # Do not overwrite the icon file.
                    continue
            config_data[key] = value
        else:
            ignored_keys.add(key)

    if 'desktop_file_paths' in metadata_dict and 'common_id' in metadata_dict:
        app_name = _get_app_name_from_common_id(
            config_data, str(metadata_dict['common_id']))
        if app_name and not _desktop_file_exists(app_name):
            for desktop_file_path in metadata_dict['desktop_file_paths']:
                if os.path.exists(desktop_file_path):
                    config_data['apps'][app_name]['desktop'] = (
                        desktop_file_path)
                    break

    return ignored_keys
Ejemplo n.º 3
0
    def test_to_dict_is_a_copy(self):
        metadata = ExtractedMetadata(summary="summary")
        metadata_dict = metadata.to_dict()
        metadata_dict["summary"] = "edited summary"

        # Ensure the metadata cannot be edited with its dict
        self.assertThat(metadata.get_summary(), Equals("summary"))
Ejemplo n.º 4
0
    def test_to_dict_is_a_copy(self):
        metadata = ExtractedMetadata(summary='summary')
        metadata_dict = metadata.to_dict()
        metadata_dict['summary'] = 'edited summary'

        # Ensure the metadata cannot be edited with its dict
        self.assertThat(metadata.get_summary(), Equals('summary'))
Ejemplo n.º 5
0
 def test_to_dict_complete(self):
     metadata = ExtractedMetadata(
         summary='summary', description='description')
     self.assertThat(metadata.to_dict(), Equals({
         'summary': 'summary',
         'description': 'description',
     }))
Ejemplo n.º 6
0
def _adopt_info(
        config_data: Dict[str, Any],
        extracted_metadata: _metadata.ExtractedMetadata):
    metadata_dict = extracted_metadata.to_dict()
    for key, value in metadata_dict.items():
        # desktop_file_ids are a special case that will be handled
        # after all the top level snapcraft.yaml keys.
        if key != 'desktop_file_ids' and key not in config_data:
            if key == 'icon':
                if _icon_file_exists() or not os.path.exists(
                        str(value)):
                    # Do not overwrite the icon file.
                    continue
            config_data[key] = value
    if 'desktop_file_ids' in metadata_dict:
        for desktop_file_id in metadata_dict['desktop_file_ids']:
            app_name = _get_app_name_from_desktop_file_id(
                config_data, desktop_file_id)
            if app_name and not _desktop_file_exists(app_name):
                for xdg_data_dir in ('usr/local/share', 'usr/share'):
                    desktop_file_path = os.path.join(
                        xdg_data_dir, 'applications',
                        desktop_file_id.replace('-', '/'))
                    if os.path.exists(desktop_file_path):
                        config_data['apps'][app_name]['desktop'] = (
                            desktop_file_path)
Ejemplo n.º 7
0
def _adopt_keys(
    config_data: Dict[str, Any], extracted_metadata: _metadata.ExtractedMetadata
) -> Set[str]:
    ignored_keys = set()
    metadata_dict = extracted_metadata.to_dict()

    # desktop_file_paths and common_ids are special cases that will be handled
    # after all the top level snapcraft.yaml keys.
    ignore = ("desktop_file_paths", "common_id")
    overrides = ((k, v) for k, v in metadata_dict.items() if k not in ignore)

    for key, value in overrides:
        if key not in config_data:
            if key == "icon":
                if _icon_file_exists() or not os.path.exists(str(value)):
                    # Do not overwrite the icon file.
                    continue
            config_data[key] = value
        else:
            ignored_keys.add(key)

    if "desktop_file_paths" in metadata_dict and "common_id" in metadata_dict:
        app_name = _get_app_name_from_common_id(
            config_data, str(metadata_dict["common_id"])
        )
        if app_name and not _desktop_file_exists(app_name):
            for desktop_file_path in metadata_dict["desktop_file_paths"]:
                if os.path.exists(desktop_file_path):
                    config_data["apps"][app_name]["desktop"] = desktop_file_path
                    break

    return ignored_keys
Ejemplo n.º 8
0
 def test_to_dict_complete(self):
     metadata = ExtractedMetadata(summary="summary",
                                  description="description")
     self.assertThat(
         metadata.to_dict(),
         Equals({
             "summary": "summary",
             "description": "description"
         }),
     )
Ejemplo n.º 9
0
def _adopt_keys(
    config_data: Dict[str, Any],
    extracted_metadata: _metadata.ExtractedMetadata,
    prime_dir: str,
) -> Set[str]:
    ignored_keys = set()
    metadata_dict = extracted_metadata.to_dict()

    # desktop_file_paths and common_ids are special cases that will be handled
    # after all the top level snapcraft.yaml keys.
    ignore = ("desktop_file_paths", "common_id")
    overrides = ((k, v) for k, v in metadata_dict.items() if k not in ignore)

    for key, value in overrides:
        if key in config_data:
            ignored_keys.add(key)
        else:
            if key == "icon":
                # Extracted appstream icon paths will be relative to prime.
                icon = pathlib.Path(prime_dir, str(value))
                if not icon.exists():
                    # Cannot find icon, ignore silently.
                    continue

                if _find_icon_file() is None:
                    # Already have icon file, do not overwrite.
                    continue

            config_data[key] = value

    if "desktop_file_paths" in metadata_dict and "common_id" in metadata_dict:
        app_name = _get_app_name_from_common_id(
            config_data, str(metadata_dict["common_id"]))
        if app_name and not _desktop_file_exists(app_name):
            for desktop_file_path in [
                    os.path.join(prime_dir, d)
                    for d in metadata_dict["desktop_file_paths"]
            ]:
                if os.path.exists(desktop_file_path):
                    config_data["apps"][app_name][
                        "desktop"] = desktop_file_path
                    break

    return ignored_keys
Ejemplo n.º 10
0
def _adopt_info(config_data: Dict[str, Any],
                extracted_metadata: _metadata.ExtractedMetadata):
    metadata_dict = extracted_metadata.to_dict()
    for key, value in metadata_dict.items():
        # desktop_file_paths are a special case that will be handled
        # after all the top level snapcraft.yaml keys.
        if key != 'desktop_file_paths' and key not in config_data:
            if key == 'icon':
                if _icon_file_exists() or not os.path.exists(str(value)):
                    # Do not overwrite the icon file.
                    continue
            config_data[key] = value
    if 'desktop_file_paths' in metadata_dict and 'common_id' in metadata_dict:
        app_name = _get_app_name_from_common_id(
            config_data, str(metadata_dict['common_id']))
        if app_name and not _desktop_file_exists(app_name):
            for desktop_file_path in metadata_dict['desktop_file_paths']:
                if os.path.exists(desktop_file_path):
                    config_data['apps'][app_name]['desktop'] = (
                        desktop_file_path)
                    break
Ejemplo n.º 11
0
def _adopt_keys(
    config_data: Dict[str, Any],
    extracted_metadata: _metadata.ExtractedMetadata,
    prime_dir: str,
) -> Set[str]:
    ignored_keys = set()
    metadata_dict = extracted_metadata.to_dict()

    # desktop_file_paths and common_ids are special cases that will be handled
    # after all the top level snapcraft.yaml keys.
    ignore = ("desktop_file_paths", "common_id")
    overrides = ((k, v) for k, v in metadata_dict.items() if k not in ignore)

    for key, value in overrides:
        if key not in config_data:
            if key == "icon":
                # Extracted appstream icon paths will be relative to the runtime tree,
                # so rebase it on the snap source root.
                value = os.path.join(prime_dir, str(value))
                if _icon_file_exists() or not os.path.exists(str(value)):
                    # Do not overwrite the icon file.
                    continue
            config_data[key] = value
        else:
            ignored_keys.add(key)

    if "desktop_file_paths" in metadata_dict and "common_id" in metadata_dict:
        app_name = _get_app_name_from_common_id(
            config_data, str(metadata_dict["common_id"]))
        if app_name and not _desktop_file_exists(app_name):
            for desktop_file_path in [
                    os.path.join(prime_dir, d)
                    for d in metadata_dict["desktop_file_paths"]
            ]:
                if os.path.exists(desktop_file_path):
                    config_data["apps"][app_name][
                        "desktop"] = desktop_file_path
                    break

    return ignored_keys
Ejemplo n.º 12
0
 def test_to_dict_complete(self):
     metadata = ExtractedMetadata(summary="summary", description="description")
     self.assertThat(
         metadata.to_dict(),
         Equals({"summary": "summary", "description": "description"}),
     )
Ejemplo n.º 13
0
 def test_to_dict_partial(self):
     metadata = ExtractedMetadata(summary="summary")
     self.assertThat(metadata.to_dict(), Equals({"summary": "summary"}))
Ejemplo n.º 14
0
 def test_to_dict_partial(self):
     metadata = ExtractedMetadata(summary="summary")
     self.assertThat(metadata.to_dict(), Equals({"summary": "summary"}))
Ejemplo n.º 15
0
 def test_to_dict_partial(self):
     metadata = ExtractedMetadata(summary='summary')
     self.assertThat(metadata.to_dict(), Equals({'summary': 'summary'}))