blob: c9566ace0615164ab25691522847c205b1e4c576 [file] [log] [blame]
#!/usr/bin/env python
#
# Copyright 2018 - The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
r"""AVDSpec class.
AVDSpec will take in args from the user and be the main data type that will
get passed into the create classes. The inferring magic will happen within
initialization of AVDSpec (like LKGB build id, image branch, etc).
"""
_BUILD_TARGET = "build_target"
_BUILD_BRANCH = "build_branch"
_BUILD_ID = "build_id"
class AVDSpec(object):
"""Class to store data on the type of AVD to create."""
def __init__(self, args):
"""Process the args into class vars.
Args:
args: Namespace object from argparse.parse_args.
"""
# Let's define the private class vars here and then process the user
# args afterwards.
self._avd_type = None
self._remote_image = None
self._num_of_instances = None
self._ProcessArgs(args)
def __repr__(self):
"""Let's make it easy to see what this class is holding."""
# TODO: I'm pretty sure there's a better way to do this, but I'm not
# quite sure what that would be.
representation = []
representation.append("")
representation.append(" - avd type: %s" % self._avd_type)
representation.append(" - num of instances requested: %s" %
self._num_of_instances)
representation.append(" - remote image details: %s" %
self._remote_image)
return "\n".join(representation)
def _ProcessArgs(self, args):
"""Main entry point to process args for the different type of args.
Split up the arg processing into related areas (image, instance type,
etc) so that we don't have one huge monolilthic method that does
everything. It makes it easier to review, write tests, and maintain.
Args:
args: Namespace object from argparse.parse_args.
"""
self._ProcessMiscArgs(args)
self._ProcessRemoteBuildArgs(args)
def _ProcessMiscArgs(self, args):
"""These args we can take as and don't belong to a group of args.
Args:
args: Namespace object from argparse.parse_args.
"""
self._avd_type = args.avd_type
self._num_of_instances = args.num
def _ProcessRemoteBuildArgs(self, args):
"""Get the remote build args.
Some of the acloud magic happens here, we will infer some of these
values if the user hasn't specified them.
Args:
args: Namespace object from argparse.parse_args.
"""
# TODO: We need some logic here to determine if we should infer remote
# build info or not.
self._remote_image = {}
if args.build_target:
self._remote_image[_BUILD_TARGET] = args.build_target
else:
# TODO: actually figure out what we want here.
pass
if args.branch:
self._remote_image[_BUILD_BRANCH] = args.branch
else:
# TODO: infer from user workspace
pass
if args.build_id:
self._remote_image[_BUILD_ID] = args.build_id
else:
# TODO: extract this info from Android Build.
pass