asperalm 0.6.4 → 0.6.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9749508ddb4ef3b305ee518fd909811c6378a817
4
- data.tar.gz: 4487201c3eea02115c14066f633169d1b6ee45f7
3
+ metadata.gz: fccbe34e2b4034ab4baa993d533fed7634dd885a
4
+ data.tar.gz: 6285104d1ca1f0918446ea129b14af1f7be4d6a6
5
5
  SHA512:
6
- metadata.gz: 913dd975fdd39d37bc3e1896fe9cbb5967691a88bce0fc12cbc24d931c4676f662e24dcfffd1f2d3c44f4be9a4d387a4513eadb973de838d5c5a5cd4c4044ed9
7
- data.tar.gz: 10aae4d2205db44bc1590ea5e01e40ed5890dd4115200079dafabe7562697de243e6e5da5342a23994e3a19f9be7f3fb465517884d155f0dc5efac3f157ad170
6
+ metadata.gz: 49d279e5f138af297e49e95348f850457b3c821c8e49cc1c5a1cf04f286ba8e0153a4e1222986681d75d56be52b8c38355edc11edede31a4b8b8468d928db347
7
+ data.tar.gz: a4073e112b9fe10641ca652387fbc11fc935dd02e588d79c7663f06429c16868ace71b4b99c01d7a8f4d37b2ce14b947ef6541bf70251708ccb63dfa97f4d73e
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Laurent/2016-2018
4
4
 
5
- Version : 0.6.4
5
+ Version : 0.6.5
6
6
 
7
7
 
8
8
  This Gem provides a Ruby language interface to FASP session start and a cross platform (ruby based) command line tool (CLI) using (mostly REST)
@@ -965,7 +965,7 @@ aslmcli orchestrator workflow id 10 status
965
965
  aslmcli orchestrator workflow list
966
966
  aslmcli orchestrator workflow status
967
967
  aslmcli preview events --skip-types=office
968
- aslmcli preview scan --skip-types=office
968
+ aslmcli preview scan --skip-types=office --log-level=info
969
969
  aslmcli preview test ~/Documents/Samples/anatomic-2k/TG18-CH/TG18-CH-2k-01.dcm --log-level=debug png --video=clips
970
970
  aslmcli server browse /
971
971
  aslmcli server cp /Upload/200KB.1 /Upload/200KB.2
@@ -998,7 +998,7 @@ aslmcli shares2 userinfo
998
998
  ```bash
999
999
  $ aslmcli -h
1000
1000
  NAME
1001
- aslmcli -- a command line tool for Aspera Applications (v0.6.4)
1001
+ aslmcli -- a command line tool for Aspera Applications (v0.6.5)
1002
1002
 
1003
1003
  --interactive=ENUM use interactive input of missing params. Values=(yes,no), current=yes
1004
1004
  --ask-options=ENUM ask even optional options. Values=(yes,no), current=no
@@ -1,8 +1,10 @@
1
1
  require 'asperalm/log'
2
2
 
3
3
  module Asperalm
4
- # Methods for running +ascmd+ commands on a node.
5
- # equivalent of SDK "command client"
4
+ # Run +ascmd+ commands on a transfer node.
5
+ # Equivalent of SDK "command client"
6
+ # execute: "ascmd -h" to get syntax
7
+ # Note: "ls" can take filter: as_ls -f *.txt -f *.bin /
6
8
  class AsCmd
7
9
  # list of supported actions
8
10
  def self.action_list; [:ls,:rm,:mv,:du,:info,:mkdir,:cp,:df,:md5sum]; end
@@ -19,176 +21,125 @@ module Asperalm
19
21
  def execute_single(action_sym,args)
20
22
  # concatenate arguments, enclose in double quotes, protect backslash and double quotes, add "as_" command and as_exit
21
23
  stdin_input=(args||[]).map{|v| '"' + v.gsub(/["\\]/n) {|s| '\\' + s } + '"'}.unshift('as_'+action_sym.to_s).join(' ')+"\nas_exit\n"
22
- # execute and get binary output
23
- bin_response=@command_executor.execute('ascmd',stdin_input)
24
- # get hash or table
25
- result=self.class.parse_result(bin_response)
26
- # raise error as exception
27
- raise Error.new(result[:errno],result[:errstr],action_sym,args) if result.is_a?(Hash) and result.keys.sort == FIELDS[:error].map{|i|i[:name]}.sort
24
+ # execute, get binary output, get hash or table result
25
+ bytebuffer=@command_executor.execute('ascmd',stdin_input).unpack('C*')
26
+ result=self.class.parse(bytebuffer,:result)
27
+ raise "ERROR: unparsed bytes remaining" unless bytebuffer.empty?
28
+ # get and delete info,always present in results
29
+ system_info=result[:info]
30
+ result.delete(:info)
31
+ # make single file result like folder
32
+ if result.has_key?(:file);result[:dir]=[result[:file]];result.delete(:file);end
28
33
  # add type field for stats
29
- if action_sym.eql?(:ls)
30
- result.each do |file|
34
+ if result.has_key?(:dir)
35
+ result[:dir].each do |file|
31
36
  if file.has_key?(:smode)
32
37
  # Converts the first character of the file mode (see 'man ls') into a type.
33
- file[:type] = case file[:smode][0,1]
34
- when 'd'; :directory
35
- when '-'; :file
36
- when 'l'; :link
37
- else :other
38
- end
38
+ file[:type]=case file[:smode][0,1];when'd';:directory;when'-';:file;when'l';:link;else:other;end
39
39
  end
40
40
  end
41
41
  end
42
+ # for info, second overrides first, so restore it
43
+ case result.keys.length;when 0;result=system_info;when 1;result=result[result.keys.first];else raise "error";end
44
+ # raise error as exception
45
+ raise Error.new(result[:errno],result[:errstr],action_sym,args) if result.is_a?(Hash) and result.keys.sort == @@TYPES[:error][:fields].map{|i|i[:name]}.sort
42
46
  return result
43
47
  end # execute_single
44
48
 
45
49
  # This exception is raised when +ascmd+ returns an error.
46
- # @example
47
- # message "(2) No such file or directory"
48
- # rc 2
49
- # ascmd_message "No such file or directory"
50
- # command :ls
51
- # args ["/non_existent/directory"]
52
50
  class Error < StandardError
53
- attr_reader :rc, :ascmd_message, :command, :args
54
- # @param code(int), message(str), command(symbol), args(string array)
55
- def initialize(rc,msg,cmd,args)
56
- @rc=rc
57
- @ascmd_message=msg
58
- @command=cmd
59
- @args=args
60
- end
51
+ attr_reader :errno, :errstr, :command, :args
52
+ def initialize(errno,errstr,cmd,args);@errno=errno;@errstr=errstr;@command=cmd;@args=args;end
61
53
 
62
- def message; "ascmd: (#{rc}) #{ascmd_message}"; end
54
+ def message; "ascmd: (#{errno}) #{errstr}"; end
63
55
 
64
- def extended_message; "ascmd: rc=#{rc} msg=\"#{ascmd_message}\" command=\"#{command}\" args=#{args}"; end
56
+ def extended_message; "ascmd: errno=#{errno} errstr=\"#{errstr}\" command=\"#{command}\" args=#{args}"; end
65
57
  end # Error
66
58
 
67
59
  private
68
60
 
69
- ENUM_START=1
70
- # desription of result strutures
71
- # from ascmdtypes.h, note that enum values start at ENUM_START, not zero (array index)
72
- FIELDS={
73
- :response=>[{:name=>:file,:type=>:stat},{:name=>:dir,:type=>:stat,:array=>true},{:name=>:size,:type=>:size},{:name=>:error,:type=>:error},{:name=>:info,:type=>:info},{:name=>:success,:type=>nil,:return_true=>true},{:name=>:exit,:type=>nil},{:name=>:df,:type=>:mnt,:concatlist=>true},{:name=>:md5sum,:type=>:md5sum}],
74
- :stat=>[{:name=>:name,:type=>:zstr},{:name=>:size,:type=>:int64},{:name=>:mode,:type=>:int32,:check=>nil},{:name=>:zmode,:type=>:zstr},{:name=>:uid,:type=>:int32,:check=>nil},{:name=>:zuid,:type=>:zstr},{:name=>:gid,:type=>:int32,:check=>nil},{:name=>:zgid,:type=>:zstr},{:name=>:ctime,:type=>:epoch},{:name=>:zctime,:type=>:zstr},{:name=>:mtime,:type=>:epoch},{:name=>:zmtime,:type=>:zstr},{:name=>:atime,:type=>:epoch},{:name=>:zatime,:type=>:zstr},{:name=>:symlink,:type=>:zstr},{:name=>:errno,:type=>:int32},{:name=>:errstr,:type=>:zstr}],
75
- :info=>[{:name=>:platform,:type=>:zstr},{:name=>:version,:type=>:zstr},{:name=>:lang,:type=>:zstr},{:name=>:territory,:type=>:zstr},{:name=>:codeset,:type=>:zstr},{:name=>:lc_ctype,:type=>:zstr},{:name=>:lc_numeric,:type=>:zstr},{:name=>:lc_time,:type=>:zstr},{:name=>:lc_all,:type=>:zstr},{:name=>:dev,:type=>:zstr,:array=>true},{:name=>:browse_caps,:type=>:zstr},{:name=>:protocol,:type=>:zstr}],
76
- :size=>[{:name=>:size,:type=>:int64},{:name=>:fcount,:type=>:int32},{:name=>:dcount,:type=>:int32},{:name=>:failed_fcount,:type=>:int32},{:name=>:failed_dcount,:type=>:int32}],
77
- :error=>[{:name=>:errno,:type=>:int32},{:name=>:errstr,:type=>:zstr}],
78
- :mnt=>[{:name=>:fs,:type=>:zstr},{:name=>:dir,:type=>:zstr},{:name=>:type,:type=>:zstr},{:name=>:total,:type=>:int64},{:name=>:used,:type=>:int64},{:name=>:free,:type=>:int64},{:name=>:fcount,:type=>:int64},{:name=>:errno,:type=>:int32},{:name=>:errstr,:type=>:zstr}],
79
- :md5sum=>[{:name=>:md5sum,:type=>:zstr}]
61
+ # description of result structures ( see ascmdtypes.h). Base types are big endian
62
+ @@TYPES={
63
+ :result =>{:decode=>:field_list,:fields=>[{:name=>:file,:is_a=>:stat},{:name=>:dir,:is_a=>:stat,:special=>:substruct},{:name=>:size,:is_a=>:size},{:name=>:error,:is_a=>:error},{:name=>:info,:is_a=>:info},{:name=>:success,:is_a=>nil,:special=>:return_true},{:name=>:exit,:is_a=>nil},{:name=>:df,:is_a=>:mnt,:special=>:restart_on_first},{:name=>:md5sum,:is_a=>:md5sum}]},
64
+ :stat =>{:decode=>:field_list,:fields=>[{:name=>:name,:is_a=>:zstr},{:name=>:size,:is_a=>:int64},{:name=>:mode,:is_a=>:int32,:check=>nil},{:name=>:zmode,:is_a=>:zstr},{:name=>:uid,:is_a=>:int32,:check=>nil},{:name=>:zuid,:is_a=>:zstr},{:name=>:gid,:is_a=>:int32,:check=>nil},{:name=>:zgid,:is_a=>:zstr},{:name=>:ctime,:is_a=>:epoch},{:name=>:zctime,:is_a=>:zstr},{:name=>:mtime,:is_a=>:epoch},{:name=>:zmtime,:is_a=>:zstr},{:name=>:atime,:is_a=>:epoch},{:name=>:zatime,:is_a=>:zstr},{:name=>:symlink,:is_a=>:zstr},{:name=>:errno,:is_a=>:int32},{:name=>:errstr,:is_a=>:zstr}]},
65
+ :info =>{:decode=>:field_list,:fields=>[{:name=>:platform,:is_a=>:zstr},{:name=>:version,:is_a=>:zstr},{:name=>:lang,:is_a=>:zstr},{:name=>:territory,:is_a=>:zstr},{:name=>:codeset,:is_a=>:zstr},{:name=>:lc_ctype,:is_a=>:zstr},{:name=>:lc_numeric,:is_a=>:zstr},{:name=>:lc_time,:is_a=>:zstr},{:name=>:lc_all,:is_a=>:zstr},{:name=>:dev,:is_a=>:zstr,:special=>:multiple},{:name=>:browse_caps,:is_a=>:zstr},{:name=>:protocol,:is_a=>:zstr}]},
66
+ :size =>{:decode=>:field_list,:fields=>[{:name=>:size,:is_a=>:int64},{:name=>:fcount,:is_a=>:int32},{:name=>:dcount,:is_a=>:int32},{:name=>:failed_fcount,:is_a=>:int32},{:name=>:failed_dcount,:is_a=>:int32}]},
67
+ :error =>{:decode=>:field_list,:fields=>[{:name=>:errno,:is_a=>:int32},{:name=>:errstr,:is_a=>:zstr}]},
68
+ :mnt =>{:decode=>:field_list,:fields=>[{:name=>:fs,:is_a=>:zstr},{:name=>:dir,:is_a=>:zstr},{:name=>:is_a,:is_a=>:zstr},{:name=>:total,:is_a=>:int64},{:name=>:used,:is_a=>:int64},{:name=>:free,:is_a=>:int64},{:name=>:fcount,:is_a=>:int64},{:name=>:errno,:is_a=>:int32},{:name=>:errstr,:is_a=>:zstr}]},
69
+ :md5sum =>{:decode=>:field_list,:fields=>[{:name=>:md5sum,:is_a=>:zstr}]},
70
+ :int8 =>{:decode=>:base,:unpack=>'C',:size=>1},
71
+ :int32 =>{:decode=>:base,:unpack=>'L>',:size=>4},
72
+ :int64 =>{:decode=>:base,:unpack=>'Q>',:size=>8},
73
+ :epoch =>{:decode=>:base,:unpack=>'Q>',:size=>8},
74
+ :zstr =>{:decode=>:base,:unpack=>'Z*'},
75
+ :blist =>{:decode=>:buffer_list}
80
76
  }
81
77
 
82
- # sizeof(int8)
83
- TLV_SIZE_TYPE = 1
84
- # sizeof(int32)
85
- TLV_SIZE_LENGTH = 4
78
+ # protocol enum start at one, but array index start at zero
79
+ ENUM_START=1
86
80
 
87
- def self.parse_result(bin_response)
88
- result_fields = parse_list(bin_response)
89
- raise "extecting 2 parts" unless result_fields.length.eql?(2)
90
- # first entry is as_info, check, but ignore it
91
- raise "expecting info at start" unless FIELDS[:response][result_fields.first[:type]-ENUM_START][:type].eql?(:info)
92
- return parse_structure(FIELDS[:response][result_fields.last[:type]-ENUM_START],result_fields.last[:value])
81
+ def self.field_description(type_name,typed_buffer)
82
+ result=@@TYPES[type_name][:fields][typed_buffer[:btype]-ENUM_START]
83
+ raise "Unrecognized field for #{type_name}: #{typed_buffer[:btype]}\n#{typed_buffer[:buffer]}" if result.nil?
84
+ return result
93
85
  end
94
86
 
95
- #
96
- def self.parse_structure(field_descr,bin_value)
97
- if field_descr[:array]
98
- return parse_list(bin_value).map{|r|parse_structure({:name=>field_descr[:name],:type=>field_descr[:type]},r[:value])}
99
- end
100
- return true if field_descr[:return_true]
101
- hash_response = {}
102
- array_response = []
103
- fields_info=FIELDS[field_descr[:type]]
104
- parse_list(bin_value).each do |field|
105
- field_info=fields_info[field[:type]-ENUM_START]
106
- raise "Unrecognized field: #{field[:type]}\n#{field[:value]}" if fields_info.nil?
107
- # if destination != hash_response, then field is a simple list of values
108
- destination=hash_response
109
- if field_info[:array]
110
- # special case: field is a list of values
111
- hash_response[field_info[:name]]||=[]
112
- destination={}
87
+ # @return a decoded type. :base : value, :buffer_list : an array of {btype,buffer}, :field_list : a hash, or array
88
+ def self.parse(buffer,type_name,state=nil)
89
+ state=state.nil? ? 0 : state+1
90
+ type_descr=@@TYPES[type_name]
91
+ raise "Unexpected type #{type_name}" if type_descr.nil?
92
+ Log.log.debug("#{" ."*state}parse:#{type_name}:#{type_descr[:decode]}:#{buffer[0,16]}...".red)
93
+ #return true if type_descr[:return_true]
94
+ result=nil
95
+ case type_descr[:decode]
96
+ when :base
97
+ num_bytes=type_name.eql?(:zstr) ? buffer.length : type_descr[:size]
98
+ raise "ERROR:not enough bytes" if buffer.length < num_bytes
99
+ byte_array=buffer.shift(num_bytes);byte_array=[byte_array] unless byte_array.is_a?(Array)
100
+ result=byte_array.pack('C*').unpack(type_descr[:unpack]).first
101
+ Log.log.debug("#{" ."*state}-> base:#{byte_array} -> #{result}")
102
+ result=Time.at(result) if type_name.eql?(:epoch)
103
+ when :buffer_list
104
+ result = []
105
+ while !buffer.empty?
106
+ btype=parse(buffer,:int8,state)
107
+ length=parse(buffer,:int32,state)
108
+ raise "ERROR:not enough bytes" if buffer.length < length
109
+ value=buffer.shift(length)
110
+ result.push({:btype=>btype,:buffer=>value})
111
+ Log.log.debug("#{" ."*state}:buffer_list[#{result.length-1}] #{result.last}")
113
112
  end
114
- if field_descr[:concatlist] and 1.eql?(field[:type])
115
- # special case: concatenated list
116
- # restart a new element at index 1
117
- hash_response={}
118
- destination=hash_response
119
- array_response.push(hash_response)
113
+ when :field_list
114
+ # by default the result is one struct
115
+ result = {}
116
+ # get individual binary fields
117
+ parse(buffer,:blist,state).each do |typed_buffer|
118
+ # what type of field is it ?
119
+ field_info=field_description(type_name,typed_buffer)
120
+ Log.log.debug("#{" ."*state}+ field(special=#{field_info[:special]})=#{field_info[:name]}".green)
121
+ case field_info[:special]
122
+ when nil
123
+ result[field_info[:name]]=parse(typed_buffer[:buffer],field_info[:is_a],state)
124
+ when :return_true
125
+ result[field_info[:name]]=true
126
+ when :substruct
127
+ result[field_info[:name]]=parse(typed_buffer[:buffer],:blist,state).map{|r|parse(r[:buffer],field_info[:is_a],state)}
128
+ when :multiple
129
+ result[field_info[:name]]||=[]
130
+ result[field_info[:name]].push(parse(typed_buffer[:buffer],field_info[:is_a],state))
131
+ when :restart_on_first
132
+ fl=result[field_info[:name]]=[]
133
+ parse(typed_buffer[:buffer],:blist,state).map do |tb|
134
+ fl.push({}) if tb[:btype].eql?(ENUM_START)
135
+ fi=field_description(field_info[:is_a],tb)
136
+ fl.last[fi[:name]]=parse(tb[:buffer],fi[:is_a],state)
137
+ end
138
+ end
120
139
  end
121
- # this level has only simple types
122
- parse_simple(destination,field_info[:name],field_info[:type],field[:value])
123
- # special case: field is a list of values
124
- hash_response[field_info[:name]].push(destination[field_info[:name]]) unless destination.eql?(hash_response)
125
- end
126
- # special case: concatenated list
127
- return array_response if field_descr[:concatlist]
128
- hash_response
129
- end
130
-
131
- # parse a list of fields
132
- def self.parse_list(bin_value)
133
- result = []
134
- offset = 0
135
- while (offset+TLV_SIZE_TYPE+TLV_SIZE_LENGTH) <= bin_value.length
136
- field={}
137
- offset+=parse_simple(field,:type,:int8,bin_value[offset])
138
- offset+=parse_simple(field,:length,:int32,bin_value[offset,TLV_SIZE_LENGTH])
139
- field[:value] = bin_value[offset, field[:length]]
140
- offset+=field[:length]
141
- result.push(field)
142
- Log.log.debug("[#{result.length-1}] #{result.last}")
143
- end
144
- raise "extra bytes found: offset=#{offset}, length=#{bin_value.length}" unless offset.eql?(bin_value.length)
145
- result
146
- end
147
-
148
- # note we assume same endian as server (native)
149
- def self.parse_simple(hash,key,type,bin_value)
150
- size=nil
151
- hash[key]=case type
152
- when :int8; size=1;bin_value.unpack('C').first
153
- when :int32; size=4;bin_value.unpack('L>').first
154
- when :int64; size=8;bin_value.unpack('Q>').first
155
- when :zstr; size=bin_value.length;bin_value.unpack('Z*').first
156
- when :epoch; size=parse_simple(hash,key,:int64,bin_value);Time.at(hash[key]) rescue nil
157
- else raise "Unexpected type #{type}"
158
- end
159
- return size
160
- end
161
- end
162
- end
163
-
164
- if ENV.has_key?('TESTIT')
165
- class LocalExecutor
166
- def execute(cmd,line)
167
- Asperalm::Log.log.info("[#{line}]")
168
- #`echo "#{line}"|ssh root@10.25.0.8 #{cmd}`
169
- `echo "#{line}"|#{cmd}`
170
- end
171
- end
172
- ascmd=Asperalm::AsCmd.new(LocalExecutor.new)
173
- #Asperalm::Log.level=:debug
174
- [
175
- ['info'],
176
- ['ls','/core.1127'],
177
- ['ls','/'],
178
- ['mkdir','/123'],
179
- ['mv','/123','/234'],
180
- ['rm','/234'],
181
- ['du','/Users/xfer'],
182
- ['cp','/tmp/123','/tmp/1234'],
183
- ['df','/'],
184
- ['df'],
185
- ['md5sum','/dev/null']
186
- ].each do |t|
187
- begin
188
- puts "testing: #{t}"
189
- puts ascmd.send(:execute_single,t.shift,t)
190
- rescue Asperalm::AsCmd::Error => e
191
- puts e.extended_message
140
+ else raise "error: unknown decode:#{type_descr[:decode]}"
141
+ end # is_a
142
+ return result
192
143
  end
193
144
  end
194
145
  end
@@ -4,7 +4,7 @@ require 'asperalm/fasp/agent'
4
4
  require 'asperalm/fasp/manager'
5
5
  require 'asperalm/fasp/listener_logger'
6
6
  require 'asperalm/fasp/listener_progress'
7
- require 'asperalm/operating_system'
7
+ require 'asperalm/open_application'
8
8
  require 'asperalm/log'
9
9
  require 'asperalm/oauth'
10
10
  require 'text-table'
@@ -22,7 +22,7 @@ module Asperalm
22
22
  singleton_class.send(:alias_method, :tool, :instance)
23
23
  def self.version;return @@TOOL_VERSION;end
24
24
  private
25
- @@TOOL_VERSION='0.6.4'
25
+ @@TOOL_VERSION='0.6.5'
26
26
  # first level command for the main tool
27
27
  @@MAIN_PLUGIN_NAME_STR='config'
28
28
  # name of application, also foldername where config is stored
@@ -138,9 +138,9 @@ module Asperalm
138
138
  @logtype_cache=value
139
139
  end
140
140
 
141
- def option_browser; OperatingSystem.open_url_method; end
141
+ def option_browser; OpenApplication.instance.url_method; end
142
142
 
143
- def option_browser=(value); OperatingSystem.open_url_method=value; end
143
+ def option_browser=(value); OpenApplication.instance.url_method=value; end
144
144
 
145
145
  # def option_fasp_folder; Fasp::Installation.instance.paths; end
146
146
  #
@@ -290,7 +290,7 @@ module Asperalm
290
290
 
291
291
  def declare_options
292
292
  @options.parser.separator "OPTIONS: global"
293
- @options.set_option(:gui_mode,OperatingSystem.default_gui_mode)
293
+ @options.set_option(:gui_mode,OpenApplication.default_gui_mode)
294
294
  @options.set_option(:fields,FIELDS_DEFAULT)
295
295
  @options.set_option(:transfer,:ascp)
296
296
  @options.set_option(:insecure,:no)
@@ -301,7 +301,7 @@ module Asperalm
301
301
  #options.set_option(:to_folder,'.')
302
302
  @options.parser.on("-h", "--help", "Show this message.") { @option_help=true }
303
303
  @options.parser.on("--show-config", "Display parameters used for the provided action.") { @option_show_config=true }
304
- @options.add_opt_list(:gui_mode,OperatingSystem.gui_modes,"method to start browser",'-gTYPE')
304
+ @options.add_opt_list(:gui_mode,OpenApplication.gui_modes,"method to start browser",'-gTYPE')
305
305
  @options.add_opt_list(:insecure,[:yes,:no],"do not validate HTTPS certificate")
306
306
  @options.add_opt_list(:flat_hash,[:yes,:no],"display hash values as additional keys")
307
307
  @options.add_opt_list(:log_level,Log.levels,"Log level")
@@ -563,10 +563,10 @@ module Asperalm
563
563
  return Main.status_result("updated: #{config_name}")
564
564
  end
565
565
  when :documentation
566
- OperatingSystem.open_uri(@@HELP_URL)
566
+ OpenApplication.instance.uri(@@HELP_URL)
567
567
  return Main.no_result
568
568
  when :open
569
- OperatingSystem.open_uri(current_config_file)
569
+ OpenApplication.instance.uri(current_config_file)
570
570
  return Main.no_result
571
571
  when :genkey # generate new rsa key
572
572
  key_filepath=@options.get_next_argument('private key file path')
@@ -128,16 +128,19 @@ module Asperalm
128
128
  when :create #
129
129
  params=Main.tool.options.get_option(:params,:optional)
130
130
  params={} if params.nil?
131
- # if transfer_server_id not provided, get it from options
131
+ server_data=nil
132
+ # if transfer_server_id not provided, get it from command line options
132
133
  if !params.has_key?('transfer_server_id')
133
- params['transfer_server_id']=server_by_cloud_region['id']
134
+ server_data=server_by_cloud_region
135
+ params['transfer_server_id']=server_data['id']
134
136
  end
137
+ Log.log.debug("using params: #{params}".bg_red.gray)
135
138
  if params.has_key?('storage')
136
139
  case params['storage']['type']
137
140
  # here we need somehow to map storage type to field to get for auth end point
138
141
  when 'softlayer_swift'
139
142
  if !params['storage'].has_key?('authentication_endpoint')
140
- server_data=all_servers.select {|i| i['id'].eql?(params['transfer_server_id'])}.first
143
+ server_data||=all_servers.select{|i|i['id'].eql?(params['transfer_server_id'])}.first
141
144
  params['storage']['credentials']['authentication_endpoint'] = server_data['swift_authentication_endpoint']
142
145
  end
143
146
  end
@@ -1,7 +1,7 @@
1
1
  require 'asperalm/cli/main'
2
2
  require 'asperalm/cli/plugins/node'
3
3
  require 'asperalm/fasp/installation'
4
- require 'asperalm/operating_system'
4
+ require 'asperalm/open_application'
5
5
 
6
6
  module Asperalm
7
7
  module Cli
@@ -75,7 +75,7 @@ module Asperalm
75
75
  api_connect_cdn.call({:operation=>'GET',:subpath=>fileurl,:save_to_file=>File.join(folder_dest,filename)})
76
76
  return {:data=>"downloaded: #{filename}",:type => :status}
77
77
  when :open #
78
- OperatingSystem.open_uri(one_link['href'])
78
+ OpenApplication.instance.uri(one_link['href'])
79
79
  return {:data=>"opened: #{one_link['href']}",:type => :status}
80
80
  end
81
81
  end
@@ -1,7 +1,7 @@
1
1
  require 'asperalm/cli/main'
2
2
  require 'asperalm/cli/basic_auth_plugin'
3
3
  require 'asperalm/cli/plugins/node'
4
- require 'asperalm/operating_system'
4
+ require 'asperalm/open_application'
5
5
  require 'asperalm/fasp/uri'
6
6
  require 'xmlsimple'
7
7
 
@@ -223,7 +223,7 @@ module Asperalm
223
223
  api_faspex=Rest.new(link_data[:faspex_base_url],{})
224
224
  pkgdatares=api_faspex.call({:operation=>'GET',:subpath=>link_data[:subpath],:url_params=>{:passcode=>link_data[:passcode]},:headers=>{'Accept'=>'application/xml'}})
225
225
  if !pkgdatares[:http].body.start_with?('<?xml ')
226
- OperatingSystem.open_uri(thelink)
226
+ OpenApplication.instance.uri(thelink)
227
227
  raise CliError, "no such package"
228
228
  end
229
229
  package_entry=XmlSimple.xml_in(pkgdatares[:http].body, {"ForceArray" => false})
@@ -1,6 +1,7 @@
1
1
  require 'asperalm/fasp/installation'
2
2
  require 'asperalm/fasp/resumer'
3
3
  require 'asperalm/fasp/manager'
4
+ require 'asperalm/open_application'
4
5
  require 'securerandom'
5
6
 
6
7
  module Asperalm
@@ -24,7 +25,7 @@ module Asperalm
24
25
  end
25
26
 
26
27
  def start_transfer_connect(transfer_spec)
27
- raise "Using connect requires a graphical environment" if !OperatingSystem.default_gui_mode.eql?(:graphical)
28
+ raise "Using connect requires a graphical environment" if !OpenApplication.default_gui_mode.eql?(:graphical)
28
29
  trynumber=0
29
30
  begin
30
31
  Log.log.debug("reading connect port file")
@@ -35,7 +36,7 @@ module Asperalm
35
36
  raise CliError,"Unable to start connect after #{trynumber} try" if trynumber > 3
36
37
  Log.log.warn("connect is not started, trying to start (#{trynumber}) : #{e}")
37
38
  trynumber+=1
38
- OperatingSystem.open_uri_graphical('fasp://initialize')
39
+ OpenApplication.uri_graphical('fasp://initialize')
39
40
  sleep 2
40
41
  retry
41
42
  end
@@ -1,5 +1,5 @@
1
1
  require 'asperalm/log'
2
- require 'asperalm/operating_system'
2
+ require 'asperalm/open_application'
3
3
  require 'singleton'
4
4
  require 'xmlsimple'
5
5
 
@@ -89,7 +89,7 @@ module Asperalm
89
89
  # returns product folders depending on OS
90
90
  def product_locations
91
91
  common_places=[]
92
- case OperatingSystem.current_os_type
92
+ case OpenApplication.current_os_type
93
93
  when :mac
94
94
  common_places.push({
95
95
  :expected=>'Connect Client',
@@ -36,7 +36,7 @@ module Asperalm
36
36
  require 'syslog/logger'
37
37
  @@logobj = Syslog::Logger.new("aslmcli")
38
38
  else
39
- raise "unknown log type: #{logtype}"
39
+ raise "unknown log type: #{logtype.class} #{logtype}"
40
40
  end
41
41
  @@logobj.level=current_severity_integer
42
42
  end
@@ -5,7 +5,7 @@
5
5
  # Laurent Martin
6
6
  #
7
7
  ##############################################################################
8
- require 'asperalm/operating_system'
8
+ require 'asperalm/open_application'
9
9
  require 'asperalm/rest'
10
10
  require 'asperalm/files_api'
11
11
  require 'base64'
@@ -263,7 +263,7 @@ module Asperalm
263
263
  def self.goto_page_and_get_request(redirect_uri,login_page_url,html_page=THANK_YOU_HTML)
264
264
  Log.log.info "login_page_url=#{login_page_url}".bg_red().gray()
265
265
  # browser start is not blocking
266
- OperatingSystem.open_uri(login_page_url)
266
+ OpenApplication.instance.uri(login_page_url)
267
267
  port=URI.parse(redirect_uri).port
268
268
  Log.log.info "listening on port #{port}"
269
269
  request_params=nil
@@ -1,13 +1,14 @@
1
1
  require 'asperalm/log'
2
2
  require 'rbconfig'
3
+ require 'singleton'
3
4
 
4
5
  module Asperalm
5
6
  # Allows a user to open a Url
6
7
  # if method is "text", then URL is displayed on terminal
7
8
  # if method is "graphical", then the URL will be opened with the default browser.
8
- class OperatingSystem
9
+ class OpenApplication
10
+ include Singleton
9
11
  def self.gui_modes; [ :text, :graphical ]; end
10
- @@open_url_method=:text
11
12
 
12
13
  def self.default_gui_mode
13
14
  case current_os_type
@@ -21,14 +22,6 @@ module Asperalm
21
22
  end
22
23
  end
23
24
 
24
- def self.open_url_method=(value)
25
- @@open_url_method=value
26
- end
27
-
28
- def self.open_url_method()
29
- @@open_url_method
30
- end
31
-
32
25
  def self.current_os_type
33
26
  case RbConfig::CONFIG['host_os']
34
27
  when /darwin|mac os/
@@ -41,7 +34,7 @@ module Asperalm
41
34
  end
42
35
 
43
36
  # command must be non blocking
44
- def self.open_uri_graphical(uri)
37
+ def self.uri_graphical(uri)
45
38
  case current_os_type
46
39
  when :mac
47
40
  system("open '#{uri.to_s}'")
@@ -52,9 +45,15 @@ module Asperalm
52
45
  end
53
46
  end
54
47
 
48
+ attr_accessor :url_method
49
+
50
+ def initialize
51
+ @url_method=:text
52
+ end
53
+
55
54
  # this is non blocking
56
- def self.open_uri(the_url)
57
- case @@open_url_method
55
+ def uri(the_url)
56
+ case @url_method
58
57
  when :graphical
59
58
  open_uri_graphical(the_url)
60
59
  when :text
@@ -65,8 +64,8 @@ module Asperalm
65
64
  puts "USER ACTION: open this:\n"+the_url.to_s.red()+"\n"
66
65
  end
67
66
  else
68
- raise StandardError,"unsupported url open method: #{@@open_url_method}"
67
+ raise StandardError,"unsupported url open method: #{@url_method}"
69
68
  end
70
69
  end
71
- end # OperatingSystem
70
+ end # OpenApplication
72
71
  end # Asperalm
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: asperalm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.4
4
+ version: 0.6.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Laurent Martin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-02-23 00:00:00.000000000 Z
11
+ date: 2018-03-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: xml-simple
@@ -142,14 +142,14 @@ dependencies:
142
142
  name: rspec
143
143
  requirement: !ruby/object:Gem::Requirement
144
144
  requirements:
145
- - - "~>"
145
+ - - ">="
146
146
  - !ruby/object:Gem::Version
147
147
  version: '3.0'
148
148
  type: :development
149
149
  prerelease: false
150
150
  version_requirements: !ruby/object:Gem::Requirement
151
151
  requirements:
152
- - - "~>"
152
+ - - ">="
153
153
  - !ruby/object:Gem::Version
154
154
  version: '3.0'
155
155
  description: A sample CLI for Aspera products.
@@ -201,7 +201,7 @@ files:
201
201
  - lib/asperalm/files_api.rb
202
202
  - lib/asperalm/log.rb
203
203
  - lib/asperalm/oauth.rb
204
- - lib/asperalm/operating_system.rb
204
+ - lib/asperalm/open_application.rb
205
205
  - lib/asperalm/preview/generator.rb
206
206
  - lib/asperalm/preview/options.rb
207
207
  - lib/asperalm/preview/utils.rb