-
Notifications
You must be signed in to change notification settings - Fork 148
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import os | ||
import tempfile | ||
from typing import Optional | ||
|
||
from .. import appstream, builddir, ostree | ||
from . import Check | ||
|
||
|
||
class DesktopfileCheck(Check): | ||
def _load(self, path: str, appid: str) -> Optional[dict]: | ||
|
||
desktop_path = f"{path}/files/share/applications/{appid}.desktop" | ||
|
||
is_baseapp = appid.endswith(".BaseApp") | ||
|
||
if not is_baseapp: | ||
if not os.path.exists(desktop_path): | ||
self.errors.add("desktop-file-not-installed") | ||
elif os.path.exists(desktop_path): | ||
data = {} # type: dict | ||
with open(desktop_path, "r", encoding="utf-8") as file: | ||
for line in file: | ||
line = line.strip() | ||
if line.startswith("#"): | ||
continue | ||
if line.startswith("[") and line.endswith("]"): | ||
group = line[1:-1] | ||
data[group] = {} | ||
if "=" in line: | ||
key = line.split("=", 1)[0] | ||
value = line.split("=", 1)[1] | ||
data[group][key] = value | ||
|
||
return data | ||
|
||
return None | ||
|
||
def _validate(self, path: str, appid: str) -> None: | ||
d = self._load(path, appid) | ||
if d is not None: | ||
icon = d["Desktop Entry"]["Icon"] | ||
if icon != appid: | ||
self.errors.add("desktop-file-wrong-icon-name") | ||
|
||
def check_build(self, path: str) -> None: | ||
appid = builddir.infer_appid(path) | ||
if not appid: | ||
return | ||
metadata = builddir.get_metadata(path) | ||
if not metadata: | ||
return | ||
is_extension = metadata.get("extension") | ||
|
||
self._validate(f"{path}", appid) | ||
appstream_path = f"{path}/files/share/app-info/xmls/{appid}.xml.gz" | ||
if ( | ||
is_extension | ||
or os.path.exists(appstream_path) | ||
and appstream.is_console(appstream_path) | ||
): | ||
self.errors.discard("desktop-file-not-installed") | ||
self.errors.discard("desktop-file-wrong-icon-name") | ||
|
||
def check_repo(self, path: str) -> None: | ||
self._populate_ref(path) | ||
ref = self.repo_primary_ref | ||
if not ref: | ||
return | ||
appid = ref.split("/")[1] | ||
|
||
with tempfile.TemporaryDirectory() as tmpdir: | ||
ret = ostree.extract_subpath(path, ref, "/", tmpdir) | ||
if ret["returncode"] != 0: | ||
raise RuntimeError("Failed to extract ostree repo") | ||
appstream_path = f"{tmpdir}/files/share/app-info/xmls/{appid}.xml.gz" | ||
self._validate(tmpdir, appid) | ||
if os.path.exists(appstream_path) and appstream.is_console(appstream_path): | ||
self.errors.discard("desktop-file-not-installed") | ||
self.errors.discard("desktop-file-wrong-icon-name") |
9 changes: 9 additions & 0 deletions
9
...lddir/desktop-file/files/share/applications/com.github.flathub_infra.desktop-file.desktop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[Desktop Entry] | ||
Version=1.0 | ||
Name=Desktop application | ||
Comment=A desktop application | ||
Exec=foo %u | ||
# Icon does not match app-id | ||
Icon=org.flathub.foo | ||
Terminal=false | ||
Type=Application |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[Application] | ||
name=com.github.flathub_infra.desktop-file |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters