Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: modules/hg/manifests/init.pp

Issue 6065002532306944: Issue 1608 - Introduce HG client module in Puppet (Closed)
Patch Set: Created Jan. 5, 2015, 3:12 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: modules/hg/manifests/init.pp
diff --git a/modules/hg/manifests/init.pp b/modules/hg/manifests/init.pp
new file mode 100644
index 0000000000000000000000000000000000000000..f7ecd7c6fb89ca012e6af05d3e20fe1f7ebb9be6
--- /dev/null
+++ b/modules/hg/manifests/init.pp
@@ -0,0 +1,142 @@
+# == Class: hg
+#
+# A very basic Mercurial client integration.
+#
+# === Parameters:
+#
+# Below please find a list of parameters recognized by class hg:
+#
+# [*path*]
+# A $path to pass on to exec{} when invoking commands. Can be overwritten
+# in each named type defined by class hg.
+#
+# [*cwd*]
+# A working directory ($cwd) to pass on to exec{} when invoking commands.
+# Can be overwritten in each named type defined by class hg.
+#
+# [*package*]
+# The name of the Mercurial (client) package on the target system.
+#
+# [*post_update*]
+# An optional shell command to trigger after a successful hg::update(),
+# using the local repository as working directory.
+#
+# === Examples:
+#
+# Below please find a set of examples demonstrating the use of class hg:
+#
+# hg {
+# path => '/usr/local/bin',
+# post_update =>
+# shellquote('test', '-e', 'ensure_dependencies.py') + ' && ' +
+# shellquote('python', 'ensure_dependencies.py'),
+# }
+#
+# hg::ensure {'/opt/sitescripts':
+# source => 'https://hg.adblockplus.org/sitescripts',
+# revision => 'tip',
+# }
Wladimir Palant 2015/01/13 08:10:48 Does this API make sense for us? We typically don'
mathias 2015/06/23 10:45:15 Well, the revision parameter is optional (and now
+#
+class hg(
+ $path = '/usr/local/bin:/usr/bin:/bin',
+ $cwd = '/',
+ $package = 'mercurial',
+ $post_update = '',
+ $user = 'root') {
+
+ include stdlib
+
+ package {$package:
+ ensure => installed,
Wladimir Palant 2015/01/13 08:10:48 Does a custom path make sense if you require Mercu
mathias 2015/06/23 10:45:14 The custom path is also used to ensure the $PATH f
+ }
+
+ Exec {
+ path => $path,
+ cwd => $cwd,
+ }
+
+ define clone(
+ $source,
+ $user = $user,
+ $target = $name) {
+
+ # Allow for accessing $hg::* class parameters
+ include hg
+
+ $command = shellquote('hg', 'clone', $source, $target)
+
+ exec {$command:
+ creates => $target,
+ user => $user,
+ require => Package[$hg::package],
+ }
+ }
+
+ define pull(
+ $source = '--',
+ $user = $user,
+ $target = $name) {
+
+ # Allow for accessing $hg::* class parameters
+ include hg
+
+ $command = shellquote('hg', '--cwd', $target, 'pull', $source)
Wladimir Palant 2015/01/13 08:10:48 Please use -R or --repository rather than --cwd.
+
+ exec {$command:
+ user => $user,
+ require => Package[$hg::package],
+ }
+ }
+
+ define update(
+ $revision = 'tip',
Wladimir Palant 2015/01/13 08:10:48 'tip' isn't a good default, it might be on a branc
+ $user = $user,
+ $target = $name) {
+
+ # Allow for accessing $hg::* class parameters
+ include hg
+
+ $command = shellquote('hg', '--cwd', $target, 'pull', '--rev', $revision)
Wladimir Palant 2015/01/13 08:10:48 Please use -R or --repository rather than --cwd.
+
+ exec {$command:
+ user => $user,
+ require => Package[$hg::package],
+ }
+
+ if $hg::post_update != '' {
Wladimir Palant 2015/01/13 08:10:48 Shouldn't this only be executed when an actual upd
+ exec {"$command #post_update":
+ command => $hg::post_update,
+ user => $user,
+ cwd => $target,
+ require => Exec[$command],
+ }
+ }
+ }
+
+ define ensure(
+ $source,
+ $revision = 'tip',
+ $user = $user,
+ $target = $name) {
+
+ hg::clone {$name:
+ source => $source,
+ user => $user,
+ target => $target,
+ }
Wladimir Palant 2015/01/13 08:10:48 Should this really be run unconditionally? What if
+
+ -> # after clone
+ hg::pull {$name:
+ source => $source,
+ user => $user,
+ target => $target,
+ }
+
+ -> # after pull
+ hg::update {$name:
+ revision => $revision,
+ user => $user,
+ target => $target,
+ }
+ }
+}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld