root/script/fix

Download in other formats: Raw | Text
Revisions
Dimitrij Denissenko
Dimitrij Denissenko
Jul 23 2009 * 07:38
(about 1 year ago)

Revision b1794537d634e7833190d162a0351bc60046c8fc

Fixed 'fix' script

Unknown File Type

A viewable MIME type was not detected. Trying to display the file content as plain text.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#!/usr/bin/env ruby

#--
# Copyright (C) 2009 Dimitrij Denissenko
# Please read LICENSE document for more information.
#++
begin
        require 'rubygems'
rescue LoadError
        raise LoadError, 'RubyGEMs are NOT installed! Please install RubyGEMs first.'
end

ROOT_PATH = File.expand_path(File.join(File.dirname(__FILE__), '..'))

def relativize_path(path)
  File.expand_path(path).gsub(%r{#{Regexp.quote(ROOT_PATH + '/')}}, '')
end

def headline(text)
  puts "\n > #{text}\n"
end

def message(code, text)
  puts "   [#{code}] #{text}\n"
end

def error(text)
  message('E', "Warning! #{text}")
end

def summary(text)
  message('=', "OK! #{text}")
end




def test_subversion_support
  headline('Testing Subversion support')

  libs = {}
  libs['Core']   = require 'svn/core'  rescue nil
  libs['Fs']     = require 'svn/fs'    rescue nil
  libs['Delta']  = require 'svn/delta' rescue nil
  libs['Repos']  = require 'svn/repos' rescue nil
  libs['Client'] = require 'svn/client' rescue nil

  ok = true
  libs.each_pair do |lib, loaded|
    ok = false if loaded.nil?
    code = loaded.nil? ? '-' : '+'
    msg  = loaded.nil? ? 'NOT' : 'successfully'
    message(code, "Svn::#{lib} library was #{msg} loaded")
  end
  if ok
    summary('All libraries were loaded. Subversion support will be fully ENABLED!')
  else
    error('At least one required library could not be loaded. Subversion support will be DISABLED!')
  end
end

def test_git_support
  headline('Testing Git support')

  if system("/usr/bin/env git --version 1> /dev/null 2> /dev/null")
    summary('Git executables are installed on your machine. GIT support will be fully ENABLED!')
  else
    error('Git executables are missing. GIT support will be DISABLED!')
  end
end


def test_environment
  headline('Checking production environment')

  loaded = false
  ENV['RAILS_ENV'] = 'production'
  begin
    require File.dirname(__FILE__) + '/../config/environment'
    loaded = true
    summary('Retrospectiva was successfully loaded!')
  rescue
    error('Cannot load Retrospectiva!')
    message('E', $!)
  end
end


def test_file_permissions
  headline("Checking file access permissions for user '#{ENV['USER']}'")

  permissions_ok = true
  ['config/runtime/**', 'log', 'attachments', 'tmp/**', 'extensions'].each do |path|
    full_path = File.join(ROOT_PATH, path)
    Dir.glob(full_path).each do |fs_obj|
      if File.writable?(fs_obj)
        message('+', "#{relativize_path(fs_obj)} - writable")
      else      
        permissions_ok = false
        message('-', "#{relativize_path(fs_obj)} - NOT writable")
      end
    end        
  end
  Dir.glob(File.join(ROOT_PATH, 'public', 'dispatch.*')).each do |fs_obj|
    if File.executable?(fs_obj)
      message('+', "#{relativize_path(fs_obj)} - executable")
    else
      permissions_ok = false
      message('-', "#{relativize_path(fs_obj)} - NOT executable")
    end    
  end        
  
  if permissions_ok
    summary('All your file system permissions are set correctly!')
  else
    error('At least one of your file system permissions IS NOT set correctly!')
  end
end


def test_tasks
  headline("Checking Retrospectiva tasks")

        manager  = Retrospectiva::TaskManager.new
  tasks_ok = true
  
  if manager.tasks.any?
    message('+', "Task configuration was found.")
    
                unused = manager.tasks.select(&:unused?)
    stale = manager.tasks.select(&:stale?)

                if unused.blank? and stale.blank?
      message('+', 'All Tasks are active.')
    end
    
    if unused.any?
      tasks_ok = false            
      message('-', "At least one task is DUE since #{unused.map(&:due_at).max}. ")
    end
    
    if stale.any?
      tasks_ok = false
      message('-', "At least one task is STALE since #{stale.map(&:started_at).max}. ")
                end                
  else
    tasks_ok = false
    message('-', "Task have not been configured yet. Please login as an admin to set-up tasks!")
  end

  if tasks_ok
    summary('Tasks have been set-up correctly!')
  else
    error('Tasks seem not to be set-up correctly!')
  end
end

puts "\n----- Retrospectiva status report\n"
test_git_support
test_subversion_support
test_environment
test_file_permissions
test_tasks
puts "\n----- Finished\n"