-
Notifications
You must be signed in to change notification settings - Fork 8
/
generate.rb
executable file
·67 lines (51 loc) · 1.81 KB
/
generate.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env ruby
require 'optparse'
require 'typhoeus'
require_relative 'lib'
DB_DIR = File.expand_path(File.dirname(__FILE__))
options = {}
OptionParser.new do |opts|
opts.on('-v', '--verbose', 'Run verbosely') do |_|
options[:verbose] = true
end
opts.on('--plugins [NUMBER_OF_ITEMS]', '-p', Integer,
'Generate a new plugins.txt file (supply number of *items* to parse, default : 1500)'
) do |value|
options[:plugins] = value
end
opts.on('--full-plugins', '-P', 'Generate a new full plugins.txt file') do |_|
options[:full_plugins] = true
end
opts.on('--themes [NUMBER_OF_ITEMS]', '-t', Integer,
'Generate a new themes.txt file (supply number of *items* to parse, default : 200)'
) do |value|
options[:themes] = value
end
opts.on('--full-themes', '-T', 'Generate a new full themes.txt file') do |_|
options[:full_themes] = true
end
opts.on('--all', '-a',
'Generate a new full plugins, full themes, popular plugins and popular themes list'
) do |_|
options[:all] = true
end
opts.on('--checksums', '-c', 'Generate the checksums for all files except the json ones') do |_|
options[:checksums] = true
end
end.parse!
if options.key?(:plugins) || options[:all]
most_popular('plugin', options[:plugins] || 1500, options[:verbose])
end
full('plugin', options[:verbose]) if options[:full_plugins] || options[:all]
if options.key?(:themes) || options[:all]
most_popular('theme', options[:themes] || 200, options[:verbose])
end
full('theme', options[:verbose]) if options[:full_themes] || options[:all]
if options[:checksums]
puts '[+] Creating Checksums ...'
Dir[File.join(DB_DIR, '*.{xml,xsd,txt}')].each do |file|
puts " [+] Generating checksum for #{file}" if options[:verbose]
write_checksum(file)
end
puts '[+] Done.'
end