pione 0.3.2 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/.s3cfg +42 -0
- data/.travis.yml +18 -4
- data/.yardopts +1 -0
- data/Gemfile +3 -0
- data/History.txt +14 -0
- data/Procfile +7 -0
- data/Rakefile +25 -0
- data/bin/pione-interactive +6 -0
- data/bin/{pione-compiler → pione-notification-listener} +1 -1
- data/bin/{pione-broker → pione-task-worker-broker} +1 -1
- data/doc/man/pione-list-param.md +36 -0
- data/example/ActionError/ActionError.pione +9 -0
- data/example/ActionError/pione-package.json +15 -0
- data/example/CountChar/CountChar.pione +1 -1
- data/example/ScoreAggregation/ScoreAggregation.pione +1 -1
- data/example/Touch/pione-package.json +15 -0
- data/lib/pione.rb +12 -0
- data/lib/pione/agent.rb +3 -3
- data/lib/pione/agent/basic-agent.rb +10 -4
- data/lib/pione/agent/input-generator.rb +3 -3
- data/lib/pione/agent/{process-manager.rb → job-manager.rb} +10 -7
- data/lib/pione/agent/job-terminator.rb +2 -2
- data/lib/pione/agent/logger.rb +3 -3
- data/lib/pione/agent/messenger.rb +20 -9
- data/lib/pione/agent/notification-listener.rb +88 -0
- data/lib/pione/agent/task-worker-broker.rb +84 -0
- data/lib/pione/agent/task-worker.rb +3 -2
- data/lib/pione/agent/tuple-space-client.rb +1 -0
- data/lib/pione/agent/tuple-space-provider.rb +17 -35
- data/lib/pione/command.rb +33 -15
- data/lib/pione/command/action.rb +105 -0
- data/lib/pione/command/basic-command.rb +34 -376
- data/lib/pione/command/command-exception.rb +12 -11
- data/lib/pione/command/common.rb +198 -0
- data/lib/pione/command/option.rb +159 -204
- data/lib/pione/command/pione-action-exec.rb +85 -0
- data/lib/pione/command/pione-action-list.rb +43 -19
- data/lib/pione/command/pione-action-print.rb +79 -0
- data/lib/pione/command/pione-action.rb +8 -67
- data/lib/pione/command/pione-clean.rb +88 -68
- data/lib/pione/command/pione-client.rb +475 -332
- data/lib/pione/command/pione-command.rb +14 -31
- data/lib/pione/command/pione-compile.rb +90 -0
- data/lib/pione/command/pione-config-get.rb +53 -0
- data/lib/pione/command/pione-config-list.rb +64 -0
- data/lib/pione/command/pione-config-set.rb +59 -0
- data/lib/pione/command/pione-config-unset.rb +50 -0
- data/lib/pione/command/pione-config.rb +61 -0
- data/lib/pione/command/pione-diagnosis-notification.rb +235 -0
- data/lib/pione/command/pione-diagnosis.rb +21 -0
- data/lib/pione/command/pione-interactive.rb +188 -0
- data/lib/pione/command/pione-lang-check-syntax.rb +163 -0
- data/lib/pione/command/pione-lang-interactive.rb +146 -0
- data/lib/pione/command/pione-lang.rb +22 -0
- data/lib/pione/command/pione-log-format.rb +163 -0
- data/lib/pione/command/pione-log-list-id.rb +48 -0
- data/lib/pione/command/pione-log.rb +19 -101
- data/lib/pione/command/pione-notification-listener.rb +95 -0
- data/lib/pione/command/pione-package-add.rb +137 -0
- data/lib/pione/command/pione-package-build.rb +122 -0
- data/lib/pione/command/pione-package-show.rb +96 -0
- data/lib/pione/command/pione-package-update.rb +59 -0
- data/lib/pione/command/pione-package.rb +11 -139
- data/lib/pione/command/pione-task-worker-broker.rb +88 -0
- data/lib/pione/command/pione-task-worker.rb +148 -98
- data/lib/pione/command/pione-tuple-space-provider.rb +62 -54
- data/lib/pione/command/pione-tuple-space-viewer.rb +105 -83
- data/lib/pione/command/pione-val.rb +39 -39
- data/lib/pione/command/spawner.rb +34 -27
- data/lib/pione/front.rb +4 -2
- data/lib/pione/front/basic-front.rb +86 -23
- data/lib/pione/front/client-front.rb +2 -2
- data/lib/pione/front/diagnosis-notification-front.rb +40 -0
- data/lib/pione/front/front-exception.rb +7 -1
- data/lib/pione/front/notification-listener-front.rb +36 -0
- data/lib/pione/front/notification-recipient-interface.rb +19 -0
- data/lib/pione/front/relay-front.rb +4 -4
- data/lib/pione/front/task-worker-broker-front.rb +19 -0
- data/lib/pione/front/task-worker-front.rb +2 -2
- data/lib/pione/front/tuple-space-provider-front.rb +3 -2
- data/lib/pione/global.rb +3 -1
- data/lib/pione/global/client-variable.rb +1 -1
- data/lib/pione/global/config.rb +63 -7
- data/lib/pione/global/diagnosis-variable.rb +26 -0
- data/lib/pione/global/item.rb +28 -5
- data/lib/pione/global/log-variable.rb +6 -5
- data/lib/pione/global/network-variable.rb +75 -4
- data/lib/pione/global/path-variable.rb +1 -1
- data/lib/pione/global/system-variable.rb +12 -12
- data/lib/pione/global/task-worker-broker-variable.rb +43 -0
- data/lib/pione/global/tuple-space-notifier-variable.rb +3 -55
- data/lib/pione/lang/boolean.rb +4 -0
- data/lib/pione/lang/data-expr.rb +1 -1
- data/lib/pione/lang/integer.rb +1 -1
- data/lib/pione/lang/string.rb +4 -0
- data/lib/pione/lang/type.rb +1 -1
- data/lib/pione/location.rb +1 -0
- data/lib/pione/location/data-location.rb +41 -13
- data/lib/pione/location/dropbox-location.rb +175 -56
- data/lib/pione/location/ftp-location.rb +4 -1
- data/lib/pione/location/http-location.rb +5 -3
- data/lib/pione/location/https-location.rb +4 -2
- data/lib/pione/location/local-location.rb +6 -3
- data/lib/pione/location/location-exception.rb +12 -0
- data/lib/pione/location/notification-scheme.rb +46 -0
- data/lib/pione/log.rb +8 -7
- data/lib/pione/log/debug.rb +9 -9
- data/lib/pione/log/domain-log.rb +6 -1
- data/lib/pione/log/message-log-receiver.rb +32 -0
- data/lib/pione/log/system-log.rb +62 -141
- data/lib/pione/model.rb +7 -0
- data/lib/pione/model/notification-listener-model.rb +29 -0
- data/lib/pione/model/task-worker-broker-model.rb +129 -0
- data/lib/pione/notification.rb +13 -0
- data/lib/pione/notification/address.rb +104 -0
- data/lib/pione/notification/exception.rb +10 -0
- data/lib/pione/notification/message.rb +109 -0
- data/lib/pione/notification/receiver.rb +90 -0
- data/lib/pione/notification/recipient.rb +68 -0
- data/lib/pione/notification/task-worker-broker-recipient.rb +85 -0
- data/lib/pione/notification/transmitter.rb +84 -0
- data/lib/pione/pnml.rb +35 -0
- data/lib/pione/pnml/annotation-extractor.rb +47 -0
- data/lib/pione/pnml/compiler.rb +176 -0
- data/lib/pione/pnml/input-merge-complement.rb +78 -0
- data/lib/pione/pnml/input-parallelization-complement.rb +75 -0
- data/lib/pione/pnml/input-reduction.rb +80 -0
- data/lib/pione/pnml/invalid-arc-elimination.rb +41 -0
- data/lib/pione/pnml/io-expansion.rb +88 -0
- data/lib/pione/pnml/isolated-element-elimination.rb +32 -0
- data/lib/pione/pnml/net-rewriter.rb +44 -0
- data/lib/pione/pnml/output-decomposition-complement.rb +77 -0
- data/lib/pione/pnml/output-reduction.rb +86 -0
- data/lib/pione/pnml/output-synchronization-complement.rb +77 -0
- data/lib/pione/pnml/pione-model.rb +417 -0
- data/lib/pione/pnml/pnml-exception.rb +23 -0
- data/lib/pione/pnml/pnml-model.rb +368 -0
- data/lib/pione/pnml/reader.rb +51 -0
- data/lib/pione/rule-engine/action-handler.rb +8 -6
- data/lib/pione/rule-engine/basic-handler.rb +5 -5
- data/lib/pione/rule-engine/engine-exception.rb +7 -6
- data/lib/pione/rule-engine/flow-handler.rb +27 -18
- data/lib/pione/system.rb +3 -1
- data/lib/pione/system/domain-dump.rb +34 -0
- data/lib/pione/system/file-cache.rb +92 -13
- data/lib/pione/system/init.rb +3 -0
- data/lib/pione/system/normalizer.rb +40 -0
- data/lib/pione/system/status.rb +5 -5
- data/lib/pione/system/system-exception.rb +14 -1
- data/lib/pione/task-worker-broker.rb +7 -0
- data/lib/pione/task-worker-broker/basic-provider.rb +20 -0
- data/lib/pione/task-worker-broker/easy-provider.rb +65 -0
- data/lib/pione/test-helper.rb +27 -0
- data/lib/pione/test-helper/command-helper.rb +9 -101
- data/lib/pione/tuple-space/basic-tuple.rb +1 -1
- data/lib/pione/tuple-space/tuple-definition.yml +4 -6
- data/lib/pione/tuple-space/tuple-space-interface.rb +3 -45
- data/lib/pione/tuple-space/tuple-space-server.rb +45 -0
- data/lib/pione/util.rb +1 -2
- data/lib/pione/util/boolean-value.rb +62 -0
- data/lib/pione/util/completion.rb +111 -0
- data/lib/pione/util/evaluatable.rb +13 -27
- data/lib/pione/util/package-parameters-list.rb +15 -27
- data/lib/pione/util/zip.rb +8 -3
- data/lib/pione/version.rb +1 -1
- data/lib/rootage.rb +20 -0
- data/lib/rootage/action.rb +114 -0
- data/lib/rootage/argument.rb +46 -0
- data/lib/rootage/command.rb +218 -0
- data/lib/rootage/core.rb +532 -0
- data/lib/rootage/exception.rb +107 -0
- data/lib/rootage/help.rb +148 -0
- data/lib/rootage/help.txt.erb +31 -0
- data/lib/rootage/log.rb +226 -0
- data/lib/rootage/normalizer.rb +184 -0
- data/lib/rootage/option.rb +152 -0
- data/lib/rootage/scenario-test-result.erb +39 -0
- data/lib/rootage/scenario.rb +362 -0
- data/lib/rootage/test-helper.rb +115 -0
- data/man/pione-list-param.1 +44 -0
- data/misc/clock.rb +9 -0
- data/misc/machine-info.sh +21 -0
- data/misc/pione-completion.bash +238 -0
- data/misc/pione-completion.erb +53 -0
- data/misc/pione-completion.zsh +238 -0
- data/misc/pione.god +22 -0
- data/misc/ui.xml +23 -0
- data/pione.gemspec +3 -1
- data/test/agent/spec_basic-agent.rb +1 -1
- data/test/agent/spec_input-generator.rb +2 -2
- data/test/agent/spec_messenger.rb +6 -9
- data/test/agent/spec_notification-listener.rb +80 -0
- data/test/agent/{spec_broker.rb → spec_task-worker-broker.rb} +13 -10
- data/test/agent/spec_tuple-space-provider.rb +10 -6
- data/test/command/command-behavior.rb +3 -11
- data/test/command/data/pione-list-param/AdvancedParameters.pione +12 -0
- data/test/command/data/pione-list-param/BasicParameters.pione +12 -0
- data/test/command/spec_pione-action-exec.rb +16 -0
- data/test/command/spec_pione-action-list.rb +15 -10
- data/test/command/spec_pione-action-print.rb +14 -0
- data/test/command/spec_pione-action.rb +6 -19
- data/test/command/spec_pione-clean.rb +29 -46
- data/test/command/spec_pione-client.rb +29 -36
- data/test/command/spec_pione-command.rb +6 -6
- data/test/command/{spec_pione-compiler.rb → spec_pione-compile.rb} +11 -13
- data/test/command/spec_pione-config-get.rb +47 -0
- data/test/command/spec_pione-config-list.rb +42 -0
- data/test/command/spec_pione-config-set.rb +38 -0
- data/test/command/spec_pione-config-unset.rb +44 -0
- data/test/command/spec_pione-config.rb +11 -0
- data/test/command/spec_pione-diagnosis-notification.rb +23 -0
- data/test/command/spec_pione-diagnosis.rb +11 -0
- data/test/command/spec_pione-lang-check-syntax.rb +12 -0
- data/test/command/spec_pione-lang.rb +11 -0
- data/test/command/spec_pione-log-format.rb +29 -0
- data/test/command/spec_pione-log-list-id.rb +17 -0
- data/test/command/spec_pione-log.rb +6 -20
- data/test/command/spec_pione-package-add.rb +55 -0
- data/test/command/spec_pione-package-build.rb +57 -0
- data/test/command/spec_pione-package-show.rb +72 -0
- data/test/command/{spec_pione-update-package-info.rb → spec_pione-package-update.rb} +12 -13
- data/test/command/spec_pione-package.rb +4 -104
- data/test/command/spec_pione-val.rb +10 -7
- data/test/global/spec_config.rb +50 -0
- data/test/global/spec_item.rb +1 -1
- data/test/literate-action/data/HelloWorld.md +1 -1
- data/test/location/location-behavior.rb +1 -1
- data/test/location/spec_dropbox-location.rb +39 -0
- data/test/location/spec_notification-scheme.rb +37 -0
- data/test/log/spec_debug.rb +5 -4
- data/test/log/spec_message-log-receiver.rb +13 -0
- data/test/log/spec_message-log.rb +6 -9
- data/test/log/spec_system-log.rb +5 -3
- data/test/notification/spec_address.rb +229 -0
- data/test/notification/spec_message.rb +30 -0
- data/test/notification/spec_receiver.rb +36 -0
- data/test/notification/spec_transmitter.rb +37 -0
- data/test/pnml/data/ConditionalBranchIf.pnml +270 -0
- data/test/pnml/data/ConditionalBranchIfElse.pnml +309 -0
- data/test/pnml/data/IOExpansionComplex.pnml +363 -0
- data/test/pnml/data/IOExpansionSimple.pnml +140 -0
- data/test/pnml/data/InputMergeComplementComplex.pnml +381 -0
- data/test/pnml/data/InputMergeComplementSimple.pnml +248 -0
- data/test/pnml/data/InputParallelizationComplementComplex.pnml +433 -0
- data/test/pnml/data/InputParallelizationComplementSimple.pnml +288 -0
- data/test/pnml/data/InputReductionComplex.pnml +192 -0
- data/test/pnml/data/InputReductionLong.pnml +344 -0
- data/test/pnml/data/InputReductionSimple.pnml +140 -0
- data/test/pnml/data/IsolatedElementElimination.pnml +171 -0
- data/test/pnml/data/OutputDecompositionComplementComplex.pnml +381 -0
- data/test/pnml/data/OutputDecompositionComplementSimple.pnml +242 -0
- data/test/pnml/data/OutputReductionComplex.pnml +186 -0
- data/test/pnml/data/OutputReductionLong.pnml +344 -0
- data/test/pnml/data/OutputReductionSimple.pnml +140 -0
- data/test/pnml/data/OutputSynchronizationComplementComplex.pnml +498 -0
- data/test/pnml/data/OutputSynchronizationComplementSimple.pnml +347 -0
- data/test/pnml/data/SampleNet.pnml +238 -0
- data/test/pnml/spec_input-merge-complement.rb +40 -0
- data/test/pnml/spec_input-parallelization-complement.rb +50 -0
- data/test/pnml/spec_input-reduction.rb +113 -0
- data/test/pnml/spec_invalid-arc-elimination.rb +33 -0
- data/test/pnml/spec_io-expansion.rb +126 -0
- data/test/pnml/spec_isolated-element-elimination.rb +25 -0
- data/test/pnml/spec_output-decomposition-complement.rb +40 -0
- data/test/pnml/spec_output-reduction.rb +114 -0
- data/test/pnml/spec_output-synchronization-complement.rb +62 -0
- data/test/pnml/spec_pione-element.rb +144 -0
- data/test/pnml/spec_pnml-element.rb +373 -0
- data/test/pnml/spec_reader.rb +16 -0
- data/test/rootage/spec_argument.rb +18 -0
- data/test/rootage/spec_command.rb +239 -0
- data/test/rootage/spec_core.rb +198 -0
- data/test/rootage/spec_scenario.rb +149 -0
- data/test/system/{spec_domain-info.rb → spec_domain-dump.rb} +6 -6
- data/test/system/spec_file-cache.rb +6 -9
- data/test/tuple-space/spec_finished-tuple.rb +1 -1
- data/test/util/{spec_package-parameters-list_1.pione → data/package-parameters-list/Param1.pione} +0 -0
- data/test/util/{spec_package-parameters-list_2.pione → data/package-parameters-list/Param2.pione} +0 -0
- data/test/util/{spec_package-parameters-list_3.pione → data/package-parameters-list/Param3.pione} +0 -0
- data/test/util/{spec_package-parameters-list_4.pione → data/package-parameters-list/Param4.pione} +0 -0
- data/test/util/spec_boolean-value.rb +32 -0
- data/test/util/spec_completion.rb +22 -0
- data/test/util/spec_package-parameters-list.rb +39 -52
- data/test/util/spec_zip.rb +28 -1
- metadata +288 -47
- data/bin/pione-tuple-space-receiver +0 -5
- data/lib/pione/agent/broker.rb +0 -304
- data/lib/pione/agent/tuple-space-receiver.rb +0 -137
- data/lib/pione/command/pione-broker.rb +0 -104
- data/lib/pione/command/pione-compiler.rb +0 -57
- data/lib/pione/command/pione-relay-account-db.rb +0 -141
- data/lib/pione/command/pione-relay-client-db.rb +0 -118
- data/lib/pione/command/pione-relay.rb +0 -59
- data/lib/pione/command/pione-syntax-checker.rb +0 -214
- data/lib/pione/command/pione-tuple-space-receiver.rb +0 -111
- data/lib/pione/command/pione-update-package-info.rb +0 -53
- data/lib/pione/front/broker-front.rb +0 -22
- data/lib/pione/front/tuple-space-receiver-front.rb +0 -11
- data/lib/pione/global/broker-variable.rb +0 -33
- data/lib/pione/system/domain-info.rb +0 -25
- data/lib/pione/util/pnml-compiler.rb +0 -168
- data/test/agent/spec_tuple-space-receiver.rb +0 -47
- data/test/util/spec_pnml-compiler.rb +0 -32
@@ -3,6 +3,8 @@ module Pione
|
|
3
3
|
class DataLocation < BasicLocation
|
4
4
|
location_type :data
|
5
5
|
|
6
|
+
KNOWN_ATTRS = [:need_caching, :real_appendable, :writable]
|
7
|
+
|
6
8
|
class << self
|
7
9
|
# @return [String]
|
8
10
|
# location's scheme name
|
@@ -17,16 +19,27 @@ module Pione
|
|
17
19
|
SCHEMES[name] = self
|
18
20
|
end
|
19
21
|
|
20
|
-
|
21
|
-
|
22
|
+
|
23
|
+
# Define a location's attribute.
|
24
|
+
#
|
25
|
+
# - need_caching : whether the location needs to be cached or not
|
26
|
+
# - real_appendable : whether the location can appendable or not
|
27
|
+
# - writable : whether the location is writable or not
|
28
|
+
def define(name, val)
|
29
|
+
if DataLocation::KNOWN_ATTRS.include?(name)
|
30
|
+
(@attr ||= Hash.new)[name] = val
|
31
|
+
else
|
32
|
+
raise ArgumentError.new(name)
|
33
|
+
end
|
22
34
|
end
|
23
35
|
|
24
|
-
|
25
|
-
|
36
|
+
# Return true if the location needs caching.
|
37
|
+
def need_caching?
|
38
|
+
@attr[:need_caching]
|
26
39
|
end
|
27
40
|
|
28
|
-
def
|
29
|
-
@
|
41
|
+
def real_appendable?
|
42
|
+
@attr[:real_appendable]
|
30
43
|
end
|
31
44
|
|
32
45
|
def writable?
|
@@ -34,7 +47,7 @@ module Pione
|
|
34
47
|
end
|
35
48
|
end
|
36
49
|
|
37
|
-
forward! :class, :scheme, :real_appendable?, :writable?
|
50
|
+
forward! :class, :scheme, :real_appendable?, :writable?, :need_caching?
|
38
51
|
forward :@uri, :host
|
39
52
|
|
40
53
|
# @return [URI]
|
@@ -62,7 +75,7 @@ module Pione
|
|
62
75
|
if scheme == "local"
|
63
76
|
self
|
64
77
|
else
|
65
|
-
Location[Temppath.create].tap {|tmp| copy(tmp)}
|
78
|
+
Location[Temppath.create].tap {|tmp| copy(tmp) if exist?}
|
66
79
|
end
|
67
80
|
end
|
68
81
|
|
@@ -164,7 +177,13 @@ module Pione
|
|
164
177
|
# data content
|
165
178
|
# @return [void]
|
166
179
|
def append(data)
|
167
|
-
|
180
|
+
if real_appendable?
|
181
|
+
raise NotImplmentedError
|
182
|
+
else
|
183
|
+
_local = local
|
184
|
+
_local.append(data)
|
185
|
+
_local.copy(self)
|
186
|
+
end
|
168
187
|
end
|
169
188
|
|
170
189
|
# Read location data.
|
@@ -264,22 +283,31 @@ module Pione
|
|
264
283
|
raise NotImplementedError
|
265
284
|
end
|
266
285
|
|
267
|
-
# Return true if data
|
286
|
+
# Return true if data at the location is a file. When there exists no
|
287
|
+
# files and no directories, then return false.
|
268
288
|
#
|
269
289
|
# @return [Boolean]
|
270
|
-
# true if data
|
290
|
+
# true if data at the location is a file
|
271
291
|
def file?
|
272
292
|
raise NotImplementedError
|
273
293
|
end
|
274
294
|
|
275
|
-
# Return true if data
|
295
|
+
# Return true if data at the location is a directory. When there exists no
|
296
|
+
# files and no direcotries, then return false.
|
276
297
|
#
|
277
298
|
# @return [Boolean]
|
278
|
-
# true if data
|
299
|
+
# true if data at the location is a directory
|
279
300
|
def directory?
|
280
301
|
raise NotImplementedError
|
281
302
|
end
|
282
303
|
|
304
|
+
# Make the path a directory.
|
305
|
+
#
|
306
|
+
# @return [void]
|
307
|
+
def mkdir
|
308
|
+
raise NotImplementedError
|
309
|
+
end
|
310
|
+
|
283
311
|
# Move to the destination.
|
284
312
|
#
|
285
313
|
# @param dest [BasicLocation]
|
@@ -4,99 +4,183 @@ module Pione
|
|
4
4
|
class DropboxLocation < DataLocation
|
5
5
|
set_scheme "dropbox"
|
6
6
|
|
7
|
+
define(:need_caching, true)
|
8
|
+
define(:real_appendable, false)
|
9
|
+
define(:writable, true)
|
10
|
+
|
7
11
|
class << self
|
8
|
-
attr_reader :
|
12
|
+
attr_reader :client
|
9
13
|
|
10
|
-
#
|
14
|
+
# Return true if Dropbox's access token cache exists.
|
11
15
|
#
|
12
|
-
# @
|
13
|
-
#
|
16
|
+
# @return [Boolean]
|
17
|
+
# true if Dropbox's access token cache exists
|
18
|
+
def cached?
|
19
|
+
cache = Pathname.new("~/.pione/dropbox_api.cache").expand_path
|
20
|
+
return (cache.exist? and cache.read.size > 0)
|
21
|
+
end
|
22
|
+
|
23
|
+
# Setup Dropbox location for CUI client. This method gets Dropbox's
|
24
|
+
# access token from cache file or OAuth2.
|
25
|
+
#
|
26
|
+
# @param tuple_space [TupleSpaceServer]
|
27
|
+
# tuple space
|
14
28
|
# @return [void]
|
15
|
-
def
|
16
|
-
|
17
|
-
tuple_consumer_secret = TupleSpace::AttributeTuple.new("dropbox_consumer_secret", nil)
|
18
|
-
tuple_access_token_key = TupleSpace::AttributeTuple.new("dropbox_access_token_key", nil)
|
19
|
-
tuple_access_token_secret = TupleSpace::AttributeTuple.new("dropbox_access_token_secret", nil)
|
29
|
+
def setup_for_cui_client(tuple_space)
|
30
|
+
return if @client
|
20
31
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
32
|
+
access_token = nil
|
33
|
+
cache = Pathname.new("~/.pione/dropbox_api.cache").expand_path
|
34
|
+
|
35
|
+
if cache.exist?
|
36
|
+
# load access token from cache file
|
37
|
+
access_token = cache.read
|
38
|
+
else
|
39
|
+
# get access token by OAtuh2
|
40
|
+
setup_consumer_key_and_secret
|
41
|
+
flow = auth_by_oauth2flow_no_redirect
|
42
|
+
access_token, user_id = get_code_for_cui_client(flow)
|
43
|
+
|
44
|
+
# cache session
|
45
|
+
cache.open("w+") {|c| c.write access_token}
|
46
|
+
end
|
47
|
+
|
48
|
+
# make a client
|
49
|
+
@client = DropboxClient.new(access_token)
|
50
|
+
|
51
|
+
# share access token in tuple space
|
52
|
+
share_access_token(tuple_space, access_token)
|
53
|
+
end
|
25
54
|
|
26
|
-
|
27
|
-
|
55
|
+
# Enable Dropbox locations. This method get an access token from the
|
56
|
+
# tuple space and make a Dropbox client. This assumes to be called from
|
57
|
+
# task worker agents.
|
58
|
+
#
|
59
|
+
# @param tuple_space_server [TupleSpaceServer]
|
60
|
+
# tuple space server
|
61
|
+
# @return [void]
|
62
|
+
def enable(tuple_space)
|
63
|
+
tuple = TupleSpace::AttributeTuple.new("dropbox_access_token", nil)
|
64
|
+
if tuple_access_token = tuple_space.read!(tuple)
|
65
|
+
@client = DropboxClient.new(tuple_access_token.value)
|
66
|
+
else
|
67
|
+
raise DropboxLocationUnavailable.new("There is no access token.")
|
68
|
+
end
|
28
69
|
end
|
29
70
|
|
30
71
|
def rebuild(path)
|
31
72
|
Location["dropbox:%s" % path]
|
32
73
|
end
|
33
74
|
|
34
|
-
#
|
75
|
+
# Setup Dropbox's consumer key and secret. They are loaded from a YAML
|
76
|
+
# file "dropbox_api.yml" at PIONE's home directory.
|
35
77
|
#
|
36
|
-
# @param tuple_space_server [TupleSpaceServer]
|
37
|
-
# tuple space server
|
38
|
-
# @param consumer_key [String]
|
39
|
-
# consumer key
|
40
|
-
# @param consumer_secret [String]
|
41
|
-
# consumer secret
|
42
78
|
# @return [void]
|
43
|
-
def
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
79
|
+
def setup_consumer_key_and_secret
|
80
|
+
path = Pathname.new("~/.pione/dropbox_api.yml").expand_path
|
81
|
+
if File.exist?(path)
|
82
|
+
api = YAML.load(path.read)
|
83
|
+
@consumer_key = api["key"]
|
84
|
+
@consumer_secret = api["secret"]
|
85
|
+
else
|
86
|
+
raise DropboxLocationUnavailable.new("There are no consumer key and consumer secret.")
|
87
|
+
end
|
50
88
|
end
|
51
89
|
|
52
|
-
#
|
90
|
+
# Authorize dropbox account by `DropboxOAuth2FlowNoRedirect`.
|
53
91
|
#
|
54
|
-
# @return [
|
55
|
-
#
|
56
|
-
def
|
57
|
-
@
|
92
|
+
# @return [String]
|
93
|
+
# authorize URL
|
94
|
+
def auth_by_oauth2flow_no_redirect
|
95
|
+
if @consumer_key and @consumer_secret
|
96
|
+
return DropboxOAuth2FlowNoRedirect.new(@consumer_key, @consumer_secret)
|
97
|
+
else
|
98
|
+
raise DropboxLocationUnavailable.new("There are no consumer key and consumer secret.")
|
99
|
+
end
|
58
100
|
end
|
59
101
|
|
60
|
-
#
|
102
|
+
# Authorize dropbox account by `DropboxOAuth2Flow`.
|
61
103
|
#
|
62
|
-
# @param
|
63
|
-
#
|
104
|
+
# @param redirect [String]
|
105
|
+
# redirect URL
|
106
|
+
# @param session [Hash]
|
107
|
+
# session
|
108
|
+
# @return [String]
|
109
|
+
# authorize URL
|
110
|
+
def auth_by_oauth2flow(redirect, session)
|
111
|
+
if @consumer_key and @consumer_secret
|
112
|
+
return DropboxOAuth2Flow.new(@consumer_key, @consumer_secret, redirect, session, :dropbox_auth_csrf_token)
|
113
|
+
else
|
114
|
+
raise DropboxLocationUnavailabel.new("There are no consumer key and consumer secret.")
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
# Share dropbox's access token with PIONE agents.
|
119
|
+
#
|
120
|
+
# @param tuple_space_server [TupleSpaceServer]
|
121
|
+
# tuple space server
|
122
|
+
# @param access_token [String]
|
123
|
+
# access token
|
64
124
|
# @return [void]
|
65
|
-
def
|
66
|
-
|
125
|
+
def share_access_token(tuple_space_server, access_token)
|
126
|
+
tuple = TupleSpace::AttributeTuple.new("dropbox_access_token", access_token)
|
127
|
+
tuple_space_server.write(tuple)
|
128
|
+
end
|
129
|
+
|
130
|
+
# Get code for CUI client.
|
131
|
+
#
|
132
|
+
# @return [Array]
|
133
|
+
# access token and Dropbox user ID
|
134
|
+
def get_code_for_cui_client(flow)
|
135
|
+
puts '1. Go to: %s' % flow.start
|
136
|
+
puts '2. Click "Allow"'
|
137
|
+
puts '3. Copy the authorization code'
|
138
|
+
print 'Enter the authorization code here: '
|
139
|
+
code = STDIN.gets.strip
|
140
|
+
flow.finish(code)
|
67
141
|
end
|
68
142
|
end
|
69
143
|
|
70
144
|
def initialize(uri)
|
71
145
|
super(uri)
|
72
|
-
@client = DropboxClient.new(self.class.session, "app_folder")
|
73
146
|
end
|
74
147
|
|
75
148
|
def create(data)
|
76
|
-
|
149
|
+
if exist?
|
150
|
+
raise ExistAlready.new(self)
|
151
|
+
else
|
152
|
+
client.put_file(@path.to_s, StringIO.new(data))
|
153
|
+
end
|
77
154
|
return self
|
78
155
|
end
|
79
156
|
|
80
157
|
def read
|
81
|
-
|
158
|
+
exist? ? client.get_file(@path.to_s) : (raise NotFound.new(self))
|
82
159
|
end
|
83
160
|
|
84
161
|
def update(data)
|
85
|
-
|
162
|
+
client.put_file(@path.to_s, StringIO.new(data), true)
|
86
163
|
return self
|
87
164
|
end
|
88
165
|
|
89
166
|
def delete
|
90
|
-
|
167
|
+
if exist?
|
168
|
+
client.file_delete(@path.to_s)
|
169
|
+
end
|
91
170
|
end
|
92
171
|
|
93
172
|
# dropbox have "modified" time only, therefore ctime is not implemented
|
94
173
|
|
95
174
|
def mtime
|
96
|
-
metadata =
|
175
|
+
metadata = client.metadata(@path.to_s)
|
97
176
|
Time.parse(metadata["modified"])
|
98
177
|
end
|
99
178
|
|
179
|
+
def size
|
180
|
+
metadata = client.metadata(@path.to_s)
|
181
|
+
return metadata["bytes"]
|
182
|
+
end
|
183
|
+
|
100
184
|
def entries(option={})
|
101
185
|
rel_entries(option).map {|entry| rebuild(@path + entry)}
|
102
186
|
end
|
@@ -104,10 +188,11 @@ module Pione
|
|
104
188
|
def rel_entries(option={})
|
105
189
|
list = []
|
106
190
|
raise NotFound.new(self) if not(directory?)
|
107
|
-
|
191
|
+
|
192
|
+
metadata = client.metadata(@path.to_s)
|
108
193
|
metadata["contents"].select{|entry| not(entry["is_deleted"])}.each do |entry|
|
109
|
-
list << entry["path"]
|
110
|
-
entry_location = rebuild(@path + entry)
|
194
|
+
list << entry["path"].sub(@path.to_s, "").sub(/^\//, "")
|
195
|
+
entry_location = rebuild(@path + File.basename(entry["path"]))
|
111
196
|
if option[:rec] and entry_location.directory?
|
112
197
|
_list = entry_location.rel_entries(option).map {|subentry| entry + subentry}
|
113
198
|
list = list + _list
|
@@ -117,25 +202,43 @@ module Pione
|
|
117
202
|
end
|
118
203
|
|
119
204
|
def exist?
|
120
|
-
metadata =
|
205
|
+
metadata = client.metadata(@path.to_s)
|
121
206
|
return not(metadata["is_deleted"])
|
207
|
+
rescue DropboxLocationUnavailable
|
208
|
+
raise
|
122
209
|
rescue DropboxError
|
123
210
|
return false
|
124
211
|
end
|
125
212
|
|
126
213
|
def file?
|
127
|
-
|
128
|
-
|
214
|
+
begin
|
215
|
+
metadata = client.metadata(@path.to_s)
|
216
|
+
return (not(metadata["is_dir"]) and not(metadata["is_deleted"]))
|
217
|
+
rescue DropboxError
|
218
|
+
# when there exists no files and no directories
|
219
|
+
false
|
220
|
+
end
|
129
221
|
end
|
130
222
|
|
131
223
|
def directory?
|
132
|
-
|
133
|
-
|
224
|
+
begin
|
225
|
+
metadata = client.metadata(@path.to_s)
|
226
|
+
return (metadata["is_dir"] and not(metadata["is_deleted"]))
|
227
|
+
rescue DropboxError
|
228
|
+
# when there exists no files and no directories
|
229
|
+
false
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
def mkdir
|
234
|
+
unless exist?
|
235
|
+
client.file_create_folder(@path.to_s)
|
236
|
+
end
|
134
237
|
end
|
135
238
|
|
136
239
|
def move(dest)
|
137
240
|
if dest.scheme == scheme
|
138
|
-
|
241
|
+
client.file_move(@path.to_s, dest.path)
|
139
242
|
else
|
140
243
|
copy(dest)
|
141
244
|
delete
|
@@ -143,10 +246,12 @@ module Pione
|
|
143
246
|
end
|
144
247
|
|
145
248
|
def copy(dest)
|
249
|
+
raise NotFound.new(self) unless exist?
|
250
|
+
|
146
251
|
if dest.scheme == scheme
|
147
|
-
|
252
|
+
client.file_copy(@path.to_s, dest.path)
|
148
253
|
else
|
149
|
-
dest.
|
254
|
+
dest.write(read)
|
150
255
|
end
|
151
256
|
end
|
152
257
|
|
@@ -161,6 +266,20 @@ module Pione
|
|
161
266
|
def turn(dest)
|
162
267
|
copy(dest)
|
163
268
|
end
|
269
|
+
|
270
|
+
private
|
271
|
+
|
272
|
+
# Check availability of Dropbox's access token.
|
273
|
+
#
|
274
|
+
# @return [void]
|
275
|
+
def client
|
276
|
+
if self.class.client.nil?
|
277
|
+
# raise an exception when Dropbox client isn't enabled
|
278
|
+
raise DropboxLocationUnavailable.new("There is no access token.")
|
279
|
+
else
|
280
|
+
self.class.client
|
281
|
+
end
|
282
|
+
end
|
164
283
|
end
|
165
284
|
end
|
166
285
|
end
|
@@ -3,7 +3,10 @@ module Pione
|
|
3
3
|
# FTPLocation represents locations on FTP server.
|
4
4
|
class FTPLocation < DataLocation
|
5
5
|
set_scheme "ftp"
|
6
|
-
|
6
|
+
|
7
|
+
define(:need_caching, true)
|
8
|
+
define(:real_appendable, false)
|
9
|
+
define(:writable, true)
|
7
10
|
|
8
11
|
# for myftp scheme
|
9
12
|
SCHEMES["myftp"] = self
|
@@ -2,8 +2,10 @@ module Pione
|
|
2
2
|
module Location
|
3
3
|
class HTTPLocation < DataLocation
|
4
4
|
set_scheme "http"
|
5
|
-
|
6
|
-
|
5
|
+
|
6
|
+
define(:need_caching, true)
|
7
|
+
define(:real_appendable, false)
|
8
|
+
define(:writable, false)
|
7
9
|
|
8
10
|
def read
|
9
11
|
http_get {|res| res.body}
|
@@ -33,7 +35,7 @@ module Pione
|
|
33
35
|
|
34
36
|
def copy(dest, option={})
|
35
37
|
# setup options
|
36
|
-
option[:keep_mtime]
|
38
|
+
option[:keep_mtime] = true if option[:keep_mtime].nil?
|
37
39
|
|
38
40
|
# copy
|
39
41
|
http_get {|rec| dest.write rec.body}
|