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,58 @@
1
+ ## $Rev$
2
+ ## $Date$
3
+ ## copyright(c) 2005-2010 kuwata-lab all rights reserved.
4
+
5
+ name: MAIN
6
+ type: map
7
+ required: yes
8
+ mapping: &main-rule
9
+ "name": { type: str }
10
+ "desc": { type: str }
11
+ "class": { type: str }
12
+ "type":
13
+ type: str
14
+ #required: yes
15
+ enum: [ seq, map, str, int, float, number, bool, text,
16
+ date, time, timestamp, any, scalar ]
17
+ "required": { type: bool } # equivarent to 'not-null'
18
+ "enum":
19
+ type: seq
20
+ sequence:
21
+ - type: scalar
22
+ unique: yes
23
+ "pattern": { type: str }
24
+ "assert": { type: str, pattern: /\bval\b/ }
25
+ "range":
26
+ type: map
27
+ mapping:
28
+ "max": { type: scalar }
29
+ "min": { type: scalar }
30
+ "max-ex": { type: scalar }
31
+ "min-ex": { type: scalar }
32
+ "length":
33
+ type: map
34
+ mapping:
35
+ "max": { type: int }
36
+ "min": { type: int }
37
+ "max-ex": { type: int }
38
+ "min-ex": { type: int }
39
+ "ident": { type: bool } # equivarent to 'primary-key' (undocumented)
40
+ "unique": { type: bool }
41
+ "default": { type: scalar } # used only in action's template
42
+ "sequence":
43
+ name: SEQUENCE
44
+ type: seq
45
+ sequence:
46
+ - type: map
47
+ mapping: *main-rule
48
+ name: MAIN
49
+ #required: yes
50
+ "mapping":
51
+ name: MAPPING
52
+ type: map
53
+ mapping:
54
+ =:
55
+ type: map
56
+ mapping: *main-rule
57
+ name: MAIN
58
+ #required: yes
@@ -0,0 +1,442 @@
1
+ ###
2
+ ### $Rev$
3
+ ### $Release: 0.7.2 $
4
+ ### copyright(c) 2005-2010 kuwata-lab all rights reserved.
5
+ ###
6
+
7
+ require 'yaml'
8
+ require 'erb'
9
+ require 'kwalify'
10
+ require 'kwalify/util'
11
+ require 'kwalify/util/ordered-hash'
12
+
13
+
14
+ module Kwalify
15
+
16
+
17
+ class CommandOptionError < KwalifyError
18
+ def initialize(message, option, error_symbol)
19
+ super(message)
20
+ @option = option
21
+ @error_symbol = error_symbol
22
+ end
23
+ attr_reader :option, :error_symbol
24
+ end
25
+
26
+
27
+ ##
28
+ ## ex.
29
+ ## command = File.basename($0)
30
+ ## begin
31
+ ## main = Kwalify::Main.new(command)
32
+ ## s = main.execute
33
+ ## print s if s
34
+ ## rescue Kwalify::CommandOptionError => ex
35
+ ## $stderr.puts "ERROR: #{ex.message}"
36
+ ## exit 1
37
+ ## rescue Kwalify::KwalifyError => ex
38
+ ## $stderr.puts "ERROR: #{ex.message}"
39
+ ## exit 1
40
+ ## end
41
+ ##
42
+ class Main
43
+
44
+
45
+ def initialize(command=nil)
46
+ @command = command || File.basename($0)
47
+ @options = {}
48
+ @properties = {}
49
+ @template_path = []
50
+ $:.each do |path|
51
+ tpath = "#{path}/kwalify/templates"
52
+ @template_path << tpath if test(?d, tpath)
53
+ end
54
+ end
55
+
56
+
57
+ def debug?
58
+ @options[:debug]
59
+ end
60
+
61
+
62
+ def _inspect()
63
+ sb = []
64
+ sb << "command: #{@command}\n"
65
+ sb << "options:\n"
66
+ @options.keys.sort {|k1,k2| k1.to_s<=>k2.to_s }.each do |key|
67
+ sb << " - #{key}: #{@options[key]}\n"
68
+ end
69
+ sb << "properties:\n"
70
+ @properties.keys.sort_by {|k| k.to_s}.each do |key|
71
+ sb << " - #{key}: #{@properties[key]}\n"
72
+ end
73
+ #sb << "template_path:\n"
74
+ #@template_path.each do |path|
75
+ # sb << " - #{path}\n"
76
+ #end
77
+ return sb.join
78
+ end
79
+
80
+
81
+ def execute(argv=ARGV)
82
+ ## parse command-line options
83
+ filenames = _parse_argv(argv)
84
+
85
+ ## help or version
86
+ if @options[:help] || @options[:version]
87
+ action = @options[:action]
88
+ s = ''
89
+ s << _version() << "\n" if @options[:version]
90
+ s << _usage() if @options[:help] && !action
91
+ s << _describe_properties(action) if @options[:help] && action
92
+ puts s
93
+ return
94
+ end
95
+
96
+ # validation
97
+ if @options[:meta2]
98
+ validate_schemafiles2(filenames)
99
+ elsif @options[:meta]
100
+ validate_schemafiles(filenames)
101
+ elsif @options[:action]
102
+ unless @options[:schema]
103
+ #* key=:command_option_actionnoschema msg="schema filename is not specified."
104
+ raise option_error(:command_option_actionnoschema, @options[:action])
105
+ end
106
+ perform_action(@options[:action], @options[:schema])
107
+ elsif @options[:schema]
108
+ if @options[:debug]
109
+ inspect_schema(@options[:schema])
110
+ else
111
+ validate_files(filenames, @options[:schema])
112
+ end
113
+ else
114
+ #* key=:command_option_noaction msg="command-line option '-f' or '-m' required."
115
+ raise option_error(:command_option_noaction, @command)
116
+ end
117
+ return
118
+ end
119
+
120
+
121
+ def self.main(command, argv=ARGV)
122
+ begin
123
+ main = Kwalify::Main.new(command)
124
+ s = main.execute(argv)
125
+ print s if s
126
+ rescue Kwalify::CommandOptionError => ex
127
+ raise ex if main.debug?
128
+ $stderr.puts ex.message
129
+ exit 1
130
+ rescue Kwalify::KwalifyError => ex
131
+ raise ex if main.debug?
132
+ $stderr.puts "ERROR: #{ex.to_s}"
133
+ exit 1
134
+ #rescue => ex
135
+ # if main.debug?
136
+ # raise ex
137
+ # else
138
+ # $stderr.puts ex.message
139
+ # exit 1
140
+ # end
141
+ end
142
+ end
143
+
144
+
145
+ private
146
+
147
+
148
+ def option_error(error_symbol, arg)
149
+ msg = Kwalify.msg(error_symbol) % arg
150
+ return CommandOptionError.new(msg, arg, error_symbol)
151
+ end
152
+
153
+
154
+ def _find_template(action)
155
+ template_filename = action + '.eruby'
156
+ unless test(?f, template_filename)
157
+ pathlist = []
158
+ pathlist.concat(@options[:tpath].split(/,/)) if @options[:tpath]
159
+ pathlist.concat(@template_path)
160
+ tpath = pathlist.find {|path| test(?f, "#{path}/#{template_filename}") }
161
+ #* key=:command_option_notemplate msg="%s: invalid action (template not found).\n"
162
+ raise option_error(:command_option_notemplate, action) unless tpath
163
+ template_filename = "#{tpath}/#{action}.eruby"
164
+ end
165
+ return template_filename
166
+ end
167
+
168
+
169
+ def apply_template(template_filename, hash)
170
+ template = File.read(template_filename)
171
+ trim_mode = 1
172
+ erb = ERB.new(template, nil, trim_mode)
173
+ context = Object.new
174
+ hash.each do |key, val|
175
+ context.instance_variable_set("@#{key}", val)
176
+ end
177
+ s = context.instance_eval(erb.src, template_filename)
178
+ return s
179
+ end
180
+
181
+
182
+ def _describe_properties(action)
183
+ template_filename = _find_template(action)
184
+ s = apply_template(template_filename, :describe=>true)
185
+ return s
186
+ end
187
+
188
+
189
+ def perform_action(action, schema_filename, describe=false)
190
+ template_filename = _find_template(action)
191
+ schema = _load_schemafile(schema_filename, ordered=true)
192
+ validator = Kwalify::Validator.new(schema)
193
+ @properties[:schema_filename] = schema_filename
194
+ hash = { :validator=>validator, :schema=>schema, :properties=>@properties }
195
+ s = apply_template(template_filename, hash)
196
+ puts s if s && !s.empty?
197
+ end
198
+
199
+
200
+ def inspect_schema(schema_filename)
201
+ schema = _load_schemafile(schema_filename)
202
+ if schema.nil?
203
+ puts "nil"
204
+ else
205
+ validator = Kwalify::Validator.new(schema) # error raised when schema is wrong
206
+ puts validator._inspect()
207
+ end
208
+ end
209
+
210
+
211
+ ## -f schemafile datafile
212
+ def validate_files(filenames, schema_filename)
213
+ schema = _load_schemafile(schema_filename)
214
+ validator = Kwalify::Validator.new(schema)
215
+ _validate_files(validator, filenames)
216
+ end
217
+
218
+
219
+ def _load_schemafile(schema_filename, ordered=false)
220
+ str = File.read(schema_filename)
221
+ if str.empty?
222
+ #* key=:schema_empty msg="%s: empty schema.\n"
223
+ msg = Kwalify.msg(:schema_emtpy) % filename
224
+ raise CommandOptionError.new(msg)
225
+ end
226
+ str = Util.untabify(str) if @options[:untabify]
227
+ parser = Kwalify::Yaml::Parser.new()
228
+ parser.preceding_alias = true if @options[:preceding]
229
+ parser.mapping_class = Kwalify::Util::OrderedHash if ordered
230
+ schema = parser.parse(str, :filename=>schema_filename) # or YAML.load(str)
231
+ return schema
232
+ end
233
+
234
+
235
+ ## -m schemafile
236
+ def validate_schemafiles(schema_filenames)
237
+ meta_validator = Kwalify::MetaValidator.instance()
238
+ _validate_files(meta_validator, schema_filenames)
239
+ end
240
+
241
+
242
+ ## -M schemafile
243
+ def validate_schemafiles2(schema_filenames)
244
+ parser = Kwalify::Yaml::Parser.new()
245
+ parser.preceding_alias = true if @options[:preceding]
246
+ for schema_filename in schema_filenames
247
+ str = File.read(schema_filename)
248
+ str = Util.untabify(str) if @options[:untabify]
249
+ schema = parser.parse(str, :filename=>schema_filename)
250
+ Kwalify::Validator.new(schema) # exception raised when schema has errors
251
+ end
252
+ end
253
+
254
+
255
+ def _validate_files(validator, filenames)
256
+ ## parser
257
+ if @options[:linenum] || @options[:preceding]
258
+ parser = Kwalify::Yaml::Parser.new(validator)
259
+ parser.preceding_alias = true if @options[:preceding]
260
+ else
261
+ parser = nil
262
+ end
263
+ ## filenames
264
+ if filenames.empty?
265
+ filenames = [ $stdin ]
266
+ end
267
+ for filename in filenames
268
+ ## read input
269
+ if filename.is_a?(IO)
270
+ input = filename.read()
271
+ filename = '(stdin)'
272
+ else
273
+ input = File.read(filename)
274
+ end
275
+ if input.empty?
276
+ #* key=:validation_empty msg="%s#%d: empty."
277
+ puts kwalify.msg(:validation_empty) % [filename, i]
278
+ #puts "#{filename}##{i}: empty."
279
+ next
280
+ end
281
+ input = Util.untabify(input) if @options[:untabify]
282
+ ## parse input
283
+ if parser
284
+ #i = 0
285
+ #ydoc = parser.parse(input, :filename=>filename)
286
+ #_show_errors(filename, i, ydoc, parser.errors)
287
+ #while parser.has_next?
288
+ # i += 1
289
+ # ydoc = parser.parse_next()
290
+ # _show_errors(filename, i, ydoc, parser.errors)
291
+ #end
292
+ i = 0
293
+ parser.parse_stream(input, :filename=>filename) do |ydoc|
294
+ _show_errors(filename, i, ydoc, parser.errors)
295
+ i += 1
296
+ end
297
+ else
298
+ i = 0
299
+ YAML.load_documents(input) do |ydoc|
300
+ errors = validator.validate(ydoc)
301
+ _show_errors(filename, i, ydoc, errors)
302
+ i += 1
303
+ end
304
+ end
305
+ end
306
+ end
307
+
308
+
309
+ def _show_errors(filename, i, ydoc, errors, ok_label="valid.", ng_label="INVALID")
310
+ if errors && !errors.empty?
311
+ puts "#{filename}##{i}: #{ng_label}"
312
+ errors.sort!
313
+ for error in errors
314
+ e = error
315
+ if @options[:emacs]
316
+ raise unless @options[:linenum]
317
+ puts "#{filename}:#{e.linenum}:#{e.column} [#{e.path}] #{e.message}\n"
318
+ elsif @options[:linenum]
319
+ puts " - (line #{e.linenum}) [#{e.path}] #{e.message}\n"
320
+ else
321
+ puts " - [#{e.path}] #{e.message}\n"
322
+ end
323
+ end
324
+ elsif ydoc.nil?
325
+ #* key=:validation_empty msg="%s#%d: empty.\n"
326
+ puts Kwalify.msg(:validation_empty) % [filename, i]
327
+ else
328
+ #* key=:validation_valid msg="%s#%d: valid."
329
+ puts Kwalify.msg(:validation_valid) % [filename, i] unless @options[:quiet]
330
+ #puts "#{filename}##{i} - #{ok_label}" unless @options[:quiet]
331
+ end
332
+ end
333
+
334
+
335
+ def _usage()
336
+ #msg = Kwalify.msg(:command_help) % [@command, @command, @command]
337
+ msg = Kwalify.msg(:command_help)
338
+ return msg
339
+ end
340
+
341
+
342
+ def _version()
343
+ return RELEASE
344
+ end
345
+
346
+
347
+ def _to_value(str)
348
+ case str
349
+ when nil, "null", "nil" ; return nil
350
+ when "true", "yes" ; return true
351
+ when "false", "no" ; return false
352
+ when /\A\d+\z/ ; return str.to_i
353
+ when /\A\d+\.\d+\z/ ; return str.to_f
354
+ when /\/(.*)\// ; return Regexp.new($1)
355
+ when /\A'.*'\z/, /\A".*"\z/ ; return eval(str)
356
+ else ; return str
357
+ end
358
+ end
359
+
360
+
361
+ def _parse_argv(argv)
362
+ option_table = {
363
+ ?h => :help,
364
+ ?v => :version,
365
+ ?q => :quiet,
366
+ ?s => :quiet,
367
+ ?t => :untabify,
368
+ #?z => :meta,
369
+ ?m => :meta,
370
+ ?M => :meta2,
371
+ ?E => :emacs,
372
+ ?l => :linenum,
373
+ ?f => :schema,
374
+ ?D => :debug,
375
+ ?a => :action,
376
+ ?I => :tpath,
377
+ ?P => :preceding,
378
+ }
379
+
380
+ errcode_table = {
381
+ #* key=:command_option_schema_required msg="-%s: schema filename required."
382
+ ?f => :command_option_schema_required,
383
+ #* key=:command_option_action_required msg="-%s: action required."
384
+ ?a => :command_option_action_required,
385
+ #* key=:command_option_tpath_required msg="-%s: template path required."
386
+ ?I => :command_option_tpath_required,
387
+ }
388
+
389
+ while argv[0] && argv[0][0] == ?-
390
+ optstr = argv.shift
391
+ optstr = optstr[1, optstr.length-1]
392
+ ## property
393
+ if optstr[0] == ?-
394
+ unless optstr =~ /\A\-([-\w]+)(?:=(.*))?\z/
395
+ #* key=:command_property_invalid msg="%s: invalid property."
396
+ raise option_error(:command_property_invalid, optstr)
397
+ end
398
+ prop_name = $1; prop_value = $2
399
+ key = prop_name.gsub(/-/, '_').intern
400
+ value = prop_value.nil? ? true : _to_value(prop_value)
401
+ @properties[key] = value
402
+ ## option
403
+ else
404
+ while optstr && !optstr.empty?
405
+ optchar = optstr[0]
406
+ optstr[0,1] = ""
407
+ unless option_table.key?(optchar)
408
+ #* key=:command_option_invalid msg="-%s: invalid command option."
409
+ raise option_error(:command_option_invalid, optchar.chr)
410
+ end
411
+ optkey = option_table[optchar]
412
+ case optchar
413
+ when ?f, ?a, ?I
414
+ arg = optstr.empty? ? argv.shift : optstr
415
+ raise option_error(errcode_table[optchar], optchar.chr) unless arg
416
+ @options[optkey] = arg
417
+ optstr = ''
418
+ else
419
+ @options[optkey] = true
420
+ end
421
+ end
422
+ end
423
+ end # end of while
424
+ #
425
+ @options[:linenum] = true if @options[:emacs]
426
+ @options[:help] = true if @properties[:help]
427
+ @options[:version] = true if @properties[:version]
428
+ filenames = argv
429
+ return filenames
430
+ end
431
+
432
+
433
+ def _domain_type?(doc)
434
+ klass = defined?(YAML::DomainType) ? YAML::DomainType : YAML::Syck::DomainType
435
+ return doc.is_a?(klass)
436
+ end
437
+
438
+
439
+ end
440
+
441
+
442
+ end