svnx 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,76 @@
1
+ #!/usr/bin/ruby -w
2
+ # -*- ruby -*-
3
+
4
+ require 'system/command/line'
5
+ require 'system/command/caching'
6
+ require 'svnx/command'
7
+ require 'logue/loggable'
8
+
9
+ module SVNx
10
+ module LogCmdLine
11
+ # this can be either an Array (for which to_a returns itself), or
12
+ # a CommandArgs, which also has to_a.
13
+ def initialize args = Array.new
14
+ super "log", args.to_a
15
+ end
16
+ end
17
+
18
+ class LogCommandLine < CommandLine
19
+ include LogCmdLine
20
+ end
21
+
22
+ class LogCommandLineCaching < CachingCommandLine
23
+ include LogCmdLine
24
+ end
25
+
26
+ class LogCommandArgs < CommandArgs
27
+ include Logue::Loggable
28
+
29
+ attr_reader :limit
30
+ attr_reader :verbose
31
+ attr_reader :revision
32
+ attr_reader :use_cache
33
+
34
+ def initialize args = Hash.new
35
+ @limit = args[:limit]
36
+ @verbose = args[:verbose]
37
+ @use_cache = args[:use_cache].nil? || args[:use_cache]
38
+ @revision = args[:revision]
39
+ super
40
+ end
41
+
42
+ def to_a
43
+ ary = Array.new
44
+ if @limit
45
+ ary << '--limit' << @limit
46
+ end
47
+ if @verbose
48
+ ary << '-v'
49
+ end
50
+
51
+ if @revision
52
+ [ @revision ].flatten.each do |rev|
53
+ ary << "-r#{rev}"
54
+ end
55
+ end
56
+
57
+ if @path
58
+ ary << @path
59
+ end
60
+
61
+ ary.compact
62
+ end
63
+ end
64
+
65
+ class LogCommand < Command
66
+ def initialize args
67
+ @use_cache = args.use_cache
68
+ super
69
+ end
70
+
71
+ def command_line
72
+ cls = @use_cache ? LogCommandLineCaching : LogCommandLine
73
+ cls.new @args
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/ruby -w
2
+ # -*- ruby -*-
3
+
4
+ require 'svnx/entries'
5
+ require 'svnx/log/entry'
6
+
7
+ module SVNx::Log
8
+ class Entries < SVNx::Entries
9
+ def get_elements doc
10
+ doc.elements['log'].elements
11
+ end
12
+
13
+ def create_entry xmlelement
14
+ Entry.new :xmlelement => xmlelement
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,53 @@
1
+ #!/usr/bin/ruby -w
2
+ # -*- ruby -*-
3
+
4
+ require 'svnx/entry'
5
+
6
+ module SVNx; module Log; end; end
7
+
8
+ module SVNx::Log
9
+ class Entry < SVNx::Entry
10
+
11
+ attr_reader :revision, :author, :date, :paths, :msg
12
+
13
+ def set_from_element elmt
14
+ set_attr_var elmt, 'revision'
15
+
16
+ %w{ author date msg }.each do |field|
17
+ set_elmt_var elmt, field
18
+ end
19
+
20
+ @paths = Array.new
21
+
22
+ elmt.elements.each('paths/path') do |pe|
23
+ kind = get_attribute pe, 'kind'
24
+ action = get_attribute pe, 'action'
25
+ name = pe.text
26
+
27
+ @paths << LogEntryPath.new(:kind => kind, :action => action, :name => name)
28
+ end
29
+ end
30
+
31
+ def message
32
+ @msg
33
+ end
34
+
35
+ def to_s
36
+ [ @revision, @author, @date, @msg, @paths ].collect { |x| x.to_s }.join " "
37
+ end
38
+ end
39
+
40
+ class LogEntryPath
41
+ attr_reader :kind, :action, :name
42
+
43
+ def initialize args = Hash.new
44
+ @kind = args[:kind]
45
+ @action = args[:action]
46
+ @name = args[:name]
47
+ end
48
+
49
+ def to_s
50
+ @name
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/ruby -w
2
+ # -*- ruby -*-
3
+
4
+ require 'svnx/command'
5
+
6
+ module SVNx
7
+ class StatusCommandLine < CommandLine
8
+ def initialize args = Array.new
9
+ super "status", args.to_a
10
+ end
11
+ end
12
+
13
+ class StatusCommandArgs < CommandArgs
14
+ def to_a
15
+ ary = Array.new
16
+ if @path
17
+ ary << @path
18
+ end
19
+ ary
20
+ end
21
+ end
22
+
23
+ class StatusCommand < Command
24
+ def command_line
25
+ StatusCommandLine.new @args
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/ruby -w
2
+ # -*- ruby -*-
3
+
4
+ require 'svnx/status/entry'
5
+ require 'svnx/entries'
6
+
7
+ module SVNx::Status
8
+ class Entries < SVNx::Entries
9
+ def get_elements doc
10
+ doc.elements['status'].elements['target'].elements
11
+ end
12
+
13
+ def create_entry xmlelement
14
+ Entry.new :xmlelement => xmlelement
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,53 @@
1
+ #!/usr/bin/ruby -w
2
+ # -*- ruby -*-
3
+
4
+ require 'svnx/entry'
5
+ require 'svnx/action'
6
+
7
+ module SVNx; module Status; end; end
8
+
9
+ module SVNx::Status
10
+ class Entry < SVNx::Entry
11
+
12
+ attr_reader :status
13
+ attr_reader :path
14
+ attr_reader :status_revision
15
+ attr_reader :action
16
+
17
+ def initialize args = Hash.new
18
+ super
19
+ @action = SVNx::Action.new @status
20
+ end
21
+
22
+ def set_from_xml xmldoc
23
+ stelmt = xmldoc.elements['status']
24
+ tgt = stelmt.elements['target']
25
+
26
+ set_attr_var tgt, 'path'
27
+
28
+ if entry = tgt.elements['entry']
29
+ set_from_element entry
30
+ else
31
+ @status = "unchanged"
32
+ end
33
+ end
34
+
35
+ def set_from_element elmt
36
+ set_attr_var elmt, 'path'
37
+
38
+ wcstatus = elmt.elements['wc-status']
39
+ @status = wcstatus.attributes['item']
40
+ @status_revision = wcstatus.attributes['revision']
41
+
42
+ if commit = wcstatus.elements['commit']
43
+ @commit_revision = commit.attributes['revision']
44
+ else
45
+ @commit_revision = nil
46
+ end
47
+ end
48
+
49
+ def to_s
50
+ "path: #{@path}; status: #{@status}"
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/ruby -w
2
+ # -*- ruby -*-
3
+
4
+ module System
5
+ class Argument < String
6
+ # just a string, but quotes itself
7
+
8
+ def to_s
9
+ '"' + super + '"'
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,50 @@
1
+ #!/usr/bin/ruby -w
2
+ # -*- ruby -*-
3
+
4
+ require 'system/command/line'
5
+ require 'zlib'
6
+ require 'logue/loggable'
7
+
8
+ module System
9
+ class CacheFile
10
+ include Logue::Loggable
11
+
12
+ attr_reader :output
13
+
14
+ def initialize cache_dir, args
15
+ @args = args
16
+ @pn = Pathname.new(cache_dir) + (args.join('-').gsub('/', '_slash_') + '.gz')
17
+ @output = nil
18
+ end
19
+
20
+ def save_file
21
+ @pn.parent.mkpath unless @pn.parent.exist?
22
+ @pn.unlink if @pn.exist?
23
+ Zlib::GzipWriter.open(@pn.to_s) do |gz|
24
+ gz.puts @output
25
+ end
26
+ end
27
+
28
+ def read_file
29
+ Zlib::GzipReader.open(@pn.to_s) do |gz|
30
+ @output = gz.readlines
31
+ end
32
+ @output
33
+ end
34
+
35
+ def readlines
36
+ if @pn.exist?
37
+ read_file
38
+ else
39
+ cl = CommandLine.new @args
40
+ @output = cl.execute
41
+ save_file
42
+ @output
43
+ end
44
+ end
45
+
46
+ def to_s
47
+ @pn.to_s
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/ruby -w
2
+ # -*- ruby -*-
3
+
4
+ require 'system/command/line'
5
+ require 'system/command/cachefile'
6
+
7
+ module System
8
+ class CachingCommandLine < CommandLine
9
+ # caches its input and values.
10
+
11
+ @@cache_dir = '/tmp' + Pathname.new($0).expand_path.to_s
12
+
13
+ class << self
14
+ def cache_dir
15
+ @@cache_dir
16
+ end
17
+
18
+ def cache_dir= dir
19
+ @@cache_dir = dir
20
+ end
21
+ end
22
+
23
+ def cache_dir
24
+ @@cache_dir
25
+ end
26
+
27
+ def cache_file
28
+ CacheFile.new cache_dir, @args
29
+ end
30
+
31
+ def execute
32
+ cachefile = cache_file
33
+ @output = cachefile.readlines
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,53 @@
1
+ #!/usr/bin/ruby -w
2
+ # -*- ruby -*-
3
+
4
+ require 'rubygems'
5
+ require 'system/command/arg'
6
+ require 'logue/loggable'
7
+ require 'riel/pathname'
8
+ require 'open3'
9
+ require 'rainbow'
10
+
11
+ module System
12
+ class CommandLine
13
+ include Logue::Loggable
14
+
15
+ attr_reader :output
16
+
17
+ def initialize args = Array.new
18
+ @args = args.dup
19
+ end
20
+
21
+ def << arg
22
+ # @args << Argument.new(arg)
23
+ @args << arg
24
+ end
25
+
26
+ def execute
27
+ cmd = to_command
28
+
29
+ info "cmd: #{cmd}".color("8A8A43")
30
+
31
+ # cmd << " 2>&1"
32
+
33
+ # I want to use popen3, but the version that works (sets $?) is in 1.9.x,
34
+ # not 1.8.x:
35
+ IO.popen(cmd + " 2>&1") do |io|
36
+ @output = io.readlines
37
+ end
38
+
39
+ if $? && $?.exitstatus != 0
40
+ info "cmd: #{cmd}".color(:red)
41
+ info "$?: #{$?.inspect}".color(:red)
42
+ info "$?.exitstatus: #{$? && $?.exitstatus}".color(:red)
43
+ raise "ERROR running command '#{cmd}': #{@output[-1]}"
44
+ end
45
+
46
+ @output
47
+ end
48
+
49
+ def to_command
50
+ @args.join ' '
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/ruby -w
2
+ # -*- ruby -*-
3
+
4
+ require 'tc'
5
+ require 'svnx/action'
6
+
7
+ module SVNx
8
+ class ActionTestCase < PVN::TestCase
9
+ def assert_action_equals expadd, expdel, expmod, expunver, *vals
10
+ vals.each do |val|
11
+ action = Action.new val
12
+ msg = "value: #{val}"
13
+ assert_equal expadd, action.added?, msg
14
+ assert_equal expdel, action.deleted?, msg
15
+ assert_equal expmod, action.modified?, msg
16
+ assert_equal expunver, action.unversioned?, msg
17
+ end
18
+ end
19
+
20
+ def test_added
21
+ assert_action_equals true, false, false, false, 'added', 'A'
22
+ end
23
+
24
+ def test_deleted
25
+ assert_action_equals false, true, false, false, 'deleted', 'D'
26
+ end
27
+
28
+ def test_modified
29
+ assert_action_equals false, false, true, false, 'modified', 'M'
30
+ end
31
+
32
+ def test_unversioned
33
+ assert_action_equals false, false, false, true, 'unversioned', '?'
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/ruby -w
2
+ # -*- ruby -*-
3
+
4
+ require 'svnx/info/tc'
5
+ require 'svnx/info/entries'
6
+
7
+ module SVNx::Info
8
+ class EntriesTestCase < SVNx::Info::TestCase
9
+ def assert_info_entry_equals entry, path, kind, revision
10
+ assert_entry_equals entry, :path => path, :kind => 'file', :url => EXPROOT + '/' + path, :root => EXPROOT, :revision => revision
11
+ end
12
+
13
+ def test_create_from_xml
14
+ entries = Entries.new :xmllines => Resources::PTP_INFO_SIXTH_TXT_DOG_RB_FIRST_TXT.readlines
15
+ assert_equal 3, entries.size
16
+
17
+ assert_info_entry_equals entries[0], 'dirzero/SixthFile.txt', 'file', '22'
18
+ assert_info_entry_equals entries[1], 'src/ruby/dog.rb', 'file', '0'
19
+ assert_info_entry_equals entries[2], 'FirstFile.txt', 'file', '22'
20
+ end
21
+ end
22
+ end