init.rb in rwdschedule-0.6 vs init.rb in rwdschedule-0.07

- old
+ new

@@ -16,218 +16,164 @@ #* You should have received a copy of the GNU General Public #* License along with these files; if not, write to the Free Software #* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #* #* For further information please contact the author by e-mail -#* at "steven@superant.com". +#* at "smalllinux@gmail.com". #***********************************************************************/ -require "ev/rwd" +require 'logger' + +LogDirectory = 'rwd_files/log/' +logfilelocation = File.join(LogDirectory, 'rwdtinker.log') + +$rwdtinkerlog = Logger.new( logfilelocation , 'weekly' ) +$rwdtinkerlog.level = Logger::INFO + +require "lib/rwd/rwd" require 'fileutils' - +require 'lib/rconftool' + +$KCODE = 'u' +require 'jcode' + $progdir = File::expand_path( File.dirname(__FILE__)) - $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 - -# Read in the configuration files - - Dir.chdir("configuration") #changes the current working directory - - fileList = Dir.new(".").entries.sort.reverse.delete_if { |x| ! (x =~ /cnf$/) } #creates an Array separated with \n - @doc = "" - fileList.length.times{ #opening of a block - fileName=fileList.pop #pops the first item out of the Array - load fileName #loads the the config file thats in fileName +tempdoc = " " + +# integrate the new configuration files +MAINconfignew = "rwdconfig.cnf" +MAINconfigdist = "rwdconfig.dist" +Rconftool::install(MAINconfigdist,MAINconfignew) + +#load main config file +load 'rwdconfig.cnf' + +Dir.chdir("configuration") #changes the current working directory + +fileList = Dir.new(".").entries.sort.reverse.delete_if { |x| ! (x =~ /dist$/) } #creates an Array separated with \n +@doc = "" +fileList.length.times{ #opening of a block +configdist =fileList.pop #pops the first item out of the Array +tempconfigfile = configdist.gsub(/\.dist$/, "") +confignew = tempconfigfile + ".cnf" +Rconftool::install(configdist,confignew) #integrates new file with old } #closing block - # END of configuration reading + # END of configuration integration + Dir.chdir($progdir) - Dir.chdir($progdir) # change back to top program directory + # Read in the configuration files + Dir.chdir("configuration") #changes the current working directory - # build the English Language hash file from the parts - startlangdir = @@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 - 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 + fileList = Dir.new(".").entries.sort.reverse.delete_if { |x| ! (x =~ /cnf$/) } #creates an Array separated with \n + @doc = "" + fileList.length.times{ #opening of a block + fileName=fileList.pop #pops the first item out of the Array + load fileName #loads the the config file thats in fileName + } #closing block + # END of configuration reading - fileLangHash=File.open(TempLangHashFile,"w") #deletes and opens a the file in fileName - fileLangHash.write($tempdoc) #writes the contents of doc into the file - fileLangHash.close - # END of Lang building - $tempdoc = " " Dir.chdir($progdir) # change back to top program directory - - # build the local Language hash file from the parts - startlangdir = @@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 - filelocalLangHash=File.open(LocalLangHashFile,"w") #deletes and opens a the file in fileName - filelocalLangHash.write($tempdoc) #writes the contents of doc into the file - filelocalLangHash.close -$tempdoc = " " + # build the English Language hash file from the parts + 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 + + def msgstr(programmsg) + if programmsg == "" + $rwdtinkerlog.info "msgstr: no translation for #{$programkey}" + else + Message.update( $programkey.to_sym => programmsg ) + end +end - Dir.chdir($progdir) # change back to top program directory + require 'lib/rwdtinker/rwdlangdir' + + tempdoc = " " + #go get all the po language file files in english + tempdoc = RwdtinkerTools.findlanguagefiles(LangDir,"en") - # build the language hash constant object from the lang parts - #get a list of the files in lang directory only - alangfile = Dir.new(@@langdir).entries.sort.reverse.delete_if { |x| ! (x =~ /rb$/) } - alangfile.length.times{ - fileName = alangfile.pop - Dir.chdir($progdir) - Dir.chdir(@@langdir) - fileLangA=File.open("#{fileName}","r") #opens the file thats in fileName as read only - $tempdoc += fileLangA.read #reads the file into the doc string - fileLangA.close - } - -Dir.chdir($progdir) - fileLangB=File.open(LangNameFile,"w") #deletes and opens a the file in fileName - fileLangB.write($tempdoc) #writes the contents of doc into the file - fileLangB.close - load LangNameFile # load the file + #writes the contents of doc into the languagehashvariable + languagehashvariable = tempdoc - $tempdoc = " " + # END of en Lang building + tempdoc = " " + Dir.chdir($progdir) # change back to top program directory - # 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 + # build the local Language hash file from the parts + + $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 - fileB=File.open(CodeNameFile,"w") #deletes and opens a the file in fileName - fileB.write($tempdoc) #writes the contents of doc into the file - fileB.close - require CodeName # load the program file + Dir.chdir($progdir) # change back to top program directory + + # lets read those po files, first english then the chosen language + temp = eval( languagehashvariable ) -# 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) - - else #it is a directory... - loadguifile(x + "/**") - end - end + - fileB=File.open(RWDFile,"w") #deletes and opens a the file in fileName - fileB.write($tempdoc) #writes the contents of doc into the file - fileB.close + # build the actual program from the code parts + require 'lib/rwdtinker/rwdcodedir' + + tempdoc = RwdtinkerTools.findprogramfiles(CodeDir) + + # load the program file + + tempcoderesult = eval( tempdoc ) + + # build the actual GUI from the gui parts + require 'lib/rwdtinker/rwdguidir' - + tempdoc = RwdtinkerTools.findguifiles(GuiDir) + -RwdTinker.file(RWDFile).serve($port) # start the main class and program + # gui variable is done + guiRWD = "" + $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 + freeportfound = false + until freeportfound + begin + @socket = UDPSocket::new() + @socket.bind(host, port) + freeportfound = true + $port = port + # Rescue the "Address in use" error + rescue Errno::EADDRINUSE + $rwdtinkerlog.warn "RWD Startup: Port #{port} on host #{host} is already in use." + port=port +1 + $rwdtinkerlog.warn "trying port: #{port}" + # Rescue the "Address not available' error + rescue Errno::EADDRNOTAVAIL + $rwdtinkerlog.warn "RWD Startup: Address #{host} is not available to bind." + port =port + 1 + $rwdtinkerlog.warn "trying port: #{port}" + # Rescue "permission denied errors + rescue Errno::EACCES + $rwdtinkerlog.warn "RWD Startup: Access denied when binding interface addresses. ?" + port =port + 1 + $rwdtinkerlog.warn "trying port: #{port}" + # Rescue all other errors + rescue + $rwdtinkerlog.warn "RWD Startup: An error occured." + port =port + 1 + $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