wpmu 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/README.md +12 -0
- data/Rakefile +1 -0
- data/bin/wpmu +5 -0
- data/lib/wpmu.rb +7 -0
- data/lib/wpmu/cli.rb +108 -0
- data/lib/wpmu/db.rb +50 -0
- data/lib/wpmu/version.rb +3 -0
- data/wpmu.gemspec +26 -0
- metadata +101 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/wpmu
ADDED
data/lib/wpmu.rb
ADDED
data/lib/wpmu/cli.rb
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
require 'thor'
|
2
|
+
require 'php_serialize'
|
3
|
+
require 'wpmu/version'
|
4
|
+
require 'wpmu/db'
|
5
|
+
|
6
|
+
module WPMU
|
7
|
+
|
8
|
+
|
9
|
+
class List < Thor
|
10
|
+
|
11
|
+
desc 'themes', 'lists themes and sites which use them (currently lists only active themes)'
|
12
|
+
def themes
|
13
|
+
themes_options = get_options('template')
|
14
|
+
themes = {}
|
15
|
+
themes_options.each do |site_id, options|
|
16
|
+
theme_name = options['template']
|
17
|
+
themes[theme_name] ||= []
|
18
|
+
themes[theme_name] << site_id
|
19
|
+
end
|
20
|
+
|
21
|
+
themes.each do |theme_name, site_ids|
|
22
|
+
puts "#{theme_name} - #{site_ids.to_s}"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
desc 'plugins', 'lists plugins and sites which use them (currently lists only active plugins)'
|
27
|
+
def plugins
|
28
|
+
plugins_options = get_options('active_plugins')
|
29
|
+
plugins = {}
|
30
|
+
plugins_options.each do |site_id, options|
|
31
|
+
encoded_list = options['active_plugins']
|
32
|
+
PHP.unserialize(encoded_list).each do |plugin_name|
|
33
|
+
plugins[plugin_name] ||= []
|
34
|
+
plugins[plugin_name] << site_id
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
plugins.each do |plugin_name, site_ids|
|
39
|
+
puts "#{plugin_name} - #{site_ids.to_s}"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
desc 'sites', 'lists sites'
|
44
|
+
def sites
|
45
|
+
sites_options = get_options(%w{blogname siteurl admin_email template active_plugins})
|
46
|
+
sites_options.each do |site_id, site_options|
|
47
|
+
site_options.each do |key, value|
|
48
|
+
if key == 'active_plugins'
|
49
|
+
puts "#{site_id}| #{key}:"
|
50
|
+
PHP.unserialize(value).each do |plugin|
|
51
|
+
puts "\t#{plugin}"
|
52
|
+
end if value
|
53
|
+
else
|
54
|
+
puts "#{site_id}| #{key}: #{value}"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
puts "\n"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
no_tasks do
|
62
|
+
|
63
|
+
# get sites ids from table names
|
64
|
+
def all_site_ids
|
65
|
+
db = WPMU::DB.get
|
66
|
+
site_ids = []
|
67
|
+
regex = /(\d+)/
|
68
|
+
|
69
|
+
db.tables.each do |table_name|
|
70
|
+
match = regex.match(table_name)
|
71
|
+
if match.class == MatchData
|
72
|
+
site_ids << match[1].to_i
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
# get unique and sort
|
77
|
+
site_ids.uniq.sort
|
78
|
+
end
|
79
|
+
|
80
|
+
# gets given set of optoins for all sites
|
81
|
+
def get_options(*option_names)
|
82
|
+
option_names.flatten!
|
83
|
+
all_sites_options = {}
|
84
|
+
all_site_ids.each do |site_id|
|
85
|
+
current_site_options = {}
|
86
|
+
table = WPMU::DB.get["okfn_org_#{site_id}_options".to_sym]
|
87
|
+
option_names.each do |option_name|
|
88
|
+
current_site_options[option_name] = table.first(:option_name => option_name)[:option_value].strip
|
89
|
+
end
|
90
|
+
all_sites_options[site_id] = current_site_options
|
91
|
+
end
|
92
|
+
all_sites_options
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
98
|
+
|
99
|
+
|
100
|
+
class CLI < Thor
|
101
|
+
|
102
|
+
desc 'list RESOURCES', 'prints listing for given type of resource'
|
103
|
+
subcommand 'list', List
|
104
|
+
|
105
|
+
end
|
106
|
+
|
107
|
+
|
108
|
+
end
|
data/lib/wpmu/db.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'sequel'
|
2
|
+
require 'mysql2'
|
3
|
+
|
4
|
+
module WPMU
|
5
|
+
|
6
|
+
class DB
|
7
|
+
|
8
|
+
class << self
|
9
|
+
def get
|
10
|
+
#TODO: fetch data from wp-config.php
|
11
|
+
@db ||= Sequel.mysql2 connection_options
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def connection_options
|
17
|
+
@connection_options ||= get_connection_options
|
18
|
+
end
|
19
|
+
|
20
|
+
def get_connection_options
|
21
|
+
connection_options = {}
|
22
|
+
map = {
|
23
|
+
:user => 'DB_USER',
|
24
|
+
:database => 'DB_NAME',
|
25
|
+
:password => 'DB_PASSWORD',
|
26
|
+
:host => 'DB_HOST'
|
27
|
+
}
|
28
|
+
wp_config_path = File.join Dir.pwd, 'wp-config.php'
|
29
|
+
begin
|
30
|
+
lines = File.open(wp_config_path){ |f| f.readlines }
|
31
|
+
rescue Errno::ENOENT
|
32
|
+
puts "couldn't find wp-config.php, please make sure you run command from root directory of your blogfarm!"
|
33
|
+
exit 1
|
34
|
+
end
|
35
|
+
lines.each do |line|
|
36
|
+
map.each_pair do |db_key, wp_key|
|
37
|
+
regex = /'#{wp_key}', '([^']+)'/
|
38
|
+
match = regex.match line
|
39
|
+
if match.class == MatchData
|
40
|
+
connection_options[db_key] = match[1]
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
connection_options
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
data/lib/wpmu/version.rb
ADDED
data/wpmu.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "wpmu/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "wpmu"
|
7
|
+
s.version = WPMU::VERSION.dup
|
8
|
+
s.authors = ["elf Pavlik"]
|
9
|
+
s.email = ["perpetual-tripper@wwelves.org"]
|
10
|
+
s.homepage = "https://gitorious.org/elf-pavlik-misc-repos/wpmu-ruby"
|
11
|
+
s.summary = %q{CLI toolset for managing Wordpress Multisite}
|
12
|
+
s.description = %q{CLI toolset for managing Wordpress Multisite}
|
13
|
+
|
14
|
+
s.files = `git ls-files`.split("\n")
|
15
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
16
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
17
|
+
s.require_paths = ["lib"]
|
18
|
+
|
19
|
+
# specify any dependencies here; for example:
|
20
|
+
# s.add_development_dependency "rspec"
|
21
|
+
# s.add_runtime_dependency "rest-client"
|
22
|
+
s.add_runtime_dependency "thor"
|
23
|
+
s.add_runtime_dependency "sequel"
|
24
|
+
s.add_runtime_dependency "mysql2"
|
25
|
+
s.add_runtime_dependency "php-serialize"
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: wpmu
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- elf Pavlik
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-03-27 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: thor
|
16
|
+
requirement: &76732910 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *76732910
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: sequel
|
27
|
+
requirement: &76732500 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *76732500
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: mysql2
|
38
|
+
requirement: &76732170 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :runtime
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *76732170
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: php-serialize
|
49
|
+
requirement: &76731690 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :runtime
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *76731690
|
58
|
+
description: CLI toolset for managing Wordpress Multisite
|
59
|
+
email:
|
60
|
+
- perpetual-tripper@wwelves.org
|
61
|
+
executables:
|
62
|
+
- wpmu
|
63
|
+
extensions: []
|
64
|
+
extra_rdoc_files: []
|
65
|
+
files:
|
66
|
+
- .gitignore
|
67
|
+
- Gemfile
|
68
|
+
- README.md
|
69
|
+
- Rakefile
|
70
|
+
- bin/wpmu
|
71
|
+
- lib/wpmu.rb
|
72
|
+
- lib/wpmu/cli.rb
|
73
|
+
- lib/wpmu/db.rb
|
74
|
+
- lib/wpmu/version.rb
|
75
|
+
- wpmu.gemspec
|
76
|
+
homepage: https://gitorious.org/elf-pavlik-misc-repos/wpmu-ruby
|
77
|
+
licenses: []
|
78
|
+
post_install_message:
|
79
|
+
rdoc_options: []
|
80
|
+
require_paths:
|
81
|
+
- lib
|
82
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ! '>='
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
requirements: []
|
95
|
+
rubyforge_project:
|
96
|
+
rubygems_version: 1.8.10
|
97
|
+
signing_key:
|
98
|
+
specification_version: 3
|
99
|
+
summary: CLI toolset for managing Wordpress Multisite
|
100
|
+
test_files: []
|
101
|
+
has_rdoc:
|