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 tempfile
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
import gi
|
||||||
import github
|
import github
|
||||||
import pygit2
|
import pygit2
|
||||||
import yaml
|
import yaml
|
||||||
from gql import Client, gql
|
from gql import Client, gql
|
||||||
from gql.transport.requests import RequestsHTTPTransport
|
from gql.transport.requests import RequestsHTTPTransport
|
||||||
|
|
||||||
|
gi.require_version("Json", "1.0")
|
||||||
|
from gi.repository import Json
|
||||||
|
|
||||||
|
|
||||||
def set_protected_branch(token, repo, branch):
|
def set_protected_branch(token, repo, branch):
|
||||||
transport = RequestsHTTPTransport(
|
transport = RequestsHTTPTransport(
|
||||||
@@ -74,6 +78,7 @@ def set_protected_branch(token, repo, branch):
|
|||||||
def detect_appid(dirname):
|
def detect_appid(dirname):
|
||||||
files = []
|
files = []
|
||||||
ret = (None, None)
|
ret = (None, None)
|
||||||
|
appid = None
|
||||||
|
|
||||||
for ext in ("yml", "yaml", "json"):
|
for ext in ("yml", "yaml", "json"):
|
||||||
files.extend(glob.glob(f"{dirname}/*.{ext}"))
|
files.extend(glob.glob(f"{dirname}/*.{ext}"))
|
||||||
@@ -86,32 +91,26 @@ def detect_appid(dirname):
|
|||||||
with open(filename) as f:
|
with open(filename) as f:
|
||||||
if ext in ("yml", "yaml"):
|
if ext in ("yml", "yaml"):
|
||||||
manifest = yaml.safe_load(f)
|
manifest = yaml.safe_load(f)
|
||||||
|
if "app-id" in manifest:
|
||||||
|
appid = manifest["app-id"]
|
||||||
|
elif "id" in manifest:
|
||||||
|
appid = manifest["id"]
|
||||||
else:
|
else:
|
||||||
result = subprocess.run(
|
parser = Json.Parser()
|
||||||
["flatpak-builder", "--show-manifest", filename],
|
if parser.load_from_file(parser, filename):
|
||||||
stdout=subprocess.PIPE,
|
root_node = parser.get_root()
|
||||||
)
|
if root_node.get_node_type() == Json.NodeType.OBJECT:
|
||||||
if result.returncode == 0:
|
json_object = root_node.get_object()
|
||||||
manifest = json.loads(result.stdout.decode("utf-8"))
|
if json_object.has_member("id"):
|
||||||
else:
|
appid = json_object.get_string_member("id")
|
||||||
print(
|
elif json_object.has_member("app-id"):
|
||||||
"flatpak-builder failed to print manifest, falling back to json Python module"
|
appid = json_object.get_string_member("app-id")
|
||||||
)
|
|
||||||
try:
|
|
||||||
with open(filename) as f:
|
|
||||||
manifest = json.load(f)
|
|
||||||
except json.decoder.JSONDecodeError:
|
|
||||||
("Manifest is not a valid JSON")
|
|
||||||
break
|
|
||||||
|
|
||||||
if manifest:
|
if not appid:
|
||||||
|
continue
|
||||||
|
|
||||||
|
if appid:
|
||||||
manifest_file = os.path.basename(filename)
|
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:
|
if os.path.splitext(manifest_file)[0] != appid:
|
||||||
print(f"Skipping {manifest_file}, does not match appid {appid}")
|
print(f"Skipping {manifest_file}, does not match appid {appid}")
|
||||||
continue
|
continue
|
||||||
|
|||||||
Reference in New Issue
Block a user