File: make-print-sample.rb

package info (click to toggle)
rabbit 3.0.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 14,220 kB
  • sloc: ruby: 29,637; lisp: 309; makefile: 43; sh: 9
file content (95 lines) | stat: -rwxr-xr-x 2,609 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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
#!/usr/bin/env ruby

require "optparse"
require "ostruct"
require "fileutils"

require "rabbit/rabbit"

options = OpenStruct.new
options.rabbit = "bin/rabbit"
options.output_base = "/tmp/rabbit-print"
options.lang_suffixes = ["", "-en"]
options.locale_dir = "data/locale"

opts = OptionParser.new do |opts|
  opts.banner = "#{opts.banner} RD_FILES"

  opts.on("--rabbit=RABBIT",
          "rabbit path",
          "(#{options.rabbit})") do |rabbit|
    options.rabbit = rabbit
  end

  opts.on("--output-base=BASE",
          "output base directory",
          "(#{options.output_base})") do |base|
    options.output_base = base
  end

  opts.on("--lang_suffixes=SUFFIX,SUFFIX,...",
          Array,
          "([#{options.lang_suffixes.join(', ')}])") do |suffixes|
    options.lang_suffixes = suffixes
  end

  opts.on("--locale-dir=DIR",
          "locale directory",
          "(#{options.locale_dir})") do |dir|
    options.locale_dir = dir
  end
end

opts.parse!(ARGV)

version = `#{options.rabbit} --version`.chop

def print(rabbit, locale_dir, rd, output, include_path, type)
  args = rabbit.split
  args.concat(["--locale-dir", locale_dir,
               "-I", include_path,
               "-p",
               "-o", output,
               rd])
  system(*args)
  puts("finished #{rd}. (#{type})")
end

def print_index(rabbit, locale_dir, rd, output, include_path, type)
  args = rabbit.split
  args.concat(["--locale-dir", locale_dir,
               "-I", include_path,
               "-p",
               "-o", output,
               "--slides-per-page", "8",
               rd])
  system(*args)
  puts("finished #{rd}. (index #{type})")
end

ARGV.each do |rd|
  base_name = File.basename(rd, ".rd")
  output_dir = File.join(options.output_base, base_name)
  FileUtils.mkdir_p(output_dir)
  puts("processing #{rd}...")
  options.lang_suffixes.each do |lang|
    base_dir = File.dirname(rd)
    target_rd = File.join(base_dir, "#{base_name}#{lang}.rd")
    ps = File.join(output_dir, "#{base_name}#{lang}-#{version}.ps")
    pdf = ps.gsub(/\.ps\z/, ".pdf")
    index_ps = File.join(output_dir, "#{base_name}#{lang}-index-#{version}.ps")
    index_pdf = index_ps.gsub(/\.ps\z/, ".pdf")

    args = [options.rabbit, options.locale_dir, target_rd]
    begin
      original_lang = ENV["LANG"]
      ENV["LANG"] = "C" if /-en\b/ =~ lang
      print(*(args + [ps, base_dir, "PS"]))
      print(*(args + [pdf, base_dir, "PDF"]))
      print_index(*(args + [index_ps, base_dir, "PS"]))
      print_index(*(args + [index_pdf, base_dir, "PDF"]))
    ensure
      ENV["LANG"] = original_lang
    end
  end
end