mirror of
https://github.com/stan220/flathub.git
synced 2026-09-08 17:28:57 +00:00
merge: Replace flatpak-builder with json-glib
This commit is contained in:
committed by
bbhtt
parent
c85708d5f8
commit
1368361275
@@ -9,12 +9,16 @@ import sys
|
||||
import tempfile
|
||||
import time
|
||||
|
||||
import gi
|
||||
import github
|
||||
import pygit2
|
||||
import yaml
|
||||
from gql import Client, gql
|
||||
from gql.transport.requests import RequestsHTTPTransport
|
||||
|
||||
gi.require_version("Json", "1.0")
|
||||
from gi.repository import Json
|
||||
|
||||
|
||||
def set_protected_branch(token, repo, branch):
|
||||
transport = RequestsHTTPTransport(
|
||||
@@ -74,6 +78,7 @@ def set_protected_branch(token, repo, branch):
|
||||
def detect_appid(dirname):
|
||||
files = []
|
||||
ret = (None, None)
|
||||
appid = None
|
||||
|
||||
for ext in ("yml", "yaml", "json"):
|
||||
files.extend(glob.glob(f"{dirname}/*.{ext}"))
|
||||
@@ -86,32 +91,26 @@ def detect_appid(dirname):
|
||||
with open(filename) as f:
|
||||
if ext in ("yml", "yaml"):
|
||||
manifest = yaml.safe_load(f)
|
||||
if "app-id" in manifest:
|
||||
appid = manifest["app-id"]
|
||||
elif "id" in manifest:
|
||||
appid = manifest["id"]
|
||||
else:
|
||||
result = subprocess.run(
|
||||
["flatpak-builder", "--show-manifest", filename],
|
||||
stdout=subprocess.PIPE,
|
||||
)
|
||||
if result.returncode == 0:
|
||||
manifest = json.loads(result.stdout.decode("utf-8"))
|
||||
else:
|
||||
print(
|
||||
"flatpak-builder failed to print manifest, falling back to json Python module"
|
||||
)
|
||||
try:
|
||||
with open(filename) as f:
|
||||
manifest = json.load(f)
|
||||
except json.decoder.JSONDecodeError:
|
||||
("Manifest is not a valid JSON")
|
||||
break
|
||||
parser = Json.Parser()
|
||||
if parser.load_from_file(parser, filename):
|
||||
root_node = parser.get_root()
|
||||
if root_node.get_node_type() == Json.NodeType.OBJECT:
|
||||
json_object = root_node.get_object()
|
||||
if json_object.has_member("id"):
|
||||
appid = json_object.get_string_member("id")
|
||||
elif json_object.has_member("app-id"):
|
||||
appid = json_object.get_string_member("app-id")
|
||||
|
||||
if manifest:
|
||||
if not appid:
|
||||
continue
|
||||
|
||||
if appid:
|
||||
manifest_file = os.path.basename(filename)
|
||||
if "app-id" in manifest:
|
||||
appid = manifest["app-id"]
|
||||
elif "id" in manifest:
|
||||
appid = manifest["id"]
|
||||
else:
|
||||
continue
|
||||
if os.path.splitext(manifest_file)[0] != appid:
|
||||
print(f"Skipping {manifest_file}, does not match appid {appid}")
|
||||
continue
|
||||
|
||||
Reference in New Issue
Block a user