knjrbfw 0.0.115 → 0.0.116

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.
@@ -5,15 +5,15 @@ class Appserver_cli
5
5
  def self.loadfile(filepath)
6
6
  require filepath
7
7
  end
8
-
8
+
9
9
  def self._(str)
10
10
  return str
11
11
  end
12
-
12
+
13
13
  def self.gettext
14
14
  return self
15
15
  end
16
-
16
+
17
17
  def self.lang_opts
18
18
  return []
19
19
  end
@@ -32,7 +32,7 @@ def _ob
32
32
  end
33
33
 
34
34
  autoinc_cli_path = "../include/autoinclude_cli.rb"
35
- if File.exists?(autoinc_cli_path)
35
+ if File.exist?(autoinc_cli_path)
36
36
  require autoinc_cli_path
37
37
  else
38
38
  require "../include/autoinclude.rb"
data/lib/knj/knj.rb CHANGED
@@ -2,40 +2,40 @@ $knjpath = "knj/" if !$knjpath
2
2
 
3
3
  module Knj
4
4
  CONFIG = {}
5
-
5
+
6
6
  def self.const_missing(name)
7
7
  if name == :Db
8
8
  filepath = "#{$knjpath}knjdb/libknjdb"
9
9
  else
10
10
  filepath = "#{$knjpath}#{name.to_s.downcase}"
11
11
  end
12
-
12
+
13
13
  require filepath
14
14
  raise "Constant still not defined: '#{name}'." if !Knj.const_defined?(name)
15
15
  return Knj.const_get(name)
16
16
  end
17
-
17
+
18
18
  def self.appserver_cli(filename)
19
19
  Knj::Os.chdir_file(filename)
20
20
  require "#{$knjpath}/includes/appserver_cli.rb"
21
21
  end
22
-
22
+
23
23
  def self.dirname(filepath)
24
- raise "Filepath does not exist: #{filepath}" if !File.exists?(filepath)
24
+ raise "Filepath does not exist: #{filepath}" if !File.exist?(filepath)
25
25
  return File.realpath(File.dirname(filepath))
26
26
  end
27
-
27
+
28
28
  #Returns the path of the knjrbfw-framework.
29
29
  def self.knjrbfw_path
30
30
  return File.realpath(File.dirname(__FILE__))
31
31
  end
32
-
32
+
33
33
  #Shortcut to Php4r.print_r.
34
34
  def self.p(*args, &block)
35
35
  require "php4r" if !Kernel.const_defined?(:Php4r)
36
36
  return Php4r.print_r(*args, &block)
37
37
  end
38
-
38
+
39
39
  def self.handle_return(args)
40
40
  if args[:block]
41
41
  args[:enum].each(&args[:block])
@@ -44,7 +44,7 @@ module Knj
44
44
  return Array_enumerator.new(args[:enum])
45
45
  end
46
46
  end
47
-
47
+
48
48
  #Loads a gem by a given name. First tries to load the gem from a custom parent directory to enable loading of development-gems.
49
49
  def self.gem_require(gem_const, gem_name = nil)
50
50
  #Support given an array for multiple gem-names in one call.
@@ -52,37 +52,37 @@ module Knj
52
52
  gem_const.each do |gem_i|
53
53
  self.gem_require(gem_i)
54
54
  end
55
-
55
+
56
56
  return nil
57
57
  end
58
-
58
+
59
59
  #Set correct names.
60
60
  gem_name = gem_const.to_s.downcase.strip if !gem_name
61
61
  gem_const = "#{gem_const.to_s[0].upcase}#{gem_const.to_s[1, gem_name.length]}"
62
-
62
+
63
63
  #Return false if the constant is already loaded.
64
64
  return false if ::Kernel.const_defined?(gem_const)
65
-
65
+
66
66
  #Try to load gem from custom development-path.
67
67
  found_custom = false
68
-
68
+
69
69
  paths = [
70
70
  "#{File.realpath("#{File.dirname(__FILE__)}/../../..")}/#{gem_name}/lib/#{gem_name}.rb"
71
71
  ]
72
72
  paths.each do |path|
73
- if File.exists?(path)
73
+ if File.exist?(path)
74
74
  require path
75
75
  found_custom = true
76
76
  break
77
77
  end
78
78
  end
79
-
79
+
80
80
  #Custom-path could not be loaded - load gem normally.
81
81
  if !found_custom
82
82
  require "rubygems"
83
83
  require gem_name.to_s
84
84
  end
85
-
85
+
86
86
  #Return true to enable detection of that something was loaded.
87
87
  return true
88
88
  end
data/lib/knj/mount.rb CHANGED
@@ -2,32 +2,32 @@ class Knj::Mount
2
2
  def self.list(args = {})
3
3
  mount_output = Knj::Os.shellcmd("mount")
4
4
  ret = []
5
-
5
+
6
6
  mount_output.scan(/^(.+?) on (.+?) type (.+) \((.+?)\)$/) do |match|
7
7
  type = match[2]
8
8
  folder_from = match[0]
9
9
  folder_to = match[1]
10
10
  opts = match[3].split(",")
11
-
11
+
12
12
  folder_from = nil if folder_from == "none"
13
- #raise "The folder doesnt exist?" if !File.exists?(folder_to)
14
-
13
+ #raise "The folder doesnt exist?" if !File.exist?(folder_to)
14
+
15
15
  add = true
16
16
  add = false if args.key?("to") and args["to"] != folder_to
17
17
  add = false if args.key?("from") and args["from"] != folder_from
18
-
18
+
19
19
  if args["from_search"]
20
20
  Knj::Strings.searchstring(args["from_search"]).each do |str|
21
21
  add = false if !folder_from or folder_from.index(str) == nil
22
22
  end
23
23
  end
24
-
24
+
25
25
  if args["to_search"]
26
26
  Knj::Strings.searchstring(args["to_search"]).each do |str|
27
27
  add = false if !folder_to or folder_to.index(str) == nil
28
28
  end
29
29
  end
30
-
30
+
31
31
  if add
32
32
  ret << Knj::Mount.new(
33
33
  :type => type,
@@ -37,26 +37,26 @@ class Knj::Mount
37
37
  )
38
38
  end
39
39
  end
40
-
40
+
41
41
  return ret
42
42
  end
43
-
43
+
44
44
  def self.mount(args)
45
45
  cmd = "mount"
46
46
  cmd << " -t #{Knj::Strings.unixsafe(args["type"])}" if args.key?("type")
47
47
  cmd << " --bind" if args["bind"]
48
48
  cmd << " #{Knj::Strings.unixsafe(args["from"])} #{Knj::Strings.unixsafe(args["to"])}"
49
-
49
+
50
50
  if args.key?("opts")
51
51
  raise "opts argument must be an array." if !args["opts"].is_a?(Array)
52
-
52
+
53
53
  cmd << "-O "
54
-
54
+
55
55
  first = true
56
56
  args["opts"].each do |opt|
57
57
  cmd << "," if !first
58
58
  first = false if first
59
-
59
+
60
60
  if opt.is_a?(Array)
61
61
  raise "Array-opt must have a length of 2." if opt.length != 2
62
62
  cmd << "#{Knj::Strings.unixsafe(opt[0])}=#{Knj::Strings.unixsafe(opt[1])}"
@@ -67,38 +67,38 @@ class Knj::Mount
67
67
  end
68
68
  end
69
69
  end
70
-
70
+
71
71
  Knj::Os.shellcmd(cmd)
72
72
  end
73
-
73
+
74
74
  def self.ensure(args)
75
75
  list = Knj::Mount.list("to_search" => args["to"])
76
76
  return false if !list.empty?
77
77
  Knj::Mount.mount(args)
78
78
  return true
79
79
  end
80
-
80
+
81
81
  attr_reader :data
82
-
82
+
83
83
  def initialize(data)
84
84
  @data = data
85
85
  end
86
-
86
+
87
87
  def [](key)
88
88
  raise "Invalid key: #{key}." if !@data.key?(key)
89
89
  return @data[key]
90
90
  end
91
-
91
+
92
92
  def unmount
93
93
  Knj::Os.shellcmd("umount #{Knj::Strings.unixsafe(@data[:to])}")
94
94
  end
95
-
95
+
96
96
  alias :umount :unmount
97
-
97
+
98
98
  def access?(args = {})
99
99
  args["timeout"] = 2 if !args.key?("timeout")
100
100
  access = false
101
-
101
+
102
102
  begin
103
103
  Timeout.timeout(args["timeout"]) do
104
104
  Dir.new(@data[:to]).each do |file|
@@ -109,7 +109,7 @@ class Knj::Mount
109
109
  rescue Timeout::Error => e
110
110
  return false
111
111
  end
112
-
112
+
113
113
  return access
114
114
  end
115
115
  end
data/lib/knj/os.rb CHANGED
@@ -1,36 +1,36 @@
1
1
  module Knj::Os
2
2
  #Returns the path of the home-dir as a string.
3
3
  #===Examples
4
- # print "Looks like the current user uses Mozilla software?" if File.exists?("#{Knj::Os.homedir}/.mozilla")
4
+ # print "Looks like the current user uses Mozilla software?" if File.exist?("#{Knj::Os.homedir}/.mozilla")
5
5
  def self.homedir
6
6
  if ENV["USERPROFILE"]
7
7
  homedir = ENV["USERPROFILE"]
8
8
  else
9
9
  homedir = File.expand_path("~")
10
10
  end
11
-
11
+
12
12
  if homedir.length <= 0
13
13
  raise "Could not figure out the homedir."
14
14
  end
15
-
15
+
16
16
  return homedir
17
17
  end
18
-
18
+
19
19
  #This method was created to make up for the fact that Dir.tmpdir sometimes returns empty strings??
20
20
  #===Examples
21
21
  # tmp_db_path = "#{Knj::Os.tmpdir}/temp_db.sqlite3"
22
22
  def self.tmpdir
23
23
  require "tmpdir"
24
24
  tmpdir = Dir.tmpdir.to_s.strip
25
-
26
- return tmpdir if tmpdir.length >= 3 and File.exists?(tmpdir)
27
- return ENV["TEMP"] if ENV["TEMP"].to_s.strip.length > 0 and File.exists?(ENV["TMP"])
28
- return ENV["TMP"] if ENV["TMP"].to_s.strip.length > 0 and File.exists?(ENV["TMP"])
29
- return "/tmp" if File.exists?("/tmp")
30
-
25
+
26
+ return tmpdir if tmpdir.length >= 3 and File.exist?(tmpdir)
27
+ return ENV["TEMP"] if ENV["TEMP"].to_s.strip.length > 0 and File.exist?(ENV["TMP"])
28
+ return ENV["TMP"] if ENV["TMP"].to_s.strip.length > 0 and File.exist?(ENV["TMP"])
29
+ return "/tmp" if File.exist?("/tmp")
30
+
31
31
  raise "Could not figure out temp-dir."
32
32
  end
33
-
33
+
34
34
  #This method returns the username of the current user.
35
35
  #===Examples
36
36
  # print "I can do what I want, I am root!" if Knj::Os.whoami == "root"
@@ -40,14 +40,14 @@ module Knj::Os
40
40
  else
41
41
  whoami = %x[whoami].strip
42
42
  end
43
-
43
+
44
44
  if whoami.length <= 0
45
45
  raise "Could not figure out the user who is logged in."
46
46
  end
47
-
47
+
48
48
  return whoami
49
49
  end
50
-
50
+
51
51
  #Returns the operating system a string.
52
52
  #===Examples
53
53
  # print "Can I please move to another machine?" if Knj::Os.os == "windows"
@@ -58,7 +58,7 @@ module Knj::Os
58
58
  elsif RUBY_PLATFORM
59
59
  teststring = RUBY_PLATFORM.to_s.downcase
60
60
  end
61
-
61
+
62
62
  if teststring.include?("windows")
63
63
  return "windows"
64
64
  elsif teststring.include?("linux")
@@ -68,7 +68,7 @@ module Knj::Os
68
68
  raise "Could not figure out OS: '#{teststring}'."
69
69
  end
70
70
  end
71
-
71
+
72
72
  #Returns the current graphical toolkit running.
73
73
  #===Examples
74
74
  # Knj::Os.toolkit #=> 'kde'
@@ -78,18 +78,18 @@ module Knj::Os
78
78
  return "kde"
79
79
  end
80
80
  end
81
-
81
+
82
82
  raise "Could not figure out the toolkit."
83
83
  end
84
-
84
+
85
85
  def self.class_exist(classstr)
86
86
  if Module.constants.index(classstr) != nil
87
87
  return true
88
88
  end
89
-
89
+
90
90
  return false
91
91
  end
92
-
92
+
93
93
  def self.chdir_file(filepath)
94
94
  if File.symlink?(filepath)
95
95
  Dir.chdir(File.dirname(File.readlink(filepath)))
@@ -97,19 +97,19 @@ module Knj::Os
97
97
  Dir.chdir(File.dirname(filepath))
98
98
  end
99
99
  end
100
-
100
+
101
101
  def self.realpath(path)
102
102
  return self.realpath(File.readlink(path)) if File.symlink?(path)
103
103
  return path
104
104
  end
105
-
105
+
106
106
  #Runs a command and returns output. Also throws an exception of something is outputted to stderr.
107
107
  def self.shellcmd(cmd)
108
108
  res = {
109
109
  :out => "",
110
110
  :err => ""
111
111
  }
112
-
112
+
113
113
  if RUBY_ENGINE == "jruby"
114
114
  begin
115
115
  IO.popen4(cmd) do |pid, stdin, stdout, stderr|
@@ -131,70 +131,70 @@ module Knj::Os
131
131
  res[:err] << stderr.read
132
132
  end
133
133
  end
134
-
134
+
135
135
  if res[:err].to_s.strip.length > 0
136
136
  raise res[:err]
137
137
  end
138
-
138
+
139
139
  return res[:out]
140
140
  end
141
-
141
+
142
142
  #Runs a command as a process of its own and wont block or be depended on this process.
143
143
  def self.subproc(cmd)
144
144
  %x[#{cmd} >> /dev/null 2>&1 &]
145
145
  end
146
-
146
+
147
147
  #Returns the xauth file for GDM.
148
148
  def self.xauth_file
149
149
  authfile = ""
150
-
151
- if File.exists?("/var/run/gdm")
150
+
151
+ if File.exist?("/var/run/gdm")
152
152
  Dir.foreach("/var/run/gdm") do |file|
153
153
  next if file == "." or file == ".." or !file.match(/^auth-for-gdm-.+$/)
154
154
  authfile = "/var/run/gdm/#{file}/database"
155
155
  end
156
156
  end
157
-
158
- if File.exists?("/var/run/lightdm")
157
+
158
+ if File.exist?("/var/run/lightdm")
159
159
  Dir.foreach("/var/run/lightdm") do |file|
160
160
  next if file == "." or file == ".."
161
-
161
+
162
162
  Dir.foreach("/var/run/lightdm/#{file}") do |f2|
163
163
  authfile = "/var/run/lightdm/#{file}/#{f2}" if f2.match(/^:(\d+)$/)
164
164
  end
165
165
  end
166
166
  end
167
-
167
+
168
168
  if authfile.to_s.length <= 0
169
169
  raise "Could not figure out authfile for GDM."
170
170
  end
171
-
171
+
172
172
  return authfile
173
173
  end
174
-
174
+
175
175
  #Checks if the display variable and xauth is set - if not sets it to the GDM xauth and defaults the display to :0.0.
176
176
  def self.check_display_env
177
177
  ret = {}
178
-
178
+
179
179
  if ENV["DISPLAY"].to_s.strip.length <= 0
180
180
  x_procs = Knj::Unix_proc.list("grep" => "/usr/bin/X")
181
181
  set_disp = nil
182
-
182
+
183
183
  x_procs.each do |x_proc|
184
184
  if match = x_proc["cmd"].match(/(:\d+)/)
185
185
  set_disp = match[1]
186
186
  break
187
187
  end
188
188
  end
189
-
189
+
190
190
  raise "Could not figure out display." if !set_disp
191
-
191
+
192
192
  ENV["DISPLAY"] = set_disp
193
193
  ret["display"] = set_disp
194
194
  else
195
195
  ret["display"] = ENV["DISPLAY"]
196
196
  end
197
-
197
+
198
198
  if !ENV["XAUTHORITY"]
199
199
  res = Knj::Os.xauth_file
200
200
  ENV["XAUTHORITY"] = res
@@ -202,31 +202,31 @@ module Knj::Os
202
202
  else
203
203
  ret["xauth"] = ENV["XAUTHORITY"]
204
204
  end
205
-
205
+
206
206
  return ret
207
207
  end
208
-
208
+
209
209
  #Returns the command used to execute the current process.
210
210
  def self.executed_cmd
211
211
  return ENV["SUDO_COMMAND"] if ENV["SUDO_COMMAND"]
212
-
212
+
213
213
  proc_self = Knj::Unix_proc.find_self
214
214
  cmd = proc_self["cmd"]
215
-
215
+
216
216
  cmd.gsub!(/^ruby([\d\.]+)/, ENV["_"]) if ENV["_"]
217
-
217
+
218
218
  return cmd
219
219
  end
220
-
220
+
221
221
  #Returns the Ruby executable that is running the current process if possible.
222
222
  def self.executed_executable
223
223
  return ENV["rvm_ruby_string"] if !ENV["rvm_ruby_string"].to_s.empty?
224
-
224
+
225
225
  if ENV["MY_RUBY_HOME"]
226
226
  ruby_bin_path = "#{ENV["MY_RUBY_HOME"]}/bin/ruby"
227
- return ruby_bin_path if File.exists?(ruby_bin_path)
227
+ return ruby_bin_path if File.exist?(ruby_bin_path)
228
228
  end
229
-
229
+
230
230
  #Try to look the executeable up by command.
231
231
  if self.os == "linux"
232
232
  unix_proc = Knj::Unix_proc.find_self
@@ -240,13 +240,13 @@ module Knj::Os
240
240
  raise "Could not find the self-process."
241
241
  end
242
242
  end
243
-
243
+
244
244
  # Code for returning RBEnv Ruby path if running through RBEnv.
245
245
  if ENV["RBENV_VERSION"] && ENV["RBENV_ROOT"]
246
246
  rbenv_path = "#{ENV["RBENV_ROOT"]}/versions/#{ENV["RBENV_VERSION"]}/bin/ruby"
247
- return rbenv_path if File.exists?(rbenv_path)
247
+ return rbenv_path if File.exist?(rbenv_path)
248
248
  end
249
-
249
+
250
250
  raise "Could not figure out the executed executable from the environment: '#{ENV.to_hash}'."
251
251
  end
252
252
  end
@@ -1,31 +1,31 @@
1
1
  class Knj::Power_manager
2
2
  def initialize(args = {})
3
3
  @args = args
4
-
5
- if !File.exists?("/proc/acpi/ac_adapter")
4
+
5
+ if !File.exist?("/proc/acpi/ac_adapter")
6
6
  raise "Could not find the proc-acpi folder."
7
7
  end
8
-
8
+
9
9
  Dir.new("/proc/acpi/ac_adapter").each do |file|
10
10
  next if file == "." or file == ".."
11
11
  fn = "/proc/acpi/ac_adapter/#{file}"
12
-
12
+
13
13
  if File.directory?(fn)
14
14
  @ac_folder = Php4r.realpath(fn)
15
15
  break
16
16
  end
17
17
  end
18
-
18
+
19
19
  raise "Could not register ac-folder." if !@ac_folder
20
20
  end
21
-
21
+
22
22
  def state
23
23
  cont = File.read("#{@ac_folder}/state")
24
-
24
+
25
25
  if match = cont.match(/state:\s*(.+)\s*/)
26
26
  return match[1]
27
27
  end
28
-
28
+
29
29
  raise "Could not figure out state."
30
30
  end
31
31
  end
@@ -6,24 +6,24 @@ path_to = ARGV[0]
6
6
 
7
7
  Dir.glob(File.join("**", ".svn")).each do |dir|
8
8
  newdir = path_to + "/" + dir
9
-
9
+
10
10
  #print dir + "\n"
11
11
  #print newdir + "\n"
12
-
13
- if File.exists?(newdir)
12
+
13
+ if File.exist?(newdir)
14
14
  print "Remove: " + newdir.to_s + "\n"
15
15
  FileUtils.rm_r(newdir)
16
16
  end
17
-
17
+
18
18
  begin
19
19
  #print "Move: " + dir + "\n"
20
20
  #FileUtils.mv(dir, newdir)
21
-
21
+
22
22
  print "Copy: " + dir + "\n"
23
23
  FileUtils.cp_r(dir, newdir)
24
24
  rescue => e
25
25
  print "Failed: " + e.message + "\n"
26
26
  end
27
-
27
+
28
28
  #print "\n"
29
29
  end
@@ -20,16 +20,16 @@ checks = [
20
20
  checks.each do |dir|
21
21
  dev_name = dir + "_dev"
22
22
  original_name = dir + "_original"
23
-
23
+
24
24
  if mode == "dev"
25
- if File.exists?(dir) and File.symlink?(dir)
25
+ if File.exist?(dir) and File.symlink?(dir)
26
26
  #do nothing.
27
- elsif File.exists?(dir) and !File.exists?(original_name)
27
+ elsif File.exist?(dir) and !File.exist?(original_name)
28
28
  File.rename(dir, original_name)
29
29
  File.rename(dev_name, dir)
30
30
  end
31
31
  elsif mode == "original"
32
- if File.exists?(dir) and File.exists?(original_name) and File.symlink?(dir)
32
+ if File.exist?(dir) and File.exist?(original_name) and File.symlink?(dir)
33
33
  File.rename(dir, dev_name)
34
34
  File.rename(original_name, dir)
35
35
  else
data/lib/knj/web.rb CHANGED
@@ -443,7 +443,7 @@ class Knj::Web
443
443
  raise "No value given in arguments for imageupload-input." if !args.key?(:value)
444
444
 
445
445
  path = args[:path].gsub("%value%", value.to_s).untaint
446
- if File.exists?(path)
446
+ if File.exist?(path)
447
447
  html << "<img src=\"image.rhtml?path=#{self.urlenc(path).html}&smartsize=100&rounded_corners=10&border_color=black&force=true&ts=#{Time.new.to_f}\" alt=\"Image\" />"
448
448
 
449
449
  if args[:dellink]