Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(734)

Side by Side Diff: hooks/utils.py

Issue 9464043: Support juju-gui-source=branch:revno
Patch Set: Support juju-gui-source=branch:revno Created 11 years, 11 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « config.yaml ('k') | revision » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 """Juju GUI charm utilities.""" 1 """Juju GUI charm utilities."""
2 2
3 __all__ = [ 3 __all__ = [
4 'AGENT', 4 'AGENT',
5 'APACHE', 5 'APACHE',
6 'API_PORT', 6 'API_PORT',
7 'CURRENT_DIR', 7 'CURRENT_DIR',
8 'HAPROXY', 8 'HAPROXY',
9 'IMPROV', 9 'IMPROV',
10 'JUJU_DIR', 10 'JUJU_DIR',
(...skipping 26 matching lines...) Expand all
37 'start_gui', 37 'start_gui',
38 'start_improv', 38 'start_improv',
39 'write_apache_config', 39 'write_apache_config',
40 ] 40 ]
41 41
42 from contextlib import contextmanager 42 from contextlib import contextmanager
43 import errno 43 import errno
44 import json 44 import json
45 import os 45 import os
46 import logging 46 import logging
47 import re
47 import shutil 48 import shutil
48 from subprocess import CalledProcessError 49 from subprocess import CalledProcessError
49 import tempfile 50 import tempfile
50 from urlparse import urlparse 51 from urlparse import urlparse
51 52
52 import apt 53 import apt
53 import tempita 54 import tempita
54 55
55 from launchpadlib.launchpad import Launchpad 56 from launchpadlib.launchpad import Launchpad
56 from shelltoolbox import ( 57 from shelltoolbox import (
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 try: 205 try:
205 yield 206 yield
206 except CalledProcessError as err: 207 except CalledProcessError as err:
207 log('Exception caught:') 208 log('Exception caught:')
208 log(err.output) 209 log(err.output)
209 raise 210 raise
210 finally: 211 finally:
211 log("<<< Exiting {}".format(script)) 212 log("<<< Exiting {}".format(script))
212 213
213 214
215 bzr_url_expression = re.compile(r"""
216 ^ # Beginning of line.
217 ((?:lp:|http:\/\/)[^:]+) # Branch URL (scheme + domain/path).
218 (?::(\d+))? # Optional branch revision.
219 $ # End of line.
220 """, re.VERBOSE)
221
222
214 def parse_source(source): 223 def parse_source(source):
215 """Parse the ``juju-gui-source`` option. 224 """Parse the ``juju-gui-source`` option.
216 225
217 Return a tuple of two elements representing info on how to deploy Juju GUI. 226 Return a tuple of two elements representing info on how to deploy Juju GUI.
218 Examples: 227 Examples:
219 - ('stable', None): latest stable release; 228 - ('stable', None): latest stable release;
220 - ('stable', '0.1.0'): stable release v0.1.0; 229 - ('stable', '0.1.0'): stable release v0.1.0;
221 - ('trunk', None): latest trunk release; 230 - ('trunk', None): latest trunk release;
222 - ('trunk', '0.1.0+build.1'): trunk release v0.1.0 bzr revision 1; 231 - ('trunk', '0.1.0+build.1'): trunk release v0.1.0 bzr revision 1;
223 - ('branch', 'lp:juju-gui'): release is made from a branch; 232 - ('branch', ('lp:juju-gui', 42): release is made from a branch -
233 in this case the second element includes the branch URL and revision;
234 - ('branch', ('lp:juju-gui', None): no revision is specified;
224 - ('url', 'http://example.com/gui'): release from a downloaded file. 235 - ('url', 'http://example.com/gui'): release from a downloaded file.
225 """ 236 """
226 if source.startswith('url:'): 237 if source.startswith('url:'):
227 source = source[4:] 238 source = source[4:]
228 # Support file paths, including relative paths. 239 # Support file paths, including relative paths.
229 if urlparse(source).scheme == '': 240 if urlparse(source).scheme == '':
230 if not source.startswith('/'): 241 if not source.startswith('/'):
231 source = os.path.join(os.path.abspath(CURRENT_DIR), source) 242 source = os.path.join(os.path.abspath(CURRENT_DIR), source)
232 source = "file://%s" % source 243 source = "file://%s" % source
233 return 'url', source 244 return 'url', source
234 if source in ('stable', 'trunk'): 245 if source in ('stable', 'trunk'):
235 return source, None 246 return source, None
236 if source.startswith('lp:') or source.startswith('http://'): 247 match = bzr_url_expression.match(source)
237 return 'branch', source 248 if match is not None:
249 return 'branch', match.groups()
238 if 'build' in source: 250 if 'build' in source:
239 return 'trunk', source 251 return 'trunk', source
240 return 'stable', source 252 return 'stable', source
241 253
242 254
243 def render_to_file(template_name, context, destination): 255 def render_to_file(template_name, context, destination):
244 """Render the given *template_name* into *destination* using *context*. 256 """Render the given *template_name* into *destination* using *context*.
245 257
246 The tempita template language is used to render contents 258 The tempita template language is used to render contents
247 (see http://pythonpaste.org/tempita/). 259 (see http://pythonpaste.org/tempita/).
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 raise 443 raise
432 uncompress = command('tar', '-x', '-z', '-C', npm_cache_dir, '-f') 444 uncompress = command('tar', '-x', '-z', '-C', npm_cache_dir, '-f')
433 cmd_log(uncompress(npm_cache_archive)) 445 cmd_log(uncompress(npm_cache_archive))
434 446
435 447
436 def fetch_gui(juju_gui_source, logpath): 448 def fetch_gui(juju_gui_source, logpath):
437 """Retrieve the Juju GUI release/branch.""" 449 """Retrieve the Juju GUI release/branch."""
438 # Retrieve a Juju GUI release. 450 # Retrieve a Juju GUI release.
439 origin, version_or_branch = parse_source(juju_gui_source) 451 origin, version_or_branch = parse_source(juju_gui_source)
440 if origin == 'branch': 452 if origin == 'branch':
453 branch_url, revision = version_or_branch
441 # Make sure we have the dependencies necessary for us to actually make 454 # Make sure we have the dependencies necessary for us to actually make
442 # a build. 455 # a build.
443 _get_build_dependencies() 456 _get_build_dependencies()
444 # Create a release starting from a branch. 457 # Create a release starting from a branch.
445 juju_gui_source_dir = os.path.join(CURRENT_DIR, 'juju-gui-source') 458 juju_gui_source_dir = os.path.join(CURRENT_DIR, 'juju-gui-source')
446 log('Retrieving Juju GUI source checkout from %s.' % version_or_branch) 459 if revision is None:
460 checkout_args = []
461 revno = 'latest revno'
462 else:
463 checkout_args = ['--revision', revision]
464 revno = 'revno {}'.format(revision)
465 log('Retrieving Juju GUI source checkout from {} ({}).'.format(
466 branch_url, revno))
447 cmd_log(run('rm', '-rf', juju_gui_source_dir)) 467 cmd_log(run('rm', '-rf', juju_gui_source_dir))
448 cmd_log(bzr_checkout(version_or_branch, juju_gui_source_dir)) 468 checkout_args.extend([branch_url, juju_gui_source_dir])
469 cmd_log(bzr_checkout(*checkout_args))
449 log('Preparing a Juju GUI release.') 470 log('Preparing a Juju GUI release.')
450 logdir = os.path.dirname(logpath) 471 logdir = os.path.dirname(logpath)
451 fd, name = tempfile.mkstemp(prefix='make-distfile-', dir=logdir) 472 fd, name = tempfile.mkstemp(prefix='make-distfile-', dir=logdir)
452 log('Output from "make distfile" sent to %s' % name) 473 log('Output from "make distfile" sent to %s' % name)
453 with environ(NO_BZR='1'): 474 with environ(NO_BZR='1'):
454 run('make', '-C', juju_gui_source_dir, 'distfile', 475 run('make', '-C', juju_gui_source_dir, 'distfile',
455 stdout=fd, stderr=fd) 476 stdout=fd, stderr=fd)
456 release_tarball = first_path_in_dir( 477 release_tarball = first_path_in_dir(
457 os.path.join(juju_gui_source_dir, 'releases')) 478 os.path.join(juju_gui_source_dir, 'releases'))
458 else: 479 else:
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
593 @property 614 @property
594 def method(self): 615 def method(self):
595 result = set() 616 result = set()
596 for mixin in self.mixins: 617 for mixin in self.mixins:
597 segment = getattr(type(mixin), name, None) 618 segment = getattr(type(mixin), name, None)
598 if segment and isinstance(segment, (list, tuple, set)): 619 if segment and isinstance(segment, (list, tuple, set)):
599 result |= set(segment) 620 result |= set(segment)
600 621
601 return result 622 return result
602 return method 623 return method
OLDNEW
« no previous file with comments | « config.yaml ('k') | revision » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b