summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Lutterkort <dlutter@redhat.com>2008-06-25 19:22:09 -0400
committerBrenton Leanhardt <bleanhar@redhat.com>2008-06-25 19:25:39 -0400
commit99f21a9eb95a228d0c1932e32e0afa01639abbb0 (patch)
tree59a01af47000e869dabbe7cae6646e9cf69e29c1
parent0d33cb7d544f347ae40a6595be3def5a557c3247 (diff)
downloadtools-99f21a9eb95a228d0c1932e32e0afa01639abbb0.tar.gz
tools-99f21a9eb95a228d0c1932e32e0afa01639abbb0.tar.xz
tools-99f21a9eb95a228d0c1932e32e0afa01639abbb0.zip
The workingdir still defaults to '~/.everest-sync', but can now be changed
by passing --workingdir
-rw-r--r--everest-sync/bin/everest-sync34
1 files changed, 21 insertions, 13 deletions
diff --git a/everest-sync/bin/everest-sync b/everest-sync/bin/everest-sync
index 6c1b56d..73a72b8 100644
--- a/everest-sync/bin/everest-sync
+++ b/everest-sync/bin/everest-sync
@@ -17,8 +17,9 @@ Main {
# Normally I wouldn't use class variables but I think it's warranted within
# the 'main' DSL. If there are any other global config variables feel free
# to put them here.
- @@app_name = AppName
- @@working_dir = File.join(ENV["HOME"], "." + @@app_name)
+ APP_NAME = "everest-sync"
+ DEFAULT_WORKING_DIR = File.join(ENV["HOME"], "." + APP_NAME)
+
@@repo_path_prefix = "/pub/git"
@@puppetmaster_base_dir = "/etc/puppet/modules/main"
@@ -29,16 +30,23 @@ Main {
option('verbose', 'v')
+ option('workingdir', 'w') {
+ description "The working directory to sync"
+ default DEFAULT_WORKING_DIR
+ attr
+ argument_required
+ }
+
def run
require 'rbconfig'
- script = File.join(Config::CONFIG['bindir'], @@app_name)
+ script = File.join(Config::CONFIG['bindir'], APP_NAME)
exec("#{script} --help")
end
mode('clean') {
def run()
- verbose("Removing #{@@working_dir}")
- FileUtils.rm_rf(@@working_dir)
+ verbose("Removing #{workingdir}")
+ FileUtils.rm_rf(workingdir)
end
}
@@ -103,13 +111,13 @@ Main {
}
mode('save') {
- description "Push the changes in #{@@working_dir} to #{@@repo_path_prefix}.\n" +
+ description "Push the changes in the working directory to #{@@repo_path_prefix}.\n" +
"The puppet modules will have their 'master' branches\n" +
"checked out to #{@@puppetmaster_base_dir}."
def run
working_git_dirs.each do |d|
- repo_base_path = d.sub(@@working_dir, "") # Chop off the working dir
+ repo_base_path = d.sub(workingdir, "") # Chop off the working dir
dest = File.join(@@repo_path_prefix, repo_base_path)
bare_repo_name = File.basename(dest)
bare_repo_parent_dir = File.dirname(dest)
@@ -178,7 +186,7 @@ Main {
end
def working_git_dirs
- Dir[@@working_dir + "/**/.git"].map {|g| File.dirname(g)}
+ Dir[workingdir + "/**/.git"].map {|g| File.dirname(g)}
end
# Just a helper method. Handle recovery
@@ -193,7 +201,7 @@ Main {
rescue Git::GitExecuteError => e
fork do
puts e.message
- puts "Type 'exit' when everything is fixed to continue '#{@@app_name}'"
+ puts "Type 'exit' when everything is fixed to continue '#{APP_NAME}'"
g.chdir {exec('bash')}
end
@@ -237,8 +245,8 @@ Main {
def start(opts={})
# Setup
- verbose "making #{@@working_dir}"
- FileUtils.mkdir_p(@@working_dir)
+ verbose "making #{workingdir}"
+ FileUtils.mkdir_p(workingdir)
@everest_repo = params['repo'].value
@@ -253,14 +261,14 @@ Main {
@git_repo_paths.each do |p|
next unless agree("Sync #{p}? (y/n)", true) if opts[:interactive]
- clone_dir = File.join(@@working_dir, p)
+ clone_dir = File.join(workingdir, p)
verbose "clone_dir = #{clone_dir}"
# Handle the case where the repo path is foo/bar
dirs = File.split(p)
if dirs.size > 1
subdirs = dirs[0..-2]
- repo_parent_dir = @@working_dir + File::SEPARATOR + File.join(subdirs)
+ repo_parent_dir = workingdir + File::SEPARATOR + File.join(subdirs)
verbose "Making #{repo_parent_dir}"
FileUtils.mkdir_p(repo_parent_dir)
end