Module: LP::Exporter::App

Defined in:
lib/lp/exporter/app.rb

Overview

Application module

Class Method Summary collapse

Class Method Details

.getOptionsHash

Parse passed options

Returns:

  • (Hash)

    options



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
# File 'lib/lp/exporter/app.rb', line 12

def self.getOptions
    options = {
        :Parser => nil,
        :LP => nil,
        :Path => './tmp/',
        :Files => [],
        :Lang => false
    }
    options[:Parser] = OptionParser.new do |opts|
        opts.banner = 'Usage: lp_exporter.rb [options] lp.cab|langpacks'
        opts.on('-p', '--path dir', 'Path to output directory') do |path|
            options[:Path] = path
        end
        opts.on('-f','--files names', Array, 'Names for files to match') do |files|
            files.each do |file|
                options[:Files] << file
            end
        end
        opts.on('-l','--[no-]lang', 'Use language name not LangID from PE') do |lang|
            options[:Lang] = lang
        end

        opts.on_tail('-h', '--help', 'Show this message') do
            puts opts
            return false
        end
    end
    begin
        options[:LP] = options[:Parser].parse!.first
    rescue OptionParser::ParseError => e
        $stderr.puts e.message
        return false
    end
    options
end

.startObject

Start Application



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/lp/exporter/app.rb', line 49

def self.start
    options = getOptions
    if not options or options[:LP].nil?
        puts options[:Parser].help
        return false
    end
    Dir.mktmpdir do |tmpdir|
        cabs = []
        if File.directory?(options[:LP])
            cabs += Dir[File.join(options[:LP],'**','*.cab')]
        else
            cabs << options[:LP]
        end
        cabs.each do |cab|
            LP::Exporter.process(cab, options[:Files], tmpdir, options[:Path], options[:Lang])
            puts 'Done for ' + cab
        end
    end
    true
end