edango 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. data/Copying.txt +679 -0
  2. data/History.txt +6 -0
  3. data/Manifest.txt +46 -0
  4. data/PostInstall.txt +6 -0
  5. data/README.rdoc +117 -0
  6. data/Rakefile +21 -0
  7. data/bin/edango +34 -0
  8. data/lib/edango.rb +42 -0
  9. data/lib/edango/context.rb +23 -0
  10. data/lib/edango/context/directories.rb +67 -0
  11. data/lib/edango/context/files.rb +37 -0
  12. data/lib/edango/context/language.rb +101 -0
  13. data/lib/edango/context/parameters.rb +44 -0
  14. data/lib/edango/context/services.rb +147 -0
  15. data/lib/edango/di/container.rb +160 -0
  16. data/lib/edango/di/helpers.rb +41 -0
  17. data/lib/edango/di/proxy.rb +54 -0
  18. data/lib/edango/di/service.rb +60 -0
  19. data/lib/edango/di/service_factory.rb +40 -0
  20. data/lib/edango/environment.rb +77 -0
  21. data/lib/edango/executor.rb +64 -0
  22. data/lib/edango/helpers/hash.rb +30 -0
  23. data/lib/edango/helpers/kernel.rb +41 -0
  24. data/lib/edango/helpers/object.rb +65 -0
  25. data/lib/edango/helpers/string.rb +29 -0
  26. data/lib/edango/helpers/symbol.rb +39 -0
  27. data/lib/edango/logic/ticket_extractor.rb +258 -0
  28. data/lib/edango/site/core.rb +182 -0
  29. data/lib/edango/site/public/favicon.ico +0 -0
  30. data/lib/edango/site/public/images/btn-back-help.png +0 -0
  31. data/lib/edango/site/public/images/bullet.png +0 -0
  32. data/lib/edango/site/public/images/ctrl-back.gif +0 -0
  33. data/lib/edango/site/public/images/frm-back-err.png +0 -0
  34. data/lib/edango/site/public/images/frm-back-help.png +0 -0
  35. data/lib/edango/site/public/images/frm-back.png +0 -0
  36. data/lib/edango/site/public/images/logo.png +0 -0
  37. data/lib/edango/site/public/scripts/jquery.js +4376 -0
  38. data/lib/edango/site/public/scripts/jquery.min.js +19 -0
  39. data/lib/edango/site/public/scripts/logic.js +6 -0
  40. data/lib/edango/site/public/styles/layout.css +270 -0
  41. data/lib/edango/site/views/errors.haml +12 -0
  42. data/lib/edango/site/views/help.haml +10 -0
  43. data/lib/edango/site/views/index.haml +27 -0
  44. data/lib/edango/site/views/layout.haml +15 -0
  45. data/lib/edango/site/views/result.haml +10 -0
  46. data/lib/edango/starter.rb +141 -0
  47. metadata +162 -0
@@ -0,0 +1,44 @@
1
+ # EDango - torrent ticket extractor.
2
+ # Copyright (C) 2010 Dmitrii Toksaitov
3
+ #
4
+ # This file is part of EDango.
5
+ #
6
+ # EDango is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # EDango is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with EDango. If not, see <http://www.gnu.org/licenses/>.
18
+
19
+ module EDango
20
+
21
+ PARAMETERS = DI::Container.new do
22
+ asset :options, :file => FILES[:options] do
23
+ {:environment => :production,
24
+ :server_logging => true,
25
+ :time_limit => 10,
26
+ :servers => ['thin', 'mongrel', 'webrick'],
27
+ :host => '0.0.0.0',
28
+ :port => 6666,
29
+ :sites => []}
30
+ end
31
+
32
+ asset :modes do
33
+ {:verbose => false,
34
+ :quiet => false,
35
+ :debug => false}
36
+ end
37
+
38
+ asset :tasks do
39
+ {:show_version => false,
40
+ :show_help => false}
41
+ end
42
+ end
43
+
44
+ end
@@ -0,0 +1,147 @@
1
+ require 'edango/di/container'
2
+
3
+ module EDango
4
+
5
+ SERVICES = DI::Container.new do
6
+ service :environment do
7
+ on_creation do
8
+ require_all *FILES[:helpers]
9
+ require 'edango/environment'
10
+
11
+ Environment.instance()
12
+ end
13
+
14
+ interface :log_error do |instance, exception, message|
15
+ instance.log_error(exception, message)
16
+ end
17
+
18
+ interface :log_warning do |instance, text|
19
+ instance.log_warning(text)
20
+ end
21
+
22
+ interface :log_message do |instance, text|
23
+ instance.log_message(text)
24
+ end
25
+
26
+ interface :show_message do |instance, text, log|
27
+ instance.show_message(text, log)
28
+ end
29
+ end
30
+
31
+ service :starter do
32
+ on_creation do
33
+ require 'edango/starter'; Starter.new()
34
+ end
35
+
36
+ interface :run do |instance|
37
+ instance.run()
38
+ end
39
+
40
+ interface :usage do |instance|
41
+ instance.options
42
+ end
43
+ end
44
+
45
+ service :core do
46
+ on_creation do
47
+ require 'edango/site/core'; Core
48
+ end
49
+
50
+ interface :run do |instance|
51
+ instance.run()
52
+ end
53
+ end
54
+
55
+ service :executor do
56
+ on_creation do
57
+ require 'edango/executor'; Executor.new()
58
+ end
59
+
60
+ interface :run do |instance|
61
+ instance.run()
62
+ end
63
+ end
64
+
65
+ service :timer do
66
+ on_creation do
67
+ require 'timeout'; Timeout
68
+ end
69
+ end
70
+
71
+ service :logic do
72
+ on_creation do
73
+ require 'edango/logic/ticket_extractor'
74
+
75
+ TicketExtractor.new()
76
+ end
77
+
78
+ interface :process do |instance, *args|
79
+ instance.extract_tickets(*args)
80
+ end
81
+
82
+ interface :errors do |instance|
83
+ instance.errors
84
+ end
85
+ end
86
+
87
+ service :web do
88
+ on_creation do
89
+ require 'sinatra/base'; Sinatra::Base
90
+ end
91
+ end
92
+
93
+ service :agent do
94
+ on_creation do
95
+ require 'mechanize'
96
+
97
+ WWW::Mechanize.new do |agent|
98
+ agent.user_agent_alias = 'Windows Mozilla'
99
+ agent.history.max_size = 0
100
+ end
101
+ end
102
+ end
103
+
104
+ service :uri do
105
+ on_creation do
106
+ require 'uri'; URI
107
+ end
108
+
109
+ interface :host do |instance, uri|
110
+ instance.parse(uri.to_s()).host.gsub(/^www\./, '') rescue ''
111
+ end
112
+
113
+ interface :valid? do |instance, uri|
114
+ (instance.parse(uri.to_s()); true) rescue false
115
+ end
116
+ end
117
+
118
+ service :logger do
119
+ on_creation do
120
+ require 'logger'
121
+
122
+ logger = Logger.new(FILES[:log], 10, 1048576)
123
+ logger.level = Logger::INFO
124
+
125
+ logger
126
+ end
127
+
128
+ interface :error do |instance, message|
129
+ message = message.inspect.strip()
130
+ instance.error(message)
131
+ end
132
+
133
+ interface :warn do |instance, message|
134
+ message = message.inspect.strip()
135
+ instance.warn(message)
136
+ end
137
+
138
+ interface [:info, :put, :write, :<<] do |instance, message|
139
+ message = message.inspect.strip()
140
+ instance.info(message)
141
+ end
142
+
143
+ interface :flush do |instance| end
144
+ end
145
+ end
146
+
147
+ end
@@ -0,0 +1,160 @@
1
+ # EDango - torrent ticket extractor.
2
+ # Copyright (C) 2010 Dmitrii Toksaitov
3
+ #
4
+ # This file is part of EDango.
5
+ #
6
+ # EDango is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # EDango is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with EDango. If not, see <http://www.gnu.org/licenses/>.
18
+
19
+ require 'yaml'
20
+
21
+ require 'edango/di/helpers'
22
+
23
+ require 'edango/di/proxy'
24
+ require 'edango/di/service_factory'
25
+
26
+ module EDango
27
+ module DI
28
+
29
+ class Container
30
+ class TrapError < Exception; end
31
+
32
+ attr_reader :services
33
+
34
+ def initialize(&block)
35
+ @services = {}
36
+ @current_service = nil
37
+
38
+ instance_eval(&block) if block_given?
39
+ end
40
+
41
+ def service(name, &block)
42
+ @current_service = name
43
+
44
+ instance_eval(&block) if block_given?
45
+
46
+ @current_service = nil
47
+ end
48
+
49
+ def on_creation(&block)
50
+ asset(@current_service, &block)
51
+ end
52
+
53
+ def asset(arg, options = {}, &block)
54
+ name, instance = arg, nil
55
+
56
+ if arg.is_a?(Hash)
57
+ name, instance = arg.to_a().first
58
+ end
59
+
60
+ path = options[:file]
61
+ if path
62
+ instance = (YAML.load_file(path) rescue nil) || instance
63
+ end
64
+
65
+ if instance or block_given?
66
+ service = find_service(name)
67
+
68
+ service[:block] = block
69
+ service[:instance] = instance
70
+ service[:file] = path
71
+ end
72
+ end
73
+
74
+ def interface(args, service_name = nil, &block)
75
+ service_name ||= @current_service
76
+
77
+ if block_given?
78
+ args = [args] unless args.is_a?(Array)
79
+
80
+ args.each do |name|
81
+ service = find_service(service_name)
82
+ service[:interfaces][name.intern()] = block if service
83
+ end
84
+ end
85
+ end
86
+
87
+ def [](name, option = nil)
88
+ result = nil
89
+
90
+ service_name = name.intern()
91
+ service = @services[service_name]
92
+
93
+ if service
94
+ result = service[:instance]
95
+ if result.nil? or option == :init
96
+ instance = service[:block].call()
97
+ if instance
98
+ result = service[:instance] =
99
+ Proxy.new(instance, service[:interfaces])
100
+ end
101
+ end
102
+ end
103
+
104
+ option == :raw ? result.delegate : result
105
+ end
106
+
107
+ def update(arg, file = nil)
108
+ services = if arg.is_a?(Symbol)
109
+ if arg == :all
110
+ file = nil; @services.values
111
+ else
112
+ [find_service(arg.intern())]
113
+ end
114
+ else
115
+ [arg]
116
+ end
117
+
118
+ services.each do |service|
119
+ serialize(service, file) if service
120
+ end
121
+ end
122
+
123
+ private
124
+ def serialize(service, file = nil)
125
+ path = file || service[:file]
126
+ instance = service[:instance]
127
+
128
+ if path and instance
129
+ begin
130
+ File.open(path, 'w+') do |io|
131
+ io.write(instance.to_yaml())
132
+ end
133
+ rescue Exception => e
134
+ puts("DI container failed to serialize service to #{path}")
135
+ puts(e.message, e.backtrace)
136
+ end
137
+ end
138
+ end
139
+
140
+ def find_service(name)
141
+ result = nil
142
+
143
+ if name
144
+ service_name = name.intern()
145
+
146
+ result = @services[service_name]
147
+ unless result
148
+ new_service = DummyServiceFactory.service
149
+ new_service.add_observer(self)
150
+
151
+ result = @services[service_name] = new_service
152
+ end
153
+ end
154
+
155
+ result
156
+ end
157
+ end
158
+
159
+ end
160
+ end
@@ -0,0 +1,41 @@
1
+ # EDango - torrent ticket extractor.
2
+ # Copyright (C) 2010 Dmitrii Toksaitov
3
+ #
4
+ # This file is part of EDango.
5
+ #
6
+ # EDango is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # EDango is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with EDango. If not, see <http://www.gnu.org/licenses/>.
18
+
19
+ class Symbol
20
+ unless method_defined?(:intern)
21
+ define_method(:intern) do
22
+ self.to_s().intern()
23
+ end
24
+ end
25
+ end
26
+
27
+ class File
28
+ def self.prepare_directory(path)
29
+ path = File.expand_path(path)
30
+
31
+ Dir.mkdir(path) unless File.directory?(path) rescue nil
32
+
33
+ path
34
+ end
35
+ end
36
+
37
+ module Kernel
38
+ def require_all(file, *files)
39
+ (files << file).each { |item| require(item) }
40
+ end
41
+ end
@@ -0,0 +1,54 @@
1
+ # EDango - torrent ticket extractor.
2
+ # Copyright (C) 2010 Dmitrii Toksaitov
3
+ #
4
+ # This file is part of EDango.
5
+ #
6
+ # EDango is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # EDango is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with EDango. If not, see <http://www.gnu.org/licenses/>.
18
+
19
+ module EDango
20
+ module DI
21
+
22
+ class Proxy
23
+ class ProxyError < Exception; end
24
+
25
+ instance_methods.each do |method|
26
+ undef_method(method) unless method =~ /(^__|^send$|^object_id$)/
27
+ end
28
+
29
+ attr_reader :delegate, :interfaces
30
+
31
+ def initialize(delegate, interfaces = {})
32
+ @delegate = delegate
33
+ @interfaces = interfaces
34
+ end
35
+
36
+ def respond_to?(symbol, include_private=false)
37
+ @delegate.respond_to?(symbol, include_private) ||
38
+ @interfaces.has_key?(symbol)
39
+ end
40
+
41
+ private
42
+ def method_missing(name, *args, &block)
43
+ interface = @interfaces[name.intern()]
44
+
45
+ unless interface.nil?
46
+ interface.call(@delegate, *args, &block)
47
+ else
48
+ @delegate.send(name, *args, &block)
49
+ end
50
+ end
51
+ end
52
+
53
+ end
54
+ end