libisi 0.3.0

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.
Files changed (91) hide show
  1. data/LICENSE +677 -0
  2. data/Manifest +89 -0
  3. data/Rakefile +34 -0
  4. data/lib/inifile.rb +119 -0
  5. data/lib/libisi.rb +948 -0
  6. data/lib/libisi/attribute.rb +32 -0
  7. data/lib/libisi/attribute/activerecord.rb +34 -0
  8. data/lib/libisi/attribute/base.rb +33 -0
  9. data/lib/libisi/base.rb +109 -0
  10. data/lib/libisi/bridge.rb +21 -0
  11. data/lib/libisi/bridge/base.rb +23 -0
  12. data/lib/libisi/bridge/java.rb +71 -0
  13. data/lib/libisi/bridge/python.rb +37 -0
  14. data/lib/libisi/cache.rb +21 -0
  15. data/lib/libisi/cache/base.rb +67 -0
  16. data/lib/libisi/cache/file_cache.rb +24 -0
  17. data/lib/libisi/chart.rb +21 -0
  18. data/lib/libisi/chart/base.rb +320 -0
  19. data/lib/libisi/chart/jfreechart.rb +682 -0
  20. data/lib/libisi/chart/jfreechart_generator.rb +206 -0
  21. data/lib/libisi/color.rb +21 -0
  22. data/lib/libisi/color/base.rb +66 -0
  23. data/lib/libisi/color/colortools.rb +92 -0
  24. data/lib/libisi/color/java.rb +44 -0
  25. data/lib/libisi/concept.rb +33 -0
  26. data/lib/libisi/concept/activerecord.rb +39 -0
  27. data/lib/libisi/concept/base.rb +58 -0
  28. data/lib/libisi/doc.rb +35 -0
  29. data/lib/libisi/doc/base.rb +414 -0
  30. data/lib/libisi/doc/html.rb +85 -0
  31. data/lib/libisi/doc/text.rb +98 -0
  32. data/lib/libisi/doc/wiki.rb +55 -0
  33. data/lib/libisi/environment.rb +21 -0
  34. data/lib/libisi/environment/base.rb +36 -0
  35. data/lib/libisi/environment/http.rb +105 -0
  36. data/lib/libisi/environment/rails.rb +27 -0
  37. data/lib/libisi/environment/root.rb +23 -0
  38. data/lib/libisi/fake_logger/logger.rb +61 -0
  39. data/lib/libisi/function/base.rb +30 -0
  40. data/lib/libisi/hal.rb +558 -0
  41. data/lib/libisi/instance.rb +27 -0
  42. data/lib/libisi/instance/activerecord.rb +21 -0
  43. data/lib/libisi/instance/base.rb +42 -0
  44. data/lib/libisi/log.rb +237 -0
  45. data/lib/libisi/mail/base.rb +32 -0
  46. data/lib/libisi/mail/tmail.rb +120 -0
  47. data/lib/libisi/parameter/base.rb +41 -0
  48. data/lib/libisi/property.rb +27 -0
  49. data/lib/libisi/property/base.rb +28 -0
  50. data/lib/libisi/reciever/base.rb +31 -0
  51. data/lib/libisi/reciever/socket.rb +31 -0
  52. data/lib/libisi/relation.rb +23 -0
  53. data/lib/libisi/request.rb +22 -0
  54. data/lib/libisi/request/base.rb +29 -0
  55. data/lib/libisi/request/http.rb +129 -0
  56. data/lib/libisi/response/base.rb +27 -0
  57. data/lib/libisi/task/base.rb +27 -0
  58. data/lib/libisi/task/http.rb +90 -0
  59. data/lib/libisi/tee.rb +296 -0
  60. data/lib/libisi/ui/base.rb +116 -0
  61. data/lib/libisi/ui/console.rb +238 -0
  62. data/lib/libisi/ui/kde.rb +94 -0
  63. data/lib/libisi/ui/nobody.rb +29 -0
  64. data/lib/libisi/ui/rails.rb +150 -0
  65. data/lib/libisi/ui/x11.rb +55 -0
  66. data/lib/libisi/uri.rb +42 -0
  67. data/lib/libisi/uri/activerecord.rb +152 -0
  68. data/lib/libisi/uri/base.rb +115 -0
  69. data/lib/libisi/uri/file.rb +43 -0
  70. data/lib/libisi/uri/ldap.rb +72 -0
  71. data/lib/libisi/uri/mysql.rb +98 -0
  72. data/lib/libisi/value.rb +31 -0
  73. data/lib/libisi/value/attribute_value.rb +19 -0
  74. data/lib/libisi/value/base.rb +55 -0
  75. data/lib/libisi/value/property_value.rb +19 -0
  76. data/lib/libisi/value/relation_value.rb +19 -0
  77. data/lib/ordered_hash.rb +228 -0
  78. data/libisi.gemspec +31 -0
  79. data/test/bridge_test.rb +77 -0
  80. data/test/cache_test.rb +65 -0
  81. data/test/chart_test.rb +179 -0
  82. data/test/color_test.rb +64 -0
  83. data/test/concept_test.rb +56 -0
  84. data/test/doc_test.rb +172 -0
  85. data/test/fixtures/test.db +0 -0
  86. data/test/ordered_hash_test.rb +39 -0
  87. data/test/profile_test.rb +36 -0
  88. data/test/request_test.rb +121 -0
  89. data/test/test +0 -0
  90. data/test/ui_test.rb +62 -0
  91. metadata +244 -0
@@ -0,0 +1,85 @@
1
+ # Copyright (C) 2007-2010 Logintas AG Switzerland
2
+ #
3
+ # This file is part of Libisi.
4
+ #
5
+ # Libisi is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # Libisi is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with Libisi. If not, see <http://www.gnu.org/licenses/>.
17
+
18
+ require "libisi/doc/base"
19
+ class HtmlDoc < BaseDoc
20
+
21
+ def start_doc(options = {}, &block)
22
+ writer(options, &block) << '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"' +
23
+ '"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">' +
24
+ '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'
25
+ end
26
+ def end_doc(options = {}, &block)
27
+ writer(options, &block) << '</html>'
28
+ end
29
+
30
+
31
+ def tr(options = {}, &block); generate_tag("tr", false, options) {yield; nil} end
32
+ def td(options = {}, &block); generate_tag("td", true, options, &block); end
33
+ def th(options = {}, &block); generate_tag("th", true, options, &block); end
34
+ def ul(options = {}, &block); generate_tag("ul", false, options, &block); end
35
+ def li(options = {}, &block); generate_tag("li", true, options, &block); end
36
+ def p(options = {}, &block); generate_tag("p", true, options, &block); end
37
+
38
+ private
39
+ def generate_attributes(tag_name, options)
40
+ ret = ""
41
+ case tag_name.to_s
42
+ when "table"
43
+ ret += " border='#{options[:style].delete(:border)}'" if (options[:style][:border] rescue nil)
44
+ ret += " class='#{options[:css_class]}'" if (options[:css_class] rescue nil)
45
+ ret += " id='#{options[:id]}'" if (options[:id] rescue nil)
46
+ when "td","th"
47
+ ret += " colspan='#{options.delete(:colspan)}'" if options[:colspan]
48
+ ret += " rowspan='#{options.delete(:rowspan)}'" if options[:rowspan]
49
+ end
50
+
51
+ style = ""
52
+
53
+ case options[:style]
54
+ when NilClass
55
+ when String; style += options[:style]
56
+ when Hash
57
+ options[:style].each {|key, val| style += "#{key.to_s.gsub("_","-")}:#{val};"}
58
+ else
59
+ raise "Unexpected style type #{options[:style].inspect}"
60
+ end
61
+
62
+ style += "text-align:#{options[:text_align]}" if options[:text_align]
63
+ ret += " style='#{style}'" if style != ""
64
+ ret
65
+ end
66
+
67
+ def generate_tag(name, content_tag, options = {}, &block)
68
+ writer(options, &block) << "<#{name}#{generate_attributes(name,options)}>"
69
+ if content_tag
70
+ writer(options, &block) << yield
71
+ else
72
+ yield
73
+ end
74
+ writer(options, &block) << "</#{name}>\n"
75
+ nil
76
+ end
77
+
78
+ def generate_table(options = {}, &block); generate_tag("table", false, options) {super;nil} end
79
+
80
+ def generate_title(text, options = {}, &block)
81
+ generate_tag("h#{(@title_depth or 0) + 1}", true, options) { text}
82
+ yield
83
+ end
84
+
85
+ end
@@ -0,0 +1,98 @@
1
+ # Copyright (C) 2007-2010 Logintas AG Switzerland
2
+ #
3
+ # This file is part of Libisi.
4
+ #
5
+ # Libisi is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # Libisi is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with Libisi. If not, see <http://www.gnu.org/licenses/>.
17
+
18
+ require "libisi/doc/base.rb"
19
+ require "text/format.rb"
20
+ class TextDoc < BaseDoc
21
+
22
+ def tr(options = {}, &block);
23
+ @rows.push([])
24
+ #writer(options, &block) << "|"
25
+ yield
26
+ #writer(options, &block) << "\n"
27
+ end
28
+ def th(options = {}, &block);
29
+ #writer(options, &block) << " #{yield.inspect.upcase} |"
30
+ @rows[-1].push(yield.to_s.upcase.gsub("\n",""))
31
+ # options[:colspan].times {@rows[-1].push(nil} if options[:colspan]
32
+ end
33
+ def td(options = {}, &block);
34
+ # writer(options, &block) << " #{yield.inspect} |"
35
+ @rows[-1].push(yield.to_s.gsub("\n",""))
36
+ options[:colspan].times {@rows[-1].push(-1)} if options[:colspan]
37
+ end
38
+
39
+ def ul(options = {}, &block)
40
+ # writer(options, &block) << "#{yield}"
41
+ yield
42
+ end
43
+ def li(options = {}, &block)
44
+ writer(options, &block) << " * #{block(yield,3).strip}\n"
45
+ end
46
+
47
+ private
48
+ def generate_bare_table(options = {}, &block);
49
+ @rows = []
50
+ # writer(options, &block) << "<<<TABLE>>>\n"
51
+ super
52
+ # writer(options, &block) << "<<<END TABLE>>>\n"
53
+
54
+ max_cols = @rows.map {|r| r.length}.max
55
+ col_lengths = []
56
+ max_cols.times {|i|
57
+ col_lengths[i] = @rows.map {|r|
58
+ (r[i] or "").to_s.length
59
+ }.max
60
+ }
61
+
62
+ @rows.each {|r|
63
+ r.length.times{|i|
64
+ r[i] = (r[i] or "").to_s.ljust(col_lengths[i])
65
+ }
66
+ writer(options, &block) << ("| " + r.join(" | ") + " |\n")
67
+ }
68
+ end
69
+
70
+ def block(text, left_margin = 0, width = 60)
71
+ f1 = Text::Format.new
72
+ f1.first_indent = 0 #left_margin
73
+ f1.left_margin = left_margin
74
+ f1.columns = width
75
+
76
+ text.split("\n").map {|t|
77
+ f1.format(t).sub(/\n$/,"")
78
+ }.join("\n")
79
+ end
80
+
81
+ class WriterWrapper
82
+ def initialize(writer, depth)
83
+ @w = writer
84
+ @d = (depth or 0).to_i
85
+ end
86
+ def <<(text)
87
+ #$log.debug("Write: #{text}")
88
+ raise "text is nil" if text.nil?
89
+ # STDOUT << ("\n" + text.inspect + "\n")
90
+ text = text.to_s.gsub(/^/m,(" " * @d))
91
+ @w << text
92
+ end
93
+ end
94
+
95
+ def writer(options = {}, &block)
96
+ WriterWrapper.new(super, @title_depth)
97
+ end
98
+ end
@@ -0,0 +1,55 @@
1
+ # Copyright (C) 2007-2010 Logintas AG Switzerland
2
+ #
3
+ # This file is part of Libisi.
4
+ #
5
+ # Libisi is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # Libisi is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with Libisi. If not, see <http://www.gnu.org/licenses/>.
17
+
18
+ require "libisi/doc/base"
19
+ class WikiDoc < BaseDoc
20
+ def initialize(options = {})
21
+ super
22
+ @indent = 0
23
+ end
24
+
25
+ def tr(options = {}, &block)
26
+ yield
27
+ writer(options, &block) << "||\n"
28
+ end
29
+ def td(options = {}, &block)
30
+ writer(options, &block) << "|| "
31
+ writer(options, &block) << yield
32
+ writer(options, &block) << " "
33
+ end
34
+ def th(options = {}, &block)
35
+ writer(options, &block) << "|| "
36
+ writer(options, &block) << yield.to_s.upcase
37
+ writer(options, &block) << " "
38
+ end
39
+ def ul(options = {}, &block)
40
+ @indent += 1
41
+ yield
42
+ @indent -= 1
43
+ end
44
+ def li(options = {}, &block)
45
+ writer(options, &block) << (" " * 2*@indent) + "* "
46
+ writer(options, &block) << yield
47
+ writer(options, &block) << "\n"
48
+ end
49
+
50
+ def p(options = {}, &block)
51
+ writer(options, &block) << yield
52
+ writer(options, &block) << "\n\n"
53
+ end
54
+
55
+ end
@@ -0,0 +1,21 @@
1
+ # Copyright (C) 2007-2010 Logintas AG Switzerland
2
+ #
3
+ # This file is part of Libisi.
4
+ #
5
+ # Libisi is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # Libisi is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with Libisi. If not, see <http://www.gnu.org/licenses/>.
17
+
18
+ require "libisi/base.rb"
19
+ class Environment < Base
20
+
21
+ end
@@ -0,0 +1,36 @@
1
+ # Copyright (C) 2007-2010 Logintas AG Switzerland
2
+ #
3
+ # This file is part of Libisi.
4
+ #
5
+ # Libisi is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # Libisi is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with Libisi. If not, see <http://www.gnu.org/licenses/>.
17
+
18
+ class BaseEnvironment
19
+
20
+ attr_reader :parent
21
+
22
+ def initialize(parent, options = nil)
23
+ #parent = RootEnvironment.new if parent.nil?
24
+ end
25
+
26
+ def type; raise "Not implemented"; end
27
+ def implementation; raise "Not implemented"; end
28
+ def instance; raise "Not implemented"; end
29
+ def execute(task); raise "Not implemented"; end
30
+
31
+ def user; parent.user; end
32
+ def uri; parent.uri; end
33
+ def name; parent.name; end
34
+ def language; parent.language; end
35
+
36
+ end
@@ -0,0 +1,105 @@
1
+ # Copyright (C) 2007-2010 Logintas AG Switzerland
2
+ #
3
+ # This file is part of Libisi.
4
+ #
5
+ # Libisi is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # Libisi is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with Libisi. If not, see <http://www.gnu.org/licenses/>.
17
+
18
+ require "libisi/environment/base"
19
+ require 'net/http'
20
+ require 'net/https'
21
+
22
+ # Environment accessible over http or https
23
+ class HttpEnvironment < BaseEnvironment
24
+
25
+ def initialize(uri, options = {})
26
+ @uri = uri
27
+ super(nil)
28
+ end
29
+
30
+ def type; :http_access; end
31
+ def implementation; :ruby; end
32
+ def uri; @uri; end
33
+
34
+ def uri_from_task(task, options = {})
35
+ m_uri = uri.to_s
36
+ m_uri = m_uri[0..-2] if m_uri =~ /\/$/
37
+ m_uri += "/" + task.function.context
38
+ m_uri += "/" + task.function.name
39
+ m_uri += "/" + task.parameter.arguments.join("/")
40
+
41
+ params = task.parameter.options.reject {|name, vals|
42
+ [:input_stream,:output_stream].include?(name)
43
+ }.map {|name, vals|
44
+ case vals
45
+ when Array, NilClass
46
+ when String
47
+ vals = [vals]
48
+ else
49
+ raise "Dont know how to parametrize class #{vals.class}"
50
+ end
51
+
52
+ vals.map {|val|
53
+ p [name, val]
54
+ if val
55
+ "#{name}=#{CGI.escape(val)}"
56
+ else
57
+ name
58
+ end
59
+ }
60
+ }.join("&")
61
+ URI.parse(m_uri + "?" + params)
62
+ end
63
+
64
+ def execute(task, options = {})
65
+ url = uri_from_task(task, options)
66
+
67
+ # TODO: initialize header
68
+ headers = nil
69
+ #headers = {
70
+ # 'Cookie' => @cookie,
71
+ # 'Referer' => 'http://profil.wp.pl/login.html',
72
+ # 'Content-Type' => 'application/x-www-form-urlencoded'
73
+ #}
74
+ request = Net::HTTP::Get.new([url.path,url.query].compact.join("?"), headers)
75
+
76
+ # TODO: login
77
+ # request.basic_auth 'account', 'password'
78
+ response = Net::HTTP.start(url.host, url.port) {|http|
79
+ http.request(request)
80
+ }
81
+
82
+ # TODO: implement more responses
83
+ case response
84
+ when Net::HTTPSuccess then response
85
+ # only sucess are allowed at the moment
86
+ #$log.info("Request sucessfuly done")
87
+ # when Net::HTTPRedirection then fetch(response['location'], limit - 1)
88
+ else
89
+ raise response.error!
90
+ end
91
+
92
+ # TODO: set cookie environment
93
+ #@cookie = resp.response['set-cookie'] if
94
+ # resp.response['set-cookie'] if
95
+
96
+ if out = task.parameter.options[:output_stream]
97
+ out.write(response.body)
98
+ out.close_write
99
+ #response.read_body(task.parameter.options[:output_stream])
100
+ else
101
+ response.body
102
+ end
103
+ end
104
+
105
+ end
@@ -0,0 +1,27 @@
1
+ # Copyright (C) 2007-2010 Logintas AG Switzerland
2
+ #
3
+ # This file is part of Libisi.
4
+ #
5
+ # Libisi is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # Libisi is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with Libisi. If not, see <http://www.gnu.org/licenses/>.
17
+
18
+ class RailsEnvironment
19
+
20
+ def type; :webapplication; end
21
+ def implementation; :rails; end
22
+
23
+ def context_object(name, options = {})
24
+ controller_name = name.camelize + "Controller"
25
+ eval(controller_name) if defined?(controller_name)
26
+ end
27
+ end
@@ -0,0 +1,23 @@
1
+ # Copyright (C) 2007-2010 Logintas AG Switzerland
2
+ #
3
+ # This file is part of Libisi.
4
+ #
5
+ # Libisi is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # Libisi is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with Libisi. If not, see <http://www.gnu.org/licenses/>.
17
+
18
+ require "libisi/environment/base.rb"
19
+ class RootEnvironment < BaseEnvironment
20
+
21
+ def user; nil; end
22
+
23
+ end