rUtilAnts 0.1.0.20091014
Sign up to get free protection for your applications and to get access to all the features.
- data/AUTHORS +3 -0
- data/ChangeLog +74 -0
- data/Credits +14 -0
- data/LICENSE +31 -0
- data/README +18 -0
- data/TODO +10 -0
- data/lib/rUtilAnts/GUI/Bug.png +0 -0
- data/lib/rUtilAnts/GUI/BugReportDialog.rb +104 -0
- data/lib/rUtilAnts/GUI.rb +577 -0
- data/lib/rUtilAnts/Logging.rb +445 -0
- data/lib/rUtilAnts/Misc.rb +132 -0
- data/lib/rUtilAnts/Platform.rb +30 -0
- data/lib/rUtilAnts/Platforms/i386-linux/PlatformInfo.rb +149 -0
- data/lib/rUtilAnts/Platforms/i386-mswin32/PlatformInfo.rb +141 -0
- data/lib/rUtilAnts/Plugins.rb +480 -0
- data/lib/rUtilAnts/URLAccess.rb +228 -0
- data/lib/rUtilAnts/URLCache.rb +145 -0
- data/lib/rUtilAnts/URLHandlers/DataImage.rb +104 -0
- data/lib/rUtilAnts/URLHandlers/FTP.rb +120 -0
- data/lib/rUtilAnts/URLHandlers/HTTP.rb +126 -0
- data/lib/rUtilAnts/URLHandlers/LocalFile.rb +100 -0
- metadata +80 -0
@@ -0,0 +1,149 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2009 Muriel Salvan (murielsalvan@users.sourceforge.net)
|
3
|
+
# Licensed under the terms specified in LICENSE file. No warranty is provided.
|
4
|
+
#++
|
5
|
+
|
6
|
+
module RUtilAnts
|
7
|
+
|
8
|
+
module Platform
|
9
|
+
|
10
|
+
class PlatformInfo
|
11
|
+
|
12
|
+
# Return the ID of the OS
|
13
|
+
# Applications may adapt their behavior based on it.
|
14
|
+
#
|
15
|
+
# Return:
|
16
|
+
# * _Integer_: OS ID
|
17
|
+
def os
|
18
|
+
return OS_LINUX
|
19
|
+
end
|
20
|
+
|
21
|
+
# Return the list of directories where we look for executables
|
22
|
+
#
|
23
|
+
# Return:
|
24
|
+
# * <em>list<String></em>: List of directories
|
25
|
+
def getSystemExePath
|
26
|
+
return ENV['PATH'].split(':')
|
27
|
+
end
|
28
|
+
|
29
|
+
# Set the list of directories where we look for executables
|
30
|
+
#
|
31
|
+
# Parameters:
|
32
|
+
# * *iNewDirsList* (<em>list<String></em>): List of directories
|
33
|
+
def setSystemExePath(iNewDirsList)
|
34
|
+
ENV['PATH'] = iNewDirsList.join(':')
|
35
|
+
end
|
36
|
+
|
37
|
+
# Return the list of file extensions that might be discretely happened to executable files.
|
38
|
+
# This is the optional extensions that can be happened when invoked from a terminal.
|
39
|
+
#
|
40
|
+
# Return:
|
41
|
+
# * <em>list<String></em>: List of extensions (including .)
|
42
|
+
def getDiscreteExeExtensions
|
43
|
+
return []
|
44
|
+
end
|
45
|
+
|
46
|
+
# Return the list of directories where we look for libraries
|
47
|
+
#
|
48
|
+
# Return:
|
49
|
+
# * <em>list<String></em>: List of directories
|
50
|
+
def getSystemLibsPath
|
51
|
+
rList = ENV['PATH'].split(':')
|
52
|
+
|
53
|
+
if (ENV['LD_LIBRARY_PATH'] != nil)
|
54
|
+
rList += ENV['LD_LIBRARY_PATH'].split(':')
|
55
|
+
end
|
56
|
+
|
57
|
+
return rList
|
58
|
+
end
|
59
|
+
|
60
|
+
# Set the list of directories where we look for libraries
|
61
|
+
#
|
62
|
+
# Parameters:
|
63
|
+
# * *iNewDirsList* (<em>list<String></em>): List of directories
|
64
|
+
def setSystemLibsPath(iNewDirsList)
|
65
|
+
ENV['LD_LIBRARY_PATH'] = iNewDirsList.join(':')
|
66
|
+
end
|
67
|
+
|
68
|
+
# This method sends a message (platform dependent) to the user, without the use of wxruby
|
69
|
+
#
|
70
|
+
# Parameters:
|
71
|
+
# * *iMsg* (_String_): The message to display
|
72
|
+
def sendMsg(iMsg)
|
73
|
+
# TODO: Handle case of xmessage not installed
|
74
|
+
# Create a temporary file with the content to display
|
75
|
+
require 'tmpdir'
|
76
|
+
lTmpFileName = "#{Dir.tmpdir}/RUA_MSG"
|
77
|
+
File.open(lTmpFileName, 'w') do |oFile|
|
78
|
+
oFile.write(iMsg)
|
79
|
+
end
|
80
|
+
system("xmessage -file #{lTmpFileName}")
|
81
|
+
File.unlink(lTmpFileName)
|
82
|
+
end
|
83
|
+
|
84
|
+
# Execute a Shell command.
|
85
|
+
# Do not wait for its termination.
|
86
|
+
#
|
87
|
+
# Parameters:
|
88
|
+
# * *iCmd* (_String_): The command to execute
|
89
|
+
# * *iInTerminal* (_Boolean_): Do we execute this command in a separate terminal ?
|
90
|
+
# Return:
|
91
|
+
# * _Exception_: Error, or nil if success
|
92
|
+
def execShellCmdNoWait(iCmd, iInTerminal)
|
93
|
+
rException = nil
|
94
|
+
|
95
|
+
if (iInTerminal)
|
96
|
+
# TODO: Handle case of xterm not installed
|
97
|
+
if (!system("xterm -e \"#{iCmd}\""))
|
98
|
+
rException = RuntimeError.new
|
99
|
+
end
|
100
|
+
else
|
101
|
+
begin
|
102
|
+
IO.popen(iCmd)
|
103
|
+
rescue Exception
|
104
|
+
rException = $!
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
return rException
|
109
|
+
end
|
110
|
+
|
111
|
+
# Execute a given URL to be launched in a browser
|
112
|
+
#
|
113
|
+
# Parameters:
|
114
|
+
# * *iURL* (_String_): The URL to launch
|
115
|
+
# Return:
|
116
|
+
# * _String_: Error message, or nil if success
|
117
|
+
def launchURL(iURL)
|
118
|
+
rError = nil
|
119
|
+
|
120
|
+
begin
|
121
|
+
IO.popen("xdg-open '#{iURL}'")
|
122
|
+
rescue Exception
|
123
|
+
rError = $!.to_s
|
124
|
+
end
|
125
|
+
|
126
|
+
return rError
|
127
|
+
end
|
128
|
+
|
129
|
+
# Get file extensions specifics to executable files
|
130
|
+
#
|
131
|
+
# Return:
|
132
|
+
# * <em>list<String></em>: List of extensions (including . character). It can be empty.
|
133
|
+
def getExecutableExtensions
|
134
|
+
return []
|
135
|
+
end
|
136
|
+
|
137
|
+
# Get prohibited characters from file names
|
138
|
+
#
|
139
|
+
# Return:
|
140
|
+
# * _String_: String of prohibited characters in file names
|
141
|
+
def getProhibitedFileNamesCharacters
|
142
|
+
return '/'
|
143
|
+
end
|
144
|
+
|
145
|
+
end
|
146
|
+
|
147
|
+
end
|
148
|
+
|
149
|
+
end
|
@@ -0,0 +1,141 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2009 Muriel Salvan (murielsalvan@users.sourceforge.net)
|
3
|
+
# Licensed under the terms specified in LICENSE file. No warranty is provided.
|
4
|
+
#++
|
5
|
+
|
6
|
+
module RUtilAnts
|
7
|
+
|
8
|
+
module Platform
|
9
|
+
|
10
|
+
class PlatformInfo
|
11
|
+
|
12
|
+
# Return the ID of the OS
|
13
|
+
# Applications may adapt their behavior based on it.
|
14
|
+
#
|
15
|
+
# Return:
|
16
|
+
# * _Integer_: OS ID
|
17
|
+
def os
|
18
|
+
return OS_WINDOWS
|
19
|
+
end
|
20
|
+
|
21
|
+
# Return the list of directories where we look for executables
|
22
|
+
#
|
23
|
+
# Return:
|
24
|
+
# * <em>list<String></em>: List of directories
|
25
|
+
def getSystemExePath
|
26
|
+
return ENV['PATH'].split(';')
|
27
|
+
end
|
28
|
+
|
29
|
+
# Set the list of directories where we look for executables
|
30
|
+
#
|
31
|
+
# Parameters:
|
32
|
+
# * *iNewDirsList* (<em>list<String></em>): List of directories
|
33
|
+
def setSystemExePath(iNewDirsList)
|
34
|
+
ENV['PATH'] = iNewDirsList.join(';')
|
35
|
+
end
|
36
|
+
|
37
|
+
# Return the list of file extensions that might be discretely happened to executable files.
|
38
|
+
# This is the optional extensions that can be happened when invoked from a terminal.
|
39
|
+
#
|
40
|
+
# Return:
|
41
|
+
# * <em>list<String></em>: List of extensions (including .)
|
42
|
+
def getDiscreteExeExtensions
|
43
|
+
return [ '.exe', '.com', '.bat' ]
|
44
|
+
end
|
45
|
+
|
46
|
+
# Return the list of directories where we look for libraries
|
47
|
+
#
|
48
|
+
# Return:
|
49
|
+
# * <em>list<String></em>: List of directories
|
50
|
+
def getSystemLibsPath
|
51
|
+
return ENV['PATH'].split(';')
|
52
|
+
end
|
53
|
+
|
54
|
+
# Set the list of directories where we look for libraries
|
55
|
+
#
|
56
|
+
# Parameters:
|
57
|
+
# * *iNewDirsList* (<em>list<String></em>): List of directories
|
58
|
+
def setSystemLibsPath(iNewDirsList)
|
59
|
+
ENV['PATH'] = iNewDirsList.join(';')
|
60
|
+
end
|
61
|
+
|
62
|
+
# This method sends a message (platform dependent) to the user, without the use of wxruby
|
63
|
+
#
|
64
|
+
# Parameters:
|
65
|
+
# * *iMsg* (_String_): The message to display
|
66
|
+
def sendMsg(iMsg)
|
67
|
+
# !!! iMsg must not be longer than 256 characters
|
68
|
+
if (iMsg.size > 256)
|
69
|
+
system("msg \"#{ENV['USERNAME']}\" /W #{iMsg[0..255]}")
|
70
|
+
else
|
71
|
+
system("msg \"#{ENV['USERNAME']}\" /W #{iMsg}")
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
# Execute a Shell command.
|
76
|
+
# Do not wait for its termination.
|
77
|
+
#
|
78
|
+
# Parameters:
|
79
|
+
# * *iCmd* (_String_): The command to execute
|
80
|
+
# * *iInTerminal* (_Boolean_): Do we execute this command in a separate terminal ?
|
81
|
+
# Return:
|
82
|
+
# * _Exception_: Error, or nil if success
|
83
|
+
def execShellCmdNoWait(iCmd, iInTerminal)
|
84
|
+
rException = nil
|
85
|
+
|
86
|
+
if (iInTerminal)
|
87
|
+
if (!system("start cmd /c #{iCmd}"))
|
88
|
+
rException = RuntimeError.new
|
89
|
+
end
|
90
|
+
else
|
91
|
+
begin
|
92
|
+
IO.popen(iCmd)
|
93
|
+
rescue Exception
|
94
|
+
rException = $!
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
return rException
|
99
|
+
end
|
100
|
+
|
101
|
+
# Execute a given URL to be launched in a browser
|
102
|
+
#
|
103
|
+
# Parameters:
|
104
|
+
# * *iURL* (_String_): The URL to launch
|
105
|
+
# Return:
|
106
|
+
# * _String_: Error message, or nil if success
|
107
|
+
def launchURL(iURL)
|
108
|
+
rError = nil
|
109
|
+
|
110
|
+
# We must put " around the URL after the http:// prefix, as otherwise & symbol will not be recognized
|
111
|
+
lMatch = iURL.match(/^(http|https|ftp|ftps):\/\/(.*)$/)
|
112
|
+
if (lMatch == nil)
|
113
|
+
rError = "URL #{iURL} is not one of http://, https://, ftp:// or ftps://. Can't invoke it."
|
114
|
+
else
|
115
|
+
IO.popen("start #{lMatch[1]}://\"#{lMatch[2]}\"")
|
116
|
+
end
|
117
|
+
|
118
|
+
return rError
|
119
|
+
end
|
120
|
+
|
121
|
+
# Get file extensions specifics to executable files
|
122
|
+
#
|
123
|
+
# Return:
|
124
|
+
# * <em>list<String></em>: List of extensions (including . character). It can be empty.
|
125
|
+
def getExecutableExtensions
|
126
|
+
return [ '.exe', '.com', '.bat' ]
|
127
|
+
end
|
128
|
+
|
129
|
+
# Get prohibited characters from file names
|
130
|
+
#
|
131
|
+
# Return:
|
132
|
+
# * _String_: String of prohibited characters in file names
|
133
|
+
def getProhibitedFileNamesCharacters
|
134
|
+
return '\\/:*?"<>|'
|
135
|
+
end
|
136
|
+
|
137
|
+
end
|
138
|
+
|
139
|
+
end
|
140
|
+
|
141
|
+
end
|