diff options
author | Markus Roberts <Markus@reality.com> | 2010-07-09 18:05:04 -0700 |
---|---|---|
committer | Markus Roberts <Markus@reality.com> | 2010-07-09 18:05:04 -0700 |
commit | 9ee56f2e67be973da49b1d3f21de1bf87de35e6f (patch) | |
tree | ddab8c01509f47664c52c8a6b165bb5a974f138f /install.rb | |
parent | 051bd98751d9d4bc97f93f66723d9b7a00c0cfb4 (diff) | |
download | puppet-9ee56f2e67be973da49b1d3f21de1bf87de35e6f.tar.gz puppet-9ee56f2e67be973da49b1d3f21de1bf87de35e6f.tar.xz puppet-9ee56f2e67be973da49b1d3f21de1bf87de35e6f.zip |
Code smell: Inconsistent indentation and related formatting issues
* Replaced 163 occurances of
defined\? +([@a-zA-Z_.0-9?=]+)
with
defined?(\1)
This makes detecting subsequent patterns easier.
3 Examples:
The code:
if ! defined? @parse_config
becomes:
if ! defined?(@parse_config)
The code:
return @option_parser if defined? @option_parser
becomes:
return @option_parser if defined?(@option_parser)
The code:
if defined? @local and @local
becomes:
if defined?(@local) and @local
* Eliminate trailing spaces.
Replaced 428 occurances of ^(.*?) +$ with \1
1 file was skipped.
test/ral/providers/host/parsed.rb because 0
* Replace leading tabs with an appropriate number of spaces.
Replaced 306 occurances of ^(\t+)(.*) with
Tabs are not consistently expanded in all environments.
* Don't arbitrarily wrap on sprintf (%) operator.
Replaced 143 occurances of
(.*['"] *%)
+(.*)
with
Splitting the line does nothing to aid clarity and hinders further refactorings.
3 Examples:
The code:
raise Puppet::Error, "Cannot create %s: basedir %s is a file" %
[dir, File.join(path)]
becomes:
raise Puppet::Error, "Cannot create %s: basedir %s is a file" % [dir, File.join(path)]
The code:
Puppet.err "Will not start without authorization file %s" %
Puppet[:authconfig]
becomes:
Puppet.err "Will not start without authorization file %s" % Puppet[:authconfig]
The code:
$stderr.puts "Could not find host for PID %s with status %s" %
[pid, $?.exitstatus]
becomes:
$stderr.puts "Could not find host for PID %s with status %s" % [pid, $?.exitstatus]
* Don't break short arrays/parameter list in two.
Replaced 228 occurances of
(.*)
+(.*)
with
3 Examples:
The code:
puts @format.wrap(type.provider(prov).doc,
:indent => 4, :scrub => true)
becomes:
puts @format.wrap(type.provider(prov).doc, :indent => 4, :scrub => true)
The code:
assert(FileTest.exists?(daily),
"Did not make daily graph for %s" % type)
becomes:
assert(FileTest.exists?(daily), "Did not make daily graph for %s" % type)
The code:
assert(prov.target_object(:first).read !~ /^notdisk/,
"Did not remove thing from disk")
becomes:
assert(prov.target_object(:first).read !~ /^notdisk/, "Did not remove thing from disk")
* If arguments must wrap, treat them all equally
Replaced 510 occurances of
lines ending in things like ...(foo, or ...(bar(1,3),
with
\1
\2
3 Examples:
The code:
midscope.to_hash(false),
becomes:
assert_equal(
The code:
botscope.to_hash(true),
becomes:
# bottomscope, then checking that we see the right stuff.
The code:
:path => link,
becomes:
* Replaced 4516 occurances of ^( *)(.*) with
The present code base is supposed to use four-space indentation. In some places we failed
to maintain that standard. These should be fixed regardless of the 2 vs. 4 space question.
15 Examples:
The code:
def run_comp(cmd)
puts cmd
results = []
old_sync = $stdout.sync
$stdout.sync = true
line = []
begin
open("| #{cmd}", "r") do |f|
until f.eof? do
c = f.getc
becomes:
def run_comp(cmd)
puts cmd
results = []
old_sync = $stdout.sync
$stdout.sync = true
line = []
begin
open("| #{cmd}", "r") do |f|
until f.eof? do
c = f.getc
The code:
s.gsub!(/.{4}/n, '\\\\u\&')
}
string.force_encoding(Encoding::UTF_8)
string
rescue Iconv::Failure => e
raise GeneratorError, "Caught #{e.class}: #{e}"
end
else
def utf8_to_pson(string) # :nodoc:
string = string.gsub(/["\\\x0-\x1f]/) { MAP[$&] }
string.gsub!(/(
becomes:
s.gsub!(/.{4}/n, '\\\\u\&')
}
string.force_encoding(Encoding::UTF_8)
string
rescue Iconv::Failure => e
raise GeneratorError, "Caught #{e.class}: #{e}"
end
else
def utf8_to_pson(string) # :nodoc:
string = string.gsub(/["\\\x0-\x1f]/) { MAP[$&] }
string.gsub!(/(
The code:
end
}
rvalues: rvalue
| rvalues comma rvalue {
if val[0].instance_of?(AST::ASTArray)
result = val[0].push(val[2])
else
result = ast AST::ASTArray, :children => [val[0],val[2]]
end
}
becomes:
end
}
rvalues: rvalue
| rvalues comma rvalue {
if val[0].instance_of?(AST::ASTArray)
result = val[0].push(val[2])
else
result = ast AST::ASTArray, :children => [val[0],val[2]]
end
}
The code:
#passwdproc = proc { @password }
keytext = @key.export(
OpenSSL::Cipher::DES.new(:EDE3, :CBC),
@password
)
File.open(@keyfile, "w", 0400) { |f|
f << keytext
}
becomes:
# passwdproc = proc { @password }
keytext = @key.export(
OpenSSL::Cipher::DES.new(:EDE3, :CBC),
@password
)
File.open(@keyfile, "w", 0400) { |f|
f << keytext
}
The code:
end
def to_manifest
"%s { '%s':\n%s\n}" % [self.type.to_s, self.name,
@params.collect { |p, v|
if v.is_a? Array
" #{p} => [\'#{v.join("','")}\']"
else
" #{p} => \'#{v}\'"
end
}.join(",\n")
becomes:
end
def to_manifest
"%s { '%s':\n%s\n}" % [self.type.to_s, self.name,
@params.collect { |p, v|
if v.is_a? Array
" #{p} => [\'#{v.join("','")}\']"
else
" #{p} => \'#{v}\'"
end
}.join(",\n")
The code:
via the augeas tool.
Requires:
- augeas to be installed (http://www.augeas.net)
- ruby-augeas bindings
Sample usage with a string::
augeas{\"test1\" :
context => \"/files/etc/sysconfig/firstboot\",
changes => \"set RUN_FIRSTBOOT YES\",
becomes:
via the augeas tool.
Requires:
- augeas to be installed (http://www.augeas.net)
- ruby-augeas bindings
Sample usage with a string::
augeas{\"test1\" :
context => \"/files/etc/sysconfig/firstboot\",
changes => \"set RUN_FIRSTBOOT YES\",
The code:
names.should_not be_include("root")
end
describe "when generating a purgeable resource" do
it "should be included in the generated resources" do
Puppet::Type.type(:host).stubs(:instances).returns [@purgeable_resource]
@resources.generate.collect { |r| r.ref }.should include(@purgeable_resource.ref)
end
end
describe "when the instance's do not have an ensure property" do
becomes:
names.should_not be_include("root")
end
describe "when generating a purgeable resource" do
it "should be included in the generated resources" do
Puppet::Type.type(:host).stubs(:instances).returns [@purgeable_resource]
@resources.generate.collect { |r| r.ref }.should include(@purgeable_resource.ref)
end
end
describe "when the instance's do not have an ensure property" do
The code:
describe "when the instance's do not have an ensure property" do
it "should not be included in the generated resources" do
@no_ensure_resource = Puppet::Type.type(:exec).new(:name => '/usr/bin/env echo')
Puppet::Type.type(:host).stubs(:instances).returns [@no_ensure_resource]
@resources.generate.collect { |r| r.ref }.should_not include(@no_ensure_resource.ref)
end
end
describe "when the instance's ensure property does not accept absent" do
it "should not be included in the generated resources" do
@no_absent_resource = Puppet::Type.type(:service).new(:name => 'foobar')
becomes:
describe "when the instance's do not have an ensure property" do
it "should not be included in the generated resources" do
@no_ensure_resource = Puppet::Type.type(:exec).new(:name => '/usr/bin/env echo')
Puppet::Type.type(:host).stubs(:instances).returns [@no_ensure_resource]
@resources.generate.collect { |r| r.ref }.should_not include(@no_ensure_resource.ref)
end
end
describe "when the instance's ensure property does not accept absent" do
it "should not be included in the generated resources" do
@no_absent_resource = Puppet::Type.type(:service).new(:name => 'foobar')
The code:
func = nil
assert_nothing_raised do
func = Puppet::Parser::AST::Function.new(
:name => "template",
:ftype => :rvalue,
:arguments => AST::ASTArray.new(
:children => [stringobj(template)]
)
becomes:
func = nil
assert_nothing_raised do
func = Puppet::Parser::AST::Function.new(
:name => "template",
:ftype => :rvalue,
:arguments => AST::ASTArray.new(
:children => [stringobj(template)]
)
The code:
assert(
@store.allowed?("hostname.madstop.com", "192.168.1.50"),
"hostname not allowed")
assert(
! @store.allowed?("name.sub.madstop.com", "192.168.0.50"),
"subname name allowed")
becomes:
assert(
@store.allowed?("hostname.madstop.com", "192.168.1.50"),
"hostname not allowed")
assert(
! @store.allowed?("name.sub.madstop.com", "192.168.0.50"),
"subname name allowed")
The code:
assert_nothing_raised {
server = Puppet::Network::Handler.fileserver.new(
:Local => true,
:Config => false
)
}
becomes:
assert_nothing_raised {
server = Puppet::Network::Handler.fileserver.new(
:Local => true,
:Config => false
)
}
The code:
'yay',
{ :failonfail => false,
:uid => @user.uid,
:gid => @user.gid }
).returns('output')
output = Puppet::Util::SUIDManager.run_and_capture 'yay',
@user.uid,
@user.gid
becomes:
'yay',
{ :failonfail => false,
:uid => @user.uid,
:gid => @user.gid }
).returns('output')
output = Puppet::Util::SUIDManager.run_and_capture 'yay',
@user.uid,
@user.gid
The code:
).times(1)
pkg.provider.expects(
:aptget
).with(
'-y',
'-q',
'remove',
'faff'
becomes:
).times(1)
pkg.provider.expects(
:aptget
).with(
'-y',
'-q',
'remove',
'faff'
The code:
johnny one two
billy three four\n"
# Just parse and generate, to make sure it's isomorphic.
assert_nothing_raised do
assert_equal(text, @parser.to_file(@parser.parse(text)),
"parsing was not isomorphic")
end
end
def test_valid_attrs
becomes:
johnny one two
billy three four\n"
# Just parse and generate, to make sure it's isomorphic.
assert_nothing_raised do
assert_equal(text, @parser.to_file(@parser.parse(text)),
"parsing was not isomorphic")
end
end
def test_valid_attrs
The code:
"testing",
:onboolean => [true, "An on bool"],
:string => ["a string", "A string arg"]
)
result = []
should = []
assert_nothing_raised("Add args failed") do
@config.addargs(result)
end
@config.each do |name, element|
becomes:
"testing",
:onboolean => [true, "An on bool"],
:string => ["a string", "A string arg"]
)
result = []
should = []
assert_nothing_raised("Add args failed") do
@config.addargs(result)
end
@config.each do |name, element|
Diffstat (limited to 'install.rb')
-rwxr-xr-x | install.rb | 495 |
1 files changed, 247 insertions, 248 deletions
diff --git a/install.rb b/install.rb index eb17ec3a3..54a714674 100755 --- a/install.rb +++ b/install.rb @@ -36,11 +36,11 @@ require 'rbconfig' require 'find' require 'fileutils' begin - require 'ftools' # apparently on some system ftools doesn't get loaded - $haveftools = true + require 'ftools' # apparently on some system ftools doesn't get loaded + $haveftools = true rescue LoadError - puts "ftools not found. Using FileUtils instead.." - $haveftools = false + puts "ftools not found. Using FileUtils instead.." + $haveftools = false end require 'optparse' require 'ostruct' @@ -55,10 +55,10 @@ end begin if $haverdoc - rst2man = %x{which rst2man.py} - $haveman = true + rst2man = %x{which rst2man.py} + $haveman = true else - $haveman = false + $haveman = false end rescue puts "Missing rst2man; skipping man page creation" @@ -88,45 +88,45 @@ libs = glob(%w{lib/**/*.rb lib/**/*.py}) tests = glob(%w{test/**/*.rb}) def do_bins(bins, target, strip = 's?bin/') - bins.each do |bf| - obf = bf.gsub(/#{strip}/, '') - install_binfile(bf, obf, target) - end + bins.each do |bf| + obf = bf.gsub(/#{strip}/, '') + install_binfile(bf, obf, target) + end end def do_libs(libs, strip = 'lib/') - libs.each do |lf| - olf = File.join(InstallOptions.site_dir, lf.gsub(/#{strip}/, '')) - op = File.dirname(olf) - if $haveftools - File.makedirs(op, true) - File.chmod(0755, op) - File.install(lf, olf, 0644, true) - else - FileUtils.makedirs(op, {:mode => 0755, :verbose => true}) - FileUtils.chmod(0755, op) - FileUtils.install(lf, olf, {:mode => 0644, :verbose => true}) + libs.each do |lf| + olf = File.join(InstallOptions.site_dir, lf.gsub(/#{strip}/, '')) + op = File.dirname(olf) + if $haveftools + File.makedirs(op, true) + File.chmod(0755, op) + File.install(lf, olf, 0644, true) + else + FileUtils.makedirs(op, {:mode => 0755, :verbose => true}) + FileUtils.chmod(0755, op) + FileUtils.install(lf, olf, {:mode => 0644, :verbose => true}) + end end - end end def do_man(man, strip = 'man/') - man.each do |mf| - omf = File.join(InstallOptions.man_dir, mf.gsub(/#{strip}/, '')) - om = File.dirname(omf) - if $haveftools - File.makedirs(om, true) - File.chmod(0755, om) - File.install(mf, omf, 0644, true) - else - FileUtils.makedirs(om, {:mode => 0755, :verbose => true}) - FileUtils.chmod(0755, om) - FileUtils.install(mf, omf, {:mode => 0644, :verbose => true}) + man.each do |mf| + omf = File.join(InstallOptions.man_dir, mf.gsub(/#{strip}/, '')) + om = File.dirname(omf) + if $haveftools + File.makedirs(om, true) + File.chmod(0755, om) + File.install(mf, omf, 0644, true) + else + FileUtils.makedirs(om, {:mode => 0755, :verbose => true}) + FileUtils.chmod(0755, om) + FileUtils.install(mf, omf, {:mode => 0644, :verbose => true}) + end + gzip = %x{which gzip} + gzip.chomp! + %x{#{gzip} -f #{omf}} end - gzip = %x{which gzip} - gzip.chomp! - %x{#{gzip} -f #{omf}} - end end # Verify that all of the prereqs are installed @@ -135,13 +135,13 @@ def check_prereqs begin require pre if pre == "facter" - # to_f isn't quite exact for strings like "1.5.1" but is good - # enough for this purpose. - facter_version = Facter.version.to_f - if facter_version < MIN_FACTER_VERSION - puts "Facter version: %s; minimum required: %s; cannot install" % [facter_version, MIN_FACTER_VERSION] - exit -1 - end + # to_f isn't quite exact for strings like "1.5.1" but is good + # enough for this purpose. + facter_version = Facter.version.to_f + if facter_version < MIN_FACTER_VERSION + puts "Facter version: %s; minimum required: %s; cannot install" % [facter_version, MIN_FACTER_VERSION] + exit -1 + end end rescue LoadError puts "Could not load %s; cannot install" % pre @@ -154,169 +154,169 @@ end # Prepare the file installation. # def prepare_installation - # Only try to do docs if we're sure they have rdoc - if $haverdoc - InstallOptions.rdoc = true - if RUBY_PLATFORM == "i386-mswin32" + # Only try to do docs if we're sure they have rdoc + if $haverdoc + InstallOptions.rdoc = true + if RUBY_PLATFORM == "i386-mswin32" + InstallOptions.ri = false + else + InstallOptions.ri = true + end + else + InstallOptions.rdoc = false InstallOptions.ri = false - else - InstallOptions.ri = true - end - else - InstallOptions.rdoc = false - InstallOptions.ri = false - end - - - if $haveman - InstallOptions.man = true - if RUBY_PLATFORM == "i386-mswin32" - InstallOptions.man = false - end - else - InstallOptions.man = false - end - - InstallOptions.tests = true - - if $haveman - InstallOptions.man = true - if RUBY_PLATFORM == "i386-mswin32" - InstallOptions.man = false - end - else - InstallOptions.man = false - end - - ARGV.options do |opts| - opts.banner = "Usage: #{File.basename($0)} [options]" - opts.separator "" - opts.on('--[no-]rdoc', 'Prevents the creation of RDoc output.', 'Default on.') do |onrdoc| - InstallOptions.rdoc = onrdoc - end - opts.on('--[no-]ri', 'Prevents the creation of RI output.', 'Default off on mswin32.') do |onri| - InstallOptions.ri = onri - end - opts.on('--[no-]man', 'Prevents the creation of man pages.', 'Default on.') do |onman| - InstallOptions.man = onman - end - opts.on('--[no-]tests', 'Prevents the execution of unit tests.', 'Default on.') do |ontest| - InstallOptions.tests = ontest end - opts.on('--destdir[=OPTIONAL]', 'Installation prefix for all targets', 'Default essentially /') do |destdir| - InstallOptions.destdir = destdir + + + if $haveman + InstallOptions.man = true + if RUBY_PLATFORM == "i386-mswin32" + InstallOptions.man = false + end + else + InstallOptions.man = false end - opts.on('--bindir[=OPTIONAL]', 'Installation directory for binaries', 'overrides Config::CONFIG["bindir"]') do |bindir| - InstallOptions.bindir = bindir + + InstallOptions.tests = true + + if $haveman + InstallOptions.man = true + if RUBY_PLATFORM == "i386-mswin32" + InstallOptions.man = false + end + else + InstallOptions.man = false end - opts.on('--sbindir[=OPTIONAL]', 'Installation directory for system binaries', 'overrides Config::CONFIG["sbindir"]') do |sbindir| - InstallOptions.sbindir = sbindir + + ARGV.options do |opts| + opts.banner = "Usage: #{File.basename($0)} [options]" + opts.separator "" + opts.on('--[no-]rdoc', 'Prevents the creation of RDoc output.', 'Default on.') do |onrdoc| + InstallOptions.rdoc = onrdoc + end + opts.on('--[no-]ri', 'Prevents the creation of RI output.', 'Default off on mswin32.') do |onri| + InstallOptions.ri = onri + end + opts.on('--[no-]man', 'Prevents the creation of man pages.', 'Default on.') do |onman| + InstallOptions.man = onman + end + opts.on('--[no-]tests', 'Prevents the execution of unit tests.', 'Default on.') do |ontest| + InstallOptions.tests = ontest + end + opts.on('--destdir[=OPTIONAL]', 'Installation prefix for all targets', 'Default essentially /') do |destdir| + InstallOptions.destdir = destdir + end + opts.on('--bindir[=OPTIONAL]', 'Installation directory for binaries', 'overrides Config::CONFIG["bindir"]') do |bindir| + InstallOptions.bindir = bindir + end + opts.on('--sbindir[=OPTIONAL]', 'Installation directory for system binaries', 'overrides Config::CONFIG["sbindir"]') do |sbindir| + InstallOptions.sbindir = sbindir + end + opts.on('--sitelibdir[=OPTIONAL]', 'Installation directory for libraries', 'overrides Config::CONFIG["sitelibdir"]') do |sitelibdir| + InstallOptions.sitelibdir = sitelibdir + end + opts.on('--mandir[=OPTIONAL]', 'Installation directory for man pages', 'overrides Config::CONFIG["mandir"]') do |mandir| + InstallOptions.mandir = mandir + end + opts.on('--quick', 'Performs a quick installation. Only the', 'installation is done.') do |quick| + InstallOptions.rdoc = false + InstallOptions.ri = false + InstallOptions.tests = false + end + opts.on('--full', 'Performs a full installation. All', 'optional installation steps are run.') do |full| + InstallOptions.rdoc = true + InstallOptions.man = true + InstallOptions.ri = true + InstallOptions.tests = true + end + opts.separator("") + opts.on_tail('--help', "Shows this help text.") do + $stderr.puts opts + exit + end + + opts.parse! end - opts.on('--sitelibdir[=OPTIONAL]', 'Installation directory for libraries', 'overrides Config::CONFIG["sitelibdir"]') do |sitelibdir| - InstallOptions.sitelibdir = sitelibdir + + tmpdirs = [ENV['TMP'], ENV['TEMP'], "/tmp", "/var/tmp", "."] + + version = [Config::CONFIG["MAJOR"], Config::CONFIG["MINOR"]].join(".") + libdir = File.join(Config::CONFIG["libdir"], "ruby", version) + + # Mac OS X 10.5 and higher declare bindir and sbindir as + # /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin + # /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/sbin + # which is not generally where people expect executables to be installed + # These settings are appropriate defaults for all OS X versions. + if RUBY_PLATFORM =~ /^universal-darwin[\d\.]+$/ + Config::CONFIG['bindir'] = "/usr/bin" + Config::CONFIG['sbindir'] = "/usr/sbin" end - opts.on('--mandir[=OPTIONAL]', 'Installation directory for man pages', 'overrides Config::CONFIG["mandir"]') do |mandir| - InstallOptions.mandir = mandir + + if not InstallOptions.bindir.nil? + bindir = InstallOptions.bindir + else + bindir = Config::CONFIG['bindir'] end - opts.on('--quick', 'Performs a quick installation. Only the', 'installation is done.') do |quick| - InstallOptions.rdoc = false - InstallOptions.ri = false - InstallOptions.tests = false + + if not InstallOptions.sbindir.nil? + sbindir = InstallOptions.sbindir + else + sbindir = Config::CONFIG['sbindir'] end - opts.on('--full', 'Performs a full installation. All', 'optional installation steps are run.') do |full| - InstallOptions.rdoc = true - InstallOptions.man = true - InstallOptions.ri = true - InstallOptions.tests = true + + if not InstallOptions.sitelibdir.nil? + sitelibdir = InstallOptions.sitelibdir + else + sitelibdir = Config::CONFIG["sitelibdir"] + if sitelibdir.nil? + sitelibdir = $:.find { |x| x =~ /site_ruby/ } + if sitelibdir.nil? + sitelibdir = File.join(libdir, "site_ruby") + elsif sitelibdir !~ Regexp.quote(version) + sitelibdir = File.join(sitelibdir, version) + end + end end - opts.separator("") - opts.on_tail('--help', "Shows this help text.") do - $stderr.puts opts - exit + + if not InstallOptions.mandir.nil? + mandir = InstallOptions.mandir + else + mandir = Config::CONFIG['mandir'] end - opts.parse! - end - - tmpdirs = [ENV['TMP'], ENV['TEMP'], "/tmp", "/var/tmp", "."] - - version = [Config::CONFIG["MAJOR"], Config::CONFIG["MINOR"]].join(".") - libdir = File.join(Config::CONFIG["libdir"], "ruby", version) - - # Mac OS X 10.5 and higher declare bindir and sbindir as - # /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin - # /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/sbin - # which is not generally where people expect executables to be installed - # These settings are appropriate defaults for all OS X versions. - if RUBY_PLATFORM =~ /^universal-darwin[\d\.]+$/ - Config::CONFIG['bindir'] = "/usr/bin" - Config::CONFIG['sbindir'] = "/usr/sbin" - end - - if not InstallOptions.bindir.nil? - bindir = InstallOptions.bindir - else - bindir = Config::CONFIG['bindir'] - end - - if not InstallOptions.sbindir.nil? - sbindir = InstallOptions.sbindir - else - sbindir = Config::CONFIG['sbindir'] - end - - if not InstallOptions.sitelibdir.nil? - sitelibdir = InstallOptions.sitelibdir - else - sitelibdir = Config::CONFIG["sitelibdir"] - if sitelibdir.nil? - sitelibdir = $:.find { |x| x =~ /site_ruby/ } - if sitelibdir.nil? - sitelibdir = File.join(libdir, "site_ruby") - elsif sitelibdir !~ Regexp.quote(version) - sitelibdir = File.join(sitelibdir, version) - end + # To be deprecated once people move over to using --destdir option + if (destdir = ENV['DESTDIR']) + bindir = "#{destdir}#{bindir}" + sbindir = "#{destdir}#{sbindir}" + mandir = "#{destdir}#{mandir}" + sitelibdir = "#{destdir}#{sitelibdir}" + + FileUtils.makedirs(bindir) + FileUtils.makedirs(sbindir) + FileUtils.makedirs(mandir) + FileUtils.makedirs(sitelibdir) + # This is the new way forward + elsif (destdir = InstallOptions.destdir) + bindir = "#{destdir}#{bindir}" + sbindir = "#{destdir}#{sbindir}" + mandir = "#{destdir}#{mandir}" + sitelibdir = "#{destdir}#{sitelibdir}" + + FileUtils.makedirs(bindir) + FileUtils.makedirs(sbindir) + FileUtils.makedirs(mandir) + FileUtils.makedirs(sitelibdir) end - end - - if not InstallOptions.mandir.nil? - mandir = InstallOptions.mandir - else - mandir = Config::CONFIG['mandir'] - end - - # To be deprecated once people move over to using --destdir option - if (destdir = ENV['DESTDIR']) - bindir = "#{destdir}#{bindir}" - sbindir = "#{destdir}#{sbindir}" - mandir = "#{destdir}#{mandir}" - sitelibdir = "#{destdir}#{sitelibdir}" - - FileUtils.makedirs(bindir) - FileUtils.makedirs(sbindir) - FileUtils.makedirs(mandir) - FileUtils.makedirs(sitelibdir) - # This is the new way forward - elsif (destdir = InstallOptions.destdir) - bindir = "#{destdir}#{bindir}" - sbindir = "#{destdir}#{sbindir}" - mandir = "#{destdir}#{mandir}" - sitelibdir = "#{destdir}#{sitelibdir}" - - FileUtils.makedirs(bindir) - FileUtils.makedirs(sbindir) - FileUtils.makedirs(mandir) - FileUtils.makedirs(sitelibdir) - end - - tmpdirs << bindir - - InstallOptions.tmp_dirs = tmpdirs.compact - InstallOptions.site_dir = sitelibdir - InstallOptions.bin_dir = bindir - InstallOptions.sbin_dir = sbindir - InstallOptions.lib_dir = libdir - InstallOptions.man_dir = mandir + + tmpdirs << bindir + + InstallOptions.tmp_dirs = tmpdirs.compact + InstallOptions.site_dir = sitelibdir + InstallOptions.bin_dir = bindir + InstallOptions.sbin_dir = sbindir + InstallOptions.lib_dir = libdir + InstallOptions.man_dir = mandir end ## @@ -326,8 +326,7 @@ def build_rdoc(files) return unless $haverdoc begin r = RDoc::RDoc.new - r.document(["--main", "README", "--title", - "Puppet -- Site Configuration Management", "--line-numbers"] + files) + r.document(["--main", "README", "--title", "Puppet -- Site Configuration Management", "--line-numbers"] + files) rescue RDoc::RDocError => e $stderr.puts e.message rescue Exception => e @@ -361,17 +360,17 @@ def build_man(bins, sbins) File.unlink("./puppet.conf.rst") # Create binary man pages - binary = bins + sbins + binary = bins + sbins binary.each do |bin| - b = bin.gsub( /(bin|sbin)\//, "") - %x{#{bin} --help > ./#{b}.rst} - %x{#{rst2man} ./#{b}.rst ./man/man8/#{b}.8} - File.unlink("./#{b}.rst") + b = bin.gsub( /(bin|sbin)\//, "") + %x{#{bin} --help > ./#{b}.rst} + %x{#{rst2man} ./#{b}.rst ./man/man8/#{b}.8} + File.unlink("./#{b}.rst") end - + rescue SystemCallError - $stderr.puts "Couldn't build man pages: " + $! - $stderr.puts "Continuing with install..." + $stderr.puts "Couldn't build man pages: " + $! + $stderr.puts "Continuing with install..." end end @@ -402,57 +401,57 @@ end # (e.g., bin/rdoc becomes rdoc); the shebang line handles running it. Under # windows, we add an '.rb' extension and let file associations do their stuff. def install_binfile(from, op_file, target) - tmp_dir = nil - InstallOptions.tmp_dirs.each do |t| - if File.directory?(t) and File.writable?(t) - tmp_dir = t - break + tmp_dir = nil + InstallOptions.tmp_dirs.each do |t| + if File.directory?(t) and File.writable?(t) + tmp_dir = t + break + end end - end - - fail "Cannot find a temporary directory" unless tmp_dir - tmp_file = File.join(tmp_dir, '_tmp') - ruby = File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name']) - - File.open(from) do |ip| - File.open(tmp_file, "w") do |op| - ruby = File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name']) - op.puts "#!#{ruby}" - contents = ip.readlines - if contents[0] =~ /^#!/ - contents.shift - end - op.write contents.join() + + fail "Cannot find a temporary directory" unless tmp_dir + tmp_file = File.join(tmp_dir, '_tmp') + ruby = File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name']) + + File.open(from) do |ip| + File.open(tmp_file, "w") do |op| + ruby = File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name']) + op.puts "#!#{ruby}" + contents = ip.readlines + if contents[0] =~ /^#!/ + contents.shift + end + op.write contents.join() + end end - end - if Config::CONFIG["target_os"] =~ /win/io and Config::CONFIG["target_os"] !~ /darwin/io - installed_wrapper = false + if Config::CONFIG["target_os"] =~ /win/io and Config::CONFIG["target_os"] !~ /darwin/io + installed_wrapper = false - if File.exists?("#{from}.bat") - FileUtils.install("#{from}.bat", File.join(target, "#{op_file}.bat"), :mode => 0755, :verbose => true) - installed_wrapper = true - end + if File.exists?("#{from}.bat") + FileUtils.install("#{from}.bat", File.join(target, "#{op_file}.bat"), :mode => 0755, :verbose => true) + installed_wrapper = true + end - if File.exists?("#{from}.cmd") - FileUtils.install("#{from}.cmd", File.join(target, "#{op_file}.cmd"), :mode => 0755, :verbose => true) - installed_wrapper = true - end + if File.exists?("#{from}.cmd") + FileUtils.install("#{from}.cmd", File.join(target, "#{op_file}.cmd"), :mode => 0755, :verbose => true) + installed_wrapper = true + end - if not installed_wrapper - tmp_file2 = File.join(tmp_dir, '_tmp_wrapper') - cwn = File.join(Config::CONFIG['bindir'], op_file) - cwv = CMD_WRAPPER.gsub('<ruby>', ruby.gsub(%r{/}) { "\\" }).gsub!('<command>', cwn.gsub(%r{/}) { "\\" } ) + if not installed_wrapper + tmp_file2 = File.join(tmp_dir, '_tmp_wrapper') + cwn = File.join(Config::CONFIG['bindir'], op_file) + cwv = CMD_WRAPPER.gsub('<ruby>', ruby.gsub(%r{/}) { "\\" }).gsub!('<command>', cwn.gsub(%r{/}) { "\\" } ) - File.open(tmp_file2, "wb") { |cw| cw.puts cwv } - FileUtils.install(tmp_file2, File.join(target, "#{op_file}.bat"), :mode => 0755, :verbose => true) + File.open(tmp_file2, "wb") { |cw| cw.puts cwv } + FileUtils.install(tmp_file2, File.join(target, "#{op_file}.bat"), :mode => 0755, :verbose => true) - File.unlink(tmp_file2) - installed_wrapper = true + File.unlink(tmp_file2) + installed_wrapper = true + end end - end - FileUtils.install(tmp_file, File.join(target, op_file), :mode => 0755, :verbose => true) - File.unlink(tmp_file) + FileUtils.install(tmp_file, File.join(target, op_file), :mode => 0755, :verbose => true) + File.unlink(tmp_file) end CMD_WRAPPER = <<-EOS |