Revisão | bac07dd405571d3812b8f22c70454955247c9da4 (tree) |
---|---|
Hora | 2007-02-11 12:12:42 |
Autor | ikeji <ikeji@f836...> |
Commiter | ikeji |
import pragger main module
git-svn-id: http://dev.ikejima.org/src/svn/pragger/trunk@285 f8368ae4-1e99-dc11-9799-0018f35ab5fa
@@ -0,0 +1,68 @@ | ||
1 | +#!/usr/bin/env ruby | |
2 | + | |
3 | +require "yaml" | |
4 | +require "optparse" | |
5 | + | |
6 | +#plugin loader | |
7 | +class Plugin | |
8 | + def initialize(folder = "./plugin") | |
9 | + Dir::glob(folder + "/*.rb").sort.each do |file| | |
10 | + load_plugin(file) | |
11 | + end | |
12 | + end | |
13 | + def load_plugin(file) | |
14 | + File.open(file) do |src| | |
15 | + instance_eval( src.read , file , 1) | |
16 | + end | |
17 | + end | |
18 | +end | |
19 | + | |
20 | +#config roader | |
21 | +class Config | |
22 | + def initialize() | |
23 | + end | |
24 | + | |
25 | + attr_accessor :command_array | |
26 | + | |
27 | + def self.load_file(fname) | |
28 | + c = Config.new | |
29 | + c.command_array = YAML.load_file(fname) | |
30 | + return c | |
31 | + end | |
32 | + | |
33 | + def self.load_array(array) | |
34 | + c = Config.new | |
35 | + c.command_array = array | |
36 | + return c | |
37 | + end | |
38 | + | |
39 | + def eval() | |
40 | + return eval_pragger(@command_array,[]) | |
41 | + end | |
42 | +end | |
43 | + | |
44 | +#interpritor | |
45 | +def eval_pragger(command_array,data) | |
46 | + command_array.each do|command| | |
47 | + puts "exec plugin " + command["module"] + "(" + command["config"].to_s + ")" | |
48 | + data = $plugin.send(command["module"],command["config"],data.clone) | |
49 | + end | |
50 | + return data | |
51 | +end | |
52 | + | |
53 | +#main | |
54 | + | |
55 | +#option | |
56 | +pluginDir = "./plugin" | |
57 | +configFile = "config.yaml" | |
58 | + | |
59 | +OptionParser.new do|opt| | |
60 | + opt.on("-c", "--configfile CONFIGFILE"){|v| configFile = v } | |
61 | + opt.on("-p", "--plugindir PLUGINDIR"){|v| pluginDir= v } | |
62 | + opt.parse!(ARGV) | |
63 | +end | |
64 | + | |
65 | +$plugin = Plugin.new(pluginDir) | |
66 | +config = Config.load_file(configFile) | |
67 | +config.eval() | |
68 | + |