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
1=== modified file 'config.yaml'
2--- config.yaml 2013-04-11 16:47:39 +0000
3+++ config.yaml 2013-04-12 19:02:28 +0000
4@@ -22,12 +22,19 @@
5 description: |
6 The repo branch to pull out from. If empty, it will pull out the
7 default branch or trunk (such as origin/master with git).
8- Note that this setting is ignored for bzr and svn as the branch is
9- specified in the URL for both of them.
10+ Note that this setting only applies to git. This option is not
11+ supported for hg. For svn and bzr, specify the branch name as
12+ part of the URL.
13 install_root:
14 type: string
15 default: "/srv/"
16- description: The vcs url to checkout.
17+ description: The root directory to checkout to.
18+ application_path:
19+ type: string
20+ default: ""
21+ description: |
22+ The relative path to install_root where the manage.py
23+ script is located.
24 additional_distro_packages:
25 type: string
26 default: ""
27
28=== modified file 'hooks/hooks.py'
29--- hooks/hooks.py 2013-04-11 16:48:57 +0000
30+++ hooks/hooks.py 2013-04-12 19:02:28 +0000
31@@ -322,6 +322,19 @@
32 this_host = run("unit-get private-address")
33 return this_host.strip()
34
35+def process_template(template_name, template_vars, destination):
36+ # --- exported service configuration file
37+ from jinja2 import Environment, FileSystemLoader
38+ template_env = Environment(
39+ loader=FileSystemLoader(os.path.join(os.environ['CHARM_DIR'],
40+ 'templates')))
41+
42+ template = \
43+ template_env.get_template(template_name).render(template_vars)
44+
45+ with open(destination, 'w') as inject_file:
46+ inject_file.write(str(template))
47+
48 ###############################################################################
49 # Hook functions
50 ###############################################################################
51@@ -339,17 +352,32 @@
52 for package in extra_pip_pkgs.split(','):
53 pip_install(package)
54
55+ if repos_username:
56+ m = re.match(".*://([^/]+)/.*", repos_url)
57+ if m is not None:
58+ repos_domain = m.group(1)
59+ template_vars = {
60+ 'repos_domain': repos_domain,
61+ 'repos_username': repos_username,
62+ 'repos_password': repos_password
63+ }
64+ from os.path import expanduser
65+ process_template('netrc.tmpl', template_vars, expanduser('~/.netrc'))
66+ else:
67+ juju_log(MSG_ERROR, '''Failed to process repos_username and repos_password:\n
68+ cannot identify domain in URL {0}'''.format(repos_url))
69+
70 if vcs == 'hg' or vcs == 'mercurial':
71- run('hg clone %s %s' % (repos_url, working_dir))
72+ run('hg clone %s %s' % (repos_url, vcs_clone_dir))
73 elif vcs == 'git' or vcs == 'git-core':
74 if repos_branch:
75- run('git clone %s -b %s %s' % (repos_url, repos_branch, working_dir))
76+ run('git clone %s -b %s %s' % (repos_url, repos_branch, vcs_clone_dir))
77 else:
78- run('git clone %s %s' % (repos_url, working_dir))
79+ run('git clone %s %s' % (repos_url, vcs_clone_dir))
80 elif vcs == 'bzr' or vcs == 'bazaar':
81- run('bzr branch %s %s' % (repos_url, working_dir))
82+ run('bzr branch %s %s' % (repos_url, vcs_clone_dir))
83 elif vcs == 'svn' or vcs == 'subversion':
84- run('svn co %s %s' % (repos_url, working_dir))
85+ run('svn co %s %s' % (repos_url, vcs_clone_dir))
86 elif vcs == '' and repos_url == '':
87 juju_log(MSG_INFO, "No version control using local template")
88 run('cp -r %s %s' % (os.path.join(os.environ['CHARM_DIR'],'template_site'),
89@@ -455,9 +483,9 @@
90 config_data = config_get()
91 vcs = config_data['vcs']
92 repos_url = config_data['repos_url']
93-repos_branch = config_data['repos_branch']
94 repos_username = config_data['repos_username']
95 repos_password = config_data['repos_password']
96+repos_branch = config_data['repos_branch']
97
98 extra_deb_pkgs = config_data['additional_distro_packages']
99 extra_pip_pkgs = config_data['additional_pip_packages']
100@@ -465,9 +493,14 @@
101 wsgi_user = config_data['wsgi_user']
102 wsgi_group = config_data['wsgi_group']
103 install_root = config_data['install_root']
104+application_path = config_data['application_path']
105
106 unit_name = os.environ['JUJU_UNIT_NAME'].split('/')[0]
107-working_dir = os.path.join(install_root, unit_name)
108+vcs_clone_dir = os.path.join(install_root, unit_name)
109+if application_path:
110+ working_dir = os.path.join(vcs_clone_dir, application_path)
111+else:
112+ working_dir = vcs_clone_dir
113 manage_path = os.path.join(working_dir, 'manage.py')
114 django_run_dir = os.path.join(working_dir, "run/")
115 django_logs_dir = os.path.join(working_dir, "logs/")
116
117=== added file 'templates/netrc.tmpl'
118--- templates/netrc.tmpl 1970-01-01 00:00:00 +0000
119+++ templates/netrc.tmpl 2013-04-12 19:02:28 +0000
120@@ -0,0 +1,10 @@
121+#------------------------------------------------------------------------------
122+# This file is managed by Juju
123+#------------------------------------------------------------------------------
124+
125+# Netrc configuration for VCS repo
126+
127+machine {{ repos_domain }}
128+ login {{ repos_username }}
129+ password {{ repos_password }}
130+

Subscribers

People subscribed via source and target branches

to all changes: