Class: Pakman::Fetcher

Inherits:
Object
  • Object
show all
Includes:
LogUtils::Logging
Defined in:
lib/pakman/fetcher.rb

Instance Method Summary collapse

Instance Method Details

#fetch_pak(manifestsrc, pakpath) ⇒ Object



10
11
12
13
14
15
16
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
# File 'lib/pakman/fetcher.rb', line 10

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 )

  logger.info "Fetching template pack '#{pakname}'"
  logger.info "    from '#{dlbase}'"
  logger.info "    saving to '#{pakpath}'"

  # step 1: download manifest
  manifestdest = "#{pakpath}/#{filename}"

  logger.info "  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.expand_path( 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$/
      logger.info "  Downloading template '#{source}'..."
    else
      logger.info "  Downloading file '#{source}'..."
    end

    fetch_file( sourcefull, destfull )
  end
  logger.info "Done (in #{Time.now-start} s)."
end