From f27329088730885693e840b038769fa4474457d8 Mon Sep 17 00:00:00 2001 From: Christian Mehlmauer Date: Mon, 10 Sep 2012 22:59:03 +0200 Subject: [PATCH] Added option to generate a full plugin list --- lib/wpstools/generate_plugin_list.rb | 20 +++++++++++++++++--- lib/wpstools/wpstools_helper.rb | 5 +++++ wpstools.rb | 12 +++++++++++- 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/lib/wpstools/generate_plugin_list.rb b/lib/wpstools/generate_plugin_list.rb index a611dd7a..1ccf56ed 100644 --- a/lib/wpstools/generate_plugin_list.rb +++ b/lib/wpstools/generate_plugin_list.rb @@ -36,7 +36,7 @@ class Generate_Plugin_List # Send a HTTP request to the WordPress most popular plugins webpage # parse the response for the plugin names. - def parse_plugins + def parse_popular_plugins found_plugins = [] page_count = 1 @@ -69,6 +69,16 @@ class Generate_Plugin_List found_plugins.uniq end + + def parse_full_plugins + found_plugins = [] + queue_count = 0 + index = @browser.get('http://plugins.svn.wordpress.org/').body + index.scan(%r{
  • (.*)/
  • }i).each do |plugin| + found_plugins << plugin[0] + end + found_plugins.uniq + end # Use the WordPress plugin SVN repo to find a # valid plugin file. This will cut down on @@ -113,9 +123,13 @@ class Generate_Plugin_List # Save the file - def save_file + def save_file(full=false) begin - plugins = parse_plugins + if (full) + plugins = parse_full_plugins + else + plugins = parse_popular_plugins + end puts "[*] We have parsed " + plugins.size.to_s plugins_with_paths = parse_plugin_files(plugins) File.open(DATA_DIR + '/plugins.txt', 'w') { |f| f.write(plugins_with_paths) } diff --git a/lib/wpstools/wpstools_helper.rb b/lib/wpstools/wpstools_helper.rb index 5794b104..373145f8 100644 --- a/lib/wpstools/wpstools_helper.rb +++ b/lib/wpstools/wpstools_helper.rb @@ -12,6 +12,9 @@ def usage() puts "- Generate a new 'most popular' plugin list, up to 150 pages ..." puts "ruby " + script_name + " --generate_plugin_list 150" puts + puts "- Generate a new full plugin list" + puts "ruby " + script_name + " --generate_full_plugin_list" + puts puts "See README for further information." puts end @@ -24,5 +27,7 @@ def help() puts "--update | -u Update to the latest revision." puts "--generate_plugin_list [number of pages] Generate a new data/plugins.txt file. (supply number of *pages* to parse, default : 150)" puts "--gpl Alias for --generate_plugin_list" + puts "--generate_full_plugin_list Generate a new full data/plugins.txt file" + puts "--gfpl Alias for --generate_full_plugin_list" puts end diff --git a/wpstools.rb b/wpstools.rb index b14b0ef3..2ac22c3b 100755 --- a/wpstools.rb +++ b/wpstools.rb @@ -37,7 +37,9 @@ begin ["--help", "-h", GetoptLong::NO_ARGUMENT], ["--verbose", "-v", GetoptLong::NO_ARGUMENT], ["--generate_plugin_list", GetoptLong::OPTIONAL_ARGUMENT], + ["--generate_full_plugin_list", GetoptLong::NO_ARGUMENT], ["--gpl", GetoptLong::OPTIONAL_ARGUMENT], + ["--gfpl", GetoptLong::OPTIONAL_ARGUMENT], ["--update", "-u", GetoptLong::NO_ARGUMENT] ) @@ -59,13 +61,21 @@ begin @generate_plugin_list = true when "--update" @update = true + when "--generate_full_plugin_list", "--gfpl" + @generate_full_plugin_list = true end end if @generate_plugin_list puts "[+] Generating new most popular plugin list" puts - Generate_Plugin_List.new(@number_of_pages, @verbose).save_file + Generate_Plugin_List.new(@number_of_pages, @verbose).save_file(false) + end + + if @generate_full_plugin_list + puts "[+] Generating new full plugin list" + puts + Generate_Plugin_List.new(-1, @verbose).save_file(true) end if @update