48.1.5
by sergio.schvezov at canonical
Adding source bootstrap tool |
1 |
#! /usr/bin/env python2.7
|
2 |
# This program is free software: you can redistribute it and/or modify it
|
|
3 |
# under the terms of the the GNU General Public License version 3, as
|
|
4 |
# published by the Free Software Foundation.
|
|
5 |
#
|
|
6 |
# This program is distributed in the hope that it will be useful, but
|
|
7 |
# WITHOUT ANY WARRANTY; without even the implied warranties of
|
|
8 |
# MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
|
|
9 |
# PURPOSE. See the applicable version of the GNU General Public
|
|
10 |
# License for more details.
|
|
285.2.1
by Michał Sawicz
Fix pep8 errors. |
11 |
#
|
48.1.5
by sergio.schvezov at canonical
Adding source bootstrap tool |
12 |
# You should have received a copy of the GNU General Public License
|
13 |
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
14 |
#
|
|
15 |
# Copyright (C) 2013 Canonical, Ltd.
|
|
16 |
||
17 |
# TODO Install packages
|
|
18 |
# TODO allow new vendor setup from existing repo
|
|
19 |
||
20 |
import argparse |
|
21 |
import logging |
|
22 |
import os |
|
23 |
import subprocess |
|
24 |
from os import path |
|
25 |
||
26 |
logging.basicConfig(level=logging.DEBUG) |
|
27 |
log = logging.getLogger() |
|
28 |
log.name = 'phablet-dev-bootstrap' |
|
29 |
||
235.1.2
by Sergio Schvezov
Allow to choose between aosp and cyanogenmod to init |
30 |
repo = { |
290.1.2
by Ricardo Salveti de Araujo
Fixing pep8 error (line > 79) |
31 |
'aosp': |
331
by Robert Bruce Park
Fix pep8 test causing trunk build failures. |
32 |
'https://code-review.phablet.ubuntu.com/p/aosp/platform/manifest.git', |
33 |
}
|
|
235.1.2
by Sergio Schvezov
Allow to choose between aosp and cyanogenmod to init |
34 |
|
290.1.1
by Ricardo Salveti de Araujo
Updating phablet-dev-bootstrap and dropping CM support (we currently only support AOSP based builds) |
35 |
repo_branch = 'phablet-4.4.2_r1' |
36 |
valid_vendors = ('mako', 'flo', 'deb', 'manta', 'hammerhead', 'generic') |
|
37 |
vendor_blobs = 'lp:~phablet-team/phablet-tools/aosp-vendor-4.4.2' |
|
48.1.5
by sergio.schvezov at canonical
Adding source bootstrap tool |
38 |
|
39 |
||
40 |
class StringSplitAction(argparse.Action): |
|
182.1.10
by Loïc Minier
PEP8 fixes. |
41 |
def __call__(self, parser, namespace, values, option_string=None): |
48.1.5
by sergio.schvezov at canonical
Adding source bootstrap tool |
42 |
setattr(namespace, self.dest, values.split(',')) |
43 |
||
44 |
||
45 |
def validate_vendors(vendors): |
|
46 |
for vendor in vendors: |
|
47 |
if vendor not in valid_vendors: |
|
48 |
log.error('Vendor device %s not supported' % vendor) |
|
49 |
exit(1) |
|
50 |
||
51 |
||
52 |
def setup_sync_dir(target_directory, continue_sync=False): |
|
53 |
'''Creates and changes to target directory'''
|
|
54 |
if not continue_sync: |
|
55 |
try: |
|
56 |
if os.path.isfile(target_directory): |
|
57 |
raise OSError('%s is not a directory' % |
|
182.1.10
by Loïc Minier
PEP8 fixes. |
58 |
target_directory) |
48.1.5
by sergio.schvezov at canonical
Adding source bootstrap tool |
59 |
elif not os.path.isdir(target_directory): |
60 |
log.debug('Creating sync directory %s' % target_directory) |
|
61 |
os.mkdir(target_directory) |
|
62 |
elif os.listdir(target_directory): |
|
63 |
raise OSError('%s is not empty and not using -c' % |
|
182.1.10
by Loïc Minier
PEP8 fixes. |
64 |
target_directory) |
48.1.5
by sergio.schvezov at canonical
Adding source bootstrap tool |
65 |
except OSError as e: |
66 |
if not e.message: |
|
182.1.10
by Loïc Minier
PEP8 fixes. |
67 |
log.error('Cannot setup environment in %s' % |
48.1.5
by sergio.schvezov at canonical
Adding source bootstrap tool |
68 |
target_directory) |
69 |
else: |
|
70 |
log.error(e.message) |
|
71 |
exit(1) |
|
72 |
log.info('Changing to workdir %s' % target_directory) |
|
73 |
os.chdir(target_directory) |
|
74 |
||
75 |
||
235.1.2
by Sergio Schvezov
Allow to choose between aosp and cyanogenmod to init |
76 |
def sync_repository(source, branch, jobs='1', reference=None): |
48.1.5
by sergio.schvezov at canonical
Adding source bootstrap tool |
77 |
'''Syncs android sources with the repo command'''
|
78 |
try: |
|
79 |
log.info('Initializing repository') |
|
80 |
init_cmd = ['repo', 'init', |
|
235.1.2
by Sergio Schvezov
Allow to choose between aosp and cyanogenmod to init |
81 |
'-u', repo[source], '-b', branch] |
48.1.5
by sergio.schvezov at canonical
Adding source bootstrap tool |
82 |
if reference: |
83 |
init_cmd += ['--reference', reference] |
|
84 |
subprocess.check_call(init_cmd) |
|
85 |
subprocess.check_call(['repo', |
|
86 |
'sync', |
|
87 |
'-j%s' % jobs] |
|
182.1.10
by Loïc Minier
PEP8 fixes. |
88 |
)
|
48.1.5
by sergio.schvezov at canonical
Adding source bootstrap tool |
89 |
except subprocess.CalledProcessError: |
90 |
log.error('Error while trying to sync repository') |
|
91 |
exit(1) |
|
92 |
||
93 |
||
94 |
def sync_vendors(vendors): |
|
290.1.1
by Ricardo Salveti de Araujo
Updating phablet-dev-bootstrap and dropping CM support (we currently only support AOSP based builds) |
95 |
cmd = '''bzr branch %s vendor''' % vendor_blobs |
48.1.5
by sergio.schvezov at canonical
Adding source bootstrap tool |
96 |
log.debug('Executing %s' % cmd) |
97 |
subprocess.check_call(cmd, shell=True, executable='/bin/bash') |
|
98 |
||
99 |
||
100 |
def parse_arguments(): |
|
101 |
parser = argparse.ArgumentParser( |
|
102 |
description='Phablet Development Environment Setup Tool') |
|
103 |
parser.add_argument('-v', |
|
104 |
'--vendors', |
|
105 |
dest='vendors', |
|
106 |
help='''Comma separated list of devices to Setup |
|
290.1.1
by Ricardo Salveti de Araujo
Updating phablet-dev-bootstrap and dropping CM support (we currently only support AOSP based builds) |
107 |
such as mako, flo, deb, manta, hammerhead, generic''', |
48.1.5
by sergio.schvezov at canonical
Adding source bootstrap tool |
108 |
action=StringSplitAction, |
182.1.10
by Loïc Minier
PEP8 fixes. |
109 |
)
|
48.1.5
by sergio.schvezov at canonical
Adding source bootstrap tool |
110 |
parser.add_argument('-j', |
111 |
'--jobs', |
|
112 |
dest='jobs', |
|
113 |
help='''Ammount of sync jobs''', |
|
114 |
default='1', |
|
182.1.10
by Loïc Minier
PEP8 fixes. |
115 |
)
|
48.1.5
by sergio.schvezov at canonical
Adding source bootstrap tool |
116 |
parser.add_argument('-c', |
117 |
'--continue', |
|
118 |
dest='continue_sync', |
|
119 |
action='store_true', |
|
120 |
help='''Continue a previously started sync''', |
|
121 |
default=False, |
|
182.1.10
by Loïc Minier
PEP8 fixes. |
122 |
)
|
48.1.5
by sergio.schvezov at canonical
Adding source bootstrap tool |
123 |
parser.add_argument('-r', |
124 |
'--reference', |
|
182.1.10
by Loïc Minier
PEP8 fixes. |
125 |
help='Use another dev environment as reference for ' |
126 |
'git', |
|
48.1.5
by sergio.schvezov at canonical
Adding source bootstrap tool |
127 |
default='', |
182.1.10
by Loïc Minier
PEP8 fixes. |
128 |
)
|
235.1.1
by Sergio Schvezov
Add branch selection for bootstrapping |
129 |
parser.add_argument('--repo-branch', |
130 |
help='Choose branch to init from', |
|
131 |
default=repo_branch, |
|
132 |
)
|
|
235.1.2
by Sergio Schvezov
Allow to choose between aosp and cyanogenmod to init |
133 |
parser.add_argument('--sources', |
290.1.1
by Ricardo Salveti de Araujo
Updating phablet-dev-bootstrap and dropping CM support (we currently only support AOSP based builds) |
134 |
default='aosp', |
135 |
choices=['aosp'], |
|
235.1.2
by Sergio Schvezov
Allow to choose between aosp and cyanogenmod to init |
136 |
help='Use to select a different source target.', |
137 |
)
|
|
48.1.5
by sergio.schvezov at canonical
Adding source bootstrap tool |
138 |
parser.add_argument('target_directory', |
139 |
help='Target directory for sources', |
|
182.1.10
by Loïc Minier
PEP8 fixes. |
140 |
)
|
48.1.5
by sergio.schvezov at canonical
Adding source bootstrap tool |
141 |
return parser.parse_args() |
142 |
||
143 |
||
144 |
def main(args): |
|
51.1.1
by Ursula Junque (Ursinha)
Making args.vendors not required so the script can be used to setup environment for unsupported devices, and it's not really used right now |
145 |
if args.vendors: |
146 |
validate_vendors(args.vendors) |
|
48.1.5
by sergio.schvezov at canonical
Adding source bootstrap tool |
147 |
setup_sync_dir(path.abspath(path.expanduser(args.target_directory)), |
148 |
args.continue_sync) |
|
235.1.2
by Sergio Schvezov
Allow to choose between aosp and cyanogenmod to init |
149 |
sync_repository(args.sources, args.repo_branch, args.jobs, args.reference) |
51.1.1
by Ursula Junque (Ursinha)
Making args.vendors not required so the script can be used to setup environment for unsupported devices, and it's not really used right now |
150 |
if args.vendors: |
151 |
sync_vendors(args.vendors) |
|
48.1.5
by sergio.schvezov at canonical
Adding source bootstrap tool |
152 |
|
153 |
||
154 |
if __name__ == "__main__": |
|
155 |
args = parse_arguments() |
|
156 |
main(args) |