Class: RunTeX::Rail

Inherits:
Tool
  • Object
show all
Defined in:
lib/runtex_rail.rb

Overview

The package rail.sty requires a run of rail.exe. If a rail-diagramms changed (or the sequence of different diagrams) the program must run again.

Constant Summary

Constants included from Catch_output

Catch_output::STDERR_ORIG, Catch_output::STDOUT_ORIG

Instance Attribute Summary

Attributes inherited from Tool

#options, #step

Instance Method Summary collapse

Methods inherited from Tool

#build_cmd, #summary

Methods included from Catch_output

#catch_screen_output, #catch_stderr, #catch_stdout

Constructor Details

#initialize(job, options = {}) ⇒ Rail

Returns a new instance of Rail.



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/runtex_rail.rb', line 10

def initialize(job, options = {})
  super(job, options, {})
  @options.keys.each{|key|
    case key
      when :source
      when :target
      else
        @job.log.error( "#{@step} #{self.class}: Unknown option #{key}" ) if @job.log.error?
    end
  }
end

Instance Method Details

#execute(step) ⇒ Object

Call Rail



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/runtex_rail.rb', line 22

def execute( step )
  super(step)

  @job.log.debug( "#{@step} Call Rail.exe to create rail-diagramms." ) if @job.log.debug?
  
  @result = { 
          :error    => [],
          :info => [],
      }
      
  if File.exist?( @options[:source])
    @job.add2zip( @options[:source] )
  else
    @job.log.error( "#{@step} Rail: Source-File is missing" ) if @job.log.error?
    @result[:error] << "Rail: Source-File is missing"
  end
  
  if File.exist?( @options[:target] )
    @job.add2zip( @options[:target] )
    raoold = File.readlines(@options[:target])
  end

  configuration = Job_chain::Configuration['rail']
  #Rail.exe don't like long filenames, but via pipe it works    

  #Problem with pipes: There is a bug with closing the file, delete/zip runs into error.

  #~ cmd = configuration['call'] + " -t < #{@options[:source]} > #{@options[:target]}"

  #-> Rename files for 8-char size, so rail.exe can handle it

  File.rename(@options[:source], 'rail_tmp.rai')
  cmd = build_cmd('rail', :railfile => 'rail_tmp')
  subrc = nil
  stdout, stderr = catch_screen_output{ subrc = system(cmd) }
  @job.log.error( "#{@step} Error Rail: #{cmd}") if !subrc and @job.log.error?

  #rename back

  File.rename('rail_tmp.rai', @options[:source])  #must exist

  if File.exist?('rail_tmp.rao')
    File.rename('rail_tmp.rao', @options[:target]) 
    #~ # Delete first two lines from rao-File (contains Version-Message)

    rao = File.readlines( @options[:target] )
    rao.each{ |raoline|
      raoline.sub!(/^(This is Rail.*)/, '%\1')
      raoline.sub!(/^(\(stdin.*)/, '%\1')
      raoline.sub!(/^\)/, '%\1)')   #last line

    }
    File.open( @options[:target], 'w' ){|rao2|
      rao2 << rao
    }
  else
    @result[:error] << "No rao-File created"
    @job.log.error( "#{@step} Error Rail: No rao-File created") if @job.log.error?
    @job.stop_rerun( :rail, "Rail: No rao-file created")   #block rerun for rail

  end #rao-file created



  stderr.each{ |errline|
    case errline
      when /(.*), line (.*): (.*)/
        #$1: Filename (e.g. 'stdin')

        @result[:error] << "Line #{$2}: #{$3}"
        @job.stop_rerun( :rail, "Rail: #{$3} on line #{$2}")   #block rerun for rail

    end
  }
  
  stdout.each{ |stdout_line|
    case stdout_line
    when /This is Rail, Version (.*)\s/
      @result[:info] << "Rail version #{$1} was called"
    when /(Der Prozess kann nicht auf die Datei zugreifen, .*)/
      @result[:error] << "#{$1}"
    end
  }

  if File.exist?( @options[:target] )
    @job.add2zip( @options[:target] )
    raonew = File.readlines(@options[:target])
    if raoold != raonew
      @job.please_rerun("Rail: rao-file changed")
    end
  else
    @job.log.error( "#{@step} Rail: .rao-File is missing" ) if @job.log.error?
    @result[:error] << "Rail: .rao-File is missing"
  end
  
  @job.helpfiles << @options[:target]
  @job.helpfiles << @options[:source]
  
  return @result
end

#inspectObject

Used in logger



111
112
113
# File 'lib/runtex_rail.rb', line 111

def inspect()
  "Rail"
end