seiya 0.0.7.2 → 0.0.7.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0702f2dbc3a8bcf07bab3bf695514ebd4f145b46
4
- data.tar.gz: 2e1410f0278a7fbfd49088d637c03f5f89adea70
3
+ metadata.gz: 3e15f457c7583450d47adc4058639963d29bb5f8
4
+ data.tar.gz: 8ac6622f365e454cba1b28532bc321bb56c64749
5
5
  SHA512:
6
- metadata.gz: 0f1f76b24c18bc73658124231906e637db83a5ce70c3fcf5c10665ca29189c5273fcff63845a5853d2ab6cedb77d4ce4cd3c89a46e656bbbff57b40c027a3150
7
- data.tar.gz: 021bddbac89b5f001e46f3d35e367245c574f843ab38b2d7bff0fd4e879995e57218518a85bba8e63751eaadf3a1b69b8d28003f37698c7c40eadd7c057e5cfc
6
+ metadata.gz: 05a98d6f25d14aef282392c23c6bddde99722d544674af380f172fac2b6e7f8873b472778f503dc5cb0a3f49fd59dc96ccc08511bd79edfe429d266c7c25c36a
7
+ data.tar.gz: 73b9bca7ac4cba29bf9752cba7350bad982ac39a95dccc6f84f84bf07bc58306e13fbfa3a53066531673882770c9643ec174f704d48ad7f27b048b6651ee2f8c
@@ -0,0 +1,32 @@
1
+ require 'seiya/command'
2
+ module Contrib
3
+ module Commands
4
+ class Gentask < Seiya::Command
5
+ def summary
6
+ 'Generate new task using pre-defined templates'
7
+ end
8
+
9
+ def usage
10
+ 'Usage
11
+ =====
12
+ seiya gentask [options] <name> <domain>
13
+
14
+ Generate new task using pre-defined templates
15
+
16
+ Options
17
+ =======
18
+ --help, -h show this help message and exit'
19
+ end
20
+
21
+ def run(*args)
22
+ task_name = args.shift
23
+ task_domain = args.shift
24
+ if task_name.nil?
25
+ puts 'Need a task_name!'
26
+ exit!
27
+ end
28
+ Seiya.gen_task_file task_name, task_domain
29
+ end
30
+ end
31
+ end
32
+ end
@@ -1,2 +1,3 @@
1
1
  require_relative './commands/create'
2
2
  require_relative './commands/crawl'
3
+ require_relative './commands/gentask'
data/lib/seiya/support.rb CHANGED
@@ -6,4 +6,11 @@ class String
6
6
  tr('-', '_').
7
7
  downcase
8
8
  end
9
+
10
+ def camelize
11
+ string = self.sub(/^[a-z\d]*/) { $&.capitalize }
12
+ string.gsub!(/(?:_|(\/))([a-z\d]*)/i) { "#{$1}#{$2.capitalize}" }
13
+ string.gsub!(/\//, '::')
14
+ string
15
+ end
9
16
  end
data/lib/seiya/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Seiya
2
- VERSION = '0.0.7.2'
2
+ VERSION = '0.0.7.3'
3
3
  end
data/lib/seiya.rb CHANGED
@@ -17,7 +17,7 @@ module Seiya
17
17
  end
18
18
  end
19
19
 
20
- def get_const(require_str, const_str)
20
+ def get_const!(require_str, const_str)
21
21
  begin
22
22
  require require_str
23
23
  rescue LoadError => e
@@ -34,9 +34,18 @@ module Seiya
34
34
  end
35
35
  end
36
36
 
37
+ def get_const(require_str, const_str)
38
+ require require_str
39
+ Util.get_const const_str
40
+ end
41
+
37
42
  def get_classes(const_path, super_class = Object)
38
43
  require_str, const_str = const_path.split '|'
39
- _module = get_const require_str, const_str
44
+ begin
45
+ _module = get_const require_str, const_str
46
+ rescue LoadError, NameError
47
+ return []
48
+ end
40
49
 
41
50
  _module.constants.select do |c|
42
51
  const = _module.const_get(c)
@@ -46,29 +55,42 @@ module Seiya
46
55
  end
47
56
  end
48
57
 
49
- def extend_load_path(path)
58
+ def get_load_path(path)
50
59
  Dir.foreach path do |f|
51
- unless %w(. ..).include? f
52
- if File.directory? File.join path, f
53
- new_path = File.join path, f
54
- extend_load_path new_path
55
- elsif f == 'tasks.rb'
56
- $:.unshift path
57
- break
60
+ if %w(. ..).include? f
61
+ next
62
+ end
63
+ new_path = File.join path, f
64
+ unless File.directory? new_path
65
+ next
66
+ end
67
+ Dir.foreach new_path do |_f|
68
+ if _f == 'tasks.rb'
69
+ return new_path
58
70
  end
59
71
  end
60
72
  end
73
+ nil
61
74
  end
62
75
 
63
- def setup(conf_file: 'seiya.ini', load_path: Dir.pwd)
64
- extend_load_path load_path
76
+ def extend_load_path(path)
77
+ load_path = get_load_path path
78
+ $:.unshift load_path unless load_path.nil?
79
+ end
65
80
 
66
- require 'inifile'
67
- require 'seiya/util'
68
- conf = IniFile.load conf_file
69
- settings_file = conf.to_h.fetch('global', {}).fetch('settings', 'settings')
70
- settings_require_str, settings_const_str = settings_file.split '|'
71
- require settings_require_str
81
+ def setup(conf_file: 'seiya.ini')
82
+ settings_const_str = ''
83
+ if File.exist? conf_file
84
+ load_path = File.dirname File.expand_path(conf_file)
85
+ extend_load_path load_path
86
+
87
+ require 'inifile'
88
+ require 'seiya/util'
89
+ conf = IniFile.load conf_file
90
+ settings_file = conf.to_h.fetch('global', {}).fetch('settings', 'settings')
91
+ settings_require_str, settings_const_str = settings_file.split '|'
92
+ require settings_require_str
93
+ end
72
94
 
73
95
  pipelines = Settings::PIPELINES
74
96
  begin
@@ -163,25 +185,67 @@ Use "seiya <command> -h" to see more info about a command
163
185
  @task_classes[task_name]
164
186
  end
165
187
 
188
+ def gen_task_file(task_name, task_domain = nil)
189
+ load_path = get_load_path Dir.pwd
190
+ if load_path.nil?
191
+ puts 'Please in a seiya project directory!'
192
+ exit!
193
+ end
194
+ base_file = File.open File.join(load_path, 'tasks.rb'), 'a'
195
+ base_file.puts "\nrequire 'tasks/#{task_name}'"
196
+ base_file.close
197
+
198
+ task_dir = File.join load_path, 'tasks'
199
+ unless File.exist? task_dir
200
+ FileUtils.mkpath task_dir
201
+ end
202
+ task_file_name = "#{File.join(task_dir, task_name)}.rb"
203
+ if File.exist? task_file_name
204
+ puts "task file: #{task_file_name} exist!"
205
+ exit!
206
+ end
207
+ task_file = File.open task_file_name, 'a'
208
+ "require 'seiya'
209
+
210
+ module Tasks
211
+ class #{task_name.camelize} < Seiya::Task
212
+ def initialize
213
+ @start_urls = [#{task_domain.nil? ? '' : "'#{task_domain}'"}]
214
+ end
215
+
216
+ def parse(response, enum)
217
+ end
218
+ end
219
+ end".split("\n").each do |line|
220
+ task_file.puts line
221
+ end
222
+ end
223
+
166
224
  def gen_project_file(project_name)
167
225
  base_path = "#{project_name}/#{project_name}"
168
- FileUtils.mkpath "#{base_path}"
226
+ FileUtils.mkpath base_path
169
227
  FileUtils.mkpath "#{base_path}/tasks"
170
228
  FileUtils.mkpath "#{base_path}/items"
171
229
  FileUtils.mkpath "#{base_path}/pipelines"
230
+
172
231
  File.write("#{project_name}/seiya.ini",
173
232
  %([global]
174
233
  settings = #{project_name}/settings|Settings
175
234
  ))
235
+
176
236
  File.write("#{base_path}/settings.rb",
177
237
  %(module Settings
178
238
  PIPELINES = {
179
239
  '#{project_name}/pipelines|Pipelines::Test' => 10,
180
240
  }
181
241
  end))
242
+
182
243
  File.write("#{base_path}/items.rb", %(require 'items/test'))
244
+
183
245
  File.write("#{base_path}/pipelines.rb", %(require 'pipelines/test'))
246
+
184
247
  File.write("#{base_path}/tasks.rb", %(require 'tasks/test'))
248
+
185
249
  File.write("#{base_path}/items/test.rb",
186
250
  %(require 'seiya'
187
251
 
@@ -192,6 +256,7 @@ module Items
192
256
  end
193
257
  end
194
258
  end))
259
+
195
260
  File.write("#{base_path}/pipelines/test.rb",
196
261
  %(require 'seiya'
197
262
 
@@ -205,6 +270,7 @@ module Pipelines
205
270
  end
206
271
  end
207
272
  end))
273
+
208
274
  File.write("#{base_path}/tasks/test.rb",
209
275
  %(require 'seiya'
210
276
  require_relative '../items'
@@ -221,5 +287,12 @@ module Tasks
221
287
  end
222
288
  end
223
289
  end))
290
+
291
+ puts "New Seiya project '#{project_name}' created in:
292
+ #{File.join(Dir.pwd, project_name)}
293
+
294
+ You can start your first task with:
295
+ cd #{project_name}
296
+ seiya gentask example example.com"
224
297
  end
225
298
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: seiya
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7.2
4
+ version: 0.0.7.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - yetone
@@ -25,6 +25,7 @@ files:
25
25
  - lib/seiya/contrib/commands.rb
26
26
  - lib/seiya/contrib/commands/crawl.rb
27
27
  - lib/seiya/contrib/commands/create.rb
28
+ - lib/seiya/contrib/commands/gentask.rb
28
29
  - lib/seiya/contrib/pipelines.rb
29
30
  - lib/seiya/item.rb
30
31
  - lib/seiya/pipeline.rb