mirror of
https://github.com/google/glazier.git
synced 2025-12-23 22:00:28 -05:00
91 lines
2.5 KiB
Python
91 lines
2.5 KiB
Python
# Copyright 2016 Google Inc. All Rights Reserved.
|
|
#
|
|
# 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.
|
|
|
|
"""Windows installation and configuration tool."""
|
|
|
|
import os
|
|
import sys
|
|
from glazier.lib import buildinfo
|
|
from glazier.lib import constants
|
|
from glazier.lib import logs
|
|
from glazier.lib.config import builder
|
|
from glazier.lib.config import runner
|
|
import gflags as flags
|
|
|
|
FLAGS = flags.FLAGS
|
|
flags.DEFINE_bool('preserve_tasks', False,
|
|
'Preserve the existing task list, if any.')
|
|
|
|
logging = logs.logging
|
|
|
|
_FAILURE_MSG = ('%s\n\nInstaller cannot continue.')
|
|
|
|
|
|
class AutoBuild(object):
|
|
"""The AutoBuild class manages the imaging process."""
|
|
|
|
def __init__(self):
|
|
logs.Setup()
|
|
self._build_info = buildinfo.BuildInfo()
|
|
|
|
def _LogFatal(self, msg):
|
|
"""Log a fatal error and exit.
|
|
|
|
Args:
|
|
msg: The error message to accompany the failure.
|
|
"""
|
|
logging.fatal(_FAILURE_MSG, msg)
|
|
sys.exit(1)
|
|
|
|
def _SetupTaskList(self):
|
|
"""Determines the location of the task list and erases if necessary."""
|
|
location = constants.WINPE_TASK_LIST
|
|
if FLAGS.environment == 'Host':
|
|
location = constants.SYS_TASK_LIST
|
|
logging.debug('Using task list at %s', location)
|
|
if not FLAGS.preserve_tasks and os.path.exists(location):
|
|
logging.debug('Purging old task list.')
|
|
try:
|
|
os.remove(location)
|
|
except OSError as e:
|
|
self._LogFatal('Unable to remove task list. %s' % e)
|
|
return location
|
|
|
|
def RunBuild(self):
|
|
"""Perform the build."""
|
|
task_list = self._SetupTaskList()
|
|
|
|
if not os.path.exists(task_list):
|
|
root_path = FLAGS.config_root_path or '/'
|
|
try:
|
|
b = builder.ConfigBuilder(self._build_info)
|
|
b.Start(out_file=task_list, in_path=root_path)
|
|
except builder.ConfigBuilderError as e:
|
|
self._LogFatal(str(e))
|
|
|
|
try:
|
|
r = runner.ConfigRunner(self._build_info)
|
|
r.Start(task_list=task_list)
|
|
except runner.ConfigRunnerError as e:
|
|
self._LogFatal(str(e))
|
|
|
|
|
|
def main(unused_argv):
|
|
ab = AutoBuild()
|
|
ab.RunBuild()
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main(sys.argv)
|