Module: Librarian::Puppet::Util

Instance Method Summary collapse

Instance Method Details

#clean_uri(uri) ⇒ Object

Remove user and password from a URI object



42
43
44
45
46
47
# File 'lib/librarian/puppet/util.rb', line 42

def clean_uri(uri)
  new_uri = uri.clone
  new_uri.user = nil
  new_uri.password = nil
  new_uri
end

#cp_r(src, dest) ⇒ Object

workaround Issue #173 FileUtils.cp_r will fail if there is a symlink that points to a missing file or when the symlink is copied before the target file when preserve is true see also tickets.opscode.com/browse/CHEF-833

If the rsync configuration parameter is set, use rsync instead of FileUtils



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/librarian/puppet/util.rb', line 27

def cp_r(src, dest)
  if rsync?
    Rsync.run(File.join(src, "/"), dest, ['-avz', '--delete'])
  else
    begin
      FileUtils.cp_r(src, dest, :preserve => true)
    rescue Errno::ENOENT, Errno::EACCES
      debug { "Failed to copy from #{src} to #{dest} preserving file types, trying again without preserving them" }
      FileUtils.rm_rf(dest)
      FileUtils.cp_r(src, dest)
    end
  end
end

#debug(*args, &block) ⇒ Object



8
9
10
# File 'lib/librarian/puppet/util.rb', line 8

def debug(*args, &block)
  environment.logger.debug(*args, &block)
end

#info(*args, &block) ⇒ Object



11
12
13
# File 'lib/librarian/puppet/util.rb', line 11

def info(*args, &block)
  environment.logger.info(*args, &block)
end

#module_name(name) ⇒ Object Also known as: organization_name

get the module name from organization-module



55
56
57
58
# File 'lib/librarian/puppet/util.rb', line 55

def module_name(name)
  # module name can't have dashes, so let's assume it is everything after the last dash
  name.rpartition('-').last
end

#normalize_name(name) ⇒ Object

normalize module name to use organization-module instead of organization/module



50
51
52
# File 'lib/librarian/puppet/util.rb', line 50

def normalize_name(name)
  name.sub('/','-')
end

#rsync?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/librarian/puppet/util.rb', line 18

def rsync?
    environment.config_db.local['rsync'] == 'true'
end

#warn(*args, &block) ⇒ Object



14
15
16
# File 'lib/librarian/puppet/util.rb', line 14

def warn(*args, &block)
  environment.logger.warn(*args, &block)
end