~lihuiguo/landscape-charm/registration-relation

« back to all changes in this revision

Viewing changes to dev/charm_helpers_sync.py

  • Committer: 🤖 Landscape Builder
  • Author(s): Simon Poirier
  • Date: 2019-05-24 14:06:39 UTC
  • mfrom: (396.1.1 charmhelpers-and-keys)
  • Revision ID: _landscape_builder-20190524140639-q3t8aavbxute9714
This branch updates charm helpers, and add the fix proposed as
https://github.com/juju/charm-helpers/pull/326

This should fix apt failures when specifying a deb source and key.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 
3
3
# Copyright 2014-2015 Canonical Limited.
4
4
#
5
 
# This file is part of charm-helpers.
6
 
#
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.
10
 
#
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.
15
 
#
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
 
8
#
 
9
#  http://www.apache.org/licenses/LICENSE-2.0
 
10
#
 
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.
18
16
 
19
17
# Authors:
20
18
#   Adam Gandelman <adamg@ubuntu.com>
31
29
 
32
30
import six
33
31
 
34
 
CHARM_HELPERS_BRANCH = 'lp:charm-helpers'
 
32
CHARM_HELPERS_REPO = 'https://github.com/juju/charm-helpers'
35
33
 
36
34
 
37
35
def parse_config(conf_file):
41
39
    return yaml.load(open(conf_file).read())
42
40
 
43
41
 
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))
 
45
    branch = None
 
46
    if '@' in repo:
 
47
        repo, branch = repo.split('@', 1)
 
48
    cmd = ['git', 'clone', '--depth=1']
 
49
    if branch is not None:
 
50
        cmd += ['--branch', branch]
 
51
    cmd += [repo, dest]
48
52
    subprocess.check_call(cmd)
49
53
    return dest
50
54
 
176
180
 
177
181
 
178
182
def sync_helpers(include, src, dest, options=None):
 
183
    if os.path.exists(dest):
 
184
        logging.debug('Removing existing directory: %s' % dest)
 
185
        shutil.rmtree(dest)
179
186
    if not os.path.isdir(dest):
180
187
        os.makedirs(dest)
181
188
 
193
200
                        inc, opts = extract_options(m, global_options)
194
201
                        sync(src, dest, '%s.%s' % (k, inc), opts)
195
202
 
 
203
 
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()
219
227
    else:
220
228
        config = {}
221
229
 
222
 
    if 'branch' not in config:
223
 
        config['branch'] = CHARM_HELPERS_BRANCH
224
 
    if opts.branch:
225
 
        config['branch'] = opts.branch
 
230
    if 'repo' not in config:
 
231
        config['repo'] = CHARM_HELPERS_REPO
 
232
    if opts.repo:
 
233
        config['repo'] = opts.repo
226
234
    if opts.dest_dir:
227
235
        config['destination'] = opts.dest_dir
228
236
 
242
250
        sync_options = config['options']
243
251
    tmpd = tempfile.mkdtemp()
244
252
    try:
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: