Class: Pakman::Fetcher
- Inherits:
-
Object
- Object
- Pakman::Fetcher
- Includes:
- LogUtils::Logging
- Defined in:
- lib/pakman/fetcher.rb
Instance Method Summary collapse
- #fetch_pak(manifestsrc, pakpath) ⇒ Object
-
#initialize(old_logger_do_not_use = nil) ⇒ Fetcher
constructor
todo/fix: remove logger from c’tor use logutils instead.
Constructor Details
#initialize(old_logger_do_not_use = nil) ⇒ Fetcher
todo/fix: remove logger from c’tor use logutils instead
11 12 13 14 15 |
# File 'lib/pakman/fetcher.rb', line 11 def initialize( old_logger_do_not_use=nil ) if old_logger_do_not_use != nil puts "*** depreciated API call [Pakman::Fetcher.initialize] - do NOT pass in logger; no longer required/needed; logger arg will get removed" end end |
Instance Method Details
#fetch_pak(manifestsrc, pakpath) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/pakman/fetcher.rb', line 17 def fetch_pak( manifestsrc, pakpath ) start = Time.now uri = URI.parse( manifestsrc ) logger.debug "scheme: #{uri.scheme}, host: #{uri.host}, port: #{uri.port}, path: #{uri.path}" dirname = File.dirname( uri.path ) filename = File.basename( uri.path ) # e.g. fullerscreen.txt (with extension) pakname = Pakman.pakname_from_file( uri.path ) logger.debug "dirname >#{dirname}<" logger.debug "filename >#{filename}<" logger.debug "pakname >#{pakname}<" dlbase = "#{uri.scheme}://#{uri.host}:#{uri.port}#{dirname}" logger.debug "dlbase: #{dlbase}" logger.debug "pakpath: #{pakpath}" FileUtils.makedirs( pakpath ) unless File.directory?( pakpath ) puts "Fetching template pack '#{pakname}'" puts " from '#{dlbase}'" puts " saving to '#{pakpath}'" # step 1: download manifest manifestdest = "#{pakpath}/#{filename}" puts " Downloading manifest '#{filename}'..." fetch_file( manifestsrc, manifestdest ) ## todo: change back to load_file_core after deprecated api got removed manifest = Manifest.load_file_core_v2( manifestdest ) # step 2: download files & templates listed in manifest manifest.each do |entry| source = entry[1] # get full (absolute) path and make sure path exists destfull = File.( source, pakpath ) # NB: turning source into dest destpath = File.dirname( destfull ) FileUtils.makedirs( destpath ) unless File.directory?( destpath ) logger.debug "destfull=>#{destfull}<" logger.debug "destpath=>#{destpath}<" sourcefull = "#{dlbase}/#{source}" if source =~ /\.erb\.|.erb$/ puts " Downloading template '#{source}'..." else puts " Downloading file '#{source}'..." end fetch_file( sourcefull, destfull ) end puts "Done (in #{Time.now-start} s)." end |