File: index_package_doc.rb

package info (click to toggle)
dhelp 0.6.32
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 604 kB
  • sloc: ruby: 1,171; sh: 555; perl: 372; makefile: 77
file content (48 lines) | stat: -rw-r--r-- 1,335 bytes parent folder | download | duplicates (5)
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
#!/usr/bin/ruby

require 'dhelp'
require 'fileutils'

SUPPORTED_FORMATS = %w(html text pdf postscript dvi)

if ARGV.size == 0
    $stderr.puts "index_package_doc.rb: index documentation contained in packages"
    $stderr.puts "SYNTAX: index_package_doc.rb <package1> [<package2> ...]"
    $stderr.puts "I need a list of packages to index"
    exit 1
end

doc_base_files = ARGV.map {|p| `dpkg -L #{p}`.split(/\s/)}.
                      flatten.
                      find_all {|line| line =~ /\/usr\/share\/doc-base\//}

doc_list = doc_base_files.map {|d| Dhelp::DocBaseDocument.new(d)}
index_paths = []
doc_list.each do |doc|
  doc.formats.each do |format|
    next unless SUPPORTED_FORMATS.include? format.format.downcase
    format.files.each do |glob_path|
      files = Dir.glob(glob_path)
      index_paths += files.select {|f| File.file? f}
    end
  end
end

puts <<EOF
Indexing the following doc-base files
-------------------------------------
#{doc_base_files.join("\n")}
EOF

# If the index doesn't exist, we have to force non-incremental indexing
options = {}
index_file = '/var/lib/dhelp/documents.index'
if File.exist? index_file and File.size(index_file) == 0
    FileUtils.rm_f index_file
end
unless File.exist? index_file
  options[:incremental] = false
end

idx = Dhelp::Indexer.new
idx.index(index_paths, options)