Class: Aspera::Ascp::Products

Inherits:
Object
  • Object
show all
Defined in:
lib/aspera/ascp/products.rb

Overview

find Aspera standard products installation in standard paths

Constant Summary collapse

CONNECT =

known product names

'IBM Aspera Connect'
ASPERA =
'IBM Aspera (Client)'
CLI_V1 =
'Aspera CLI (deprecated)'
DRIVE =
'Aspera Drive (deprecated)'
HSTS =
'IBM Aspera High-Speed Transfer Server'
INFO_META_FILE =

product information manifest: XML (part of aspera product)

'product-info.mf'
BIN_SUBFOLDER =
'bin'
ETC_SUBFOLDER =
'etc'
VAR_RUN_SUBFOLDER =
File.join('var', 'run')
@@found_products =

rubocop:disable Style/ClassVars

nil

Class Method Summary collapse

Class Method Details

.ascp_filenameObject

filename for ascp with optional extension (Windows)



128
129
130
# File 'lib/aspera/ascp/products.rb', line 128

def ascp_filename
  return "ascp#{Environment.exe_extension}"
end

.connect_uriObject

Returns the file path of local connect where API’s URI can be read.

Returns:

  • the file path of local connect where API’s URI can be read



141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/aspera/ascp/products.rb', line 141

def connect_uri
  connect = folders(CONNECT)
  folder = File.join(connect[:run_root], VAR_RUN_SUBFOLDER)
  ['', 's'].each do |ext|
    uri_file = File.join(folder, "http#{ext}.uri")
    Log.log.debug{"checking connect port file: #{uri_file}"}
    if File.exist?(uri_file)
      return File.open(uri_file, &:gets).strip
    end
  end
  raise "no connect uri file found in #{folder}"
end

.folders(name) ⇒ Object

Returns folder paths for specified applications.

Parameters:

  • name

    Connect or CLI

Returns:

  • folder paths for specified applications



134
135
136
137
138
# File 'lib/aspera/ascp/products.rb', line 134

def folders(name)
  found = Products.installed_products.select{|i|i[:expected].eql?(name) || i[:name].eql?(name)}
  raise "Product: #{name} not found, please install." if found.empty?
  return found.first
end

.installed_productsObject

Returns the list of installed products in format of product_locations_on_current_os.

Returns:

  • the list of installed products in format of product_locations_on_current_os



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/aspera/ascp/products.rb', line 94

def installed_products
  if @@found_products.nil?
    scan_locations = product_locations_on_current_os.clone
    # add SDK as first search path
    scan_locations.unshift({
      expected: 'SDK',
      app_root: Installation.instance.sdk_folder,
      sub_bin:  ''
    })
    # search installed products: with ascp
    @@found_products = scan_locations.select! do |item| # rubocop:disable Style/ClassVars
      # skip if not main folder
      next false unless Dir.exist?(item[:app_root])
      Log.log.debug{"Found #{item[:app_root]}"}
      sub_bin = item[:sub_bin] || BIN_SUBFOLDER
      item[:ascp_path] = File.join(item[:app_root], sub_bin, ascp_filename)
      # skip if no ascp
      next false unless File.exist?(item[:ascp_path])
      # read info from product info file if present
      product_info_file = "#{item[:app_root]}/#{INFO_META_FILE}"
      if File.exist?(product_info_file)
        res_s = XmlSimple.xml_in(File.read(product_info_file), {'ForceArray' => false})
        item[:name] = res_s['name']
        item[:version] = res_s['version']
      else
        item[:name] = item[:expected]
      end
      true # select this version
    end
  end
  return @@found_products
end

.product_locations_on_current_osObject

:expected M app name is taken from the manifest if present, else defaults to this value :app_root M main folder for the application :log_root O location of log files (Linux uses syslog) :run_root O only for Connect Client, location of http port file :sub_bin O subfolder with executables, default : bin

Returns:

  • product folders depending on OS fields



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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/aspera/ascp/products.rb', line 30

def product_locations_on_current_os
  result =
    case Aspera::Environment.os
    when Aspera::Environment::OS_WINDOWS then [{
      expected: CONNECT,
      app_root: File.join(ENV.fetch('LOCALAPPDATA', nil), 'Programs', 'Aspera', 'Aspera Connect'),
      log_root: File.join(ENV.fetch('LOCALAPPDATA', nil), 'Aspera', 'Aspera Connect', 'var', 'log'),
      run_root: File.join(ENV.fetch('LOCALAPPDATA', nil), 'Aspera', 'Aspera Connect')
    }, {
      expected: CLI_V1,
      app_root: File.join('C:', 'Program Files', 'Aspera', 'cli'),
      log_root: File.join('C:', 'Program Files', 'Aspera', 'cli', 'var', 'log')
    }, {
      expected: HSTS,
      app_root: File.join('C:', 'Program Files', 'Aspera', 'Enterprise Server'),
      log_root: File.join('C:', 'Program Files', 'Aspera', 'Enterprise Server', 'var', 'log')
    }]
    when Aspera::Environment::OS_MACOS then [{
      expected: CONNECT,
      app_root: File.join(Dir.home, 'Applications', 'Aspera Connect.app'),
      log_root: File.join(Dir.home, 'Library', 'Logs', 'Aspera_Connect'),
      run_root: File.join(Dir.home, 'Library', 'Application Support', 'Aspera', 'Aspera Connect'),
      sub_bin:  File.join('Contents', 'Resources')
    }, {
      expected: CONNECT,
      app_root: File.join('', 'Applications', 'Aspera Connect.app'),
      log_root: File.join(Dir.home, 'Library', 'Logs', 'Aspera_Connect'),
      run_root: File.join(Dir.home, 'Library', 'Application Support', 'Aspera', 'Aspera Connect'),
      sub_bin:  File.join('Contents', 'Resources')
    }, {
      expected: CLI_V1,
      app_root: File.join(Dir.home, 'Applications', 'Aspera CLI'),
      log_root: File.join(Dir.home, 'Library', 'Logs', 'Aspera')
    }, {
      expected: HSTS,
      app_root: File.join('', 'Library', 'Aspera'),
      log_root: File.join(Dir.home, 'Library', 'Logs', 'Aspera')
    }, {
      expected: DRIVE,
      app_root: File.join('', 'Applications', 'Aspera Drive.app'),
      log_root: File.join(Dir.home, 'Library', 'Logs', 'Aspera_Drive'),
      sub_bin:  File.join('Contents', 'Resources')
    }, {
      expected: ASPERA,
      app_root: File.join('', 'Applications', 'IBM Aspera.app'),
      log_root: File.join(Dir.home, 'Library', 'Logs', 'IBM Aspera'),
      sub_bin:  File.join('Contents', 'Resources', 'sdk', 'aspera', 'bin')
    }]
    else [{ # other: Linux and Unix family
      expected: CONNECT,
      app_root: File.join(Dir.home, '.aspera', 'connect'),
      run_root: File.join(Dir.home, '.aspera', 'connect')
    }, {
      expected: CLI_V1,
      app_root: File.join(Dir.home, '.aspera', 'cli')
    }, {
      expected: HSTS,
      app_root: File.join('', 'opt', 'aspera')
    }]
    end
  result # .each {|item| item.deep_do {|h, _k, _v, _m|h.freeze}}.freeze
end