jenkins-bot has submitted this change and it was merged.

Change subject: Factor out `$DIR` global and scope plugin classes
......................................................................


Factor out `$DIR` global and scope plugin classes

Removed the `$DIR` global from `Vagrantfile` and the `PastePuppet`
implementation in favor of `Environment#path`.

Moved all plugin classes that were previously defined in the global
namespace to `MediaWikiVagrant` module scope.

Change-Id: I2aabec28a97dfe89ad371d4dde0c05351bdba69a
---
M Vagrantfile
M lib/mediawiki-vagrant.rb
M lib/mediawiki-vagrant/git-update.rb
M lib/mediawiki-vagrant/import-dump.rb
M lib/mediawiki-vagrant/paste-puppet.rb
M lib/mediawiki-vagrant/run-tests.rb
M lib/mediawiki-vagrant/version.rb
7 files changed, 91 insertions(+), 75 deletions(-)

Approvals:
  BryanDavis: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/Vagrantfile b/Vagrantfile
index dc58b2e..a464228 100644
--- a/Vagrantfile
+++ b/Vagrantfile
@@ -26,7 +26,6 @@
 # Patches and contributions are welcome!
 # http://www.mediawiki.org/wiki/How_to_become_a_MediaWiki_hacker
 #
-$DIR = File.expand_path('..', __FILE__)
 
 # Ensure we're using the latest version of the plugin
 require_relative 'lib/mediawiki-vagrant/version'
@@ -49,7 +48,7 @@
 
 require 'mediawiki-vagrant/settings/definitions'
 
-mwv = MediaWikiVagrant::Environment.new($DIR)
+mwv = MediaWikiVagrant::Environment.new(File.expand_path('..', __FILE__))
 settings = mwv.load_settings
 
 Vagrant.configure('2') do |config|
@@ -247,13 +246,16 @@
 
 # Migrate {apt,composer}-cache to cache/{apt,composer}
 ['apt', 'composer'].each do |type|
-    src = File.join $DIR, "#{type}-cache"
-    if File.directory? src
-        dst = File.join $DIR, 'cache', type
-        Dir.foreach(src) do |f|
-            next if File.directory? f or f.start_with? '.'
-            File.rename(File.join(src, f), File.join(dst, f)) rescue nil
-        end rescue nil
+    src = mwv.path("#{type}-cache")
+
+    if src.directory?
+        dst = mwv.path('cache', type)
+
+        src.each_child do |src_file|
+            unless src_file.directory? || src_file.basename.fnmatch?('.*')
+                src_file.rename(dst.join(src_file.basename)) rescue nil
+            end
+        end
     end
 end
 
@@ -263,6 +265,6 @@
 # to the parent directory.  Editing it without copying it will only cause
 # sadness.
 begin
-    require File.join($DIR, 'Vagrantfile-extra')
+    require mwv.path('Vagrantfile-extra')
 rescue LoadError
 end
diff --git a/lib/mediawiki-vagrant.rb b/lib/mediawiki-vagrant.rb
index 5e0ac53..2dca567 100644
--- a/lib/mediawiki-vagrant.rb
+++ b/lib/mediawiki-vagrant.rb
@@ -91,17 +91,17 @@
 
     provisioner 'mediawiki_reload' do
       require 'mediawiki-vagrant/reload'
-      MediaWikiVagrant::Reload
+      Reload
     end
 
     config(:lsb_check, :provisioner) do
       require 'mediawiki-vagrant/lsb_check/config'
-      MediaWikiVagrant::LsbCheck::Config
+      LsbCheck::Config
     end
 
     provisioner :lsb_check do
       require 'mediawiki-vagrant/lsb_check/provisioner'
-      MediaWikiVagrant::LsbCheck::Provisioner
+      LsbCheck::Provisioner
     end
 
   end
diff --git a/lib/mediawiki-vagrant/git-update.rb 
b/lib/mediawiki-vagrant/git-update.rb
index 19c2d37..65768f5 100644
--- a/lib/mediawiki-vagrant/git-update.rb
+++ b/lib/mediawiki-vagrant/git-update.rb
@@ -1,17 +1,19 @@
-class GitUpdates < Vagrant.plugin(2, :command)
-  def self.synopsis
-    "fetches new code from Gerrit"
-  end
-
-  def execute
-    if %w(-h --help).include? @argv.first
-      @env.ui.info 'Usage: vagrant git-update [-h]'
-      return 0
+module MediaWikiVagrant
+  class GitUpdates < Vagrant.plugin(2, :command)
+    def self.synopsis
+      "fetches new code from Gerrit"
     end
 
-    with_target_vms(nil, :single_target => true) do |vm|
-      opts = { :extra_args => @argv.unshift('run-git-update') }
-      vm.action :ssh, :ssh_opts => opts
+    def execute
+      if %w(-h --help).include? @argv.first
+        @env.ui.info 'Usage: vagrant git-update [-h]'
+        return 0
+      end
+
+      with_target_vms(nil, :single_target => true) do |vm|
+        opts = { :extra_args => @argv.unshift('run-git-update') }
+        vm.action :ssh, :ssh_opts => opts
+      end
     end
   end
 end
diff --git a/lib/mediawiki-vagrant/import-dump.rb 
b/lib/mediawiki-vagrant/import-dump.rb
index 8ae86ec..8bcb42b 100644
--- a/lib/mediawiki-vagrant/import-dump.rb
+++ b/lib/mediawiki-vagrant/import-dump.rb
@@ -1,16 +1,18 @@
-class ImportDump < Vagrant.plugin(2, :command)
-  def self.synopsis
-    "imports an XML file into MediaWiki"
-  end
-
-  def execute
-    if ['-h', '--help'].include? @argv.first
-      @env.ui.info "Usage: vagrant import-dump dumpfile.xml [-h]"
-      return 0
+module MediaWikiVagrant
+  class ImportDump < Vagrant.plugin(2, :command)
+    def self.synopsis
+      "imports an XML file into MediaWiki"
     end
-    opts = { extra_args: @argv.unshift('import-mediawiki-dump') }
-    with_target_vms(nil, :single_target => true) do |vm|
-      vm.action :ssh, ssh_opts: opts
+
+    def execute
+      if ['-h', '--help'].include? @argv.first
+        @env.ui.info "Usage: vagrant import-dump dumpfile.xml [-h]"
+        return 0
+      end
+      opts = { extra_args: @argv.unshift('import-mediawiki-dump') }
+      with_target_vms(nil, :single_target => true) do |vm|
+        vm.action :ssh, ssh_opts: opts
+      end
     end
   end
 end
diff --git a/lib/mediawiki-vagrant/paste-puppet.rb 
b/lib/mediawiki-vagrant/paste-puppet.rb
index 9745595..8f633ff 100644
--- a/lib/mediawiki-vagrant/paste-puppet.rb
+++ b/lib/mediawiki-vagrant/paste-puppet.rb
@@ -1,34 +1,42 @@
 require 'net/http'
+require 'pathname'
 
-class PastePuppet < Vagrant.plugin(2, :command)
+require 'mediawiki-vagrant/plugin_environment'
 
-  URL = URI('http://dpaste.de/api/')
+module MediaWikiVagrant
+  class PastePuppet < Vagrant.plugin(2, :command)
+    include PluginEnvironment
 
-  def self.synopsis
-    "uploads your puppet logs to dpaste.de pastebin"
-  end
+    URL = URI.parse('http://dpaste.de/api/')
 
-  def latest_logfile
-    Dir[File.join $DIR, '/logs/puppet/*.log'].max_by { |f| File.mtime f }
-  end
+    def self.synopsis
+      "uploads your puppet logs to dpaste.de pastebin"
+    end
 
-  def execute
-    begin
-      res = Net::HTTP.post_form URL, content: File.read(latest_logfile)
-      raise unless res.value.nil? and res.body =~ /^"[^"]+"$/
-    rescue RuntimeError
-      @env.ui.error "Unexpected response from #{URL}."
-      1
-    rescue TypeError
-      @env.ui.error 'No Puppet log files found.'
-      1
-    rescue SocketError, Net::HTTPExceptions
-      @env.ui.error "Unable to connect to #{URL}."
-      1
-    else
-      @env.ui.success "HTTP #{res.code} #{res.msg}"
-      @env.ui.info res.body[1...-1]
-      0
+    def execute
+      begin
+        res = Net::HTTP.post_form URL, content: latest_logfile.read
+        raise unless res.value.nil? and res.body =~ /^"[^"]+"$/
+      rescue RuntimeError
+        @env.ui.error "Unexpected response from #{URL}."
+        1
+      rescue TypeError
+        @env.ui.error 'No Puppet log files found.'
+        1
+      rescue SocketError, Net::HTTPExceptions
+        @env.ui.error "Unable to connect to #{URL}."
+        1
+      else
+        @env.ui.success "HTTP #{res.code} #{res.msg}"
+        @env.ui.info res.body[1...-1]
+        0
+      end
+    end
+
+    private
+
+    def latest_logfile
+      Pathname.glob(@mwv.path('logs', 'puppet', '*.log')).max_by(&:mtime)
     end
   end
 end
diff --git a/lib/mediawiki-vagrant/run-tests.rb 
b/lib/mediawiki-vagrant/run-tests.rb
index 1e6bcee..87db3eb 100644
--- a/lib/mediawiki-vagrant/run-tests.rb
+++ b/lib/mediawiki-vagrant/run-tests.rb
@@ -1,16 +1,18 @@
-class RunTests < Vagrant.plugin(2, :command)
-  def self.synopsis
-    "runs MediaWiki's test suite"
-  end
-
-  def execute
-    if ['-h', '--help'].include? @argv.first
-      @env.ui.info "Usage: vagrant run-tests [tests] [-h]"
-      return 0
+module MediaWikiVagrant
+  class RunTests < Vagrant.plugin(2, :command)
+    def self.synopsis
+      "runs MediaWiki's test suite"
     end
-    opts = { extra_args: @argv.unshift('run-mediawiki-tests') }
-    with_target_vms(nil, :single_target => true) do |vm|
-      vm.action :ssh, ssh_opts: opts
+
+    def execute
+      if ['-h', '--help'].include? @argv.first
+        @env.ui.info "Usage: vagrant run-tests [tests] [-h]"
+        return 0
+      end
+      opts = { extra_args: @argv.unshift('run-mediawiki-tests') }
+      with_target_vms(nil, :single_target => true) do |vm|
+        vm.action :ssh, ssh_opts: opts
+      end
     end
   end
 end
diff --git a/lib/mediawiki-vagrant/version.rb b/lib/mediawiki-vagrant/version.rb
index 11bdbc8..fbe133e 100644
--- a/lib/mediawiki-vagrant/version.rb
+++ b/lib/mediawiki-vagrant/version.rb
@@ -1,3 +1,3 @@
 module MediaWikiVagrant
-  VERSION = '0.8.0'
+  VERSION = '0.9.0'
 end

-- 
To view, visit https://gerrit.wikimedia.org/r/232648
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I2aabec28a97dfe89ad371d4dde0c05351bdba69a
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/vagrant
Gerrit-Branch: master
Gerrit-Owner: Dduvall <dduv...@wikimedia.org>
Gerrit-Reviewer: BryanDavis <bda...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to