svnutils 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/lib/LICENSE +10 -0
  2. data/lib/svnutils.rb +90 -0
  3. data/test/tc_svnutils.rb +64 -0
  4. metadata +49 -0
data/lib/LICENSE ADDED
@@ -0,0 +1,10 @@
1
+ Copyright (c) 2006, Christopher Maujean and project contributors
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
5
+
6
+ * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8
+ * Neither the name of the NGSLib nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
9
+
10
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/lib/svnutils.rb ADDED
@@ -0,0 +1,90 @@
1
+ # $Id: svnutils.rb 45 2006-08-13 23:58:26Z cmaujean $
2
+ # See LICENSE for copyright information
3
+
4
+ require 'ostruct'
5
+
6
+ #
7
+ # use the svn Id Keyword expansion to report svn file information
8
+ # revision, developer, filename, date and time of last revision.
9
+ #
10
+
11
+ class SVNUtils
12
+ @@files = Hash.new
13
+
14
+ # get the svn version of a file
15
+ def SVNUtils.revision(target_file)
16
+ if not @@files[target_file]
17
+ parse_file(target_file)
18
+ end
19
+ return @@files[target_file].revision
20
+ end
21
+
22
+ # get the last developer who checked in the file
23
+ def SVNUtils.developer(target_file)
24
+ if not @@files[target_file]
25
+ parse_file(target_file)
26
+ end
27
+ return @@files[target_file].developer
28
+ end
29
+
30
+ # get the svn filename of the file
31
+ def SVNUtils.filename(target_file)
32
+ if not @@files[target_file]
33
+ parse_file(target_file)
34
+ end
35
+ return @@files[target_file].filename
36
+ end
37
+
38
+ # get the date the last revision was made to the file
39
+ def SVNUtils.date(target_file)
40
+ if not @@files[target_file]
41
+ parse_file(target_file)
42
+ end
43
+ return @@files[target_file].date
44
+ end
45
+
46
+ # get the time the last revision was made to the file
47
+ def SVNUtils.time(target_file)
48
+ if not @@files[target_file]
49
+ parse_file(target_file)
50
+ end
51
+ return @@files[target_file].time
52
+ end
53
+
54
+
55
+ # parse the file, so we can get its values
56
+ def SVNUtils.parse_file(target_file)
57
+ if not File.exist?(target_file)
58
+ raise SVNUtils::FileNotFound, target_file
59
+ end
60
+
61
+ # get first id from the file
62
+ File.readlines(target_file).each do |line|
63
+ match = []
64
+ match = line.scan(/\$Id:(.+)\$/)
65
+ if not match[0].nil?
66
+ matchset = match[0][0].strip.split(" ")
67
+ @@files[target_file] = OpenStruct.new
68
+ m = @@files[target_file]
69
+ m.filename, m.revision, m.date, m.time, m.developer = matchset
70
+ break
71
+ end
72
+ end
73
+
74
+ # what if there is no Id tag in the given file?
75
+ if @@files[target_file].nil?
76
+ @@files[target_file] = OpenStruct.new
77
+ @@files[target_file].filename = "No ID tag found"
78
+ @@files[target_file].revision = "No ID tag found"
79
+ @@files[target_file].date = "No ID tag found"
80
+ @@files[target_file].time = "No ID tag found"
81
+ @@files[target_file].developer = "No ID tag found"
82
+
83
+ end
84
+ end
85
+ end
86
+
87
+ class SVNUtils::FileNotFound < RuntimeError
88
+ end
89
+
90
+ # vi:sw=2 ts=2
@@ -0,0 +1,64 @@
1
+ require 'test/unit'
2
+ require 'svnutils'
3
+ require 'fileutils'
4
+
5
+ class TestSVNUtils < Test::Unit::TestCase
6
+ def setup
7
+ # put the testfile down.
8
+ f = File.new('svnutils/test/data/testfile', "w+")
9
+ f.puts
10
+ f.puts("$Id: testfile 42 2006-08-13 23:18:33Z cmaujean $")
11
+ f.puts
12
+ f.close
13
+
14
+ # put the empty file down
15
+ f = File.new('svnutils/test/data/noidfile', "w+")
16
+ f.puts;f.puts;f.puts;f.puts "This ain't no disco";f.puts
17
+ end
18
+
19
+ # utility method for testing
20
+ def kill_file
21
+ # clean up the test/data/testfile file
22
+ FileUtils.rm("svnutils/test/data/testfile")
23
+ end
24
+
25
+ def teardown
26
+ FileUtils.rm('svnutils/test/data/noidfile')
27
+ end
28
+
29
+
30
+ def test_id_functions
31
+ testfile = 'svnutils/test/data/testfile'
32
+
33
+ # test exception throwing
34
+ assert_raise SVNUtils::FileNotFound do
35
+ version = SVNUtils::revision('test/data/thisfileisnothere')
36
+ end
37
+
38
+ assert_nothing_raised do
39
+ version = SVNUtils::revision(testfile)
40
+ end
41
+
42
+ # test no id tag in file
43
+ noidversion = SVNUtils::revision('svnutils/test/data/noidfile')
44
+ assert_equal "No ID tag found", noidversion, "No ID Version should be: No ID tag found"
45
+
46
+ # test individual data
47
+ version = SVNUtils::revision(testfile)
48
+ assert_equal "42", version, "Version extracted: #{version}"
49
+
50
+ # lets see if we kept the file data
51
+ kill_file()
52
+ version = SVNUtils::revision(testfile)
53
+ developer = SVNUtils::developer(testfile)
54
+ date = SVNUtils::date(testfile)
55
+ time = SVNUtils::time(testfile)
56
+ filename = SVNUtils::filename(testfile)
57
+
58
+ assert_equal "42", version, "Version extracted: #{version}"
59
+ assert_equal "cmaujean", developer, "Developer extracted: #{developer}"
60
+ assert_equal "2006-08-13", date, "Date extracted: #{date}"
61
+ assert_equal "23:18:33Z", time, "Time extracted: #{time}"
62
+ assert_equal "testfile", filename, "Filename extracted: #{filename}"
63
+ end
64
+ end
metadata ADDED
@@ -0,0 +1,49 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.9.0
3
+ specification_version: 1
4
+ name: svnutils
5
+ version: !ruby/object:Gem::Version
6
+ version: 0.1.0
7
+ date: 2006-08-13 00:00:00 -07:00
8
+ summary: a read only, line oriented, sparse file class
9
+ require_paths:
10
+ - lib
11
+ email: cmaujean@gmail.com
12
+ homepage: http://rubyforge.org/projects/ngslib
13
+ rubyforge_project:
14
+ description:
15
+ autorequire:
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: true
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
24
+ version:
25
+ platform: ruby
26
+ signing_key:
27
+ cert_chain:
28
+ post_install_message:
29
+ authors:
30
+ - Christopher Maujean
31
+ files:
32
+ - lib/svnutils.rb
33
+ - lib/LICENSE
34
+ - test/data
35
+ - test/tc_svnutils.rb
36
+ test_files:
37
+ - test/tc_svnutils.rb
38
+ rdoc_options: []
39
+
40
+ extra_rdoc_files: []
41
+
42
+ executables: []
43
+
44
+ extensions: []
45
+
46
+ requirements: []
47
+
48
+ dependencies: []
49
+