aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSeb Bacon <seb.bacon@gmail.com>2011-07-05 09:56:59 +0100
committerSeb Bacon <seb.bacon@gmail.com>2011-07-05 09:56:59 +0100
commit74a7c2a1659ce9101c11e7bf6c53eeca2feef576 (patch)
tree959a25e29dca3e18f3fba6715549245648a26855
parent5b78f72751b0bfa24f436420131e6ac6514ffa80 (diff)
parent74249524b08a2782d1f7272af3c66f081977367d (diff)
Merge branch 'master' of github.com:sebbacon/alaveteli
-rw-r--r--app/controllers/application_controller.rb2
-rw-r--r--app/models/incoming_message.rb89
-rw-r--r--config/alert-tracks-debian.ugly57
-rw-r--r--config/boot.rb21
-rw-r--r--config/crontab.ugly4
-rw-r--r--config/environment.rb2
-rw-r--r--public/stylesheets/ie6-custom.css2
-rwxr-xr-xscript/runner47
-rw-r--r--vendor/plugins/acts_as_xapian/lib/acts_as_xapian.rb6
9 files changed, 134 insertions, 96 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 91754e2ba..e39865dd9 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -31,7 +31,7 @@ class ApplicationController < ActionController::Base
def site_name
# XXX should come from database:
site_name = "WhatDoTheyKnow"
- return site_name
+ return site_name
end
# Help work out which request causes RAM spike.
diff --git a/app/models/incoming_message.rb b/app/models/incoming_message.rb
index 119eb0b4b..4d3c08df3 100644
--- a/app/models/incoming_message.rb
+++ b/app/models/incoming_message.rb
@@ -194,65 +194,54 @@ class FOIAttachment
end
# Whether this type can be shown in the Google Docs Viewer.
- # PDF, PowerPoint and TIFF are listed on https://docs.google.com/viewer
- # .doc and .docx were added later http://gmailblog.blogspot.com/2010/06/view-doc-attachments-right-in-your.html
- # .xls appears to work fine too
+ # The full list of supported types can be found at
+ # https://docs.google.com/support/bin/answer.py?hl=en&answer=1189935
def has_google_docs_viewer?
- if self.content_type == 'application/vnd.ms-word'
- return true
- elsif self.content_type == 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
- return true
- elsif self.content_type == 'application/pdf'
- return true
- elsif self.content_type == 'image/tiff'
- return true
- elsif self.content_type == 'application/vnd.ms-powerpoint'
- return true
- elsif self.content_type == 'application/vnd.ms-excel'
- return true
- end
+ return !! {
+ "application/pdf" => true, # .pdf
+ "image/tiff" => true, # .tiff
+
+ "application/vnd.ms-word" => true, # .doc
+ "application/vnd.openxmlformats-officedocument.wordprocessingml.document" => true, # .docx
+
+ "application/vnd.ms-powerpoint" => true, # .ppt
+ "application/vnd.openxmlformats-officedocument.presentationml.presentation" => true, # .pptx
+
+ "application/vnd.ms-excel" => true, # .xls
+ "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" => true, # .xlsx
+
+ } [self.content_type]
end
# Whether this type has a "View as HTML"
def has_body_as_html?
- if self.content_type == 'text/plain'
- return true
- elsif self.content_type == 'application/vnd.ms-word'
- return true
- elsif self.content_type == 'application/vnd.ms-excel'
- return true
- elsif self.content_type == 'application/pdf'
- return true
- elsif self.content_type == 'application/rtf'
- return true
- end
- # We use the same "View as HTML" link to embed the Google Doc Viewer
- # (when it can't do a conversion locally)
- if self.has_google_docs_viewer?
- return true
- end
- return false
+ return (
+ !!{
+ "text/plain" => true,
+ "application/rtf" => true,
+ }[self.content_type] or
+ self.has_google_docs_viewer?
+ )
end
# Name of type of attachment type - only valid for things that has_body_as_html?
def name_of_content_type
- if self.content_type == 'text/plain'
- return "Text file"
- elsif self.content_type == 'application/vnd.ms-word'
- return "Word document"
- elsif self.content_type == 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
- return "Word document - XML"
- elsif self.content_type == 'application/vnd.ms-excel'
- return "Excel spreadsheet"
- elsif self.content_type == 'application/pdf'
- return "PDF file"
- elsif self.content_type == 'application/rtf'
- return "RTF file"
- elsif self.content_type == 'application/vnd.ms-powerpoint'
- return "PowerPoint presentation"
- elsif self.content_type == 'image/tiff'
- return "TIFF image"
- end
+ return {
+ "text/plain" => "Text file",
+ 'application/rtf' => "RTF file",
+
+ 'application/pdf' => "PDF file",
+ 'image/tiff' => "TIFF image",
+
+ 'application/vnd.ms-word' => "Word document",
+ 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' => "Word document",
+
+ 'application/vnd.ms-powerpoint' => "PowerPoint presentation",
+ 'application/vnd.openxmlformats-officedocument.presentationml.presentation' => "PowerPoint presentation",
+
+ 'application/vnd.ms-excel' => "Excel spreadsheet",
+ 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' => "Excel spreadsheet",
+ }[self.content_type]
end
# For "View as HTML" of attachment
diff --git a/config/alert-tracks-debian.ugly b/config/alert-tracks-debian.ugly
index 6dfa811a4..e4cc12b38 100644
--- a/config/alert-tracks-debian.ugly
+++ b/config/alert-tracks-debian.ugly
@@ -13,33 +13,60 @@
# !!(*= $daemon_name *)!! Start the WhatDoTheyKnow email alert daemon
NAME=!!(*= $daemon_name *)!!
-DAEMON=/data/vhost/!!(*= $vhost *)!!/alaveteli/script/alert-tracks-daemon
+DAEMON=/data/vhost/!!(*= $vhost *)!!/alaveteli/script/runner
+DAEMON_ARGS="--daemon TrackMailer.alert_tracks_loop"
PIDFILE=/data/vhost/!!(*= $vhost *)!!/alert-tracks.pid
+LOGFILE=/data/vhost/!!(*= $vhost *)!!/logs/alert-tracks.log
DUSER=!!(*= $user *)!!
trap "" 1
-export PIDFILE
+export PIDFILE LOGFILE
+
+quietly_start_daemon() {
+ /sbin/start-stop-daemon --quiet --start --pidfile "$PIDFILE" --chuid "$DUSER" --startas "$DAEMON" -- $DAEMON_ARGS
+}
+
+start_daemon() {
+ /sbin/start-stop-daemon --start --pidfile "$PIDFILE" --chuid "$DUSER" --startas "$DAEMON" -- $DAEMON_ARGS
+}
+
+stop_daemon() {
+ /sbin/start-stop-daemon --stop --pidfile "$PIDFILE"
+}
+
+restart() { stop; start; }
case "$1" in
+ check)
+ quietly_start_daemon
+ if [ $? -ne 1 ]
+ then
+ echo "WhatDoTheyKnow alert daemon was not running; now restarted"
+ exit 1
+ else
+ exit 0
+ fi
+ ;;
+
start)
- echo -n "Starting WhatDoTheyKnow alert daemon: $NAME"
- start-stop-daemon --start --pidfile $PIDFILE --chuid $DUSER --exec $DAEMON > /dev/null
- ;;
-
+ echo -n "Starting WhatDoTheyKnow alert daemon: $NAME"
+ start_daemon
+ ;;
+
stop)
- echo -n "Stopping WhatDoTheyKnow alert daemon: $NAME"
- start-stop-daemon --stop --pidfile $PIDFILE --oknodo
- ;;
-
+ echo -n "Stopping WhatDoTheyKnow alert daemon: $NAME"
+ stop_daemon
+ ;;
+
restart)
- echo -n "Restarting WhatDoTheyKnow alert daemon: $NAME"
- start-stop-daemon --stop --pidfile $PIDFILE --oknodo
- start-stop-daemon --start --pidfile $PIDFILE --chuid $DUSER --exec $DAEMON > /dev/null
- ;;
+ echo -n "Restarting WhatDoTheyKnow alert daemon: $NAME"
+ stop_daemon
+ start_daemon
+ ;;
*)
- echo "Usage: /etc/init.d/$NAME {start|stop|restart}"
+ echo "Usage: /etc/init.d/$NAME {start|stop|restart|check}"
exit 1
;;
esac
diff --git a/config/boot.rb b/config/boot.rb
index 30e4851a5..90fd9cd4d 100644
--- a/config/boot.rb
+++ b/config/boot.rb
@@ -54,6 +54,7 @@ module Rails
def load_initializer
require "#{RAILS_ROOT}/vendor/rails/railties/lib/initializer"
Rails::Initializer.run(:install_gem_spec_stubs)
+ Rails::GemDependency.add_frozen_gem_path
end
end
@@ -71,13 +72,17 @@ module Rails
gem 'rails'
end
rescue Gem::LoadError => load_error
- $stderr.puts %(Missing the Rails #{version} gem. Please `gem install -v=#{version} rails`, update your RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do have installed, or comment out RAILS_GEM_VERSION to use the latest version installed.)
- exit 1
+ if load_error.message =~ /Could not find RubyGem rails/
+ STDERR.puts %(Missing the Rails #{version} gem. Please `gem install -v=#{version} rails`, update your RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do have installed, or comment out RAILS_GEM_VERSION to use the latest version installed.)
+ exit 1
+ else
+ raise
+ end
end
class << self
def rubygems_version
- Gem::RubyGemsVersion if defined? Gem::RubyGemsVersion
+ Gem::RubyGemsVersion rescue nil
end
def gem_version
@@ -91,15 +96,16 @@ module Rails
end
def load_rubygems
+ min_version = '1.3.2'
require 'rubygems'
- unless rubygems_version >= '0.9.4'
- $stderr.puts %(Rails requires RubyGems >= 0.9.4 (you have #{rubygems_version}). Please `gem update --system` and try again.)
+ unless rubygems_version >= min_version
+ $stderr.puts %Q(Rails requires RubyGems >= #{min_version} (you have #{rubygems_version}). Please `gem update --system` and try again.)
exit 1
end
rescue LoadError
- $stderr.puts %(Rails requires RubyGems >= 0.9.4. Please install RubyGems and try again: http://rubygems.rubyforge.org)
+ $stderr.puts %Q(Rails requires RubyGems >= #{min_version}. Please install RubyGems and try again: http://rubygems.rubyforge.org)
exit 1
end
@@ -115,5 +121,8 @@ module Rails
end
end
+
+
# All that for this:
Rails.boot!
+
diff --git a/config/crontab.ugly b/config/crontab.ugly
index 9193899af..5820151a0 100644
--- a/config/crontab.ugly
+++ b/config/crontab.ugly
@@ -11,8 +11,8 @@ MAILTO=cron-!!(*= $site *)!!@mysociety.org
# Every 5 minutes
*/5 * * * * !!(*= $user *)!! run-with-lockfile -n /data/vhost/!!(*= $vhost *)!!/update-xapian-index.lock /data/vhost/!!(*= $vhost *)!!/!!(*= $vcspath *)!!/script/update-xapian-index || echo "stalled?"
-# # Every 10 minutes
-# 5,15,25,35,45,55 * * * * !!(*= $user *)!! run-with-lockfile -n /data/vhost/!!(*= $vhost *)!!/alert-tracks.lock /data/vhost/!!(*= $vhost *)!!/!!(*= $vcspath *)!!/script/alert-tracks || echo "stalled?"
+# Every 10 minutes
+5,15,25,35,45,55 * * * * !!(*= $user *)!! /etc/init.d/foi-alert-tracks check
# Once an hour
39 * * * * !!(*= $user *)!! run-with-lockfile -n /data/vhost/!!(*= $vhost *)!!/alert-overdue-requests.lock /data/vhost/!!(*= $vhost *)!!/!!(*= $vcspath *)!!/script/alert-overdue-requests || echo "stalled?"
diff --git a/config/environment.rb b/config/environment.rb
index 33be4a060..28598a9ef 100644
--- a/config/environment.rb
+++ b/config/environment.rb
@@ -6,7 +6,7 @@
# ENV['RAILS_ENV'] ||= 'production'
# Specifies gem version of Rails to use when vendor/rails is not present
-RAILS_GEM_VERSION = '2.3.2' unless defined? RAILS_GEM_VERSION
+RAILS_GEM_VERSION = '2.3.11' unless defined? RAILS_GEM_VERSION
# Bootstrap the Rails environment, frameworks, and default configuration
require File.join(File.dirname(__FILE__), 'boot')
diff --git a/public/stylesheets/ie6-custom.css b/public/stylesheets/ie6-custom.css
index ae02fe158..6ebde600c 100644
--- a/public/stylesheets/ie6-custom.css
+++ b/public/stylesheets/ie6-custom.css
@@ -2,5 +2,5 @@
#banner
{
- background-image: url(../images/navimg/alaveteli-100pxd.jpg);
+ background-image: url(../images/navimg/bnnr-temp-100pxd.jpg);
}
diff --git a/script/runner b/script/runner
index c12421aa2..5a5254c47 100755
--- a/script/runner
+++ b/script/runner
@@ -6,22 +6,35 @@ script_dir = File.dirname(__FILE__)
alaveteli_dir = File.join(script_dir, "..")
Dir.chdir(alaveteli_dir) do
- require File.join(alaveteli_dir, 'config', 'boot')
- if daemon_mode
- # Run in daemon mode.
- #
- # If the environment variable PIDFILE is present,
- # write the pid of the daemon process to that file.
-
- pid = fork { require 'commands/runner' }
- if ENV.has_key? "PIDFILE"
- File.open(ENV["PIDFILE"], 'w') do |fh|
- fh.puts pid
- end
+ require File.join(alaveteli_dir, 'config', 'boot')
+ if daemon_mode
+ # Run in daemon mode.
+
+ # If the environment variable LOGFILE is present,
+ # redirect STDERR and STDOUT to that file.
+ if ENV.has_key? "LOGFILE"
+ STDERR.reopen(STDOUT.reopen(ENV["LOGFILE"], "a"))
+ STDOUT.sync=true
+ puts "Daemon starting at #{Time.new}"
+ end
+
+ # Load the runner in a subprocess
+ pid = fork do
+ require 'commands/runner'
+ exit 0
+ end
+
+ # If the environment variable PIDFILE is present,
+ # write the pid of the daemon process to that file.
+ if ENV.has_key? "PIDFILE"
+ File.open(ENV["PIDFILE"], 'w') do |fh|
+ fh.puts pid
+ end
+ end
+
+ Process.detach(pid)
+ else
+ # Not daemon mode
+ require 'commands/runner'
end
- Process.detach(pid)
- else
-
- require 'commands/runner'
- end
end
diff --git a/vendor/plugins/acts_as_xapian/lib/acts_as_xapian.rb b/vendor/plugins/acts_as_xapian/lib/acts_as_xapian.rb
index d8f0adaa3..2f66b68be 100644
--- a/vendor/plugins/acts_as_xapian/lib/acts_as_xapian.rb
+++ b/vendor/plugins/acts_as_xapian/lib/acts_as_xapian.rb
@@ -98,7 +98,7 @@ module ActsAsXapian
# make the directory for the xapian databases to go in
Dir.mkdir(db_parent_path) unless File.exists?(db_parent_path)
- @@db_path = File.join(db_parent_path, environment)
+ @@db_path = File.join(db_parent_path, environment)
# make some things that don't depend on the db
# XXX this gets made once for each acts_as_xapian. Oh well.
@@ -124,8 +124,8 @@ module ActsAsXapian
begin
@@db = Xapian::Database.new(@@db_path)
@@enquire = Xapian::Enquire.new(@@db)
- rescue IOError
- raise "Xapian database not opened; have you built it with scripts/rebuild-xapian-index ?"
+ rescue IOError => e
+ raise "Failed to open Xapian database #{@@db_path}: #{e.message}"
end
init_query_parser