Class: SiSU_Remote::Get

Inherits:
Object
  • Object
show all
Defined in:
lib/sisu/remote.rb

Instance Method Summary collapse

Constructor Details

#initialize(opt, get_s) ⇒ Get

Returns a new instance of Get.



133
134
135
136
137
138
139
140
141
# File 'lib/sisu/remote.rb', line 133

def initialize(opt,get_s)
  @opt,@get_s=opt,get_s
  @msg,@msgs='',nil
  @tell=lambda {
    SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],
    @msg,
    "#{@msgs.inspect if @msgs}")
  }
end

Instance Method Details

#fnsObject



142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
# File 'lib/sisu/remote.rb', line 142

def fns
  begin
    require 'open-uri'
    require 'pp'
  rescue LoadError
    SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:fuchsia).
      error('open-uri or pp NOT FOUND (LoadError)')
  end
  require_relative 'ao_composite'                   # ao_composite.rb
  @rgx_image=/(?:^|[^_\\])\{\s*(\S+?\.(?:png|jpg|gif))/
  threads=[]
  for requested_page in @get_s
    re_fnb=/((?:https?|file):\/\/[^\/ ]+?\/[^\/ ]+?)\/\S+?\/([^\/]+?)\.ss(t)/ #revisit and remove DO
    threads << Thread.new(requested_page) do |url|
      open(url) do |f|
        raise "#{url} not found" unless f
        base_uri,fnb=re_fnb.match(url)[1..2] if re_fnb
        imagedir=base_uri + '/_sisu/image' #check on
        downloaded_file=File.new("#{fnb}.-sst",'w+')
        image_download_url=SiSU_Assemble::RemoteImage.new.image(imagedir)
        images=[]
        f.collect.each do |r|                            # work area
          unless r =~/^%+\s/
            if r !~/^%+\s/ \
            and r =~@rgx_image
              images << r.scan(@rgx_image).uniq
            end
          end
          downloaded_file << r
        end
        if images \
        and images.length > 1
          images=images.flatten.uniq
          images.delete_if {|x| x =~/https?:\/\// }
          images=images.sort
          @msg,@msgs='downloading images:', [ images.join(',') ]
          @tell.call.warn unless @opt.act[:quiet][:set]==:on
          image_info=image_download_url + images
          SiSU_Assemble::RemoteImage.new.download_images(image_info)
          #SiSU_Assemble::RemoteImage.new.download_images(image_download_url,images)
          @msg,@msgs='downloading done',nil
          @tell.call.warn unless @opt.act[:quiet][:set]==:on
        end
        downloaded_file.close
      end
    end
  end
  threads.each {|thr| thr.join} if threads #and threads.length > 0
end

#sisupodObject



191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
# File 'lib/sisu/remote.rb', line 191

def sisupod
  get_p=@get_s
  if get_p.length > 0                                     #% remote sisupod
    begin
      require 'net/http'
    rescue LoadError
      SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:fuchsia).
        error('net/http NOT FOUND (LoadError)')
    end
    for requested_pod in get_p
      pod_info=RemoteDownload.new(requested_pod)
      Net::HTTP.start(pod_info.pod.site) do |http|
        resp=http.get("#{pod_info.pod.path}/#{pod_info.pod.name_source}")
        open(pod_info.pod.name,'wb') do |file|
          file.write(resp.body)
         end
      end
    end
  end
end