class Berkshelf::BzrLocation
Attributes
Public Class Methods
# File lib/berkshelf/locations/bzr.rb, line 35 def initialize(dependency, options = {}) super @uri = options[:bzr] @revision = options[:revision] @ref = options[:ref] || 'last:' end
Public Instance Methods
# File lib/berkshelf/locations/bzr.rb, line 88 def ==(other) other.is_a?(BzrLocation) && other.uri == uri && other.ref == ref end
@see BaseLocation#cached_cookbook
# File lib/berkshelf/locations/bzr.rb, line 80 def cached_cookbook if installed? @cached_cookbook ||= CachedCookbook.from_path(install_path) else nil end end
Install this bzr cookbook into the cookbook store. This method leverages a cached bzr copy and a scratch directory to prevent bad cookbooks from making their way into the cookbook store.
@see BaseLocation#install
# File lib/berkshelf/locations/bzr.rb, line 55 def install if cached? && valid? Dir.chdir(cache_path) do bzr %|pull| end else FileUtils.mkdir_p(cache_path.dirname) bzr %|branch #{uri} #{cache_path}| end Dir.chdir(cache_path) do bzr %|update -r #{@revision || @ref}| end @revision ||= revid(cache_path) # Validate the scratched path is a valid cookbook validate_cached!(cache_path) # If we got this far, we should copy FileUtils.rm_rf(install_path) if install_path.exist? FileUtils.cp_r(cache_path, install_path) install_path.chmod(0777 & ~File.umask) end
Determine if this revision is installed.
@return [Boolean]
# File lib/berkshelf/locations/bzr.rb, line 46 def installed? revision && install_path.exist? end
# File lib/berkshelf/locations/bzr.rb, line 98 def to_lock out = " bzr: #{uri}\n" out << " revision: #{revision}\n" out << " ref: #{ref}\n" if ref out end
# File lib/berkshelf/locations/bzr.rb, line 94 def to_s "#{uri} (at ref: #{ref})" end
Private Instance Methods
Perform a bazaar command.
@param [String] command
the command to run
@param [Boolean] error
whether to raise error if the command fails
@raise [String]
the +$stdout+ from the command
# File lib/berkshelf/locations/bzr.rb, line 116 def bzr(command, error = true) unless Berkshelf.which('bzr') || Berkshelf.which('bzr.exe') raise BzrNotInstalled.new end response = Buff::ShellOut.shell_out(%|bzr #{command}|) if error && !response.success? # All bzr output is on stdout, not stderr raise BzrCommandError.new(command, cache_path, stderr = response.stdout) end response.stdout.strip end
The path where this bazaar repository is cached.
@return [Pathname]
# File lib/berkshelf/locations/bzr.rb, line 199 def cache_path Pathname.new(Berkshelf.berkshelf_path) .join('.cache', 'bzr', Digest::SHA1.hexdigest(uri)) end
Determine if this bazaar repo has already been downloaded.
@return [Boolean]
# File lib/berkshelf/locations/bzr.rb, line 183 def cached? cache_path.exist? end
The path where this cookbook would live in the store, if it were installed.
@return [Pathname, nil]
# File lib/berkshelf/locations/bzr.rb, line 191 def install_path Berkshelf.cookbook_store.storage_path .join("#{dependency.name}-#{revision.gsub('-', '_')}") end
Retrieve repository branch name or parent branch from a info output
@return [string]
# File lib/berkshelf/locations/bzr.rb, line 152 def retrieve_branch(output) result = output.match(/repository branch: (.*)/) return result.captures if result != nil result = output.match(/parent branch: (.*)/) return result.captures if result != nil '' end
Get revid from bazaar repository. @param [String] path
the path to the bazaar repository
@return [String | nil]
the bazaar revid
# File lib/berkshelf/locations/bzr.rb, line 136 def revid(path) Dir.chdir(path) do stdout = bzr %|testament --strict| if stdout testament = stdout.match(/revision-id: (.*)/) unless testament[1] raise BazaarError.new('Unable to find bazaar revid') end 'revid:' + testament[1] end end end
Determine if a bazaar cached location is valid Needed when we use alias in Berksfile
@return [Boolean]
# File lib/berkshelf/locations/bzr.rb, line 164 def valid? # Get information stdout_cached='' Dir.chdir(cache_path) do stdout_cached = retrieve_branch(bzr %|info|) end stdout_new = retrieve_branch(bzr %|info #{uri}|) # Check if alias has been moved to a new release if stdout_cached != stdout_new then FileUtils.rm_rf cache_path false else true end end