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,206 @@
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 JfreechartGenerator
19
+
20
+ def initialize(chart, range_name, options = {})
21
+ @chart = chart
22
+ @range_name = range_name
23
+ @options = options
24
+ end
25
+
26
+ def generateToolTip(dataset,row,column)
27
+ row_key = dataset.getRowKey(row).toString
28
+ col_key = dataset.getColumnKey(column).toString
29
+
30
+ #p ["R", row, row_key,"C",column,col_key]
31
+ "Range: #{@range_name} Row: #{row_key} Col: #{col_key}"
32
+
33
+
34
+ case @options[:tooltip]
35
+ when NilClass
36
+ begin
37
+ data = @chart.ranges[@range_name][row_key][col_key]
38
+ #p data
39
+ ret = "#{row_key}/#{col_key}"
40
+ ret += " #{data[:start]} - #{data[:end]}" if data[:start]
41
+ ret += " (#{data[:percentage].to_s})" if data[:percentage]
42
+ ret
43
+ rescue
44
+ "#{@range_name}/#{row_key}/#{col_key} (dnf)"
45
+ end
46
+ when Proc
47
+ @options[:tooltip].call(range_name, row_key, col_key)
48
+ when String
49
+ @options[:tooltip]
50
+ else
51
+ raise "Unexpected tooltip class #{options[:tooltip]}"
52
+ end
53
+ rescue
54
+ $log.error($!)
55
+ $log.error($!.backtrace.join("\n"))
56
+ nil
57
+ end
58
+
59
+ end
60
+
61
+ =begin
62
+ public class MyGenerator implements CategoryURLGenerator,
63
+ CategoryToolTipGenerator,
64
+ PieURLGenerator,
65
+ PieToolTipGenerator,
66
+ XYURLGenerator,
67
+ XYToolTipGenerator {
68
+ private String prefix = "index.html";
69
+ private String seriesParameterName = "series";
70
+ private String categoryParameterName = "category";
71
+ private String rangeParameterName = "range";
72
+ private String rangeKey = null;
73
+ private CreateChart createChart = null;
74
+
75
+ private CategoryDataset theDataset = null;
76
+
77
+ public MyGenerator(String prefix, CategoryDataset ds) {
78
+ super();
79
+ this.prefix = prefix;
80
+ this.theDataset = ds;
81
+ }
82
+
83
+ public MyGenerator(String prefix) {
84
+ this.prefix = prefix;
85
+ }
86
+ public MyGenerator(String prefix, String rangeKey, CreateChart createChart) {
87
+ this.prefix = prefix;
88
+ this.rangeKey = rangeKey;
89
+ this.createChart = createChart;
90
+ }
91
+
92
+ public MyGenerator(String prefix,
93
+ String seriesParameterName,
94
+ String categoryParameterName) {
95
+ this.prefix = prefix;
96
+ this.seriesParameterName = seriesParameterName;
97
+ this.categoryParameterName = categoryParameterName;
98
+ }
99
+
100
+ public MyGenerator(String prefix,
101
+ String seriesParameterName,
102
+ String categoryParameterName,
103
+ String rangeParameterName,
104
+ String rangeKey) {
105
+ this.prefix = prefix;
106
+ this.seriesParameterName = seriesParameterName;
107
+ this.categoryParameterName = categoryParameterName;
108
+ this.rangeParameterName = rangeParameterName;
109
+ this.rangeKey = rangeKey;
110
+ }
111
+
112
+ public String myGenerateURL(Comparable seriesKey, Comparable categoryKey, Comparable rangeKey) {
113
+ if (categoryKey.toString().equals("<<REST>>") ||
114
+ seriesKey.toString().equals("<<REST>>") ||
115
+ (rangeKey != null && rangeKey.toString().equals("<<REST>>"))) { return "";}
116
+
117
+ String url = this.prefix;
118
+ boolean firstParameter = url.indexOf("?") == -1;
119
+
120
+ if (categoryKey.toString().equals("rest_value")) { return "";}
121
+ if (seriesKey.toString().equals("rest_serie")) { return "";}
122
+
123
+ url += firstParameter ? "?" : "&";
124
+ try {
125
+ url += this.seriesParameterName + "="
126
+ + URLEncoder.encode(seriesKey.toString(),"UTF-8");
127
+ url += "&" + this.categoryParameterName + "="
128
+ + URLEncoder.encode(categoryKey.toString(),"UTF-8");
129
+ if (rangeKey != null) {
130
+ url += "&" + this.rangeParameterName + "="
131
+ + URLEncoder.encode(rangeKey.toString(),"UTF-8");
132
+ }
133
+ }
134
+ catch ( java.io.UnsupportedEncodingException uee ) {
135
+ uee.printStackTrace();
136
+ }
137
+
138
+ return url;
139
+ }
140
+
141
+ public String myGenerateToolTip(Comparable seriesKey, Comparable categoryKey, Comparable rangeKey, Number value) {
142
+ String text = "";
143
+ if (this.rangeKey != null && !this.rangeKey.equals("<<NULL>>")) {
144
+ text += this.rangeKey + ", ";
145
+ }
146
+
147
+ if (seriesKey != null && !seriesKey.toString().equals("<<NULL>>")) {
148
+ text += seriesKey.toString() + ", ";
149
+ }
150
+
151
+ text += this.createChart.xAxis + "=" + categoryKey.toString() + ", ";
152
+
153
+ text += "value: " + value;
154
+ return text;
155
+ }
156
+
157
+ /** Pie **/
158
+
159
+ public String generateURL(PieDataset data, Comparable categoryKey, int pieIndex) {
160
+ Comparable seriesKey = theDataset.getRowKey(pieIndex);
161
+ return myGenerateURL(seriesKey, categoryKey, null);
162
+ }
163
+ public String generateToolTip(PieDataset data, Comparable categoryKey) {
164
+ /** not working **/
165
+ Comparable seriesKey = theDataset.getRowKey(0);
166
+ return myGenerateToolTip(seriesKey, categoryKey, null,999);
167
+ }
168
+
169
+
170
+ /** Category **/
171
+
172
+ public String generateURL(CategoryDataset dataset,
173
+ int series,
174
+ int category) {
175
+ Comparable seriesKey = dataset.getRowKey(series);
176
+ Comparable categoryKey = dataset.getColumnKey(category);
177
+
178
+ return myGenerateURL(seriesKey, categoryKey, this.rangeKey);
179
+ }
180
+
181
+ public String generateToolTip(CategoryDataset dataset,
182
+ int series, int category) {
183
+ Comparable seriesKey = dataset.getRowKey(series);
184
+ Comparable categoryKey = dataset.getColumnKey(category);
185
+
186
+ return myGenerateToolTip(seriesKey, categoryKey, this.rangeKey,dataset.getValue(seriesKey,categoryKey));
187
+ }
188
+
189
+ /** XY **/
190
+ public String generateURL(XYDataset dataset, int series, int item) {
191
+ Comparable seriesKey = dataset.getSeriesKey(series);
192
+ Comparable categoryKey = (Comparable)dataset.getX(series,item);
193
+
194
+ return myGenerateURL(seriesKey, categoryKey, this.rangeKey);
195
+ }
196
+
197
+ public String generateToolTip(XYDataset dataset, int series, int item) {
198
+ Comparable seriesKey = dataset.getSeriesKey(series);
199
+ Comparable categoryKey = (Comparable)dataset.getX(series,item);
200
+
201
+ return myGenerateToolTip(seriesKey, categoryKey, this.rangeKey,dataset.getY(series,item));
202
+ }
203
+
204
+
205
+ }
206
+ =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 Color < Base
20
+
21
+ end
@@ -0,0 +1,66 @@
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 BaseColor
19
+
20
+ def object(type_name)
21
+ case type_name
22
+ when "java", "java/paint"
23
+ Color.create("java", self)
24
+ end
25
+ end
26
+
27
+ def red; rgb[0]; end
28
+ def red=(val); self.rgb=[val,green,blue]; end
29
+ def green; rgb[1]; end
30
+ def green=(val); self.rgb=[red,val,blue]; end
31
+ def blue; rgb[2]; end
32
+ def blue=(val); self.rgb=[red,green,val]; end
33
+ def rgb
34
+ h = html
35
+ h = $1 if h =~ /^\#(.*)\;?$/
36
+ case h.length
37
+ when 3
38
+ [h[0..0].hex,h[1..1].hex,h[2..2].hex]
39
+ when 6
40
+ [h[0..1].hex,h[2..3].hex,h[4..5].hex]
41
+ else
42
+ raise "Unexpected html value #{html.inspect}"
43
+ end
44
+ end
45
+
46
+ def rgb=(values)
47
+ r,g,b = values
48
+ self.html = r.to_s(16).rjust(2,"0") + g.to_s(16).rjust(2,"0") + b.to_s(16).rjust(2,"0")
49
+ end
50
+
51
+ def hue(value=nil); adjust(:hue, value); end
52
+ def brightness(value=nil); adjust(:brightness, value); end
53
+ def saturation(value=nil); adjust(:saturation, value); end
54
+
55
+ def adjust(property, value=nil)
56
+ return self.send("#{property.to_s}_implementation") if value == nil
57
+
58
+ case value
59
+ when /^((\+|\-)?\d+\.?\d*)%/
60
+ self.send("#{property.to_s}_percentage_implementation",$1.to_f)
61
+ else
62
+ raise "Not implemented hue #{value}"
63
+ end
64
+ end
65
+
66
+ end
@@ -0,0 +1,92 @@
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/color/base.rb"
19
+ require "color/rgb.rb"
20
+ require "color/hsl.rb"
21
+
22
+ class ColortoolsColor < BaseColor
23
+
24
+ def ColortoolsColor.get_color(name)
25
+ normalized_name = name.to_s.split("_").map {|n| n.capitalize}.join
26
+
27
+ Color::RGB.constants.each {|c|
28
+ if c == normalized_name or
29
+ c.scan(/[A-Z][a-z]*/).map {|n| n.downcase}.join.capitalize == normalized_name
30
+ return ColortoolsColor.new(Color::RGB.const_get(c))
31
+ end
32
+ }
33
+ return nil
34
+ end
35
+
36
+ attr_accessor :rgb_color
37
+
38
+ def initialize(options = {})
39
+ #Color::RGB.new(32, 64, 128)
40
+ #Color::RGB.new(0x20, 0x40, 0x80)
41
+ case options
42
+ when Color::RGB
43
+ @rgb_color = options
44
+ when ColortoolsColor
45
+ @rgb_color = options.rgb_color.dup
46
+ else
47
+ raise "Require html color from options got: #{options.inspect}" unless
48
+ options.class == String or options.class == Symbol
49
+ if col = ColortoolsColor.get_color(options)
50
+ @rgb_color = col.rgb_color
51
+ else
52
+ # try html color
53
+ begin
54
+ @rgb_color = Color::RGB.from_html(options)
55
+ rescue ArgumentError
56
+ raise "Color #{options} not found"
57
+ end
58
+ end
59
+ end
60
+ end
61
+
62
+ def data(mime_type)
63
+ case mime_type
64
+ when "text/htmlcolor"
65
+ return @rgb_color.html
66
+ else
67
+ raise "Dont know how to be a #{mime_type}"
68
+ end
69
+ end
70
+
71
+ def html=(value)
72
+ @rgb_color = Color::RGB.from_html(value)
73
+ end
74
+
75
+ def html
76
+ @rgb_color.html
77
+ end
78
+
79
+ def hue_percentage_implementation(percentage)
80
+ @rgb_color = @rgb_color.adjust_hue(percentage)
81
+ end
82
+
83
+ def brightness_implementation; @rgb_color.brightness; end
84
+ def brightness_percentage_implementation(percentage)
85
+ @rgb_color = @rgb_color.adjust_brightness(percentage)
86
+ end
87
+
88
+ def saturation_percentage_implementation(percentage)
89
+ @rgb_color = @rgb_color.adjust_saturation(percentage)
90
+ end
91
+
92
+ end
@@ -0,0 +1,44 @@
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/color/base.rb"
19
+ require "libisi/bridge/java.rb"
20
+
21
+ class JavaColor < BaseColor
22
+
23
+ def method_missing(m, *args)
24
+ @obj.send(m, *args)
25
+ end
26
+
27
+ attr_accessor :java_object
28
+
29
+ def initialize(options = {})
30
+ # create javacolor out of color-tools
31
+ options = Color.create("colortools",options) if
32
+ options.class == String or options.class == Symbol
33
+
34
+ raise "Cannot create color out of #{options}" unless
35
+ options.respond_to?(:rgb)
36
+ rgb = options.rgb
37
+ @java_object = JavaBridge.import("java.awt.Color").new(*rgb)
38
+ end
39
+
40
+ def html
41
+ "#" + [@java_object.getRed.to_s(16),@java_object.getGreen.to_s(16),@java_object.getBlue.to_s(16)].map {|v| v.ljust(2,"0")}.join
42
+ end
43
+
44
+ end
@@ -0,0 +1,33 @@
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
+ require "libisi/concept/base.rb"
20
+ class Concept < Base
21
+
22
+ def self.create(klass, options = {})
23
+ if defined?(ActiveRecord::Base) and
24
+ klass.superclass == ActiveRecord::Base
25
+ require "libisi/concept/activerecord.rb"
26
+ # this is a activerecord concept
27
+ return ActiverecordConcept.new(klass, options)
28
+ end
29
+
30
+ return BaseConcept.new(klass, options)
31
+ end
32
+
33
+ end