rUtilAnts 0.1.0.20091014

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,126 @@
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 URLCache
9
+
10
+ module URLHandlers
11
+
12
+ # Handler of HTTP URLs
13
+ class HTTP
14
+
15
+ # Get a list of regexps matching the URL to get to this handler
16
+ #
17
+ # Return:
18
+ # * <em>list<Regexp></em>: The list of regexps matching URLs from this handler
19
+ def self.getMatchingRegexps
20
+ return [
21
+ /^(http|https):\/\/.*$/
22
+ ]
23
+ end
24
+
25
+ # Constructor
26
+ #
27
+ # Parameters:
28
+ # * *iURL* (_String_): The URL that this handler will manage
29
+ def initialize(iURL)
30
+ @URL = iURL
31
+ lURLMatch = iURL.match(/^(http|https):\/\/([^\/]*)\/(.*)$/)
32
+ if (lURLMatch == nil)
33
+ lURLMatch = iURL.match(/^(http|https):\/\/(.*)$/)
34
+ end
35
+ if (lURLMatch == nil)
36
+ logBug "URL #{iURL} was identified as an http like, but it appears to be false."
37
+ else
38
+ @URLProtocol, @URLServer, @URLPath = lURLMatch[1..3]
39
+ end
40
+ end
41
+
42
+ # Get the server ID
43
+ #
44
+ # Return:
45
+ # * _String_: The server ID
46
+ def getServerID
47
+ return "#{@URLProtocol}://#{@URLServer}"
48
+ end
49
+
50
+ # Get the current CRC of the URL
51
+ #
52
+ # Return:
53
+ # * _Integer_: The CRC
54
+ def getCRC
55
+ # We consider HTTP URLs to be definitive: CRCs will never change.
56
+ return 0
57
+ end
58
+
59
+ # Get a corresponding file base name.
60
+ # This method has to make sure file extensions are respected, as it can be used for further processing.
61
+ #
62
+ # Return:
63
+ # * _String_: The file name
64
+ def getCorrespondingFileBaseName
65
+ # Check that extension has no characters following the URL (#, ? and ;)
66
+ return getValidFileName(File.basename(@URLPath.gsub(/^([^#\?;]*).*$/,'\1')))
67
+ end
68
+
69
+ # Get the content of the URL
70
+ #
71
+ # Parameters:
72
+ # * *iFollowRedirections* (_Boolean_): Do we follow redirections while accessing the content ?
73
+ # Return:
74
+ # * _Integer_: Type of content returned
75
+ # * _Object_: The content, depending on the type previously returned:
76
+ # ** _Exception_ if CONTENT_ERROR: The corresponding error
77
+ # ** _String_ if CONTENT_REDIRECT: The new URL
78
+ # ** _String_ if CONTENT_STRING: The real content
79
+ # ** _String_ if CONTENT_LOCALFILENAME: The name of the local file name storing the content
80
+ # ** _String_ if CONTENT_LOCALFILENAME_TEMPORARY: The name of the temporary local file name storing the content
81
+ def getContent(iFollowRedirections)
82
+ rContentFormat = nil
83
+ rContent = nil
84
+
85
+ begin
86
+ require 'net/http'
87
+ Net::HTTP.start(@URLServer) do |iHTTPConnection|
88
+ lResponse = iHTTPConnection.get("/#{@URLPath}")
89
+ if ((iFollowRedirections) and
90
+ (lResponse.is_a?(Net::HTTPRedirection)))
91
+ # We access the file through a new URL
92
+ rContent = lResponse['location']
93
+ lNewURLMatch = rContent.match(/^(ftp|ftps|http|https):\/\/(.*)$/)
94
+ if (lNewURLMatch == nil)
95
+ if (rContent[0..0] == '/')
96
+ rContent = "#{@URLProtocol}://#{@URLServer}#{rContent}"
97
+ else
98
+ rContent = "#{@URLProtocol}://#{@URLServer}/#{File.dirname(@URLPath)}/#{rContent}"
99
+ end
100
+ end
101
+ rContentFormat = CONTENT_REDIRECT
102
+ elsif (lResponse.is_a?(Net::HTTPOK))
103
+ # We have the web page
104
+ rContent = lResponse.body
105
+ rContentFormat = CONTENT_STRING
106
+ else
107
+ # An error occurred
108
+ rContent = RuntimeError.new("Access error to #{@URL}: #{lResponse.code}.")
109
+ rContentFormat = CONTENT_ERROR
110
+ end
111
+ end
112
+ rescue Exception
113
+ rContent = $!
114
+ rContentFormat = CONTENT_ERROR
115
+ end
116
+
117
+ return rContentFormat, rContent
118
+ end
119
+
120
+ end
121
+
122
+ end
123
+
124
+ end
125
+
126
+ end
@@ -0,0 +1,100 @@
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 URLCache
9
+
10
+ module URLHandlers
11
+
12
+ # Handler of file URLs
13
+ class LocalFile
14
+
15
+ # Get a list of regexps matching the URL to get to this handler
16
+ #
17
+ # Return:
18
+ # * <em>list<Regexp></em>: The list of regexps matching URLs from this handler
19
+ def self.getMatchingRegexps
20
+ return [
21
+ /^file:\/\/\/(.*)$/
22
+ ]
23
+ end
24
+
25
+ # Constructor
26
+ #
27
+ # Parameters:
28
+ # * *iURL* (_String_): The URL that this handler will manage
29
+ def initialize(iURL)
30
+ @URL = iURL
31
+ lURLMatch = iURL.match(/^file:\/\/([^\/]*)\/(.*)$/)
32
+ if (lURLMatch != nil)
33
+ @URL = lURLMatch[1]
34
+ end
35
+ end
36
+
37
+ # Get the server ID
38
+ #
39
+ # Return:
40
+ # * _String_: The server ID
41
+ def getServerID
42
+ return nil
43
+ end
44
+
45
+ # Get the current CRC of the URL
46
+ #
47
+ # Return:
48
+ # * _Integer_: The CRC
49
+ def getCRC
50
+ # We consider the file's modification time
51
+ if (File.exists?(@URL))
52
+ return File.mtime(@URL)
53
+ else
54
+ return 0
55
+ end
56
+ end
57
+
58
+ # Get a corresponding file base name.
59
+ # This method has to make sure file extensions are respected, as it can be used for further processing.
60
+ #
61
+ # Return:
62
+ # * _String_: The file name
63
+ def getCorrespondingFileBaseName
64
+ return File.basename(@URL)
65
+ end
66
+
67
+ # Get the content of the URL
68
+ #
69
+ # Parameters:
70
+ # * *iFollowRedirections* (_Boolean_): Do we follow redirections while accessing the content ?
71
+ # Return:
72
+ # * _Integer_: Type of content returned
73
+ # * _Object_: The content, depending on the type previously returned:
74
+ # ** _Exception_ if CONTENT_ERROR: The corresponding error
75
+ # ** _String_ if CONTENT_REDIRECT: The new URL
76
+ # ** _String_ if CONTENT_STRING: The real content
77
+ # ** _String_ if CONTENT_LOCALFILENAME: The name of the local file name storing the content
78
+ # ** _String_ if CONTENT_LOCALFILENAME_TEMPORARY: The name of the temporary local file name storing the content
79
+ def getContent(iFollowRedirections)
80
+ rContentFormat = nil
81
+ rContent = nil
82
+
83
+ if (File.exists?(@URL))
84
+ rContent = @URL
85
+ rContentFormat = CONTENT_LOCALFILENAME
86
+ else
87
+ rContent = Errno::ENOENT.new(@URL)
88
+ rContentFormat = CONTENT_ERROR
89
+ end
90
+
91
+ return rContentFormat, rContent
92
+ end
93
+
94
+ end
95
+
96
+ end
97
+
98
+ end
99
+
100
+ end
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rUtilAnts
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0.20091014
5
+ platform: ruby
6
+ authors:
7
+ - Muriel Salvan
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-10-14 00:00:00 +02:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: rUtilAnts is used by several projects. It includes common standard code.
17
+ email: murielsalvan@users.sourceforge.net
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README
24
+ - TODO
25
+ - ChangeLog
26
+ - LICENSE
27
+ - AUTHORS
28
+ - Credits
29
+ files:
30
+ - lib/rUtilAnts/Plugins.rb
31
+ - lib/rUtilAnts/GUI.rb
32
+ - lib/rUtilAnts/Platform.rb
33
+ - lib/rUtilAnts/URLAccess.rb
34
+ - lib/rUtilAnts/Logging.rb
35
+ - lib/rUtilAnts/URLCache.rb
36
+ - lib/rUtilAnts/Misc.rb
37
+ - lib/rUtilAnts/URLHandlers/HTTP.rb
38
+ - lib/rUtilAnts/URLHandlers/FTP.rb
39
+ - lib/rUtilAnts/URLHandlers/LocalFile.rb
40
+ - lib/rUtilAnts/URLHandlers/DataImage.rb
41
+ - lib/rUtilAnts/GUI/Bug.png
42
+ - lib/rUtilAnts/GUI/BugReportDialog.rb
43
+ - lib/rUtilAnts/Platforms/i386-linux/PlatformInfo.rb
44
+ - lib/rUtilAnts/Platforms/i386-mswin32/PlatformInfo.rb
45
+ - README
46
+ - TODO
47
+ - ChangeLog
48
+ - LICENSE
49
+ - AUTHORS
50
+ - Credits
51
+ has_rdoc: true
52
+ homepage: http://rutilants.sourceforge.net/
53
+ licenses: []
54
+
55
+ post_install_message:
56
+ rdoc_options: []
57
+
58
+ require_paths:
59
+ - lib
60
+ required_ruby_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: "0"
65
+ version:
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: "0"
71
+ version:
72
+ requirements: []
73
+
74
+ rubyforge_project: rutilants
75
+ rubygems_version: 1.3.2
76
+ signing_key:
77
+ specification_version: 3
78
+ summary: A collection of various utility libraries.
79
+ test_files: []
80
+