From 7310101ce7739889fd4681864978f2c71722bbd6 Mon Sep 17 00:00:00 2001 From: Hans Hagen Date: Thu, 27 Apr 2006 15:59:00 +0200 Subject: stable 2006.04.27 15:59 --- scripts/context/ruby/base/ctx.rb | 30 +++++++++++++++++++++++++++--- scripts/context/ruby/base/switch.rb | 36 +++++++++++++++++++++++++++++++----- scripts/context/ruby/ctxtools.rb | 11 +++++++++-- 3 files changed, 67 insertions(+), 10 deletions(-) (limited to 'scripts') diff --git a/scripts/context/ruby/base/ctx.rb b/scripts/context/ruby/base/ctx.rb index 6c8dd5a44..e39751fb6 100644 --- a/scripts/context/ruby/base/ctx.rb +++ b/scripts/context/ruby/base/ctx.rb @@ -23,6 +23,8 @@ class CtxRunner attr_reader :environments, :modules, :filters + @@suffix = 'prep' + def initialize(jobname=nil,logger=nil) if @logger = logger then def report(str='') @@ -129,13 +131,29 @@ class CtxRunner REXML::XPath.each(@xmldata.root,"/ctx:job/ctx:process/ctx:resources/ctx:filter") do |fil| @filters << justtext(fil) end + commands = Hash.new + REXML::XPath.each(@xmldata.root,"/ctx:job/ctx:preprocess/ctx:processors/ctx:processor") do |pre| + begin + commands[pre.attributes['name']] = pre + rescue + end + end + suffix = @@suffix + begin + suffix = REXML::XPath.match(@xmldata.root,"/ctx:job/ctx:preprocess/@suffix").to_s + rescue + puts $! + suffix = @@suffix + else + if suffix && suffix.empty? then suffix = @@suffix end + end REXML::XPath.each(@xmldata.root,"/ctx:job/ctx:preprocess/ctx:files") do |files| REXML::XPath.each(files,"ctx:file") do |pattern| preprocessor = pattern.attributes['processor'] if preprocessor and not preprocessor.empty? then pattern = justtext(pattern) Dir.glob(pattern).each do |oldfile| - newfile = "#{oldfile}.prep" + newfile = "#{oldfile}.#{suffix}" if File.needsupdate(oldfile,newfile) then begin File.delete(newfile) @@ -144,11 +162,17 @@ class CtxRunner end # there can be a sequence of processors preprocessor.split(',').each do |pp| - if command = REXML::XPath.first(@xmldata.root,"/ctx:job/ctx:preprocess/ctx:processors/ctx:processor[@name='#{pp}']") then + if command = commands[pp] then # a lie: no command = REXML::Document.new(command.to_s) # don't infect original command = command.elements["ctx:processor"] - report("preprocessing #{oldfile} using #{pp}") + begin + if suf = command.attributes['suffix'] then + newfile = "#{oldfile}.#{suf}" + end + rescue + end + report("preprocessing #{oldfile} into #{newfile} using #{pp}") REXML::XPath.each(command,"ctx:old") do |value| replace(value,oldfile) end REXML::XPath.each(command,"ctx:new") do |value| replace(value,newfile) end variables['old'] = oldfile diff --git a/scripts/context/ruby/base/switch.rb b/scripts/context/ruby/base/switch.rb index 97575cdaa..64b1abef0 100644 --- a/scripts/context/ruby/base/switch.rb +++ b/scripts/context/ruby/base/switch.rb @@ -47,23 +47,49 @@ class File @@update_eps = 1 + # def File.needsupdate(oldname,newname) + # begin + # oldtime = File.stat(oldname).mtime.to_i + # newtime = File.stat(newname).mtime.to_i + # if newtime >= oldtime + # return false + # elsif oldtime-newtime < @@update_eps then + # return false + # else + # return true + # end + # rescue + # return true + # end + # end + def File.needsupdate(oldname,newname) begin oldtime = File.stat(oldname).mtime.to_i newtime = File.stat(newname).mtime.to_i - delta = newtime - oldtime - delta < @@update_eps +# str = "o:#{oldtime} n:#{newtime} d:#{newtime-oldtime}" + if newtime >= oldtime +# puts "original is unchanged: #{str}" + return false + elsif oldtime-newtime < @@update_eps then +# puts "original is within range: #{str}" + return false + else +# puts "original is updated: #{str}" + return true + end rescue return true end end def File.syncmtimes(oldname,newname) + return begin if $mswindows then - # does not work (yet) - t = File.mtime(oldname) # i'm not sure if the time is frozen, so we do it here - File.utime(0,t,oldname,newname) + # does not work (yet) / gives future timestamp + # t = File.mtime(oldname) # i'm not sure if the time is frozen, so we do it here + # File.utime(0,t,oldname,newname) else t = File.mtime(oldname) # i'm not sure if the time is frozen, so we do it here File.utime(0,t,oldname,newname) diff --git a/scripts/context/ruby/ctxtools.rb b/scripts/context/ruby/ctxtools.rb index 0ba1a7561..6d36051fa 100644 --- a/scripts/context/ruby/ctxtools.rb +++ b/scripts/context/ruby/ctxtools.rb @@ -421,6 +421,12 @@ class Commands recurse = @commandline.option("recurse") $dontaskprefixes.push(Dir.glob("mpx-*")) + + if purgeall then + $dontaskprefixes.push(Dir.glob("*.tex.prep")) + $dontaskprefixes.push(Dir.glob("*.xml.prep")) + end + $dontaskprefixes.flatten! $dontaskprefixes.sort! @@ -433,7 +439,7 @@ class Commands if ! pattern || pattern.empty? then globbed = if recurse then "**/*.*" else "*.*" end files = Dir.glob(globbed) - report("purging files : #{globbed}") + report("purging#{if all then ' all' end} temporary files : #{globbed}") else pattern.each do |pat| globbed = if recurse then "**/#{pat}-*.*" else "#{pat}-*.*" end @@ -441,7 +447,7 @@ class Commands globbed = if recurse then "**/#{pat}.*" else "#{pat}.*" end files.push(Dir.glob(globbed)) end - report("purging files : #{pattern.join(' ')}") + report("purging#{if all then ' all' end} temporary files : #{pattern.join(' ')}") end files.flatten! files.sort! @@ -2142,6 +2148,7 @@ commandline.registeraction('purgefiles' , 'remove temporary files [--all commandline.registeraction('documentation' , 'generate documentation [--type=] [filename]') commandline.registeraction('filterpages' ) # no help, hidden temporary feature commandline.registeraction('purgeallfiles' ) # no help, compatibility feature +commandline.registeraction('purgefiles' ) # no help, compatibility feature commandline.registeraction('patternfiles' , 'generate pattern files [--all --xml --utf8] [languagecode]') commandline.registeraction('dpxmapfiles' , 'convert pdftex mapfiles to dvipdfmx [--force] [texmfroot]') commandline.registeraction('listentities' , 'create doctype entity definition from enco-uc.tex') -- cgit v1.2.3