check-appstream-compliance.py 2.21 KB
Newer Older
1 2 3
#!/usr/bin/python3
import sys
import argparse
Ben Cooksley's avatar
Ben Cooksley committed
4
import subprocess
5 6 7 8
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.')
9
parser.add_argument('--product', type=str, required=True)
10 11 12 13
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)
14
parser.add_argument('--withDiverted', type=str, required=True)
15 16 17
arguments = parser.parse_args()

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

# 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
25
if sys.platform != "linux" or not buildSpecification['do-appstream-check']:
26 27 28
	# Bail!
	sys.exit(0)

29 30 31 32 33 34 35 36 37 38 39
# Before we can process it, we need to determine which prefix to check
installRoot = arguments.installTo
if arguments.withDiverted != None:
	installRoot = os.path.join( arguments.withDiverted, CommonUtils.makePathRelative(arguments.installTo) )

# Make sure we have Appstream metadata to process
appstreamDirectory = os.path.join( installRoot, 'share', 'metainfo' )
if not os.path.exists( appstreamDirectory ):
	# Bail!
	sys.exit(0)

40
# Determine the command we need to run
41 42
commandToRun = "appstreamcli validate --pedantic {0}/*"
commandToRun = commandToRun.format( appstreamDirectory )
43 44 45 46 47

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

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