pione 0.3.2 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (304) hide show
  1. data/.gitignore +2 -0
  2. data/.s3cfg +42 -0
  3. data/.travis.yml +18 -4
  4. data/.yardopts +1 -0
  5. data/Gemfile +3 -0
  6. data/History.txt +14 -0
  7. data/Procfile +7 -0
  8. data/Rakefile +25 -0
  9. data/bin/pione-interactive +6 -0
  10. data/bin/{pione-compiler → pione-notification-listener} +1 -1
  11. data/bin/{pione-broker → pione-task-worker-broker} +1 -1
  12. data/doc/man/pione-list-param.md +36 -0
  13. data/example/ActionError/ActionError.pione +9 -0
  14. data/example/ActionError/pione-package.json +15 -0
  15. data/example/CountChar/CountChar.pione +1 -1
  16. data/example/ScoreAggregation/ScoreAggregation.pione +1 -1
  17. data/example/Touch/pione-package.json +15 -0
  18. data/lib/pione.rb +12 -0
  19. data/lib/pione/agent.rb +3 -3
  20. data/lib/pione/agent/basic-agent.rb +10 -4
  21. data/lib/pione/agent/input-generator.rb +3 -3
  22. data/lib/pione/agent/{process-manager.rb → job-manager.rb} +10 -7
  23. data/lib/pione/agent/job-terminator.rb +2 -2
  24. data/lib/pione/agent/logger.rb +3 -3
  25. data/lib/pione/agent/messenger.rb +20 -9
  26. data/lib/pione/agent/notification-listener.rb +88 -0
  27. data/lib/pione/agent/task-worker-broker.rb +84 -0
  28. data/lib/pione/agent/task-worker.rb +3 -2
  29. data/lib/pione/agent/tuple-space-client.rb +1 -0
  30. data/lib/pione/agent/tuple-space-provider.rb +17 -35
  31. data/lib/pione/command.rb +33 -15
  32. data/lib/pione/command/action.rb +105 -0
  33. data/lib/pione/command/basic-command.rb +34 -376
  34. data/lib/pione/command/command-exception.rb +12 -11
  35. data/lib/pione/command/common.rb +198 -0
  36. data/lib/pione/command/option.rb +159 -204
  37. data/lib/pione/command/pione-action-exec.rb +85 -0
  38. data/lib/pione/command/pione-action-list.rb +43 -19
  39. data/lib/pione/command/pione-action-print.rb +79 -0
  40. data/lib/pione/command/pione-action.rb +8 -67
  41. data/lib/pione/command/pione-clean.rb +88 -68
  42. data/lib/pione/command/pione-client.rb +475 -332
  43. data/lib/pione/command/pione-command.rb +14 -31
  44. data/lib/pione/command/pione-compile.rb +90 -0
  45. data/lib/pione/command/pione-config-get.rb +53 -0
  46. data/lib/pione/command/pione-config-list.rb +64 -0
  47. data/lib/pione/command/pione-config-set.rb +59 -0
  48. data/lib/pione/command/pione-config-unset.rb +50 -0
  49. data/lib/pione/command/pione-config.rb +61 -0
  50. data/lib/pione/command/pione-diagnosis-notification.rb +235 -0
  51. data/lib/pione/command/pione-diagnosis.rb +21 -0
  52. data/lib/pione/command/pione-interactive.rb +188 -0
  53. data/lib/pione/command/pione-lang-check-syntax.rb +163 -0
  54. data/lib/pione/command/pione-lang-interactive.rb +146 -0
  55. data/lib/pione/command/pione-lang.rb +22 -0
  56. data/lib/pione/command/pione-log-format.rb +163 -0
  57. data/lib/pione/command/pione-log-list-id.rb +48 -0
  58. data/lib/pione/command/pione-log.rb +19 -101
  59. data/lib/pione/command/pione-notification-listener.rb +95 -0
  60. data/lib/pione/command/pione-package-add.rb +137 -0
  61. data/lib/pione/command/pione-package-build.rb +122 -0
  62. data/lib/pione/command/pione-package-show.rb +96 -0
  63. data/lib/pione/command/pione-package-update.rb +59 -0
  64. data/lib/pione/command/pione-package.rb +11 -139
  65. data/lib/pione/command/pione-task-worker-broker.rb +88 -0
  66. data/lib/pione/command/pione-task-worker.rb +148 -98
  67. data/lib/pione/command/pione-tuple-space-provider.rb +62 -54
  68. data/lib/pione/command/pione-tuple-space-viewer.rb +105 -83
  69. data/lib/pione/command/pione-val.rb +39 -39
  70. data/lib/pione/command/spawner.rb +34 -27
  71. data/lib/pione/front.rb +4 -2
  72. data/lib/pione/front/basic-front.rb +86 -23
  73. data/lib/pione/front/client-front.rb +2 -2
  74. data/lib/pione/front/diagnosis-notification-front.rb +40 -0
  75. data/lib/pione/front/front-exception.rb +7 -1
  76. data/lib/pione/front/notification-listener-front.rb +36 -0
  77. data/lib/pione/front/notification-recipient-interface.rb +19 -0
  78. data/lib/pione/front/relay-front.rb +4 -4
  79. data/lib/pione/front/task-worker-broker-front.rb +19 -0
  80. data/lib/pione/front/task-worker-front.rb +2 -2
  81. data/lib/pione/front/tuple-space-provider-front.rb +3 -2
  82. data/lib/pione/global.rb +3 -1
  83. data/lib/pione/global/client-variable.rb +1 -1
  84. data/lib/pione/global/config.rb +63 -7
  85. data/lib/pione/global/diagnosis-variable.rb +26 -0
  86. data/lib/pione/global/item.rb +28 -5
  87. data/lib/pione/global/log-variable.rb +6 -5
  88. data/lib/pione/global/network-variable.rb +75 -4
  89. data/lib/pione/global/path-variable.rb +1 -1
  90. data/lib/pione/global/system-variable.rb +12 -12
  91. data/lib/pione/global/task-worker-broker-variable.rb +43 -0
  92. data/lib/pione/global/tuple-space-notifier-variable.rb +3 -55
  93. data/lib/pione/lang/boolean.rb +4 -0
  94. data/lib/pione/lang/data-expr.rb +1 -1
  95. data/lib/pione/lang/integer.rb +1 -1
  96. data/lib/pione/lang/string.rb +4 -0
  97. data/lib/pione/lang/type.rb +1 -1
  98. data/lib/pione/location.rb +1 -0
  99. data/lib/pione/location/data-location.rb +41 -13
  100. data/lib/pione/location/dropbox-location.rb +175 -56
  101. data/lib/pione/location/ftp-location.rb +4 -1
  102. data/lib/pione/location/http-location.rb +5 -3
  103. data/lib/pione/location/https-location.rb +4 -2
  104. data/lib/pione/location/local-location.rb +6 -3
  105. data/lib/pione/location/location-exception.rb +12 -0
  106. data/lib/pione/location/notification-scheme.rb +46 -0
  107. data/lib/pione/log.rb +8 -7
  108. data/lib/pione/log/debug.rb +9 -9
  109. data/lib/pione/log/domain-log.rb +6 -1
  110. data/lib/pione/log/message-log-receiver.rb +32 -0
  111. data/lib/pione/log/system-log.rb +62 -141
  112. data/lib/pione/model.rb +7 -0
  113. data/lib/pione/model/notification-listener-model.rb +29 -0
  114. data/lib/pione/model/task-worker-broker-model.rb +129 -0
  115. data/lib/pione/notification.rb +13 -0
  116. data/lib/pione/notification/address.rb +104 -0
  117. data/lib/pione/notification/exception.rb +10 -0
  118. data/lib/pione/notification/message.rb +109 -0
  119. data/lib/pione/notification/receiver.rb +90 -0
  120. data/lib/pione/notification/recipient.rb +68 -0
  121. data/lib/pione/notification/task-worker-broker-recipient.rb +85 -0
  122. data/lib/pione/notification/transmitter.rb +84 -0
  123. data/lib/pione/pnml.rb +35 -0
  124. data/lib/pione/pnml/annotation-extractor.rb +47 -0
  125. data/lib/pione/pnml/compiler.rb +176 -0
  126. data/lib/pione/pnml/input-merge-complement.rb +78 -0
  127. data/lib/pione/pnml/input-parallelization-complement.rb +75 -0
  128. data/lib/pione/pnml/input-reduction.rb +80 -0
  129. data/lib/pione/pnml/invalid-arc-elimination.rb +41 -0
  130. data/lib/pione/pnml/io-expansion.rb +88 -0
  131. data/lib/pione/pnml/isolated-element-elimination.rb +32 -0
  132. data/lib/pione/pnml/net-rewriter.rb +44 -0
  133. data/lib/pione/pnml/output-decomposition-complement.rb +77 -0
  134. data/lib/pione/pnml/output-reduction.rb +86 -0
  135. data/lib/pione/pnml/output-synchronization-complement.rb +77 -0
  136. data/lib/pione/pnml/pione-model.rb +417 -0
  137. data/lib/pione/pnml/pnml-exception.rb +23 -0
  138. data/lib/pione/pnml/pnml-model.rb +368 -0
  139. data/lib/pione/pnml/reader.rb +51 -0
  140. data/lib/pione/rule-engine/action-handler.rb +8 -6
  141. data/lib/pione/rule-engine/basic-handler.rb +5 -5
  142. data/lib/pione/rule-engine/engine-exception.rb +7 -6
  143. data/lib/pione/rule-engine/flow-handler.rb +27 -18
  144. data/lib/pione/system.rb +3 -1
  145. data/lib/pione/system/domain-dump.rb +34 -0
  146. data/lib/pione/system/file-cache.rb +92 -13
  147. data/lib/pione/system/init.rb +3 -0
  148. data/lib/pione/system/normalizer.rb +40 -0
  149. data/lib/pione/system/status.rb +5 -5
  150. data/lib/pione/system/system-exception.rb +14 -1
  151. data/lib/pione/task-worker-broker.rb +7 -0
  152. data/lib/pione/task-worker-broker/basic-provider.rb +20 -0
  153. data/lib/pione/task-worker-broker/easy-provider.rb +65 -0
  154. data/lib/pione/test-helper.rb +27 -0
  155. data/lib/pione/test-helper/command-helper.rb +9 -101
  156. data/lib/pione/tuple-space/basic-tuple.rb +1 -1
  157. data/lib/pione/tuple-space/tuple-definition.yml +4 -6
  158. data/lib/pione/tuple-space/tuple-space-interface.rb +3 -45
  159. data/lib/pione/tuple-space/tuple-space-server.rb +45 -0
  160. data/lib/pione/util.rb +1 -2
  161. data/lib/pione/util/boolean-value.rb +62 -0
  162. data/lib/pione/util/completion.rb +111 -0
  163. data/lib/pione/util/evaluatable.rb +13 -27
  164. data/lib/pione/util/package-parameters-list.rb +15 -27
  165. data/lib/pione/util/zip.rb +8 -3
  166. data/lib/pione/version.rb +1 -1
  167. data/lib/rootage.rb +20 -0
  168. data/lib/rootage/action.rb +114 -0
  169. data/lib/rootage/argument.rb +46 -0
  170. data/lib/rootage/command.rb +218 -0
  171. data/lib/rootage/core.rb +532 -0
  172. data/lib/rootage/exception.rb +107 -0
  173. data/lib/rootage/help.rb +148 -0
  174. data/lib/rootage/help.txt.erb +31 -0
  175. data/lib/rootage/log.rb +226 -0
  176. data/lib/rootage/normalizer.rb +184 -0
  177. data/lib/rootage/option.rb +152 -0
  178. data/lib/rootage/scenario-test-result.erb +39 -0
  179. data/lib/rootage/scenario.rb +362 -0
  180. data/lib/rootage/test-helper.rb +115 -0
  181. data/man/pione-list-param.1 +44 -0
  182. data/misc/clock.rb +9 -0
  183. data/misc/machine-info.sh +21 -0
  184. data/misc/pione-completion.bash +238 -0
  185. data/misc/pione-completion.erb +53 -0
  186. data/misc/pione-completion.zsh +238 -0
  187. data/misc/pione.god +22 -0
  188. data/misc/ui.xml +23 -0
  189. data/pione.gemspec +3 -1
  190. data/test/agent/spec_basic-agent.rb +1 -1
  191. data/test/agent/spec_input-generator.rb +2 -2
  192. data/test/agent/spec_messenger.rb +6 -9
  193. data/test/agent/spec_notification-listener.rb +80 -0
  194. data/test/agent/{spec_broker.rb → spec_task-worker-broker.rb} +13 -10
  195. data/test/agent/spec_tuple-space-provider.rb +10 -6
  196. data/test/command/command-behavior.rb +3 -11
  197. data/test/command/data/pione-list-param/AdvancedParameters.pione +12 -0
  198. data/test/command/data/pione-list-param/BasicParameters.pione +12 -0
  199. data/test/command/spec_pione-action-exec.rb +16 -0
  200. data/test/command/spec_pione-action-list.rb +15 -10
  201. data/test/command/spec_pione-action-print.rb +14 -0
  202. data/test/command/spec_pione-action.rb +6 -19
  203. data/test/command/spec_pione-clean.rb +29 -46
  204. data/test/command/spec_pione-client.rb +29 -36
  205. data/test/command/spec_pione-command.rb +6 -6
  206. data/test/command/{spec_pione-compiler.rb → spec_pione-compile.rb} +11 -13
  207. data/test/command/spec_pione-config-get.rb +47 -0
  208. data/test/command/spec_pione-config-list.rb +42 -0
  209. data/test/command/spec_pione-config-set.rb +38 -0
  210. data/test/command/spec_pione-config-unset.rb +44 -0
  211. data/test/command/spec_pione-config.rb +11 -0
  212. data/test/command/spec_pione-diagnosis-notification.rb +23 -0
  213. data/test/command/spec_pione-diagnosis.rb +11 -0
  214. data/test/command/spec_pione-lang-check-syntax.rb +12 -0
  215. data/test/command/spec_pione-lang.rb +11 -0
  216. data/test/command/spec_pione-log-format.rb +29 -0
  217. data/test/command/spec_pione-log-list-id.rb +17 -0
  218. data/test/command/spec_pione-log.rb +6 -20
  219. data/test/command/spec_pione-package-add.rb +55 -0
  220. data/test/command/spec_pione-package-build.rb +57 -0
  221. data/test/command/spec_pione-package-show.rb +72 -0
  222. data/test/command/{spec_pione-update-package-info.rb → spec_pione-package-update.rb} +12 -13
  223. data/test/command/spec_pione-package.rb +4 -104
  224. data/test/command/spec_pione-val.rb +10 -7
  225. data/test/global/spec_config.rb +50 -0
  226. data/test/global/spec_item.rb +1 -1
  227. data/test/literate-action/data/HelloWorld.md +1 -1
  228. data/test/location/location-behavior.rb +1 -1
  229. data/test/location/spec_dropbox-location.rb +39 -0
  230. data/test/location/spec_notification-scheme.rb +37 -0
  231. data/test/log/spec_debug.rb +5 -4
  232. data/test/log/spec_message-log-receiver.rb +13 -0
  233. data/test/log/spec_message-log.rb +6 -9
  234. data/test/log/spec_system-log.rb +5 -3
  235. data/test/notification/spec_address.rb +229 -0
  236. data/test/notification/spec_message.rb +30 -0
  237. data/test/notification/spec_receiver.rb +36 -0
  238. data/test/notification/spec_transmitter.rb +37 -0
  239. data/test/pnml/data/ConditionalBranchIf.pnml +270 -0
  240. data/test/pnml/data/ConditionalBranchIfElse.pnml +309 -0
  241. data/test/pnml/data/IOExpansionComplex.pnml +363 -0
  242. data/test/pnml/data/IOExpansionSimple.pnml +140 -0
  243. data/test/pnml/data/InputMergeComplementComplex.pnml +381 -0
  244. data/test/pnml/data/InputMergeComplementSimple.pnml +248 -0
  245. data/test/pnml/data/InputParallelizationComplementComplex.pnml +433 -0
  246. data/test/pnml/data/InputParallelizationComplementSimple.pnml +288 -0
  247. data/test/pnml/data/InputReductionComplex.pnml +192 -0
  248. data/test/pnml/data/InputReductionLong.pnml +344 -0
  249. data/test/pnml/data/InputReductionSimple.pnml +140 -0
  250. data/test/pnml/data/IsolatedElementElimination.pnml +171 -0
  251. data/test/pnml/data/OutputDecompositionComplementComplex.pnml +381 -0
  252. data/test/pnml/data/OutputDecompositionComplementSimple.pnml +242 -0
  253. data/test/pnml/data/OutputReductionComplex.pnml +186 -0
  254. data/test/pnml/data/OutputReductionLong.pnml +344 -0
  255. data/test/pnml/data/OutputReductionSimple.pnml +140 -0
  256. data/test/pnml/data/OutputSynchronizationComplementComplex.pnml +498 -0
  257. data/test/pnml/data/OutputSynchronizationComplementSimple.pnml +347 -0
  258. data/test/pnml/data/SampleNet.pnml +238 -0
  259. data/test/pnml/spec_input-merge-complement.rb +40 -0
  260. data/test/pnml/spec_input-parallelization-complement.rb +50 -0
  261. data/test/pnml/spec_input-reduction.rb +113 -0
  262. data/test/pnml/spec_invalid-arc-elimination.rb +33 -0
  263. data/test/pnml/spec_io-expansion.rb +126 -0
  264. data/test/pnml/spec_isolated-element-elimination.rb +25 -0
  265. data/test/pnml/spec_output-decomposition-complement.rb +40 -0
  266. data/test/pnml/spec_output-reduction.rb +114 -0
  267. data/test/pnml/spec_output-synchronization-complement.rb +62 -0
  268. data/test/pnml/spec_pione-element.rb +144 -0
  269. data/test/pnml/spec_pnml-element.rb +373 -0
  270. data/test/pnml/spec_reader.rb +16 -0
  271. data/test/rootage/spec_argument.rb +18 -0
  272. data/test/rootage/spec_command.rb +239 -0
  273. data/test/rootage/spec_core.rb +198 -0
  274. data/test/rootage/spec_scenario.rb +149 -0
  275. data/test/system/{spec_domain-info.rb → spec_domain-dump.rb} +6 -6
  276. data/test/system/spec_file-cache.rb +6 -9
  277. data/test/tuple-space/spec_finished-tuple.rb +1 -1
  278. data/test/util/{spec_package-parameters-list_1.pione → data/package-parameters-list/Param1.pione} +0 -0
  279. data/test/util/{spec_package-parameters-list_2.pione → data/package-parameters-list/Param2.pione} +0 -0
  280. data/test/util/{spec_package-parameters-list_3.pione → data/package-parameters-list/Param3.pione} +0 -0
  281. data/test/util/{spec_package-parameters-list_4.pione → data/package-parameters-list/Param4.pione} +0 -0
  282. data/test/util/spec_boolean-value.rb +32 -0
  283. data/test/util/spec_completion.rb +22 -0
  284. data/test/util/spec_package-parameters-list.rb +39 -52
  285. data/test/util/spec_zip.rb +28 -1
  286. metadata +288 -47
  287. data/bin/pione-tuple-space-receiver +0 -5
  288. data/lib/pione/agent/broker.rb +0 -304
  289. data/lib/pione/agent/tuple-space-receiver.rb +0 -137
  290. data/lib/pione/command/pione-broker.rb +0 -104
  291. data/lib/pione/command/pione-compiler.rb +0 -57
  292. data/lib/pione/command/pione-relay-account-db.rb +0 -141
  293. data/lib/pione/command/pione-relay-client-db.rb +0 -118
  294. data/lib/pione/command/pione-relay.rb +0 -59
  295. data/lib/pione/command/pione-syntax-checker.rb +0 -214
  296. data/lib/pione/command/pione-tuple-space-receiver.rb +0 -111
  297. data/lib/pione/command/pione-update-package-info.rb +0 -53
  298. data/lib/pione/front/broker-front.rb +0 -22
  299. data/lib/pione/front/tuple-space-receiver-front.rb +0 -11
  300. data/lib/pione/global/broker-variable.rb +0 -33
  301. data/lib/pione/system/domain-info.rb +0 -25
  302. data/lib/pione/util/pnml-compiler.rb +0 -168
  303. data/test/agent/spec_tuple-space-receiver.rb +0 -47
  304. data/test/util/spec_pnml-compiler.rb +0 -32
@@ -1,57 +0,0 @@
1
- module Pione
2
- module Command
3
- # PionePackage is a command body of "pione-package".
4
- class PioneCompiler < BasicCommand
5
- #
6
- # basic informations
7
- #
8
-
9
- command_name "pione-compiler"
10
- command_banner "pione-compiler translates from PNML to PIONE document."
11
-
12
- #
13
- # options
14
- #
15
-
16
- use_option :debug
17
-
18
- define_option(:name) do |item|
19
- item.long = '--name=NAME'
20
- item.desc = 'set package name'
21
- item.value = proc {|val| val}
22
- end
23
-
24
- define_option(:editor) do |item|
25
- item.long = '--editor=NAME'
26
- item.desc = 'set package editor'
27
- item.value = proc {|val| val}
28
- end
29
-
30
- define_option(:tag) do |item|
31
- item.long = '--tag=NAME'
32
- item.desc = 'set package tag'
33
- item.value = proc {|val| val}
34
- end
35
-
36
- #
37
- # command lifecycle: execution phase
38
- #
39
-
40
- setup :source
41
-
42
- def setup_source
43
- @source = @argv.first
44
- end
45
-
46
- #
47
- # command lifecycle: execution phase
48
- #
49
-
50
- execute :compile_to_pnml
51
-
52
- def execute_compile_to_pnml
53
- print Util::PNMLCompiler.new(Location[@source], option[:name], option[:editor], option[:tag]).compile
54
- end
55
- end
56
- end
57
- end
@@ -1,141 +0,0 @@
1
- module Pione
2
- module Command
3
- # PioneRelayAccountDB is a command that adds, deletes, shows your accounts
4
- # of relay servers.
5
- class PioneRelayAccountDB < BasicCommand
6
- #
7
- # basic informations
8
- #
9
-
10
- command_name "pione-relay-account-db"
11
- command_banner "Add, delete, or show your accounts of relay servers."
12
-
13
- #
14
- # options
15
- #
16
-
17
- use_option :color
18
- use_option :debug
19
-
20
- define_option(:add) do |item|
21
- item.short = "-a"
22
- item.long = "--add"
23
- item.desc = "add an account"
24
- item.action = lambda {|_, option| option[:action] = :add}
25
- end
26
-
27
- define_option(:delete) do |item|
28
- item.short = "-d"
29
- item.long = "--delete"
30
- item.desc = "delete an account"
31
- item.action = lambda {|_, option| option[:action] = :delete}
32
- end
33
-
34
- define_option(:list) do |item|
35
- item.short = "-l"
36
- item.long = "--list"
37
- item.desc = "list accounts"
38
- item.action = lambda {|_, option| option[:action] = :list}
39
- end
40
-
41
- define_option(:realm) do |item|
42
- item.short = "-r"
43
- item.long = "--realm=REALM"
44
- item.desc = "realm name"
45
- item.value = lambda {|name| name}
46
- end
47
-
48
- define_option(:name) do |item|
49
- item.short = "-u"
50
- item.long = "--user=NAME"
51
- item.desc = "user name"
52
- item.value = lambda {|name| name}
53
- end
54
-
55
- define_option(:password) do |item|
56
- item.short = "-p"
57
- item.long = "--password=PASSWORD"
58
- item.desc = "password"
59
- item.value = lambda {|password| password}
60
- end
61
-
62
- define_option(:file) do |item|
63
- item.short = "-f"
64
- item.long = "--file=PATH"
65
- item.desc = "account db path"
66
- item.action = lambda {|_, _, path| Global.relay_account_db_path = path}
67
- end
68
-
69
- validate_option do |option|
70
- abort("error: -a, -d, or -l") unless option[:action]
71
- end
72
-
73
- #
74
- # instance methods
75
- #
76
-
77
- def initialize(*options)
78
- super(*options)
79
- @realm = nil
80
- @name = nil
81
- @password = nil
82
- end
83
-
84
- #
85
- # command lifecycle: setup phase
86
- #
87
-
88
- setup :account_db
89
- setup [:add, :delete] => :realm
90
- setup :add => :name_and_password
91
-
92
- # Set account db.
93
- def setup_account_db
94
- Global.relay_account_db = RelayAccountDB.new(Global.relay_account_db_path)
95
- end
96
-
97
- # Get realm name from user input.
98
- def setup_realm
99
- @realm = option[:realm] || HighLine.new.ask("Realm: ") unless @realm
100
- end
101
-
102
- # Get user name and password from user input.
103
- def setup_name_and_password
104
- @name = option[:name] || HighLine.new.ask("Name: ")
105
- unless @password = option[:password]
106
- @password = HighLine.new.ask("Password: "){|q| q.echo = "*"}
107
- password = HighLine.new.ask("Re-enter password: "){|q| q.echo = "*"}
108
- abort("error: password mismatch") unless @password == password
109
- end
110
- end
111
-
112
- #
113
- # command lifecycle: execution phase
114
- #
115
-
116
- execute :add => :add
117
- execute :delete => :delete
118
- execute :list => :list
119
-
120
- # Add a user.
121
- def execute_add
122
- Global.relay_account_db.add(@realm, @name, @password)
123
- Global.relay_account_db.save
124
- end
125
-
126
- # Delete a user.
127
- def execute_delete
128
- Global.relay_account_db.delete(@realm)
129
- Global.relay_account_db.save
130
- end
131
-
132
- # Show all users.
133
- def execute_list
134
- puts "%s accounts in %s" % [db.realms.size, Global.relay_account_db_path]
135
- Global.relay_account_db.realms.each do |realm|
136
- puts "%s:%s" % [realm, Global.relay_account_db[realm].name]
137
- end
138
- end
139
- end
140
- end
141
- end
@@ -1,118 +0,0 @@
1
- module Pione
2
- module Command
3
- # PioneRelayClientDB is a command that adds, deletes, or shows clients in
4
- # relay server.
5
- class PioneRelayClientDB < BasicCommand
6
- #
7
- # basic informations
8
- #
9
-
10
- command_name "pione-relay-client-db"
11
- command_banner "Add, delete, or show clients in this relay server."
12
-
13
- #
14
- # options
15
- #
16
-
17
- use_option :color
18
- use_option :debug
19
-
20
- define_option(:add) do |item|
21
- item.short = "-a"
22
- item.long = "--add"
23
- item.desc = "add a client"
24
- item.action = lambda {|_, option| option[:action] = :add}
25
- end
26
-
27
- define_option(:delete) do |item|
28
- item.short = "-d"
29
- item.long = "--delete"
30
- item.desc = "delete a client"
31
- item.action = lambda {|_, option| option[:action] = :delete}
32
- end
33
-
34
- define_option(:list) do |item|
35
- item.short = "-l"
36
- item.long = "--list"
37
- item.desc = "list clients"
38
- item.action = lambda {|_, option| option[:action] = :list}
39
- end
40
-
41
- define_option(:name) do |item|
42
- item.short = "-u"
43
- item.long = "--user=NAME"
44
- item.desc = "user name"
45
- item.value = lambda {|name| name}
46
- end
47
-
48
- define_option(:password) do |item|
49
- item.short = "-p"
50
- item.long = "--password=PASSWORD"
51
- item.desc = "password"
52
- item.value = lambda {|password| password}
53
- end
54
-
55
- define_option(:file) do |item|
56
- item.short = "-f"
57
- item.long = "--file=PATH"
58
- item.desc = "client db path"
59
- item.action = lambda {|_, option, path| Global.relay_client_db_path = path}
60
- end
61
-
62
- validate_option do |option|
63
- abort("error: -a, -d, or -l") unless option[:action]
64
- end
65
-
66
- #
67
- # command lifecycle: setup phase
68
- #
69
-
70
- setup :client_db
71
- setup [:add, :delete] => :name
72
- setup :add => :password
73
-
74
- # set client db
75
- def setup_client_db
76
- Global.relay_client_db = RelayClientDB.new(Global.relay_client_db_path)
77
- end
78
-
79
- # set name
80
- def setup_name
81
- option[:name] = HighLine.new.ask("Name: ") unless option[:name]
82
- end
83
-
84
- # set password
85
- def setup_password
86
- unless option[:password]
87
- option[:password] = HighLine.new.ask("Password: "){|q| q.echo = "*"}
88
- password = HighLine.new.ask("Re-enter password: "){|q| q.echo = "*"}
89
- abort("error: password mismatch") unless option[:password] == password
90
- end
91
- end
92
-
93
- #
94
- # command lifecycle: execution phase
95
- #
96
-
97
- execute :add => :add
98
- execute :delete => :delete
99
- execute :list => :list
100
-
101
- def execute_add
102
- Global.relay_client_db.add(option[:name], option[:password])
103
- Global.relay_client_db.save
104
- end
105
-
106
- def execute_delete
107
- Global.relay_client_db.delete(option[:name])
108
- Global.relay_client_db.save
109
- end
110
-
111
- def execute_list
112
- names = Global.relay_client_db.names
113
- puts "%s clients in %s" % [names.size, Global.relay_client_db_path]
114
- names.each {|user| puts user}
115
- end
116
- end
117
- end
118
- end
@@ -1,59 +0,0 @@
1
- module Pione
2
- module Command
3
- # PioneRelay is a command for connecting relay server.
4
- class PioneRelay < BasicCommand
5
- #
6
- # basic informations
7
- #
8
-
9
- command_name("pione-relay") {|cmd| "relay-port: %s" % cmd.option[:relay_port]}
10
- command_banner "Run relay process for connecting between clients and brokers."
11
- command_front Front::RelayFront
12
-
13
- #
14
- # options
15
- #
16
-
17
- use_option :color
18
- use_option :debug
19
- use_option :my_ip_address
20
-
21
- define_option(:realm) do |item|
22
- item.long = "--realm name"
23
- item.desc = "set relay realm name for client authentification"
24
- item.action = lambda {|_, _, name| Global.relay_realm = name}
25
- end
26
-
27
- define_option(:relay_port) do |item|
28
- item.long = "--relay-port port"
29
- item.desc = "set relay port"
30
- item.default = Global.relay_port
31
- item.value = lambda {|port| port}
32
- end
33
-
34
- validate_option do |option|
35
- abort("error: no realm name") if Global.relay_realm.nil? or Global.relay_realm.empty?
36
- abort("error: no relay port") unless option[:relay_port]
37
- end
38
-
39
- #
40
- # command lifecycle: execution phase
41
- #
42
-
43
- execute :relay
44
-
45
- def execute_relay
46
- # wake up tuple space provider process
47
- Pione::TupleSpaceProvider.spawn
48
-
49
- puts DRb.front.uri
50
- DRb::DRbServer.new(
51
- "relay://:%s" % option[:relay_port],
52
- nil,
53
- {:SSLCertName => Global.relay_ssl_certname}
54
- )
55
- DRb.thread.join
56
- end
57
- end
58
- end
59
- end
@@ -1,214 +0,0 @@
1
- module Pione
2
- module Command
3
- # PioneSyntaxChecker is a command for checking syntax tree and model of the
4
- # PIONE document.
5
- class PioneSyntaxChecker < BasicCommand
6
- #
7
- # basic informations
8
- #
9
-
10
- command_name "pione-syntax-checker"
11
- command_banner "Print syntax tree of PIONE notation."
12
-
13
- #
14
- # options
15
- #
16
-
17
- use_option :color
18
- use_option :debug
19
-
20
- option_default(:readline_mode, true)
21
-
22
- define_option(:expr) do |item|
23
- item.short = '-e'
24
- item.long = '--expr=EXPR'
25
- item.desc = 'check the expression string and exit'
26
- item.action = lambda do |_, option, e|
27
- option[:expr] = e
28
- option[:readline_mode] = false
29
- end
30
- end
31
-
32
- define_option(:syntax) do |item|
33
- item.short = '-s'
34
- item.long = '--syntax'
35
- item.desc = 'show syntax tree'
36
- item.default = false
37
- item.value = true
38
- end
39
-
40
- define_option(:transform) do |item|
41
- item.short = '-t'
42
- item.long = '--transformer'
43
- item.desc = 'show transformer result'
44
- item.default = false
45
- item.value = true
46
- end
47
-
48
- define_option(:file) do |item|
49
- item.short = '-f'
50
- item.long = '--file=PATH'
51
- item.desc = 'check syntax of the document'
52
- item.action = lambda do |_, option, path|
53
- option[:document] = path
54
- option[:readline_mode] = false
55
- end
56
- end
57
-
58
- define_option(:parser) do |item|
59
- item.long = "--parser=NAME"
60
- item.desc = "set parser"
61
- item.value = lambda {|name| name}
62
- end
63
-
64
- #
65
- # instance methods
66
- #
67
-
68
- def initialize(*argv)
69
- super
70
- @history = File.join(Global.dot_pione_dir, "pione-history")
71
- end
72
-
73
- #
74
- # command lifecycle: setup phase
75
- #
76
-
77
- setup :pp
78
- setup :readline => :readline_mode
79
-
80
- def setup_pp
81
- require 'pp'
82
- end
83
-
84
- def setup_readline_mode
85
- require 'readline'
86
- restore_history
87
- end
88
-
89
- #
90
- # command lifecycle: execute phase
91
- #
92
-
93
- execute :readline => :readline_mode
94
- execute :file => :file
95
- execute :expr => :expr
96
-
97
- def execute_readline_mode
98
- buf = ""
99
- mark = ">"
100
-
101
- # start loop
102
- while buf += Readline.readline("#{mark} ".color(:red), true)
103
- if /[^\s]/.match(buf)
104
- # don't record if previous line is the same
105
- if Readline::HISTORY.size > 1 && Readline::HISTORY[-2] == buf
106
- Readline::HISTORY.pop
107
- end
108
- if buf[-1] == "\\"
109
- buf[-1] = "\n"
110
- mark = "+"
111
- next
112
- else
113
- # print parsing result
114
- print_result(DocumentParser.new.expr, buf)
115
- buf = ""
116
- mark = ">"
117
- end
118
- else
119
- # don't record if it is an empty line
120
- Readline::HISTORY.pop
121
- end
122
- end
123
- end
124
-
125
- def execute_file
126
- print_result(DocumentParser.new, Pathname.new(option[:document]).read)
127
- end
128
-
129
- def execute_expr
130
- parser_name = option[:parser] ? option[:parser] : :expr
131
- print_result(DocumentParser.new.send(parser_name), option[:expr])
132
- end
133
-
134
- #
135
- # command lifecycle: termination phase
136
- #
137
-
138
- terminate :readline => :history
139
-
140
- def terminate_history
141
- save_history if readline_mode?
142
- end
143
-
144
- #
145
- # helper methods
146
- #
147
-
148
- private
149
-
150
- # Return action mode.
151
- def action_mode
152
- return :readline if readline_mode?
153
- return :file if option[:document]
154
- return :expr if option[:expr]
155
- end
156
-
157
- # Return true if readline mode is enabled.
158
- def readline_mode?
159
- option[:readline_mode]
160
- end
161
-
162
- # Print parsing result of the string.
163
- def print_result(parser, str)
164
- begin
165
- stree = parser.parse(str)
166
- transformer_option = {}
167
- transformer_option[:package_name] = option[:package_name] || "PioneSyntaxChecker"
168
- transformer_option[:filename] = option[:filename] || "NoFile"
169
- model = DocumentTransformer.new.apply(stree, transformer_option)
170
- if option[:syntax]
171
- puts "syntax:".color(:green)
172
- pp stree
173
- end
174
- if option[:transform]
175
- puts "model:".color(:green)
176
- pp model
177
- end
178
- if model.kind_of?(Array)
179
- model.each {|m| p m}
180
- else
181
- p model.eval(Lang::Environment.new)
182
- end
183
- rescue Lang::ParserError, Parslet::ParseFailed => e
184
- msg = "Pione syntax error: %s (%s)" % [e.message, e.class.name]
185
- readline_mode? ? puts(msg) : abort(msg)
186
- rescue Lang::PioneTypeError, Lang::VariableBindingError => e
187
- msg = "Pione model error: %s (%s)" % [e.message, e.class.name]
188
- readline_mode? ? puts(msg) : abort(msg)
189
- rescue Lang::MethodNotFound => e
190
- msg = "%s (%s)" % [e.message, e.class.name]
191
- readline_mode? ? puts(msg) : abort(msg)
192
- end
193
- end
194
-
195
- # Restore readline's history.
196
- def restore_history
197
- if File.exist?(@history)
198
- File.readlines(@history).reverse.each do |line|
199
- Readline::HISTORY.push line.chomp
200
- end
201
- end
202
- end
203
-
204
- # Save history to file.
205
- def save_history
206
- File.open(@history, "w+") do |file|
207
- Readline::HISTORY.to_a.reverse[0..100].each do |line|
208
- file.puts(line) if /\S/.match(line)
209
- end
210
- end
211
- end
212
- end
213
- end
214
- end