チケット #10 (closed enhancement: fixed)

登録: 2 年 前

最終更新: 3 ヶ月 前

-pオプションの意味

報告者: soutaro 担当者: soutaro
優先度: major マイルストーン: First Release 0.1
コンポーネント: pragger バージョン:
キーワード: 関係者: ikeji

チケットの概要

現行のpraggerでは,-pオプションを利用して,pluginを配置するディレクトリを変更できます. このオプションの意味を「pluginを配置するディレクトリの追加」に変更するのはどうでしょう? privateなプラグインが利用しやすくなる予定.あと#8ともちょと関係があるかもしれません.

この件についてコメントを募集します.

pragger.rbに対するパッチを添付しますが,このパッチは他にもいろいろ変更を含んでいるので,良くないパッチだと思います.すみません.

一応,このパッチでの変更点をリストします.

  1. $plugins変数にプラグインを全て登録
  2. Pathnameを利用して,File.readlinkを除去
  3. Plugin#sourceメソッドで,プラグインのソースコードを取得
  4. -uオプションを,-uオプションと-lオプションに分離
  5. eval_praggerのreturnを排除
  6. プラグインの説明とするコメントの書式の変更

いろいろと微妙なやつがあるので,IKeJIと直接相談したかったんですが,つかまらないのでTracに登録します.ちなみに全体の行数はたぶんちょっと短くなるはず(39行).

Index: pragger.rb
===================================================================
--- pragger.rb  (revision 41)
+++ pragger.rb  (working copy)
@@ -3,44 +3,37 @@
 require 'yaml'
 require 'optparse'
 require 'kconv'
+require 'pathname'
 
+$plugins = {}
 class Plugin
+  attr_reader :source
   def initialize(file)
-      instance_eval( File.read(file).toutf8 , file , 1)
+    @source = File.read(file).toutf8
+    instance_eval( @source, file , 1)
   end
-  def self.load_plugins(folder = "plugin")
-    Dir.glob(File.join(folder, "**/*.rb")).sort.inject({}) do |plugins,file|
-      plugins.update( Hash[ file[folder.size+1..-1].to_s.gsub("/","::")[0..-4] , Plugin.new(file) ])
+  def self.load_plugins(folder = (Pathname.new(__FILE__).realpath.parent + "plugin").to_s)
+    Dir.glob(File.join(folder, "**/*.rb")).sort.each do |file|
+      $plugins.update( Hash[ file[folder.size+1..-1].to_s.gsub("/","::")[0..-4] , Plugin.new(file) ])
     end
   end
 end
 
 def eval_pragger(command_array,data)
-  command_array.inject({}) do|data,command|
+  command_array.inject({}) do |data,command|
     puts "exec plugin #{command["module"]}"
-    $plugin[command["module"]].send(command["module"].sub(/.*::/,""), command["config"], data.clone)
+    $plugins[command["module"]].send(command["module"].sub(/.*::/,""), command["config"], data.clone)
   end
-  return data
 end
 
-baseDir = begin File.readlink(__FILE__) 
-          rescue Exception 
-          (__FILE__) end
-pluginDir = File.join(File.dirname(baseDir), "plugin")
+Plugin.load_plugins()
 configFile = "config.yaml"
-OptionParser.new do|opt|
-  opt.on("-c", "--configfile CONFIGFILE"){|v| configFile = v }
-  opt.on("-p", "--plugindir PLUGINDIR"){|v| pluginDir= v }
-  opt.on("-u", "--pluginusage [PLUGINNAME]"){|v| 
-    if(v==nil)
-      Plugin.load_plugin(pluginDir).each{|k,v| puts k }
-    else
-      File.read(File.join(pluginDir,v.gsub("::","/")+".rb")).sub(/#(.*)/){ puts $1 }
-    end
-    exit
-  }
+OptionParser.new do |opt|
+  opt.on("-c", "--configfile CONFIGFILE") {|v| configFile = v }
+  opt.on("-p", "--plugindir PLUGINDIR") {|v| Plugin.load_plugins v }
+  opt.on("-u", "--pluginusage PLUGINNAME") {|v| $plugins[v].source.gsub(/^##(.*)/){ puts $1 }; exit }
+  opt.on("-l", "--listplugin") { $plugins.keys.sort.each{|k| puts k }; exit }
   opt.parse!(ARGV)
 end
 
-$plugin = Plugin.load_plugins(pluginDir)
 eval_pragger(YAML.load(File.read(configFile).toutf8),[])

添付ファイル

チケットの履歴

2007/02/22 09:45:51 更新者:ikeji

  • ステータスnew から closed に更新されました。
  • 解決方法fixed に更新されました。

おお。これはいいですね。 勝手で申しわけないですが、取り込んでしまいました。

2007/02/22 09:48:04 更新者:ikeji

[49]ですね。

Windows版でも動くのを確認してあります。

2008/05/09 23:57:36 更新者:anonymous

2008/10/04 23:51:36 更新者:anonymous

Both annotations and contributions will only clutter the interface by default as a design pattern rather than trying to put it all together. That way you can never create offline or print docs of high quality without again having the devs or current admins maintain the comments and annotations. Hopefully a small Wiki quality team will evolve (i am against ops or admins) to review and summarize the contributions. I hope this gives us more users as contributors than having the docs focused on the devs. Cheers, duns stair railing Computer Components I still prefer a wiki like approach since the php (or mysql) docs are very cluttered when you have to take their comments in account. On the other hand they are professionally maintained imho, since they are *much* better than KDE documentation. KDE is by far larger and has so many different apps, which need screenshots and end user not dev/api docs, that more help http://www.about-china.net.cn is needed as long as the devs prefer to code than to write nice docs. And it is their choice to some degree imo. Technically interested but non-dev end users, which are plenty out there, are the users of and the best contributers to the docs, since they know what to write about. And they are certainly more than devs.


追記/更新 #10 (-pオプションの意味)




チケット属性を変更する
操作