Permalink
Browse files

First gem commit

  • Loading branch information...
1 parent 4d62180 commit 549b18a88f08e152647e093104f993e4f2f5bdd7 @stefanoverna stefanoverna committed Nov 30, 2011
View
@@ -0,0 +1 @@
+tmp/*
View
@@ -0,0 +1,4 @@
+source 'http://rubygems.org'
+
+# Specify your gem's dependencies in wordmove.gemspec
+gemspec
View
@@ -0,0 +1,64 @@
+PATH
+ remote: .
+ specs:
+ wordmove (0.0.1)
+ activesupport (~> 3.0.0)
+ escape
+ hashie
+ i18n
+ net-scp
+ net-ssh
+ paint
+ rake
+ thor
+
+GEM
+ remote: http://rubygems.org/
+ specs:
+ activesupport (3.0.11)
+ aruba (0.4.7)
+ childprocess (>= 0.2.2)
+ cucumber (>= 1.1.1)
+ ffi (= 1.0.9)
+ rspec (>= 2.7.0)
+ builder (3.0.0)
+ childprocess (0.2.3)
+ ffi (~> 1.0.6)
+ cucumber (1.1.3)
+ builder (>= 2.1.2)
+ diff-lcs (>= 1.1.2)
+ gherkin (~> 2.6.7)
+ json (>= 1.4.6)
+ term-ansicolor (>= 1.0.6)
+ diff-lcs (1.1.3)
+ escape (0.0.4)
+ ffi (1.0.9)
+ gherkin (2.6.8)
+ json (>= 1.4.6)
+ hashie (1.2.0)
+ i18n (0.6.0)
+ json (1.6.2)
+ net-scp (1.0.4)
+ net-ssh (>= 1.99.1)
+ net-ssh (2.2.1)
+ paint (0.8.3)
+ rake (0.9.2.2)
+ rspec (2.7.0)
+ rspec-core (~> 2.7.0)
+ rspec-expectations (~> 2.7.0)
+ rspec-mocks (~> 2.7.0)
+ rspec-core (2.7.1)
+ rspec-expectations (2.7.0)
+ diff-lcs (~> 1.1.2)
+ rspec-mocks (2.7.0)
+ term-ansicolor (1.0.7)
+ thor (0.14.6)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ aruba
+ cucumber
+ rspec
+ wordmove!
View
@@ -0,0 +1,2 @@
+#!/usr/bin/env rake
+require "bundler/gem_tasks"
View
@@ -0,0 +1,4 @@
+#!/usr/bin/env ruby
+
+require 'wordmove/cli'
+Wordmove::CLI.start
View
@@ -0,0 +1,30 @@
+Feature: Generating Movefile
+ In order to configure Wordmove
+ As a WP developer
+ I want Wordmove to generate me a Wordmove skeleton file
+
+ Scenario: Wordmove creation
+ When I run "wordmove init"
+ Then the following files should exist:
+ | Movefile |
+ Then the file "Movefile" should contain:
+ """
+ local:
+ vhost: "http://vhost.local"
+ wordpress_path: "~/dev/sites/your_site"
+ database:
+ username: "username"
+ password: "password"
+ host: "host"
+ remote:
+ vhost: "http://remote.com"
+ wordpress_path: "/var/www/your_site"
+ database:
+ username: "username"
+ password: "password"
+ host: "host"
+ ssh:
+ username: "username"
+ password: "password"
+ host: "host"
+ """
View
No changes.
View
No changes.
@@ -0,0 +1,3 @@
+Then /^the file "([^"]*)" should contain:$/ do |file, content|
+ check_file_content(file, content, true)
+end
@@ -0,0 +1,2 @@
+require 'aruba/cucumber'
+
View
@@ -0,0 +1,4 @@
+require "wordmove/version"
+
+module Wordmove
+end
View
@@ -0,0 +1,36 @@
+require 'thor'
+require 'wordmove/generators/movefile'
+require 'wordmove/deployer'
+
+module Wordmove
+ class CLI < Thor
+
+ desc "init", "Generates a brand new Movefile"
+ def init
+ Wordmove::Generators::Movefile.start
+ end
+
+ desc "pull", "Pulls Wordpress data from remote host to the local machine"
+ method_option :skip_db, :aliases => "-d", :type => :boolean
+ method_option :skip_uploads, :aliases => "-u", :type => :boolean
+ method_option :skip_themes, :aliases => "-t", :type => :boolean
+ method_option :skip_plugins, :aliases => "-p", :type => :boolean
+ method_option :config, :aliases => "-c"
+ def pull
+ deployer = Wordmove::Deployer.new(options)
+ deployer.pull
+ end
+
+ desc "push", "Push Wordpress data to remote host from local machine"
+ method_option :skip_db, :aliases => "-d", :type => :boolean
+ method_option :skip_uploads, :aliases => "-u", :type => :boolean
+ method_option :skip_themes, :aliases => "-t", :type => :boolean
+ method_option :skip_plugins, :aliases => "-p", :type => :boolean
+ method_option :config, :aliases => "-c"
+ def push
+ deployer = Wordmove::Deployer.new(options)
+ deployer.push
+ end
+
+ end
+end
View
@@ -0,0 +1,152 @@
+require 'active_support/core_ext'
+require 'hashie'
+require 'paint/pa'
+require 'escape'
+require 'net/ssh'
+require 'net/scp'
+
+require 'wordmove/hosts/local_host'
+require 'wordmove/hosts/remote_host'
+
+module Wordmove
+
+ class Deployer
+
+ def initialize(options = {})
+ @options = Hashie::Mash.new(options)
+ end
+
+ def push
+ %w(db uploads themes plugins).each do |step|
+ unless @options["skip_#{step}".to_s]
+ pa "Pushing #{step.titleize}...", :cyan
+ send "push_#{step}"
+ end
+ end
+ end
+
+ def pull
+ %w(db uploads themes plugins).each do |step|
+ unless @options["skip_#{step}".to_s]
+ pa "Pushing #{step.titleize}...", :cyan
+ send "pull_#{step}"
+ end
+ end
+ end
+
+ private
+
+ def push_db
+ local_mysql_dump_path = local_wpcontent_path("database_dump.sql")
+ remote_mysql_dump_path = remote_wpcontent_path("database_dump.sql")
+
+ locally do |host|
+ host.run "mysqldump", "--host=#{config.local.database.host}", "--user=#{config.local.database.username}", "--password=#{config.local.database.password}", config.local.database.name, :stdout => local_mysql_dump_path
+ File.open(local_mysql_dump_path, 'a') do |file|
+ file.write "UPDATE wp_options SET option_value=\"#{config.remote.vhost}\" WHERE option_name=\"siteurl\" OR option_name=\"home\";\n"
+ end
+ end
+
+ remotely do |host|
+ host.download_file local_mysql_dump_path, remote_mysql_dump_path
+ host.run "mysql", "--user=#{config.remote.database.username}", "--password=#{config.remote.database.password}", "--host=#{config.remote.database.host}", "--database=#{config.remote.database.name}", :stdin => remote_mysql_dump_path
+ host.run "rm", remote_mysql_dump_path
+ end
+
+ locally do |host|
+ host.run "rm", local_mysql_dump_path
+ end
+ end
+
+ def push_uploads
+ remotely do |host|
+ host.download_dir local_wpcontent_path("uploads"), remote_wpcontent_path("uploads")
+ end
+ end
+
+ def push_themes
+ remotely do |host|
+ host.download_dir local_wpcontent_path("themes"), remote_wpcontent_path("themes")
+ end
+ end
+
+ def push_plugins
+ remotely do |host|
+ host.download_dir local_wpcontent_path("plugins"), remote_wpcontent_path("plugins")
+ end
+ end
+
+ def pull_db
+ local_mysql_dump_path = local_wpcontent_path("database_dump.sql")
+ remote_mysql_dump_path = remote_wpcontent_path("database_dump.sql")
+
+ remotely do |host|
+ host.run "mysqldump", "--host=#{config.remote.database.host}", "--user=#{config.remote.database.username}", "--password=#{config.remote.database.password}", config.remote.database.name, :stdout => remote_mysql_dump_path
+ host.upload_file remote_mysql_dump_path, local_mysql_dump_path
+ end
+
+ locally do |host|
+ File.open(local_mysql_dump_path, 'a') do |file|
+ file.write "UPDATE wp_options SET option_value=\"#{config.local.vhost}\" WHERE option_name=\"siteurl\" OR option_name=\"home\";\n"
+ end
+ host.run "mysql", "--user=#{config.local.database.username}", "--password=#{config.local.database.password}", "--host=#{config.local.database.host}", "--database=#{config.local.database.name}", :stdin => local_mysql_dump_path
+ host.run "rm", local_mysql_dump_path
+ end
+
+ remotely do |host|
+ host.run "rm", remote_mysql_dump_path
+ end
+
+ end
+
+ def pull_uploads
+ remotely do |host|
+ host.upload_dir remote_wpcontent_path("uploads"), local_wpcontent_path("uploads")
+ end
+ end
+
+ def pull_themes
+ remotely do |host|
+ host.upload_dir remote_wpcontent_path("themes"), local_wpcontent_path("themes")
+ end
+ end
+
+ def pull_plugins
+ remotely do |host|
+ host.upload_dir remote_wpcontent_path("plugins"), local_wpcontent_path("plugins")
+ end
+ end
+
+ def config
+ if @config.blank?
+ config_path = @options[:config] || "Movefile"
+ unless File.exists? config_path
+ raise Thor::Error, "Could not find a valid Movefile"
+ end
+ @config = Hashie::Mash.new(YAML::load(File.open(config_path)))
+ end
+ @config
+ end
+
+ def local_wpcontent_path(*args)
+ File.join(config.local.wordpress_path, "wp-content", *args)
+ end
+
+ def remote_wpcontent_path(*args)
+ File.join(config.remote.wordpress_path, "wp-content", *args)
+ end
+
+ def locally
+ host = LocalHost.new(config.local)
+ yield host
+ host.close
+ end
+
+ def remotely
+ host = RemoteHost.new(config.remote)
+ yield host
+ host.close
+ end
+
+ end
+end
@@ -0,0 +1,25 @@
+local:
+ vhost: "http://vhost.local"
+ wordpress_path: "~/dev/sites/your_site"
+ database:
+ name: "database_name"
+ username: "username"
+ password: "password"
+ host: "host"
+remote:
+ vhost: "http://remote.com"
+ wordpress_path: "/var/www/your_site"
+ exclude:
+ - .git
+ - .DS_Store
+ - .sass-cache
+ database:
+ name: "database_name"
+ username: "username"
+ password: "password"
+ host: "host"
+ ssh:
+ username: "username"
+ password: "password"
+ host: "host"
+
@@ -0,0 +1,18 @@
+require 'thor/group'
+
+module Wordmove
+ module Generators
+ class Movefile < Thor::Group
+ include Thor::Actions
+
+ def self.source_root
+ File.dirname(__FILE__)
+ end
+
+ def copy_movefile
+ template "Movefile"
+ end
+
+ end
+ end
+end
@@ -0,0 +1,36 @@
+module Wordmove
+ class LocalHost
+
+ attr_reader :options
+
+ def initialize(options = {})
+ @options = Hashie::Mash.new(options)
+ end
+
+ def run(*args)
+ command = shell_command(*args)
+ pa "Executing locally #{command}", :green, :bright
+ unless system(command)
+ raise Thor::Error, "Error executing \"#{command}\""
+ end
+ end
+
+ def close
+ end
+
+ protected
+
+ def shell_command(*args)
+ options = args.extract_options!
+ command = Escape.shell_command(args)
+ if options[:stdin]
+ command += " < #{options[:stdin]}"
+ end
+ if options[:stdout]
+ command += " > #{options[:stdout]}"
+ end
+ command
+ end
+
+ end
+end
Oops, something went wrong.

0 comments on commit 549b18a

Please sign in to comment.