浏览代码

Add config file :)

Antoine Leroyer 11 年之前
父节点
当前提交
4a1e4e89d5
共有 4 个文件被更改,包括 27 次插入13 次删除
  1. 10 0
      config.yml-dist
  2. 1 0
      lib/rSeed.rb
  3. 1 4
      lib/rSeed/config.rb
  4. 15 9
      lib/rSeed/server.rb

+ 10 - 0
config.yml-dist

@@ -0,0 +1,10 @@
+#
+# Config file for rSeed
+#
+
+rtorrent:
+  rpc_host: "localhost"     # Hostname, should be localhost
+  rpc_port: 80              # Default port for your HTTP server
+  rpc_path: "/RPC2"         # Location directive in your HTTP instance to connect to rTorrent
+
+

+ 1 - 0
lib/rSeed.rb

@@ -12,6 +12,7 @@ require "net/http"
 require "sinatra"
 require "xmlrpc/client"
 require "sys/filesystem"
+require "yaml"
 
 require "rSeed/server"
 require "rSeed/config"

+ 1 - 4
lib/rSeed/config.rb

@@ -3,10 +3,7 @@ module RSeed
         extend self
     
         @data = {
-            :data_path => "/tmp",
-            :rpc_host => "seed.aonoscantrad.fr",
-            :rpc_path => "/RPC2",
-            :rpc_port => "80",
+            "data_path" => "/tmp",
         }
 
         def set(key, val = nil, &blk)

+ 15 - 9
lib/rSeed/server.rb

@@ -3,15 +3,6 @@
 module RSeed
   class Server < Sinatra::Base
 
-    # ConstrucThor huhu
-    # -----------------
-    def initialize(*args, &blk)
-      super
-      RSeed::Config.instance_eval(&blk) if block_given?
-      @config = Config
-      @rtorrent = Rtorrent.new(@config.get(:rpc_host), @config.get(:rpc_path), @config.get(:rpc_port))
-    end
-
     # Sinatra Conf
     # ------------
     set :root, File.join(File.dirname(__FILE__), '..', '..')
@@ -22,6 +13,21 @@ module RSeed
       cache_control :public, :must_revalidate, :max_age => 60
     end
 
+    # ConstrucThor huhu
+    # -----------------
+    def initialize(*args, &blk)
+      super
+      RSeed::Config.instance_eval(&blk) if block_given?
+      @config = Config
+      confFile = File.join(settings.root, 'config.yml')
+      if File.exists? confFile
+        YAML.load_file(confFile).each_value do |c|
+          c.each {|key, value| @config.set(key,value)}
+        end
+      end
+      @rtorrent = Rtorrent.new(@config.get("rpc_host"), @config.get("rpc_path"), @config.get("rpc_port"))
+    end
+
     # Helperz
     # -------
     helpers do