le1t0-deprec 2.1.6.070 → 2.1.6.071

Sign up to get free protection for your applications and to get access to all the features.
data/lib/deprec.rb CHANGED
@@ -53,4 +53,30 @@ Capistrano::Configuration.instance.deprec.namespaces.keys.each do |ns_name|
53
53
  end
54
54
  end
55
55
  end
56
+ unless ns.respond_to?(:diff_config)
57
+ Capistrano::Configuration.instance.namespace :deprec do
58
+ namespace ns_name do
59
+ task :diff_config_project do
60
+ return unless defined?(PROJECT_CONFIG_FILES) && PROJECT_CONFIG_FILES[ns_name]
61
+
62
+ PROJECT_CONFIG_FILES[ns_name].each do |config_file|
63
+ deprec2.compare_files(ns_name, config_file[:template], config_file[:path])
64
+ end
65
+ end
66
+
67
+ task :diff_config_system do
68
+ return unless defined?(SYSTEM_CONFIG_FILES) && SYSTEM_CONFIG_FILES[ns_name]
69
+
70
+ SYSTEM_CONFIG_FILES[ns_name].each do |config_file|
71
+ deprec2.compare_files(ns_name, config_file[:template], config_file[:path])
72
+ end
73
+ end
74
+
75
+ task :diff_config do
76
+ diff_config_project
77
+ diff_config_system
78
+ end
79
+ end
80
+ end
81
+ end
56
82
  end
@@ -33,6 +33,21 @@ module Deprec2
33
33
 
34
34
  DEPREC_TEMPLATES_BASE = File.join(File.dirname(__FILE__), 'templates')
35
35
 
36
+ def compare_files(app, local_file, remote_file)
37
+ stage = exists?(:stage) ? fetch(:stage).to_s : ''
38
+
39
+ run "cat #{remote_file}" do |channel, stream, data|
40
+ local_file_full_path = local_file[0,1] == "/" ? local_file :
41
+ (File.exists?(File.join('config', stage, channel.properties[:host], app.to_s, local_file)) ? File.join('config', stage, channel.properties[:host], app.to_s, local_file) : File.join('config', stage, app.to_s, local_file))
42
+ tmp_file = File.join('/', 'tmp', "#{(channel.properties[:host] + remote_file).gsub(/\/\./, '_')}_#{Time.now.strftime("%Y%m%d%H%M%S")}.tmp")
43
+ File.open(tmp_file, "w") do |f|
44
+ f.write data
45
+ end
46
+ puts `diff #{local_file} #{tmp_file}`
47
+ FileUtils.rm_f(tmp_file)
48
+ end
49
+ end
50
+
36
51
  # Render template (usually a config file)
37
52
  #
38
53
  # Usually we render it to a file on the local filesystem.
@@ -1,27 +1,9 @@
1
1
  # Copyright 2009-2010 by le1t0@github. All rights reserved.
2
2
 
3
- # might be used in other scripts as well for checking differences with deployed configs for example
4
- # (if someone edited server configs by mistake, instead of editing inside the project)
5
- def compare_files(local_file, remote_file)
6
- tmp_file = File.join('/', 'tmp', "capistrano_compare_#{Time.now.strftime("%Y%m%d%H%M%S")}.tmp")
7
- File.open(tmp_file, 'w') do |f|
8
- run "cat #{remote_file}" do |channel, stream, data|
9
- f.write(data)
10
- end
11
- end
12
-
13
- puts `diff #{local_file} #{tmp_file} && echo "files are the same!"`
14
- FileUtils.rm_f(tmp_file)
15
- end
16
-
17
3
  Capistrano::Configuration.instance(:must_exist).load do
18
4
  namespace :deprec do
19
5
  namespace :cap do
20
6
 
21
- task :compare do
22
- compare_files(ENV["LOCAL"], ENV["REMOTE"])
23
- end
24
-
25
7
  desc "Show Capistrano variables"
26
8
  task :vars do
27
9
  y variables
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: le1t0-deprec
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 2.1.6.070
5
+ version: 2.1.6.071
6
6
  platform: ruby
7
7
  authors:
8
8
  - Le1t0
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-02-25 00:00:00 +01:00
13
+ date: 2011-02-28 00:00:00 +01:00
14
14
  default_executable: depify
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency