Sha256: d2f0c0544926c6ba7b2a2630a7b32f9e16686b3437009409cf49ad8fcd52335c

Contents?: true

Size: 1.84 KB

Versions: 1

Compression:

Stored size: 1.84 KB

Contents

require 'stringio'
require 'rexml/document'

module BuildMaster

class SvnInfo
  attr_reader :path, :repository_root
  
  def initialize(path)
    @path = path
    analyze_entry_file(File.join(path, ".svn", "entries"))
  end
  
  def analyze_entry_file(path)
    content = load_content(path)
    xml = REXML::Document.new(content)
    xml.root.each_element_with_attribute('name', '', 1) do |element|
      @repository_root = element.attributes['repos']
    end
  end
  
  def load_content(path)
    buffer = StringIO.new
    File.open(path, 'r') do |file|
      while (line = file.gets)
        buffer.puts(line)
      end
    end
    return buffer.string
  end
end

class SvnDriver
    include Shell
    
    def SvnDriver::from_path(directory)
        return SvnDriver.new(SvnInfo.new(directory))
    end
    
    def initialize(svn_info, &command_runner)
        @svn_info = svn_info
        if (command_runner)
            @command_runner = command_runner
        else
            @command_runner = Proc.new {|command| run(command)}
        end
    end
    
    def status
        command_for_path('status')
    end
    
    def update
        command_for_path('update')
    end
    
    def commit(comment)
        command_for_path('commit', " -m \"#{comment}\"") 
    end
    
    def tag(tag_name)
        run_command("svn copy #{@svn_info.repository_root}/trunk #{@svn_info.repository_root}/tags/#{tag_name} -m \"ruby buildmaster\"")
    end
    
    def checkout(output)
        run_command("svn checkout #{@svn_info.repository_root}/trunk #{output}")
    end
    
    def command(command)
        command_for_path(command)
    end
    
    private
    
    def command_for_path(svn_command, argument='')
        run_command("svn #{svn_command} #{@svn_info.path}#{argument}")
    end
end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
BuildMaster-0.8.0 lib/buildmaster/svn_driver.rb