Class: ITunes::Store::Transporter::Shell

Inherits:
Object
  • Object
show all
Defined in:
lib/itunes/store/transporter/shell.rb

Overview

:nodoc:

Constant Summary collapse

EXE_NAME =
"iTMSTransporter"
WINDOWS_EXE =
"#{EXE_NAME}.CMD"
DEFAULT_UNIX_PATH =
"/usr/local/itms/bin/#{EXE_NAME}"
OSX_APPLICATION_LOADER_PATHS =
[
  "/Applications/Application Loader.app/Contents/MacOS/itms/bin/#{EXE_NAME}",
  "/Developer/Applications/Utilities/Application Loader.app/Contents/MacOS/itms/bin/#{EXE_NAME}"
]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path = nil) ⇒ Shell

Returns a new instance of Shell.



56
57
58
# File 'lib/itunes/store/transporter/shell.rb', line 56

def initialize(path = nil)
  @path = path || self.class.default_path
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



9
10
11
# File 'lib/itunes/store/transporter/shell.rb', line 9

def path
  @path
end

Class Method Details

.default_pathObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/itunes/store/transporter/shell.rb', line 31

def default_path
  case
    when windows?
      # The Transporter installer prefers x86
      # But... I think ruby normalizes this to just PROGRAMFILES
      root = ENV["PROGRAMFILES(x86)"] || ENV["PROGRAMFILES"] # Need C:\ in case?
      File.join(root, "itms", WINDOWS_EXE)
    when osx?
      paths = OSX_APPLICATION_LOADER_PATHS.dup
      root  = `xcode-select --print-path`.chomp rescue ""

      if !root.empty?
        ["/Applications/Application Loader.app/Contents/MacOS/itms/bin/#{EXE_NAME}",
         "/Applications/Application Loader.app/Contents/itms/bin/#{EXE_NAME}"].each do |path|
          paths << File.join(root, "..", path)
        end
      end

      paths.find { |path| File.exist?(path) } || DEFAULT_UNIX_PATH
    else
      DEFAULT_UNIX_PATH
  end
end

.osx?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/itunes/store/transporter/shell.rb', line 27

def osx?
  ChildProcess.os == :macosx
end

.windows?Boolean

Returns:

  • (Boolean)


21
22
23
24
25
# File 'lib/itunes/store/transporter/shell.rb', line 21

def windows?
  # We just need to know where iTMSTransporter lives, though cygwin
  # can crow when it receives a Windows path.
  ChildProcess.windows? || ChildProcess.os == :cygwin
end

Instance Method Details

#exec(argv, &block) ⇒ Object

Raises:

  • (ArgumentError)


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
# File 'lib/itunes/store/transporter/shell.rb', line 60

def exec(argv, &block)
  raise ArgumentError, "block required" unless block_given?

  begin
    process = ChildProcess.build(path, *argv)

    stdout = IO.pipe
    stderr = IO.pipe

    stdout[1].sync = true
    process.io.stdout = stdout[1]

    stderr[1].sync = true
    process.io.stderr = stderr[1]

    process.start

    stdout[1].close
    stderr[1].close

    poll(stdout[0], stderr[0], &block)
  rescue ChildProcess::Error, SystemCallError => e
    raise TransporterError, e.message
  ensure
    process.wait if process.alive?
    [ stdout, stderr ].flatten.each { |io| io.close if !io.closed? }
  end

  process.exit_code
end