Class: Sprout::System::UnixSystem

Inherits:
BaseSystem show all
Defined in:
flashsdk/lib/flashsdk/adl.rb,
sprout/lib/sprout/system/unix_system.rb,
flashsdk/lib/flashplayer/system_mixins.rb

Overview

All others inherit from this class

Direct Known Subclasses

OSXSystem

Instance Method Summary (collapse)

Methods inherited from BaseSystem

#alt_separator?, #application_home, #env_home, #env_homedrive, #env_homedrive_and_homepath, #env_homepath, #env_userprofile, #execute_silent, #execute_thread, #find_home, #get_and_execute_process_runner, #get_process_runner, #home, #home=, #library, #read_from, #tilde_home, #worst_case_home

Instance Method Details

- (Object) attempt_to_repair_executable(path)

Repair Windows Line endings found in non-windows executables (Flex SDK is regularly published with broken CRLFs)

path String path to the executable file.



46
47
48
# File 'sprout/lib/sprout/system/unix_system.rb', line 46

def attempt_to_repair_executable path
  repair_executable(path) if should_repair_executable(path)
end

- (Boolean) can_execute?(platform)

Returns:

  • (Boolean)


34
35
36
# File 'sprout/lib/sprout/system/unix_system.rb', line 34

def can_execute? platform
  [:unix, :linux].include?(platform) || super
end

- (Object) clean_path(path)



6
7
8
9
10
11
12
13
14
15
16
# File 'sprout/lib/sprout/system/unix_system.rb', line 6

def clean_path path
  return if path.nil?
  if(path.include? '../')
    path = File.expand_path path
  end

  if(path.index(' '))
    return path.split(' ').join('\ ')
  end
  return path
end

- (Object) execute(tool, options = '')



18
19
20
21
# File 'sprout/lib/sprout/system/unix_system.rb', line 18

def execute(tool, options='')
  attempt_to_repair_executable tool
  super(tool, options)
end

- (Object) format_application_name(name)

Ensure Application name String begins with a dot (.), and does not include spaces.



27
28
29
30
31
32
# File 'sprout/lib/sprout/system/unix_system.rb', line 27

def format_application_name(name)
  if(name.index('.') != 0)
    name = '.' + name
  end
  return name.split(" ").join("_").downcase
end

- (Object) open_flashplayer_with(exe, swf)



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'flashsdk/lib/flashplayer/system_mixins.rb', line 65

def open_flashplayer_with exe, swf
  player_open = false
  trap("INT") { 
    close_flashplayer
    @player_thread.kill
  }

  @player_thread = Thread.new {
    require 'open4'
    @player_pid, stdin, stdout, stderr = Open4.popen4("#{exe} #{swf}")
    player_open = true
    stdout.read
  }

  # Wait until the player process has actually
  # openned...
  while !player_open
    sleep 0.1
  end

  @player_thread
end

- (Object) repair_executable(path)



50
51
52
53
54
55
56
57
58
59
# File 'sprout/lib/sprout/system/unix_system.rb', line 50

def repair_executable path
  content = File.read(path)
  if(content.match(/\r\n/))
    Sprout.stdout.puts "[WARNING] Sprouts is about to replace invalid Windows line endings on an executable at: (#{path})"
    content.gsub!(/\r\n/, "\n")
    File.open(path, 'w+') do |f|
      f.write content
    end
  end
end

- (Object) should_repair_executable(path)

Determine if we should call repair_executable for the file at the provided path String.

Will this corrupt binaries? Yes... Yes. it. will.

This also fails on UTF-8 files since Ruby's regex appears to choke on UTF-8??



69
70
71
# File 'sprout/lib/sprout/system/unix_system.rb', line 69

def should_repair_executable path
  return (File.exists?(path) && !File.directory?(path) && File.read(path).match(/^\#\!\/bin\/sh/))
end