3
3
# Copyright 2014-2015 Canonical Limited.
5
# This file is part of charm-helpers.
7
# charm-helpers is free software: you can redistribute it and/or modify
8
# it under the terms of the GNU Lesser General Public License version 3 as
9
# published by the Free Software Foundation.
11
# charm-helpers is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# GNU Lesser General Public License for more details.
16
# You should have received a copy of the GNU Lesser General Public License
17
# along with charm-helpers. If not, see <http://www.gnu.org/licenses/>.
5
# Licensed under the Apache License, Version 2.0 (the "License");
6
# you may not use this file except in compliance with the License.
7
# You may obtain a copy of the License at
9
# http://www.apache.org/licenses/LICENSE-2.0
11
# Unless required by applicable law or agreed to in writing, software
12
# distributed under the License is distributed on an "AS IS" BASIS,
13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
# See the License for the specific language governing permissions and
15
# limitations under the License.
20
18
# Adam Gandelman <adamg@ubuntu.com>
41
39
return yaml.load(open(conf_file).read())
44
def clone_helpers(work_dir, branch):
42
def clone_helpers(work_dir, repo):
45
43
dest = os.path.join(work_dir, 'charm-helpers')
46
logging.info('Checking out %s to %s.' % (branch, dest))
47
cmd = ['bzr', 'checkout', '--lightweight', branch, dest]
44
logging.info('Cloning out %s to %s.' % (repo, dest))
47
repo, branch = repo.split('@', 1)
48
cmd = ['git', 'clone', '--depth=1']
49
if branch is not None:
50
cmd += ['--branch', branch]
48
52
subprocess.check_call(cmd)
178
182
def sync_helpers(include, src, dest, options=None):
183
if os.path.exists(dest):
184
logging.debug('Removing existing directory: %s' % dest)
179
186
if not os.path.isdir(dest):
180
187
os.makedirs(dest)
193
200
inc, opts = extract_options(m, global_options)
194
201
sync(src, dest, '%s.%s' % (k, inc), opts)
196
204
if __name__ == '__main__':
197
205
parser = optparse.OptionParser()
198
206
parser.add_option('-c', '--config', action='store', dest='config',
199
207
default=None, help='helper config file')
200
208
parser.add_option('-D', '--debug', action='store_true', dest='debug',
201
209
default=False, help='debug')
202
parser.add_option('-b', '--branch', action='store', dest='branch',
203
help='charm-helpers bzr branch (overrides config)')
210
parser.add_option('-r', '--repository', action='store', dest='repo',
211
help='charm-helpers git repository (overrides config)')
204
212
parser.add_option('-d', '--destination', action='store', dest='dest_dir',
205
213
help='sync destination dir (overrides config)')
206
214
(opts, args) = parser.parse_args()
222
if 'branch' not in config:
223
config['branch'] = CHARM_HELPERS_BRANCH
225
config['branch'] = opts.branch
230
if 'repo' not in config:
231
config['repo'] = CHARM_HELPERS_REPO
233
config['repo'] = opts.repo
226
234
if opts.dest_dir:
227
235
config['destination'] = opts.dest_dir
242
250
sync_options = config['options']
243
251
tmpd = tempfile.mkdtemp()
245
checkout = clone_helpers(tmpd, config['branch'])
253
checkout = clone_helpers(tmpd, config['repo'])
246
254
sync_helpers(config['include'], checkout, config['destination'],
247
255
options=sync_options)
248
256
except Exception as e: