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,115 @@
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 BaseUri
19
+
20
+ attr_accessor :uri, :options
21
+
22
+ def initialize(uri, options = {})
23
+ @uri = uri
24
+ @options = options
25
+ end
26
+
27
+ def credential_hash
28
+ uis = (uri.userinfo or "").split(":")
29
+ ret = {}
30
+ # URI unescape to allow special characters,
31
+ # probably not rfc conform
32
+ ret[:user] = URI.unescape(uis[0]) if uis[0]
33
+ ret[:password] = URI.unescape(uis[1]) if uis[1]
34
+ ret
35
+ end
36
+
37
+ def base_uri
38
+ u = uri.dup
39
+ u.path = ""
40
+ u
41
+ end
42
+
43
+ def user
44
+ options[:user] or credential_hash[:user]
45
+ end
46
+ def password
47
+ options[:password] or credential_hash[:password] or
48
+ (options[:use_password] and $ui.password("Please enter password for #{base_uri.to_s}"))
49
+ end
50
+
51
+ def execute_command(command)
52
+ return command if uri.host == "localhost"
53
+ l = uri.host
54
+ # l = "#{uri.userinfo}@#{l}" if uri.userinfo
55
+ execute_on_remote_command(l, command)
56
+ end
57
+
58
+ def find(*args)
59
+ options = {}
60
+ options = args.pop if args[-1].class == Hash
61
+
62
+ raise "No more than one argument allowed at the moment" if
63
+ args.length > 1
64
+
65
+ m_items = (self.items or [])
66
+ if conditions = options[:conditions]
67
+ conditions.each {|field, value|
68
+ raise "Only unless Symbol => (Regex|String) pairs allowed for conditions:" +
69
+ "#{field.inspect}(#{field.class.name}) => #{value.inspect}(#{value.class.name})" if
70
+ field.class != Symbol or ![String,Regexp].include?(value.class)
71
+
72
+ $log.debug("Filtering items for #{field} => #{value}")
73
+
74
+ case value
75
+ when String
76
+ compare_proc = Proc.new {|v| v == value }
77
+ when Regexp
78
+ compare_proc = Proc.new {|v| v =~ value }
79
+ end
80
+
81
+ m_items = m_items.select {|i|
82
+ item_value = i.send(field )
83
+ case item_value
84
+ when String
85
+ compare_proc.call(item_value)
86
+ when Array
87
+ item_value.select{|v| compare_proc.call(v)}.length > 0
88
+ when NilClass
89
+ false
90
+ else
91
+ raise "Item field value #{item_value.inspect} of #{i.inspect} has unexpected type #{item_value.class.name}"
92
+ end
93
+ }
94
+ $log.debug("There are still #{m_items.length} items after filter #{field} => #{value}")
95
+ }
96
+ end
97
+
98
+ case args.first
99
+ when :first then m_items[0]
100
+ when :last then m_items[-1]
101
+ when :all then m_items
102
+ else
103
+ key_proc = primary_key
104
+ key_proc = Proc.new {|i| i.send(primary_key)} if primary_key.class == String
105
+ m_items.each {|i|
106
+ return i if key_proc.call(i).to_s == args.first.to_s
107
+ }
108
+
109
+ raise self.entry_not_found_exception if self.respond_to?(:entry_not_found_exception)
110
+ raise "Item #{args.first} not found"
111
+
112
+ end
113
+ end
114
+
115
+ end
@@ -0,0 +1,43 @@
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/uri/base"
19
+ class FileData < BaseUri
20
+
21
+ def initialize(uri, options = {})
22
+ super
23
+ raise "Only local files allowed. Host is #{uri.host}" unless
24
+ ["127.0.0.1","localhost"].include?(uri.host)
25
+ @file = Pathname.new(uri.path[1..-1])
26
+ end
27
+
28
+ def file; @file; end
29
+ def pathname; @file; end
30
+
31
+ def primary_key; Proc.new {|pathname| pathname.basename.to_s}; end
32
+
33
+ def column_names; ["size","dirname","basename"]; end
34
+
35
+ def items
36
+ if @file.directory?
37
+ @file.entries
38
+ else
39
+ @file.readlines
40
+ end
41
+ end
42
+
43
+ end
@@ -0,0 +1,72 @@
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/uri/base"
19
+ class LdapData < BaseUri
20
+ @@num = 0
21
+
22
+ require "active_ldap"
23
+
24
+ def initialize(uri, options = {})
25
+ super
26
+ end
27
+
28
+ def primary_key; ldap_class.dn_attribute ;end
29
+
30
+ def column_names;
31
+ return @column_names if @column_names
32
+ $log.debug("Finding column names")
33
+ @column_names = items.map {|i| i.attribute_names}.flatten.uniq.compact.sort
34
+ end
35
+
36
+ def items; ldap_class.find(:all); end
37
+ def entry_not_found_exception; ActiveLdap::EntryNotFound; end
38
+ def create(attributes,&block); ldap_class.create(attributes,&block) ;end
39
+ def new(attributes, &block); ldap_class.new(attributes, &block); end
40
+
41
+ private
42
+ def ldap_class
43
+ return @myclass if @myclass
44
+
45
+ LdapData.module_eval("class LdapClass#{@@num} < ActiveLdap::Base; end")
46
+ @myclass = eval("LdapClass#{@@num}")
47
+ @@num += 1
48
+
49
+ path_items = uri.path.split("/")[1..-1]
50
+ base = path_items[0]
51
+ $log.debug("Base dn: #{base}")
52
+ $log.debug("Bind dn: #{user}")
53
+
54
+ @myclass.setup_connection(
55
+ :host => uri.host,
56
+ :port => (uri.port or 389),
57
+ :base => base,
58
+ :logger => $log,
59
+ :bind_dn => user,
60
+ :password_block => Proc.new { password },
61
+ :allow_anonymous => false,
62
+ :try_sasl => false,
63
+ :method => (options[:method] or "tls") #:tls, :ssl, :plain
64
+ )
65
+ klass = path_items[1..-2].reverse.join(",")
66
+ $log.debug("prefix: #{klass}")
67
+ dn = path_items[-1]
68
+ $log.debug("dn_attribute: #{dn}")
69
+ @myclass.ldap_mapping :prefix => klass,:dn_attribute => dn
70
+ end
71
+
72
+ 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/uri/base"
19
+ class MysqlData < BaseUri
20
+
21
+ def initialize(uri, options = {})
22
+ super
23
+ self.database
24
+ end
25
+
26
+ def database
27
+ db = uri.path
28
+ db = db[1..-1] if db =~ /^\//
29
+ raise "Unexpected database name #{db}" if db =~ /\//
30
+ db
31
+ end
32
+
33
+ def mysql_command(command = "mysql")
34
+ cmd = command
35
+ cmd += " -u #{user}" if user
36
+ cmd += " -p#{password}" if password
37
+ cmd
38
+ end
39
+ def execute_mysql(sql)
40
+ execute_command("echo '#{sql}' | " + mysql_command)
41
+ end
42
+
43
+ def source_command
44
+ cmd = mysql_command("mysqldump")
45
+ if uri.path
46
+ cmd += " #{database}"
47
+ else
48
+ cmd += " --all-databases"
49
+ end
50
+ cmd
51
+ end
52
+
53
+ def target_command
54
+ cmd = mysql_command
55
+ cmd += " #{database}" if uri.path
56
+ cmd
57
+ end
58
+
59
+ def copy_command(target = nil)
60
+ raise "Convert mysql to #{target.class} not implemented." unless target.class == self.class or target.class == NilClass
61
+ raise "You must specify a source database if you give a target database." if database.nil? and database
62
+
63
+ ret = execute_command(source_command)
64
+ if target
65
+ ret += "|" + target.execute_command(target.target_command)
66
+ end
67
+ ret
68
+ end
69
+
70
+ def readable_command
71
+ if database
72
+ execute_command("echo 'show tables' | " + mysql_command + " #{database} 2>&1 > /dev/null")
73
+ else
74
+ execute_command("echo 'show databases' | " + mysql_command + " 2>&1 > /dev/null")
75
+ end
76
+ end
77
+
78
+ def make_readable_command
79
+ if database
80
+ execute_mysql("GRANT SELECT, LOCK TABLES ON #{database}.* TO #{user}@localhost IDENTIFIED BY \"#{password}\"")
81
+ else
82
+ execute_mysql("GRANT SELECT, LOCK TABLES ON *.* TO #{user}@localhost IDENTIFIED BY \"#{password}\"")
83
+ end
84
+ end
85
+
86
+ def create_command
87
+ execute_mysql("CREATE DATABASE #{database}")
88
+ end
89
+
90
+ def make_writable_command
91
+ if database
92
+ execute_mysql("GRANT ALL ON #{database}.* TO #{user}@localhost IDENTIFIED BY \"#{password}\"")
93
+ else
94
+ execute_mysql("GRANT ALL ON *.* TO #{user}@localhost IDENTIFIED BY \"#{password}\"")
95
+ end
96
+ end
97
+
98
+ end
@@ -0,0 +1,31 @@
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/value/base.rb"
20
+ class Value < Base
21
+
22
+ def self.create(source, instance, options = {})
23
+ case source.class.name
24
+ when /Attribute/,/Property/
25
+ BaseValue.new(source, instance, options)
26
+ else
27
+ raise "Unexpected source for new value #{source.class.name}"
28
+ end
29
+ end
30
+
31
+ end
@@ -0,0 +1,19 @@
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 AttributeValue < BaseValue
19
+ 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
+ class BaseValue
19
+
20
+ attr_reader :source, :instance
21
+
22
+ def initialize(source, instance, options = {})
23
+ @source = source
24
+ @instance = instance
25
+ end
26
+
27
+ def unit; source.respond_to?(:unit) and source.unit; end
28
+ def type; source.respond_to?(:type) and source.type; end
29
+ def name; source.name; end
30
+
31
+ def data_object; instance.send(name); end
32
+ def to_s; data_object.to_s; end
33
+ def inspect; "#{to_s} <#{type or "?"}/#{unit or "?"}>"; end
34
+
35
+ def to_doc(options)
36
+ raise "No doc initialized" unless $doc
37
+
38
+ case type
39
+ when :integer
40
+ i = data_object
41
+ if i < 0
42
+ $doc.print(:color => "red") {
43
+ i.to_s
44
+ }
45
+ else
46
+ $doc.print {
47
+ i.to_s
48
+ }
49
+ end
50
+ }
51
+ when :text
52
+ $doc.p { data_object.to_s }
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,19 @@
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 PropertyValue < BaseValue
19
+ end