#!/usr/bin/env ruby require "qte" require "qpe" include Qte include Qpe class MainWindow < QMainWindow def initialize super self.setCaption(tr("EBtLog2HTML")) @label = QLabel.new(tr("保存先はebtのログの場所から一個上がって./ebt_html"),self) @label4= QLabel.new(tr("↓ebtのログの場所"),self) @qstn3=QLineEdit.new(tr("/mnt/cf/ebt/"),self) @myb01=QPushButton.new(tr("save"),self) connect(@myb01,QSIGNAL("clicked()"),self,'run') @label.setGeometry(15, 105, 580, 30) @label4.setGeometry(15, 185, 580, 30) @qstn3.setGeometry(15, 295, 290, 40) @myb01.setGeometry(305, 295, 290, 40) end def myselect dlg = UkFileDialog.new(self,"/home/zaurus/Documents/", 0, "フォルダの選択") res = dlg.exec() if (res == QDialog::Accepted) filePath = dlg.filePath() end end def run @ss=@qstn3.text().utf8().to_str() if @ss[-1,1]!="/";@ss=@ss+"/";end if (!FileTest.directory?(@ss)) exit() end # ebtpath="/mnt/cf/ebt/" # mkpath="/mnt/cf/ebt_html/" ebtpath=@ss tmp=ebtpath[0..-2] mkpath=tmp[0..tmp.rindex("/")]+"ebt_html/" @@mkpath="#{mkpath}"; if (!FileTest.directory?(mkpath)) Dir.mkdir(mkpath); end dirs = Array.new();files = Array.new() Dir.foreach(ebtpath) { |file| if (FileTest.directory?(File.join(ebtpath, file))); dirs.push(file) else; files.push(file); end } @fp = File.new(mkpath+"index.html", "w"); @fp.puts"\nebt Log\n" @fp.puts"" @fp.puts"" @fp.puts"\n" @fp.close ### make menu page ### mkpath=mkpath+"top/" if (!FileTest.directory?(mkpath)) Dir.mkdir(mkpath); end fp = File.new(mkpath+"menu.html", "w"); fp.puts"\n\n" #files=files.sort tmp=[] files.size.times{|i| if (files[i].index(".txt")==nil);next;end; fname=files[i][0..files[i].index(".")-1] pathname="";cnt=0 open(ebtpath+fname+".txt", "r").map{|z|pathname=z;if pathname[-1,1]=="\n";pathname.chop!;end;break} tmp<<[pathname, fname] # fp.puts"・#{pathname}
" } tmp=tmp.sort; tmp.size.times{|k|fp.puts"・#{tmp[k][0]}/open
"} fp.puts"\n" fp.close ### make top page ### fpath="" open(ebtpath+"home.index","r").map{|s|fpath=s} tmp=[] open(ebtpath+fpath+".txt","r").map{|s|tmp<\n\n" tmp.size.times{|i|fp.print tmp[i]+"
"} fp.puts"\n" fp.close ### make root files ### files.each{|s| if (s.index("txt")!=nil); tmp=[] open(ebtpath+s, "r").map{|w|tmp<\n\n" tmp.size.times{|i|fp.print tmp[i]+"
"} fp.puts"\n" fp.close elsif (s.index("index")!=nil) tmp=[] open(ebtpath+s, "r").map{|w|tmp<\n\n" pathname=""; open(ebtpath+fname+".txt", "r").map{|z| pathname=z;if pathname[-1,1]=="\n";pathname.chop!;end;break } fp.puts"・#{pathname}
" buf=[] tmp.size.times{|i| if tmp[i][-1,1]=="\n";tmp[i].chop!;end;if tmp[i][0,1]=="/";tmp[i]=tmp[i][1..-1];end pathname=""; open(ebtpath+tmp[i]+".txt","r").map{|z| pathname=z;if pathname[-1,1]=="\n";pathname.chop!;end;break } buf<<[pathname,tmp[i]] # fp.puts"・#{pathname}
" } buf=buf.sort buf.size.times{|k|fp.puts"・#{buf[k][0]}/open
"} fp.puts"\n" fp.close else system("cp #{ebtpath+s} #{mkpath+s}") fp = File.new(mkpath+"menu.html", "a"); fp.puts"#{s}
" fp.close end } ### make other files ### d_month=["01","02","03","04","05","06","07","08","09","10","11","12"] dirs.size.times{|i| if dirs[i][0,1]==".";next;end if (!FileTest.directory?(mkpath+dirs[i])) Dir.mkdir(mkpath+dirs[i]) end d_month.size.times{|mon| dirpath=ebtpath+dirs[i]+"/"+d_month[mon] if (!FileTest.directory?(dirpath)) # puts"no#{dirpath}" else # puts"ok#{dirpath}" if (!FileTest.directory?(mkpath+dirs[i]+"/"+d_month[mon])) Dir.mkdir(mkpath+dirs[i]+"/"+d_month[mon]); end files=[] Dir.foreach(dirpath) { |file| if (FileTest.directory?(File.join(dirpath, file))); if file[0,1]==".";next;end puts"okasii!#{file}" else; files.push(file); end } files.size.times{|q|#puts files[q] @qstn3.setText(tr(files[q])) s = files[q] if (s.index("txt")!=nil); tmp=[] open(dirpath+"/"+s, "r").map{|w|tmp<\n\n" tmp.size.times{|v|fp.print tmp[v]+"
"} fp.puts"\n" fp.close elsif (s.index("index")) tmp=[] open(ebtpath+dirs[i]+"/"+d_month[mon]+"/"+s, "r").map{|w|tmp<\n\n" fp.puts"・#{pathname}
" buf=[] tmp.size.times{|o| if tmp[o].size<2;next;end if tmp[o][-1,1]=="\n";tmp[o].chop!;end;if tmp[o][0,1]=="/";tmp[o]=tmp[o][1..-1];end pathname=""; open(ebtpath+tmp[o]+".txt", "r").map{|z| pathname=z;if pathname[-1,1]=="\n";pathname.chop!;end;break } buf<<[pathname, tmp[o]] # fp.puts"・#{pathname}
" } buf=buf.sort buf.size.times{|k|fp.puts"・#{buf[k][0]}/open
"} fp.puts"\n" fp.close else fname=s[0..s.index(".")-1] system("cp #{ebtpath+dirs[i]+"/"+d_month[mon]+"/"+s} #{mkpath+dirs[i]+"/"+d_month[mon]+"/"+s}") fp = File.new(mkpath+dirs[i]+"/"+d_month[mon]+"/"+fname+"_m.html", "a"); fp.puts"#{s}
" fp.close end } end } } @myb01.setText(tr("save終わりました。")) end end class MyApplication < QPEApplication def initialize super([$0]+ARGV) self.setDefaultCodec(QTextCodec::codecForName("utf-8")) end end app=MyApplication.new app.showMainWidget(MainWindow.new()) app.exec