check-appstream-compliance.py 1.71 KB
Newer Older
1 2 3 4 5 6 7
#!/usr/bin/python3
import sys
import argparse
from helperslib import BuildSpecs, BuildSystem, CommonUtils, EnvironmentHandler

# Parse the command line arguments we've been given
parser = argparse.ArgumentParser(description='Utility to determine whether an application is appstream compliant.')
8
parser.add_argument('--product', type=str, required=True)
9 10 11 12 13 14 15
parser.add_argument('--project', type=str, required=True)
parser.add_argument('--branchGroup', type=str, required=True)
parser.add_argument('--platform', type=str, required=True)
parser.add_argument('--usingInstall', type=str, required=True)
arguments = parser.parse_args()

# Load our build specification, which governs how we handle this build
16
buildSpecification = BuildSpecs.Loader( product=arguments.product, project=arguments.project, branchGroup=arguments.branchGroup, platform=arguments.platform )
17 18 19 20 21 22

# Determine the environment we need to provide for the compilation process
buildEnvironment = EnvironmentHandler.generateFor( installPrefix=arguments.usingInstall )

# If we aren't running on Linux, or if Appstream Check's have been disabled for this build, bail
# Appstream isn't relevant outside Linux, so even if the tooling was available (probably not) there is little point running the checks there
23
if sys.platform != "linux" or not buildSpecification['do-appstream-check']:
24 25 26 27 28 29 30 31 32 33 34 35 36 37
	# Bail!
	sys.exit(0)

# Determine the command we need to run
commandToRun = "appstreamcli validate-tree --pedantic {0}"
commandToRun = commandToRun.format( arguments.usingInstall )

# Now run it!
try:
	subprocess.check_call( commandToRun, stdout=sys.stdout, stderr=sys.stderr, shell=True, env=buildEnvironment )
except Exception:
	sys.exit(1)

# The project passed appstream validation successfully
38
sys.exit(0)