Merge lp:~brunogirin/charms/precise/python-django/python-hooks-repos-options into lp:~patrick-hetu/charms/precise/python-django/python-hooks

Proposed by Bruno Girin
Status: Merged
Merged at revision: 32
Proposed branch: lp:~brunogirin/charms/precise/python-django/python-hooks-repos-options
Merge into: lp:~patrick-hetu/charms/precise/python-django/python-hooks
Diff against target: 130 lines (+60/-10)
3 files modified
config.yaml (+10/-3)
hooks/hooks.py (+40/-7)
templates/netrc.tmpl (+10/-0)
To merge this branch: bzr merge lp:~brunogirin/charms/precise/python-django/python-hooks-repos-options
Reviewer Review Type Date Requested Status
Patrick Hetu Approve
Review via email: mp+158699@code.launchpad.net

Description of the change

Added support for the following options:
- repos_username
- repos_password
- repos_branch
- application_path

See config.yaml for details of what the options do.

To post a comment you must log in.
Revision history for this message
Patrick Hetu (patrick-hetu) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'config.yaml'
--- config.yaml 2013-04-11 16:47:39 +0000
+++ config.yaml 2013-04-12 19:02:28 +0000
@@ -22,12 +22,19 @@
22 description: |22 description: |
23 The repo branch to pull out from. If empty, it will pull out the23 The repo branch to pull out from. If empty, it will pull out the
24 default branch or trunk (such as origin/master with git).24 default branch or trunk (such as origin/master with git).
25 Note that this setting is ignored for bzr and svn as the branch is25 Note that this setting only applies to git. This option is not
26 specified in the URL for both of them.26 supported for hg. For svn and bzr, specify the branch name as
27 part of the URL.
27 install_root:28 install_root:
28 type: string29 type: string
29 default: "/srv/"30 default: "/srv/"
30 description: The vcs url to checkout.31 description: The root directory to checkout to.
32 application_path:
33 type: string
34 default: ""
35 description: |
36 The relative path to install_root where the manage.py
37 script is located.
31 additional_distro_packages:38 additional_distro_packages:
32 type: string39 type: string
33 default: ""40 default: ""
3441
=== modified file 'hooks/hooks.py'
--- hooks/hooks.py 2013-04-11 16:48:57 +0000
+++ hooks/hooks.py 2013-04-12 19:02:28 +0000
@@ -322,6 +322,19 @@
322 this_host = run("unit-get private-address")322 this_host = run("unit-get private-address")
323 return this_host.strip()323 return this_host.strip()
324324
325def process_template(template_name, template_vars, destination):
326 # --- exported service configuration file
327 from jinja2 import Environment, FileSystemLoader
328 template_env = Environment(
329 loader=FileSystemLoader(os.path.join(os.environ['CHARM_DIR'],
330 'templates')))
331
332 template = \
333 template_env.get_template(template_name).render(template_vars)
334
335 with open(destination, 'w') as inject_file:
336 inject_file.write(str(template))
337
325###############################################################################338###############################################################################
326# Hook functions339# Hook functions
327###############################################################################340###############################################################################
@@ -339,17 +352,32 @@
339 for package in extra_pip_pkgs.split(','):352 for package in extra_pip_pkgs.split(','):
340 pip_install(package)353 pip_install(package)
341354
355 if repos_username:
356 m = re.match(".*://([^/]+)/.*", repos_url)
357 if m is not None:
358 repos_domain = m.group(1)
359 template_vars = {
360 'repos_domain': repos_domain,
361 'repos_username': repos_username,
362 'repos_password': repos_password
363 }
364 from os.path import expanduser
365 process_template('netrc.tmpl', template_vars, expanduser('~/.netrc'))
366 else:
367 juju_log(MSG_ERROR, '''Failed to process repos_username and repos_password:\n
368 cannot identify domain in URL {0}'''.format(repos_url))
369
342 if vcs == 'hg' or vcs == 'mercurial':370 if vcs == 'hg' or vcs == 'mercurial':
343 run('hg clone %s %s' % (repos_url, working_dir))371 run('hg clone %s %s' % (repos_url, vcs_clone_dir))
344 elif vcs == 'git' or vcs == 'git-core':372 elif vcs == 'git' or vcs == 'git-core':
345 if repos_branch:373 if repos_branch:
346 run('git clone %s -b %s %s' % (repos_url, repos_branch, working_dir))374 run('git clone %s -b %s %s' % (repos_url, repos_branch, vcs_clone_dir))
347 else:375 else:
348 run('git clone %s %s' % (repos_url, working_dir))376 run('git clone %s %s' % (repos_url, vcs_clone_dir))
349 elif vcs == 'bzr' or vcs == 'bazaar':377 elif vcs == 'bzr' or vcs == 'bazaar':
350 run('bzr branch %s %s' % (repos_url, working_dir))378 run('bzr branch %s %s' % (repos_url, vcs_clone_dir))
351 elif vcs == 'svn' or vcs == 'subversion':379 elif vcs == 'svn' or vcs == 'subversion':
352 run('svn co %s %s' % (repos_url, working_dir))380 run('svn co %s %s' % (repos_url, vcs_clone_dir))
353 elif vcs == '' and repos_url == '':381 elif vcs == '' and repos_url == '':
354 juju_log(MSG_INFO, "No version control using local template")382 juju_log(MSG_INFO, "No version control using local template")
355 run('cp -r %s %s' % (os.path.join(os.environ['CHARM_DIR'],'template_site'),383 run('cp -r %s %s' % (os.path.join(os.environ['CHARM_DIR'],'template_site'),
@@ -455,9 +483,9 @@
455config_data = config_get()483config_data = config_get()
456vcs = config_data['vcs']484vcs = config_data['vcs']
457repos_url = config_data['repos_url']485repos_url = config_data['repos_url']
458repos_branch = config_data['repos_branch']
459repos_username = config_data['repos_username']486repos_username = config_data['repos_username']
460repos_password = config_data['repos_password']487repos_password = config_data['repos_password']
488repos_branch = config_data['repos_branch']
461489
462extra_deb_pkgs = config_data['additional_distro_packages']490extra_deb_pkgs = config_data['additional_distro_packages']
463extra_pip_pkgs = config_data['additional_pip_packages']491extra_pip_pkgs = config_data['additional_pip_packages']
@@ -465,9 +493,14 @@
465wsgi_user = config_data['wsgi_user']493wsgi_user = config_data['wsgi_user']
466wsgi_group = config_data['wsgi_group']494wsgi_group = config_data['wsgi_group']
467install_root = config_data['install_root']495install_root = config_data['install_root']
496application_path = config_data['application_path']
468497
469unit_name = os.environ['JUJU_UNIT_NAME'].split('/')[0]498unit_name = os.environ['JUJU_UNIT_NAME'].split('/')[0]
470working_dir = os.path.join(install_root, unit_name)499vcs_clone_dir = os.path.join(install_root, unit_name)
500if application_path:
501 working_dir = os.path.join(vcs_clone_dir, application_path)
502else:
503 working_dir = vcs_clone_dir
471manage_path = os.path.join(working_dir, 'manage.py')504manage_path = os.path.join(working_dir, 'manage.py')
472django_run_dir = os.path.join(working_dir, "run/")505django_run_dir = os.path.join(working_dir, "run/")
473django_logs_dir = os.path.join(working_dir, "logs/")506django_logs_dir = os.path.join(working_dir, "logs/")
474507
=== added file 'templates/netrc.tmpl'
--- templates/netrc.tmpl 1970-01-01 00:00:00 +0000
+++ templates/netrc.tmpl 2013-04-12 19:02:28 +0000
@@ -0,0 +1,10 @@
1#------------------------------------------------------------------------------
2# This file is managed by Juju
3#------------------------------------------------------------------------------
4
5# Netrc configuration for VCS repo
6
7machine {{ repos_domain }}
8 login {{ repos_username }}
9 password {{ repos_password }}
10

Subscribers

People subscribed via source and target branches

to all changes: