summaryrefslogtreecommitdiff
path: root/apexer/apexer.py
diff options
context:
space:
mode:
authorAbhijeet Kaur <abkaur@google.com>2018-12-19 15:20:59 +0000
committerAbhijeet Kaur <abkaur@google.com>2018-12-24 16:15:31 +0000
commit7e021e8dcae1098eccf972eb9e71448134fdc08b (patch)
tree68da03bc5dbf626c2189e6b996e4e7589ba64afe /apexer/apexer.py
parent1583dcffc54545ffeb5ffeed2dc576ed002d3905 (diff)
Use protobuf as schema for JSON APEX manifest
Validate necessary fields in the manifest using protobuf. Add class for apex manifest for better usability of the JSON fields. Test: ./runtests.sh Bug: 116129963 Change-Id: Icf5091ebc9fb4faca437cada3b93cd98c4b77ba6
Diffstat (limited to 'apexer/apexer.py')
-rw-r--r--apexer/apexer.py26
1 files changed, 11 insertions, 15 deletions
diff --git a/apexer/apexer.py b/apexer/apexer.py
index c15b6da..db4dd50 100644
--- a/apexer/apexer.py
+++ b/apexer/apexer.py
@@ -24,7 +24,6 @@ Typical usage: apexer input_dir output.apex
import argparse
import hashlib
-import json
import os
import re
import shutil
@@ -32,6 +31,8 @@ import subprocess
import sys
import tempfile
import uuid
+from apex_manifest import ValidateApexManifest
+from apex_manifest import ApexManifestError
if 'APEXER_TOOL_PATH' not in os.environ:
sys.stderr.write("""
@@ -168,22 +169,17 @@ def CreateApex(args, work_dir):
print "Using tools from " + str(tool_path_list)
try:
- with open(args.manifest) as f:
- manifest = json.load(f)
- except ValueError:
+ with open(args.manifest, "r") as f:
+ manifest_raw = f.read()
+ manifest_apex = ValidateApexManifest(manifest_raw)
+ except ApexManifestError as err:
print("'" + args.manifest + "' is not a valid manifest file")
+ print err.errmessage
return False
except IOError:
print("Cannot read manifest file: '" + args.manifest + "'")
return False
- if 'name' not in manifest or manifest['name'] is None:
- print("Invalid manifest: 'name' does not exist")
- return False
-
- package_name = manifest['name']
- version_number = manifest['version']
-
# create an empty ext4 image that is sufficiently big
# Sufficiently big = twice the size of the input directory
# For the case when the input directory is really small, the minimum of the
@@ -207,8 +203,8 @@ def CreateApex(args, work_dir):
if args.payload_type == 'image':
key_name = os.path.basename(os.path.splitext(args.key)[0])
- if package_name != key_name:
- print("package name '" + package_name + "' does not match with key name '" + key_name + "'")
+ if manifest_apex.package_name != key_name:
+ print("package name '" + manifest_apex.package_name + "' does not match with key name '" + key_name + "'")
return False
img_file = os.path.join(content_dir, 'apex_payload.img')
@@ -265,7 +261,7 @@ def CreateApex(args, work_dir):
cmd.extend(['--prop', "apex.key:" + key_name])
# Set up the salt based on manifest content which includes name
# and version
- salt = hashlib.sha256(json.dumps(manifest)).hexdigest()
+ salt = hashlib.sha256(manifest_raw).hexdigest()
cmd.extend(['--salt', salt])
cmd.extend(['--image', img_file])
RunCommand(cmd, args.verbose)
@@ -300,7 +296,7 @@ def CreateApex(args, work_dir):
if args.verbose:
print('Creating AndroidManifest ' + android_manifest_file)
with open(android_manifest_file, 'w+') as f:
- f.write(PrepareAndroidManifest(package_name, version_number))
+ f.write(PrepareAndroidManifest(manifest_apex.package_name, manifest_apex.version_number))
# copy manifest to the content dir so that it is also accessible
# without mounting the image