init.rb in rwdruby-1.07 vs init.rb in rwdruby-1.08
- old
+ new
@@ -19,49 +19,23 @@
#*
#* For further information please contact the author by e-mail
#* at "smalllinux@gmail.com".
#***********************************************************************/
+require 'logger'
+
+$rwdtinkerlog = Logger.new( 'rwd_files/log/rwdtinker.log', 'weekly' )
+$rwdtinkerlog.level = Logger::INFO
+
require "lib/rwd/rwd"
require 'fileutils'
require 'lib/rconftool'
$progdir = File::expand_path( File.dirname(__FILE__))
-$tempdoc = " "
+tempdoc = " "
-def findfiles(d)
- a = Array.new(Dir[d].entries.sort)
- #loop through and get the files names
- a.each do |x|
- #adjust the filters to the files you want to see...
- if(!test(?d,x))
- # only rwd files
- if x =~ /rb|rwd|txt/
- fileA=File.open("#{x}","r") #opens the file thats in fileName as read only
- $tempdoc+=fileA.read #reads the file into the doc string
- fileA.close
- end
- end
- end
-end
-def loadguifile(d)
- a = Array.new(Dir[d].entries.sort)
- #loop through and get the files names
- a.each do |x|
- #adjust the filters to the files you want to see...
- if(!test(?d,x))
- # only rwd files
- if x =~ /rb|rwd|txt/
-
- load x #opens the file thats in fileName and reads it
- $tempdoc += $rwdguivar # adds the file into the doc string
- end
- end
- end
-end
-
# integrate the new configuration files
MAINconfignew = "rwdconfig.cnf"
MAINconfigdist = "rwdconfig.dist"
Rconftool::install(MAINconfigdist,MAINconfignew)
@@ -92,152 +66,74 @@
} #closing block
# END of configuration reading
Dir.chdir($progdir) # change back to top program directory
+
# build the English Language hash file from the parts
- languagehashvariable = 'Message = Hash.new { |hh, kk| hh[kk] = "ERROR: Message not found: #{kk.inspect}."; hh[kk] }
- langmessage = {' + "\n"
- startlangdir = File.join(LangDir,"en")
- #get a list of the files and subdirectories on the starting directory only
- alanghash = Array.new(Dir[startlangdir].entries.sort)
- #loop through the list, ignore the files and add all new directories found
- alanghash.each do |x|
- #if a directory...
- if(test(?d,x))
- # add to the original list of directories
- @@tmproot = x + "/**"
- #adds the new ones to the array
- blanghash = Dir[@@tmproot].entries.sort
- blanghash.each do |x|
- if(test(?d,x))
- alanghash.push(x) #appends to the end of the array...
- end
- end
- end
+ Message = Hash.new { |hh, kk| hh[kk] = "ERROR: Message not found: #{kk.inspect}."; hh[kk] }
+ langmessage = { :clear => "Clear", :rwdtinker => "Rwdtinker" } ; langmessage.each { |kk, vv| Message[kk] = vv }
+
+ def msgid(programkey)
+ $programkey = programkey
end
- alanghash.each do |x|
- #if it is a file...
- if(!test(?d,x))
- alanghash.delete(x)
- else #it is a directory...
- findfiles(x + "/**")
- end
- end
+
+ def msgstr(programmsg)
+ if programmsg == ""
+ $rwdtinkerlog.info "msgstr: no translation for #{$programkey}"
+ else
+ Message.update( $programkey.to_sym => programmsg )
+ end
+end
+
+ require 'lib/rwdtinker/rwdlangdir'
+
+ tempdoc = " "
+ #go get all the po language file files in english
+ tempdoc = RwdtinkerTools.findlanguagefiles(LangDir,"en")
-
#writes the contents of doc into the languagehashvariable
- languagehashvariable = languagehashvariable + $tempdoc + "} ; langmessage.each { |kk, vv| Message[kk] = vv }"
+ languagehashvariable = tempdoc
# END of en Lang building
- $tempdoc = " "
+ tempdoc = " "
Dir.chdir($progdir) # change back to top program directory
# build the local Language hash file from the parts
- startlangdir = File.join(LangDir,$lang)
- #get a list of the files and subdirectories on the starting directory only
- alanghash = Array.new(Dir[startlangdir].entries.sort)
- #loop through the list, ignore the files and add all new directories found
- alanghash.each do |x|
- #if a directory...
- if(test(?d,x))
- # add to the original list of directories
- @@tmproot = x + "/**"
- #adds the new ones to the array
- blanghash = Dir[@@tmproot].entries.sort
- blanghash.each do |x|
- if(test(?d,x))
- alanghash.push(x) #appends to the end of the array...
- end
- end
- end
- end
- alanghash.each do |x|
- #if it is a file...
- if(!test(?d,x))
- alanghash.delete(x)
- else #it is a directory...
- findfiles(x + "/**")
- end
- end
+
+ $lang = $langarray[0] # pick the language of choice
+
+ # Go get all the po files for the language of choice
+ tempdoc = RwdtinkerTools.findlanguagefiles(LangDir,$lang)
+ # the contents of doc into the variable
+ languagehashvariable = languagehashvariable + tempdoc
+ Dir.chdir($progdir) # change back to top program directory
+
+ # lets read those po files, first english then the chosen language
+ temp = eval( languagehashvariable )
- #writes the contents of doc into the variable
- languagehashvariable = languagehashvariable + " ; Message.update(" + $tempdoc + ' :rwdtinker => "Rwdtinker" ) '
+
-
- $tempdoc = " "
-
- Dir.chdir($progdir) # change back to top program directory
-
- temp = eval( languagehashvariable )
-
- $tempdoc = " "
-
# build the actual program from the code parts
- #get a list of the files and subdirectories on the starting directory only
- a = Array.new(Dir[CodeDir].entries.sort)
- #loop through the list, ignore the files and add all new directories found
- a.each do |x|
- #if a directory...
- if(test(?d,x))
- # add to the original list of directories
- @@root = x + "/**"
- #adds the new ones to the array
- b = Dir[@@root].entries.sort
- b.each do |x|
- if(test(?d,x))
- a.push(x) #appends to the end of the array...
- end
- end
- end
- end
- a.each do |x|
- #if it is a file...
- if(!test(?d,x))
- a.delete(x)
- else #it is a directory...
- findfiles(x + "/**")
- end
- end
+ require 'lib/rwdtinker/rwdcodedir'
+
+ tempdoc = RwdtinkerTools.findprogramfiles(CodeDir)
-
# load the program file
- tempcoderesult = eval( $tempdoc )
+
+ tempcoderesult = eval( tempdoc )
# build the actual GUI from the gui parts
- $tempdoc = " "
- #get a list of the files and subdirectories on the starting directory only
- a = Array.new(Dir[GuiDir].entries.sort)
- #loop through the list, ignore the files and add all new directories found
- a.each do |x|
- #if a directory...
- if(test(?d,x))
- #use this new dir find to add to the original list of directories
- @@root = x + "/**"
- #adds the new ones to the array
- b = Dir[@@root].entries.sort
- b.each do |x|
- if(test(?d,x))
- a.push(x) #appends to the end of the array...
- end
- end
- end
- end
- a.each do |x|
- #if it is a file...
- if(!test(?d,x))
- a.delete(x)
+ require 'lib/rwdtinker/rwdguidir'
+
+ tempdoc = RwdtinkerTools.findguifiles(GuiDir)
+
- else #it is a directory...
- loadguifile(x + "/**")
- end
- end
-
# gui variable is done
guiRWD = ""
- $rwd_gui_tinker = $tempdoc
+ $rwd_gui_tinker = tempdoc
require 'socket' # Network stuff
host = "127.0.0.1"
port = $port
# Create a socket to listen on and bind it to the host and port
@@ -248,30 +144,30 @@
@socket.bind(host, port)
freeportfound = true
$port = port
# Rescue the "Address in use" error
rescue Errno::EADDRINUSE
- puts "RWD Startup: Port #{port} on host #{host} is already in use."
+ $rwdtinkerlog.warn "RWD Startup: Port #{port} on host #{host} is already in use."
port=port +1
- puts "trying port: #{port}"
+ $rwdtinkerlog.warn "trying port: #{port}"
# Rescue the "Address not available' error
rescue Errno::EADDRNOTAVAIL
- puts "RWD Startup: Address #{host} is not available to bind."
+ $rwdtinkerlog.warn "RWD Startup: Address #{host} is not available to bind."
port =port + 1
- puts "trying port: #{port}"
+ $rwdtinkerlog.warn "trying port: #{port}"
# Rescue "permission denied errors
rescue Errno::EACCES
- puts "RWD Startup: Access denied when binding interface addresses. ?"
+ $rwdtinkerlog.warn "RWD Startup: Access denied when binding interface addresses. ?"
port =port + 1
- puts "trying port: #{port}"
+ $rwdtinkerlog.warn "trying port: #{port}"
# Rescue all other errors
rescue
- puts "RWD Startup: An error occured."
+ $rwdtinkerlog.warn "RWD Startup: An error occured."
port =port + 1
- puts "trying port: #{port}"
+ $rwdtinkerlog.warn "trying port: #{port}"
# Rescue all other errors
end
-
+ $port = port
end
RwdTinker.new( $rwd_gui_tinker ).serve(port) # start the main class and program