forked from google/glazier
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathautobuild.py
90 lines (72 loc) · 2.54 KB
/
autobuild.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# 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)