Module: RUtilAnts::Platform::PlatformInfo
- Defined in:
- lib/rUtilAnts/Platforms/unix/PlatformInfo.rb,
lib/rUtilAnts/Platforms/linux/PlatformInfo.rb,
lib/rUtilAnts/Platforms/cygwin/PlatformInfo.rb,
lib/rUtilAnts/Platforms/macosx/PlatformInfo.rb,
lib/rUtilAnts/Platforms/windows/PlatformInfo.rb
Instance Method Summary collapse
-
#create_shortcut(iSrc, iDst) ⇒ Object
Create a shortcut (ln -s on Cygwin/Unix systems, a .lnk file on Windows systems).
-
#discrete_exe_extensions ⇒ Object
Return the list of file extensions that might be discretely happened to executable files.
-
#display_msg(iMsg) ⇒ Object
This method sends a message (platform dependent) to the user, without the use of wxruby.
-
#exec_cmd_async(iCmd, iInTerminal) ⇒ Object
Execute a Shell command.
-
#executables_ext ⇒ Object
Get file extensions specifics to executable files.
-
#get_shortcut_file_name(iDst) ⇒ Object
Get the real file name of a shortcut.
-
#get_shortcut_target(iShortcutName) ⇒ Object
Get the name of a real file name, pointed by a shortcut.
-
#os ⇒ Object
Return the ID of the OS Applications may adapt their behavior based on it.
-
#os_open_file(file_name) ⇒ Object
Open a given file with the default OS application.
-
#os_open_url(iURL) ⇒ Object
Execute a given URL to be launched in a browser.
-
#prohibited_file_names_chars ⇒ Object
Get prohibited characters from file names.
-
#set_system_exe_paths(iNewDirsList) ⇒ Object
Set the list of directories where we look for executables.
-
#set_system_lib_paths(iNewDirsList) ⇒ Object
Set the list of directories where we look for libraries.
-
#system_exe_paths ⇒ Object
Return the list of directories where we look for executables.
-
#system_lib_paths ⇒ Object
Return the list of directories where we look for libraries.
Instance Method Details
#create_shortcut(iSrc, iDst) ⇒ Object
Create a shortcut (ln -s on Cygwin/Unix systems, a .lnk file on Windows systems)
- Parameters
-
iSrc (String): The source file
-
iDst (String): The destination file
131 132 133 134 |
# File 'lib/rUtilAnts/Platforms/unix/PlatformInfo.rb', line 131 def create_shortcut(iSrc, iDst) require 'fileutils' FileUtils::ln_s(iSrc, iDst) end |
#discrete_exe_extensions ⇒ Object
Return the list of file extensions that might be discretely happened to executable files. This is the optional extensions that can be happened when invoked from a terminal.
- Return
-
list<String>: List of extensions (including .)
37 38 39 |
# File 'lib/rUtilAnts/Platforms/unix/PlatformInfo.rb', line 37 def discrete_exe_extensions return [] end |
#display_msg(iMsg) ⇒ Object
This method sends a message (platform dependent) to the user, without the use of wxruby
- Parameters
-
iMsg (String): The message to display
67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/rUtilAnts/Platforms/unix/PlatformInfo.rb', line 67 def display_msg(iMsg) # TODO: Handle case of xmessage not installed # Create a temporary file with the content to display require 'tmpdir' lTmpFileName = "#{Dir.tmpdir}/RUA_MSG" File.open(lTmpFileName, 'w') do |oFile| oFile.write(iMsg) end system("xmessage -file #{lTmpFileName}") File.unlink(lTmpFileName) end |
#exec_cmd_async(iCmd, iInTerminal) ⇒ Object
Execute a Shell command. Do not wait for its termination.
- Parameters
-
iCmd (String): The command to execute
-
iInTerminal (Boolean): Do we execute this command in a separate terminal ?
85 86 87 88 89 90 91 92 |
# File 'lib/rUtilAnts/Platforms/unix/PlatformInfo.rb', line 85 def exec_cmd_async(iCmd, iInTerminal) if (iInTerminal) # TODO: Handle case of xterm not installed raise "Error while executing \"xterm -e \"#{iCmd}\"\": exit status #{$?.exitstatus}" if (!system("xterm -e \"#{iCmd}\"")) else IO.popen(iCmd) end end |
#executables_ext ⇒ Object
Get file extensions specifics to executable files
- Return
-
list<String>: List of extensions (including . character). It can be empty.
114 115 116 |
# File 'lib/rUtilAnts/Platforms/unix/PlatformInfo.rb', line 114 def executables_ext return [] end |
#get_shortcut_file_name(iDst) ⇒ Object
Get the real file name of a shortcut
- Parameters
-
iDst (String): The destination file that will host the shortcut
- Return
-
String: The real shortcut file name
153 154 155 |
# File 'lib/rUtilAnts/Platforms/unix/PlatformInfo.rb', line 153 def get_shortcut_file_name(iDst) return iDst end |
#get_shortcut_target(iShortcutName) ⇒ Object
Get the name of a real file name, pointed by a shortcut. On Windows systems, it will be the target of the lnk file.
- Parameters
-
iShortcutName (String): Name of the shortcut (same name used by create_shortcut). Don’t use OS specific extensions in this name (no .lnk).
- Return
-
String: The real file name pointed by this shortcut
143 144 145 |
# File 'lib/rUtilAnts/Platforms/unix/PlatformInfo.rb', line 143 def get_shortcut_target(iShortcutName) return File.readlink(iShortcutName) end |
#os ⇒ Object
Return the ID of the OS Applications may adapt their behavior based on it.
- Return
-
Integer: OS ID
12 13 14 |
# File 'lib/rUtilAnts/Platforms/unix/PlatformInfo.rb', line 12 def os return OS_LINUX end |
#os_open_file(file_name) ⇒ Object
Open a given file with the default OS application
- Parameters
-
file_name (String): The file to open
106 107 108 |
# File 'lib/rUtilAnts/Platforms/unix/PlatformInfo.rb', line 106 def os_open_file(file_name) IO.popen("xdg-open \"#{file_name}\"") end |
#os_open_url(iURL) ⇒ Object
Execute a given URL to be launched in a browser
- Parameters
-
iURL (String): The URL to launch
98 99 100 |
# File 'lib/rUtilAnts/Platforms/unix/PlatformInfo.rb', line 98 def os_open_url(iURL) IO.popen("xdg-open '#{iURL}'") end |
#prohibited_file_names_chars ⇒ Object
Get prohibited characters from file names
- Return
-
String: String of prohibited characters in file names
122 123 124 |
# File 'lib/rUtilAnts/Platforms/unix/PlatformInfo.rb', line 122 def prohibited_file_names_chars return '/' end |
#set_system_exe_paths(iNewDirsList) ⇒ Object
Set the list of directories where we look for executables
- Parameters
-
iNewDirsList (list<String>): List of directories
28 29 30 |
# File 'lib/rUtilAnts/Platforms/unix/PlatformInfo.rb', line 28 def set_system_exe_paths(iNewDirsList) ENV['PATH'] = iNewDirsList.join(':') end |
#set_system_lib_paths(iNewDirsList) ⇒ Object
Set the list of directories where we look for libraries
- Parameters
-
iNewDirsList (list<String>): List of directories
59 60 61 |
# File 'lib/rUtilAnts/Platforms/unix/PlatformInfo.rb', line 59 def set_system_lib_paths(iNewDirsList) ENV['LD_LIBRARY_PATH'] = iNewDirsList.join(':') end |
#system_exe_paths ⇒ Object
Return the list of directories where we look for executables
- Return
-
list<String>: List of directories
20 21 22 |
# File 'lib/rUtilAnts/Platforms/unix/PlatformInfo.rb', line 20 def system_exe_paths return ENV['PATH'].split(':') end |
#system_lib_paths ⇒ Object
Return the list of directories where we look for libraries
- Return
-
list<String>: List of directories
45 46 47 48 49 50 51 52 53 |
# File 'lib/rUtilAnts/Platforms/unix/PlatformInfo.rb', line 45 def system_lib_paths rList = ENV['PATH'].split(':') if (ENV['LD_LIBRARY_PATH'] != nil) rList += ENV['LD_LIBRARY_PATH'].split(':') end return rList end |