tpkg 2.3.3 → 2.3.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (205) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +1 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE +20 -0
  5. data/Portfile +39 -0
  6. data/Portfile.template +39 -0
  7. data/README.md +43 -0
  8. data/Rakefile +468 -18
  9. data/bin/gem2tpkg +2 -2
  10. data/bin/tpkg +18 -13
  11. data/bin/tpkg_uploader +132 -0
  12. data/ca.pem +1 -0
  13. data/control +7 -0
  14. data/depend +3 -0
  15. data/externals-etch/authorized_keys +40 -0
  16. data/externals-etch/group +9 -0
  17. data/externals-etch/iptables +38 -0
  18. data/externals-etch/limits +30 -0
  19. data/externals-etch/nfs +30 -0
  20. data/externals-etch/sudo +30 -0
  21. data/externals-etch/supplemental_groups +8 -0
  22. data/externals-etch/sysctl +30 -0
  23. data/externals-etch/user +41 -0
  24. data/externals/group +39 -0
  25. data/externals/supplemental_groups +48 -0
  26. data/externals/user +39 -0
  27. data/lib/tpkg.rb +260 -991
  28. data/lib/tpkg/os.rb +164 -0
  29. data/lib/tpkg/os/debian.rb +159 -0
  30. data/lib/tpkg/os/freebsd.rb +113 -0
  31. data/lib/tpkg/os/macosx.rb +113 -0
  32. data/lib/tpkg/os/redhat.rb +173 -0
  33. data/lib/tpkg/os/solaris.rb +101 -0
  34. data/lib/tpkg/os/windows.rb +26 -0
  35. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify.rb +67 -0
  36. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/errors.rb +127 -0
  37. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/kwalify.schema.yaml +58 -0
  38. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/main.rb +442 -0
  39. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/messages.rb +173 -0
  40. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/meta-validator.rb +275 -0
  41. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/parser/base.rb +127 -0
  42. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/parser/yaml.rb +841 -0
  43. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/rule.rb +559 -0
  44. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/templates/genclass-java.eruby +222 -0
  45. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/templates/genclass-php.eruby +104 -0
  46. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/templates/genclass-ruby.eruby +113 -0
  47. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/types.rb +156 -0
  48. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/util.rb +158 -0
  49. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/util/assert-text-equal.rb +46 -0
  50. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/util/hash-interface.rb +18 -0
  51. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/util/hashlike.rb +51 -0
  52. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/util/option-parser.rb +220 -0
  53. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/util/ordered-hash.rb +57 -0
  54. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/util/testcase-helper.rb +112 -0
  55. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/validator.rb +282 -0
  56. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/yaml-parser.rb +870 -0
  57. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh.rb +219 -0
  58. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/agent.rb +179 -0
  59. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/constants.rb +18 -0
  60. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/key_manager.rb +219 -0
  61. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/methods/abstract.rb +60 -0
  62. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/methods/hostbased.rb +71 -0
  63. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/methods/keyboard_interactive.rb +66 -0
  64. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/methods/password.rb +39 -0
  65. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/methods/publickey.rb +92 -0
  66. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/pageant.rb +183 -0
  67. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/session.rb +134 -0
  68. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/buffer.rb +340 -0
  69. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/buffered_io.rb +198 -0
  70. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/config.rb +205 -0
  71. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/connection/channel.rb +630 -0
  72. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/connection/constants.rb +33 -0
  73. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/connection/session.rb +597 -0
  74. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/connection/term.rb +178 -0
  75. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/errors.rb +85 -0
  76. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/key_factory.rb +102 -0
  77. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/known_hosts.rb +129 -0
  78. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/loggable.rb +61 -0
  79. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/packet.rb +102 -0
  80. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/prompt.rb +93 -0
  81. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/proxy/command.rb +75 -0
  82. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/proxy/errors.rb +14 -0
  83. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/proxy/http.rb +94 -0
  84. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/proxy/socks4.rb +70 -0
  85. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/proxy/socks5.rb +142 -0
  86. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/ruby_compat.rb +43 -0
  87. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/service/forward.rb +288 -0
  88. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/test.rb +89 -0
  89. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/test/channel.rb +129 -0
  90. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/test/extensions.rb +152 -0
  91. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/test/kex.rb +44 -0
  92. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/test/local_packet.rb +51 -0
  93. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/test/packet.rb +81 -0
  94. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/test/remote_packet.rb +38 -0
  95. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/test/script.rb +157 -0
  96. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/test/socket.rb +64 -0
  97. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/algorithms.rb +384 -0
  98. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/cipher_factory.rb +97 -0
  99. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/constants.rb +30 -0
  100. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/hmac.rb +31 -0
  101. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/hmac/abstract.rb +79 -0
  102. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/hmac/md5.rb +12 -0
  103. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/hmac/md5_96.rb +11 -0
  104. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/hmac/none.rb +15 -0
  105. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/hmac/sha1.rb +13 -0
  106. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/hmac/sha1_96.rb +11 -0
  107. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/identity_cipher.rb +55 -0
  108. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/kex.rb +13 -0
  109. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/kex/diffie_hellman_group1_sha1.rb +208 -0
  110. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/kex/diffie_hellman_group_exchange_sha1.rb +77 -0
  111. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/openssl.rb +127 -0
  112. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/packet_stream.rb +235 -0
  113. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/server_version.rb +71 -0
  114. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/session.rb +276 -0
  115. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/state.rb +206 -0
  116. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/verifiers/lenient.rb +30 -0
  117. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/verifiers/null.rb +12 -0
  118. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/verifiers/strict.rb +53 -0
  119. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/version.rb +62 -0
  120. data/lib/tpkg/version.rb +3 -0
  121. data/man/man1/cpan2tpkg.1 +82 -0
  122. data/man/man1/gem2tpkg.1 +120 -0
  123. data/man/man1/tpkg.1 +411 -0
  124. data/pkginfo +8 -0
  125. data/postinstall.solaris +11 -0
  126. data/postremove.solaris +16 -0
  127. data/schema/schema-1.0.5.yml +0 -0
  128. data/schema/schema-1.0.6.yml +0 -0
  129. data/schema/schema-1.0.7.yml +0 -0
  130. data/schema/schema-1.0.8.yml +0 -0
  131. data/schema/schema-1.0.9.yml +0 -0
  132. data/schema/schema.yml +0 -0
  133. data/schema/tpkg-1.0.0.dtd +0 -0
  134. data/schema/tpkg-1.0.1.dtd +0 -0
  135. data/schema/tpkg-1.0.2.dtd +0 -0
  136. data/schema/tpkg-1.0.3.dtd +0 -0
  137. data/schema/tpkg-1.0.4.dtd +0 -0
  138. data/schema/tpkg-1.0.5.dtd +0 -0
  139. data/schema/tpkg-1.0.6.dtd +0 -0
  140. data/schema/tpkg-1.0.7.dtd +0 -0
  141. data/schema/tpkg-1.0.8.dtd +0 -0
  142. data/schema/tpkg-1.0.9.dtd +0 -0
  143. data/schema/tpkg.dtd +0 -0
  144. data/test/TODO +30 -0
  145. data/test/premadetestpkg/pkg_without_file_metadata-1.0-1.tpkg +0 -0
  146. data/test/test_checksum.rb +53 -0
  147. data/test/test_compress.rb +55 -0
  148. data/test/test_conflict.rb +41 -0
  149. data/test/test_crontabs.rb +398 -0
  150. data/test/test_dependency.rb +1113 -0
  151. data/test/test_downgrade.rb +80 -0
  152. data/test/test_download.rb +95 -0
  153. data/test/test_encrypt.rb +136 -0
  154. data/test/test_filemetadata.rb +131 -0
  155. data/test/test_initscript.rb +93 -0
  156. data/test/test_install.rb +186 -0
  157. data/test/test_lock.rb +82 -0
  158. data/test/test_make.rb +410 -0
  159. data/test/test_metadata.rb +805 -0
  160. data/test/test_misc.rb +379 -0
  161. data/test/test_options.rb +1711 -0
  162. data/test/test_os.rb +193 -0
  163. data/test/test_os_debian.rb +99 -0
  164. data/test/test_os_freebsd.rb +89 -0
  165. data/test/test_os_macosx.rb +79 -0
  166. data/test/test_os_redhat.rb +124 -0
  167. data/test/test_os_solaris.rb +85 -0
  168. data/test/test_os_windows.rb +26 -0
  169. data/test/test_query.rb +134 -0
  170. data/test/test_remove.rb +539 -0
  171. data/test/test_tar.rb +99 -0
  172. data/test/test_unpack.rb +977 -0
  173. data/test/test_upgrade.rb +398 -0
  174. data/test/test_version.rb +54 -0
  175. data/test/testcmds/crontab +14 -0
  176. data/test/testcmds/debian/apt-cache +145 -0
  177. data/test/testcmds/debian/dpkg-query +16 -0
  178. data/test/testcmds/freebsd/pkg_info +13 -0
  179. data/test/testcmds/macosx/port +35 -0
  180. data/test/testcmds/redhat/rpmbuild +6 -0
  181. data/test/testcmds/redhat/yum +90 -0
  182. data/test/testcmds/solaris/pkginfo +25 -0
  183. data/test/testcmds/solaris/pkgutil +36 -0
  184. data/test/testpkg/reloc/encfile +2 -0
  185. data/test/testpkg/reloc/file +2 -0
  186. data/test/testpkg/reloc/precryptfile +1 -0
  187. data/test/testpkg/reloc/precryptfile.plaintext +3 -0
  188. data/test/testpkg/tpkg-bad-ownergroup.xml +25 -0
  189. data/test/testpkg/tpkg-bad-ownergroup.yml +18 -0
  190. data/test/testpkg/tpkg-default-perms.xml +28 -0
  191. data/test/testpkg/tpkg-default-perms.yml +20 -0
  192. data/test/testpkg/tpkg-good-ownergroup.xml +25 -0
  193. data/test/testpkg/tpkg-good-ownergroup.yml +18 -0
  194. data/test/testpkg/tpkg-nativedeps.yml +13 -0
  195. data/test/testpkg/tpkg-nofiles.xml +14 -0
  196. data/test/testpkg/tpkg-nofiles.yml +9 -0
  197. data/test/testpkg/tpkg.xml +35 -0
  198. data/test/testpkg/tpkg.yml +25 -0
  199. data/test/tpkgtest.rb +300 -0
  200. data/tpkg.conf +16 -0
  201. data/tpkg.gemspec +24 -0
  202. data/tpkg.spec +28 -0
  203. data/tpkg.xml +17 -0
  204. data/tpkg_profile.sh +32 -0
  205. metadata +306 -31
@@ -0,0 +1,158 @@
1
+ ###
2
+ ### $Rev$
3
+ ### $Release: 0.7.2 $
4
+ ### copyright(c) 2005-2010 kuwata-lab all rights reserved.
5
+ ###
6
+
7
+ module Kwalify
8
+
9
+ module Util
10
+
11
+ module_function
12
+
13
+ ##
14
+ ## expand tab character to spaces
15
+ ##
16
+ ## ex.
17
+ ## untabified_str = YamlHelper.untabify(tabbed_str)
18
+ ##
19
+ def untabify(str, width=8)
20
+ return str if str.nil?
21
+ list = str.split(/\t/, -1) # if 2nd arg is negative then split() doesn't remove tailing empty strings
22
+ last = list.pop
23
+ sb = ''
24
+ list.each do |s|
25
+ column = (n = s.rindex(?\n)) ? s.length - n - 1 : s.length
26
+ n = width - (column % width)
27
+ sb << s << (' ' * n)
28
+ end
29
+ sb << last if last
30
+ return sb
31
+ end
32
+
33
+
34
+ ## traverse schema
35
+ ##
36
+ ## ex.
37
+ ## schema = YAML.load_file('myschema.yaml')
38
+ ## Kwalify::Util.traverse_schema(schema) do |rulehash|
39
+ ## ## add module prefix to class name
40
+ ## if rulehash['class']
41
+ ## rulehash['class'] = 'MyModule::' + rulehash['class']
42
+ ## end
43
+ ## end
44
+ def traverse_schema(schema, &block) #:yield: rulehash
45
+ hash = schema
46
+ _done = {}
47
+ _traverse_schema(hash, _done, &block)
48
+ end
49
+
50
+ def _traverse_schema(hash, _done={}, &block)
51
+ return if _done.key?(hash.__id__)
52
+ _done[hash.__id__] = hash
53
+ yield hash
54
+ if hash['mapping']
55
+ hash['mapping'].each {|k, v| _traverse_schema(v, _done, &block) }
56
+ elsif hash['sequence']
57
+ _traverse_schema(hash['sequence'][0], _done, &block)
58
+ end
59
+ end
60
+ private :_traverse_schema
61
+
62
+
63
+ ## traverse rule
64
+ ##
65
+ ## ex.
66
+ ## schema = YAML.load_file('myschema.yaml')
67
+ ## validator = Kwalify::Validator.new(schema)
68
+ ## Kwalify::Util.traverse_rule(validator) do |rule|
69
+ ## p rule if rule.classname
70
+ ## end
71
+ def traverse_rule(validator, &block) #:yield: rule
72
+ rule = validator.is_a?(Rule) ? validator : validator.rule
73
+ _done = {}
74
+ _traverse_rule(rule, _done, &block)
75
+ end
76
+
77
+ def _traverse_rule(rule, _done={}, &block)
78
+ return if _done.key?(rule.__id__)
79
+ _done[rule.__id__] = rule
80
+ yield rule
81
+ rule.sequence.each do |seq_rule|
82
+ _traverse_rule(seq_rule, _done, &block)
83
+ end if rule.sequence
84
+ rule.mapping.each do |name, map_rule|
85
+ _traverse_rule(map_rule, _done, &block)
86
+ end if rule.mapping
87
+ end
88
+ private :_traverse_rule
89
+
90
+
91
+ ##
92
+ ## get class object. if not found, NameError raised.
93
+ ##
94
+ def get_class(classname)
95
+ klass = Object
96
+ classname.split('::').each do |name|
97
+ klass = klass.const_get(name)
98
+ end
99
+ return klass
100
+ end
101
+
102
+
103
+ ##
104
+ ## create a hash table from list of hash with primary key.
105
+ ##
106
+ ## ex.
107
+ ## hashlist = [
108
+ ## { "name"=>"Foo", "gender"=>"M", "age"=>20, },
109
+ ## { "name"=>"Bar", "gender"=>"F", "age"=>25, },
110
+ ## { "name"=>"Baz", "gender"=>"M", "age"=>30, },
111
+ ## ]
112
+ ## hashtable = YamlHelper.create_hashtable(hashlist, "name")
113
+ ## p hashtable
114
+ ## # => { "Foo" => { "name"=>"Foo", "gender"=>"M", "age"=>20, },
115
+ ## # "Bar" => { "name"=>"Bar", "gender"=>"F", "age"=>25, },
116
+ ## # "Baz" => { "name"=>"Baz", "gender"=>"M", "age"=>30, }, }
117
+ ##
118
+ def create_hashtable(hashlist, primarykey, flag_duplicate_check=true)
119
+ hashtable = {}
120
+ hashlist.each do |hash|
121
+ key = hash[primarykey]
122
+ unless key
123
+ riase "primary key '#{key}' not found."
124
+ end
125
+ if flag_duplicate_check && hashtable.key?(key)
126
+ raise "primary key '#{key}' duplicated (value '#{hashtable[key]}')"
127
+ end
128
+ hashtable[key] = hash
129
+ end if hashlist
130
+ return hashtable
131
+ end
132
+
133
+
134
+ ##
135
+ ## get nested value directly.
136
+ ##
137
+ ## ex.
138
+ ## val = YamlHelper.get_value(obj, ['aaa', 0, 'xxx'])
139
+ ##
140
+ ## This is equal to the following:
141
+ ## begin
142
+ ## val = obj['aaa'][0]['xxx']
143
+ ## rescue NameError
144
+ ## val = nil
145
+ ## end
146
+ ##
147
+ def get_value(obj, path)
148
+ val = obj
149
+ path.each do |key|
150
+ return nil unless val.is_a?(Hash) || val.is_a?(Array)
151
+ val = val[key]
152
+ end if path
153
+ return val
154
+ end
155
+
156
+ end
157
+
158
+ end
@@ -0,0 +1,46 @@
1
+ ###
2
+ ### $Rev$
3
+ ### $Release: 0.7.2 $
4
+ ### copyright(c) 2005-2010 kuwata-lab all rights reserved.
5
+ ###
6
+
7
+ require 'test/unit/testcase'
8
+ require 'tempfile'
9
+
10
+
11
+ class Test::Unit::TestCase # :nodoc:
12
+
13
+ def assert_text_equal(expected, actual, message=nil, options={}) # :nodoc:
14
+ expected = expected.to_s
15
+ actual = actual.to_s
16
+ diffopt = options[:diffopt] || '-u'
17
+ flag_cut = options.key?(:cut) ? options[:key] : true
18
+
19
+ if expected == actual
20
+ assert(true)
21
+ return
22
+ end
23
+ if expected[-1] != ?\n || actual[-1] != ?\n
24
+ expected += "\n"
25
+ actual += "\n"
26
+ end
27
+ begin
28
+ expfile = Tempfile.new(".expected.")
29
+ expfile.write(expected); expfile.flush()
30
+ actfile = Tempfile.new(".actual.")
31
+ actfile.write(actual); actfile.flush()
32
+ diff = `diff #{diffopt} #{expfile.path} #{actfile.path}`
33
+ ensure
34
+ expfile.close(true) if expfile
35
+ actfile.close(true) if actfile
36
+ end
37
+ # cut 1st & 2nd lines
38
+ message = (flag_cut ? diff.gsub(/\A.*\n.*\n/, '') : diff) unless message
39
+ #raise Test::Unit::AssertionFailedError.new(message)
40
+ assert_block(message) { false } # or assert(false, message)
41
+ end
42
+
43
+ alias assert_equal_with_diff assert_text_equal # for compatibility
44
+ alias assert_text_equals assert_text_equal # for typo
45
+
46
+ end
@@ -0,0 +1,18 @@
1
+ ###
2
+ ### $Rev$$
3
+ ### $Release: 0.7.2 $
4
+ ### copyright(c) 2005-2010 kuwata-lab all rights reserved.
5
+ ###
6
+
7
+ require 'kwalify/util/hashlike'
8
+
9
+ module Kwalify
10
+
11
+ ##
12
+ ## OBSOLETE: use Hash::Util::HashLike instead.
13
+ ##
14
+ module HashInterface
15
+ include Kwalify::Util::HashLike
16
+ end
17
+
18
+ end
@@ -0,0 +1,51 @@
1
+ ###
2
+ ### $Rev$
3
+ ### $Release: 0.7.2 $
4
+ ### copyright(c) 2005-2010 kuwata-lab all rights reserved.
5
+ ###
6
+
7
+ module Kwalify
8
+
9
+ module Util
10
+
11
+ ##
12
+ ## add hash-like methods
13
+ ##
14
+ module HashLike
15
+
16
+ def [](key)
17
+ instance_variable_get("@#{key}")
18
+ end
19
+
20
+ def []=(key, val)
21
+ instance_variable_set("@#{key}", val)
22
+ end
23
+
24
+ #--
25
+ #def keys()
26
+ # instance_variables().collect { |name| name[1, name.length-1] }
27
+ #end
28
+ #++
29
+
30
+ def key?(key)
31
+ instance_variables().include?("@#{key}")
32
+ end
33
+ if Object.instance_methods.include?('instance_variable_defined?')
34
+ def key?(key)
35
+ instance_variable_defined?("@#{key}")
36
+ end
37
+ end
38
+
39
+ def each # not necessary
40
+ instance_variables().each do |name|
41
+ key = name[1, name.length-1]
42
+ val = instance_variable_get(name)
43
+ yield(key, val)
44
+ end
45
+ end
46
+
47
+ end
48
+
49
+ end
50
+
51
+ end
@@ -0,0 +1,220 @@
1
+ ###
2
+ ### $Rev$
3
+ ### $Release: 0.7.2 $
4
+ ### copyright(c) 2005-2010 kuwata-lab all rights reserved.
5
+ ###
6
+
7
+ class CommandOptionError < StandardError
8
+ def initialize(option, error_symbol, message=nil)
9
+ if !message
10
+ case error_symbol
11
+ when :no_argument
12
+ message = "-%s: argument required." % option
13
+ when :unknown_option
14
+ message = "-%s: unknown option." % option
15
+ when :invalid_property
16
+ message = "-%s: invalid property." % option
17
+ else
18
+ message = "*** internal error(optchar=#{option}, error_symbol=#{error_symbol}) ***"
19
+ end
20
+ end
21
+ super(message)
22
+ @option = option
23
+ @error_symbol = error_symbol
24
+ end
25
+
26
+ attr_reader :option, :error_symbol
27
+ end
28
+
29
+
30
+ ##
31
+ ## ex.
32
+ ## ## create parser
33
+ ## arg_none = "hv" # ex. -h -v
34
+ ## arg_required = "xf" # ex. -x suffix -f filename
35
+ ## arg_optional = "i" # ex. -i (or -i10)
36
+ ## parser = CommandOptionParser.new(arg_none, arg_required, arg_optional)
37
+ ##
38
+ ## ## parse options
39
+ ## argv = %w[-h -v -f filename -i 10 aaa bbb]
40
+ ## options, properties = parser.parse(argv)
41
+ ## p options #=> { ?h=>true, ?v=>true, ?f=>"filename", ?i=>true }
42
+ ## p argv #=> ["10", "aaa", "bbb"]
43
+ ##
44
+ ## ## parse options #2
45
+ ## argv = %w[-hvx.txt -ffilename -i10 aaa bbb]
46
+ ## options, properties = parser.parse(argv)
47
+ ## p options #=> { ?h=>true, ?v=>true, ?x=>".txt", ?f=>"filename", ?i=>10 }
48
+ ## p argv #=> ["aaa", "bbb"]
49
+ ##
50
+ ## ## parse properties
51
+ ## argv = %w[-hi --index=10 --user-name=foo --help]
52
+ ## options, properties = parser.parse(argv)
53
+ ## p options #=> {?h=>true, ?i=>true}
54
+ ## p properties #=> {"index"=>"10", "user-name"=>"foo", "help"=>nil}
55
+ ##
56
+ ## ## parse properties with auto-convert
57
+ ## argv = %w[-hi --index=10 --user-name=foo --help]
58
+ ## options, properties = parser.parse(argv, true)
59
+ ## p options #=> {?h=>true, ?i=>true}
60
+ ## p properties #=> {:index=>10, :user_name=>foo, :help=>true}
61
+ ##
62
+ ## ## -a: unknown option.
63
+ ## argv = %w[-abc]
64
+ ## begin
65
+ ## options, properties = parser.parse(argv)
66
+ ## rescue CommandOptionError => ex
67
+ ## $stderr.puts ex.message # -a: unknown option.
68
+ ## end
69
+ ##
70
+ ## ## -f: argument required.
71
+ ## argv = %w[-f]
72
+ ## begin
73
+ ## options, properties = parser.parse(argv)
74
+ ## rescue CommandOptionError => ex
75
+ ## $stderr.puts ex.message # -f: argument required.
76
+ ## end
77
+ ##
78
+ ## ## --@prop=10: invalid property.
79
+ ## argv = %w[--@prop=10]
80
+ ## begin
81
+ ## options, properties = parser.parse(argv)
82
+ ## rescue CommandOptionError => ex
83
+ ## $stderr.puts ex.message # --@prop=10: invalid property.
84
+ ## end
85
+ ##
86
+
87
+ class CommandOptionParser
88
+
89
+ ## arg_none: option string which takes no argument
90
+ ## arg_required: option string which takes argument
91
+ ## arg_otpional: option string which may takes argument optionally
92
+ def initialize(arg_none=nil, arg_required=nil, arg_optional=nil)
93
+ @arg_none = arg_none || ""
94
+ @arg_required = arg_required || ""
95
+ @arg_optional = arg_optional || ""
96
+ end
97
+
98
+
99
+ def self.to_value(str)
100
+ case str
101
+ when nil, "null", "nil" ; return nil
102
+ when "true", "yes" ; return true
103
+ when "false", "no" ; return false
104
+ when /\A\d+\z/ ; return str.to_i
105
+ when /\A\d+\.\d+\z/ ; return str.to_f
106
+ when /\/(.*)\// ; return Regexp.new($1)
107
+ when /\A'.*'\z/, /\A".*"\z/ ; return eval(str)
108
+ else ; return str
109
+ end
110
+ end
111
+
112
+
113
+ ## argv:: array of string
114
+ ## auto_convert:: if true, convert properties value to int, boolean, string, regexp, ... (default false)
115
+ def parse(argv, auto_convert=false)
116
+ options = {}
117
+ properties = {}
118
+ while argv[0] && argv[0][0] == ?-
119
+ optstr = argv.shift
120
+ optstr = optstr[1, optstr.length-1]
121
+ #
122
+ if optstr[0] == ?- ## property
123
+ unless optstr =~ /\A\-([-\w]+)(?:=(.*))?/
124
+ raise CommandOptionError.new(optstr, :invalid_property)
125
+ end
126
+ prop_name = $1; prop_value = $2
127
+ if auto_convert
128
+ key = prop_name.gsub(/-/, '_').intern
129
+ value = prop_value.nil? ? true : CommandOptionParser.to_value(prop_value)
130
+ properties[key] = value
131
+ else
132
+ properties[prop_name] = prop_value
133
+ end
134
+ #
135
+ else ## options
136
+ while optstr && !optstr.empty?
137
+ optchar = optstr[0]
138
+ optstr[0,1] = ""
139
+ #puts "*** debug: optchar=#{optchar.chr}, optstr=#{optstr.inspect}"
140
+ if @arg_none.include?(optchar)
141
+ options[optchar] = true
142
+ elsif @arg_required.include?(optchar)
143
+ arg = optstr.empty? ? argv.shift : optstr
144
+ raise CommandOptionError.new(optchar.chr, :no_argument) unless arg
145
+ options[optchar] = arg
146
+ optstr = nil
147
+ elsif @arg_optional.include?(optchar)
148
+ arg = optstr.empty? ? true : optstr
149
+ options[optchar] = arg
150
+ optstr = nil
151
+ else
152
+ raise CommandOptionError.new(optchar.chr, :unknown_option)
153
+ end
154
+ end
155
+ end
156
+ #
157
+ end # end of while
158
+
159
+ return options, properties
160
+ end
161
+
162
+ end
163
+
164
+
165
+ if __FILE__ == $0
166
+ ## create parser
167
+ arg_none = "hv" # ex. -h -v
168
+ arg_required = "xf" # ex. -x suffix -f filename
169
+ arg_optional = "i" # ex. -i (or -i10)
170
+ parser = CommandOptionParser.new(arg_none, arg_required, arg_optional)
171
+
172
+ ## parse options
173
+ argv = %w[-h -v -f filename -i 10 aaa bbb]
174
+ options, properties = parser.parse(argv)
175
+ p options #=> { ?h=>true, ?v=>true, ?f=>"filename", ?i=>true }
176
+ p argv #=> ["10", "aaa", "bbb"]
177
+
178
+ ## parse options #2
179
+ argv = %w[-hvx.txt -ffilename -i10 aaa bbb]
180
+ options, properties = parser.parse(argv)
181
+ p options #=> { ?h=>true, ?v=>true, ?x=>".txt", ?f=>"filename", ?i=>"10" }
182
+ p argv #=> ["aaa", "bbb"]
183
+
184
+ ## parse properties
185
+ argv = %w[-hi --index=10 --user-name=foo --help]
186
+ options, properties = parser.parse(argv)
187
+ p options #=> {?h=>true, ?i=>true}
188
+ p properties #=> {"index"=>"10", "user-name"=>"foo", "help"=>nil}
189
+
190
+ ## parse properties with auto-convert
191
+ argv = %w[-hi --index=10 --user-name=foo --help]
192
+ options, properties = parser.parse(argv, true)
193
+ p options #=> {?h=>true, ?i=>true}
194
+ p properties #=> {:index=>10, :user_name=>foo, :help=>true}
195
+
196
+ ## -a: unknown option.
197
+ argv = %w[-abc]
198
+ begin
199
+ options, properties = parser.parse(argv)
200
+ rescue CommandOptionError => ex
201
+ $stderr.puts ex.message # -a: unknown option.
202
+ end
203
+
204
+ ## -f: argument required.
205
+ argv = %w[-f]
206
+ begin
207
+ options, properties = parser.parse(argv)
208
+ rescue CommandOptionError => ex
209
+ $stderr.puts ex.message # -f: argument required.
210
+ end
211
+
212
+ ## --@prop=10: invalid property.
213
+ argv = %w[--@prop=10]
214
+ begin
215
+ options, properties = parser.parse(argv)
216
+ rescue CommandOptionError => ex
217
+ $stderr.puts ex.message # --@prop=10: invalid property.
218
+ end
219
+
220
+ end