~noskcaj/ubuntu/saucy/dhelp/apache2.4

« back to all changes in this revision

Viewing changes to dhelp_parse.rb

  • Committer: Bazaar Package Importer
  • Author(s): Colin Watson
  • Date: 2008-06-19 01:25:07 UTC
  • Revision ID: james.westby@ubuntu.com-20080619012507-adt75omul1shucde
Tags: 0.6.9ubuntu1
* Resynchronise with Debian. Remaining changes:
  - Recommends: firefox-3.0.
  - Exit zero if the bdb module is not available; this usually indicates
    that dhelp is not configured yet.

Show diffs side-by-side

added added

removed removed

Lines of Context:
61
61
    version           "0.1.0"
62
62
    author            "Esteban Manchado Vel�zquez"
63
63
    copyright         "Copyright (c) 2005-2007, Esteban Manchado Vel�zquez"
64
 
    synopsis          "[-h] -a doc-base_file | -d doc-base_file | -r"
 
64
    synopsis          "[-h] -a doc-base_file1 d-b_f2 ... | -d doc-base_file1 d-b_f2 ... | -r"
65
65
    short_description "Debian online help system parser"
66
66
    long_description  "Dhelp parser to add/remove/reindex dhelp files"
67
67
 
68
68
    option :help
69
 
    option :names => %w(-a), :arity => 1,
 
69
    option :names => %w(-a), :arity => [0,-1],
70
70
           :opt_found => lambda {|opt, name, value| @action = :add;
71
 
                                                    @doc_base_file = value.first },
 
71
                                                    @doc_base_files = value },
72
72
           :opt_description => "add documents registered in the given doc-base file"
73
 
    option :names => %w(-d), :arity => 1,
 
73
    option :names => %w(-d), :arity => [0,-1],
74
74
           :opt_found => lambda {|opt, name, value| @action = :delete;
75
 
                                                    @doc_base_file = value.first },
76
 
           :opt_description => "ignored, for compatibility"
 
75
                                                    @doc_base_files = value },
 
76
           :opt_description => "remove documents registered in the given doc-base file"
77
77
    option :names => %w(-r), :arity => [0,0],
78
78
           :opt_found => lambda { @action = :reindex },
79
79
           :opt_description => "ignored, for compatibility"
80
 
    option :names => %w(-v), :arity => [0,0],
81
 
           :opt_description => "verbose mode"
82
80
 
83
81
    expected_args [0,0]
84
82
 
105
103
 
106
104
    # List of directories to look for doc-base documents
107
105
    doc_base_dirs = conf.search_directories.map {|d| File.expand_path(d)}
108
 
    deleted_docs  = []
109
 
    indexer = Indexer.new(:search_dirs => doc_base_dirs)
 
106
    pool = Dhelp::DhelpDocumentPool.new(:doc_base_dir => doc_base_dirs)
110
107
 
111
108
    case @action
112
109
    when :add
113
 
      # We are given a doc-base file. We have to extract its files and feed
114
 
      # them to the indexer
115
 
      if File.readable? @doc_base_file
116
 
        doc_base_doc = Dhelp::DocBaseDocument.new(@doc_base_file)
117
 
        indexer.index(doc_base_doc.files)
118
 
      else
119
 
        $stderr.puts "Can't read doc-base file '#{@doc_base_file}'"
120
 
        return 1
 
110
      @doc_base_files.each do |doc_base_file|
 
111
        if File.readable? doc_base_file
 
112
          doc_base_doc = Dhelp::DocBaseDocument.new(doc_base_file)
 
113
          pool.register(doc_base_doc)
 
114
        else
 
115
          $stderr.puts "Can't read doc-base file '#{doc_base_file}'"
 
116
          return 1
 
117
        end
121
118
      end
122
119
    when :delete
123
 
      # There's no easy way to "unindex" a file apart from rebuilding the whole
124
 
      # thing from scratch, so we'll have to leave with false positives in
125
 
      # searches. However, the doc-base file is there when someone de-register
126
 
      # a document, so we have to skip it when regenerating the documentation
127
 
      # directory
128
 
      deleted_docs = @doc_base_file
 
120
      @doc_base_files.each do |doc_base_file|
 
121
        pool.deregister(doc_base_file)
 
122
      end
129
123
    when :reindex
130
124
      # Simply ignore, the documentation directory will be up-to-date anyway.
131
 
      # See above note for :delete action.
132
125
    else
133
126
      $stderr.puts usage
134
127
      return 1
135
128
    end
136
129
 
137
130
    # Always executed
138
 
    pool = DocBaseDocumentPool.new(:dirs => doc_base_dirs,
139
 
                                   :skip => deleted_docs)
140
131
    exporter = Dhelp::Exporter::Html.new(pool)
141
132
    exporter.export(:dir => DEFAULT_INDEX_ROOT)
142
133
  rescue => e