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

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

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

30
# Before we can process it, we need to determine which prefix to check
Ben Cooksley's avatar
Ben Cooksley committed
31
installRoot = arguments.usingInstall
32
if arguments.withDiverted != None:
Ben Cooksley's avatar
Ben Cooksley committed
33
	installRoot = os.path.join( arguments.withDiverted, CommonUtils.makePathRelative(arguments.usingInstall) )
34 35 36 37 38 39 40

# 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)

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

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

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