aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/alaveteli_external_command.rb33
-rw-r--r--lib/external_command.rb135
-rw-r--r--lib/public_body_categories.rb43
-rw-r--r--lib/public_body_categories_en.rb160
-rw-r--r--lib/world_foi_websites.rb40
5 files changed, 182 insertions, 229 deletions
diff --git a/lib/alaveteli_external_command.rb b/lib/alaveteli_external_command.rb
new file mode 100644
index 000000000..b967c89b5
--- /dev/null
+++ b/lib/alaveteli_external_command.rb
@@ -0,0 +1,33 @@
+require 'external_command'
+
+module AlaveteliExternalCommand
+ class << self
+ def run(program_name, *args)
+ # Run an external program, and return its output.
+ # Standard error is suppressed unless the program
+ # fails (i.e. returns a non-zero exit status).
+ opts = {}
+ if !args.empty? && args[-1].is_a?(Hash)
+ opts = args.pop
+ end
+
+ xc = ExternalCommand.new(program_name, *args)
+ if opts.has_key? :append_to
+ xc.out = opts[:append_to]
+ end
+ xc.run()
+ if xc.status != 0
+ # Error
+ $stderr.puts("Error from #{program_name} #{args.join(' ')}:")
+ $stderr.print(xc.err)
+ return nil
+ else
+ if opts.has_key? :append_to
+ opts[:append_to] << "\n\n"
+ else
+ return xc.out
+ end
+ end
+ end
+ end
+end
diff --git a/lib/external_command.rb b/lib/external_command.rb
deleted file mode 100644
index 96292854f..000000000
--- a/lib/external_command.rb
+++ /dev/null
@@ -1,135 +0,0 @@
-# Run an external command, capturing its stdout and stderr
-# streams into variables.
-#
-# So it’s rather like the `backtick` built-in, except that:
-# - The command is run as-is, rather than being parsed by the shell;
-# - Standard error is also captured.
-#
-# After the run() method has been called, the instance variables
-# out, err and status contain the contents of the process’s stdout,
-# the contents of its stderr, and the exit status.
-#
-# Example usage:
-# require 'external_command'
-# xc = ExternalCommand("ls", "-l").run()
-# puts "Ran ls -l with exit status #{xc.status}"
-# puts "===STDOUT===\n#{xc.out}"
-# puts "===STDERR===\n#{xc.err}"
-#
-# The out and err attributes are writeable. If you assign
-# a string, after calling the constructor and before calling
-# run(), then the subprocess output/error will be appended
-# to this string.
-
-# <rant author="robin">
-# In any sane language, this would be implemented with a
-# single child process. The parent process would block on
-# select(), and when the child process terminated, the
-# select call would be interrupted by a CHLD signal
-# and return EINTR. Unfortunately Ruby goes out of its
-# way to prevent this from working, automatically restarting
-# the select call if EINTR is returned. Therefore we
-# use a parent-child-grandchild arrangement, where the
-# parent blocks on select() and the child blocks on
-# waitpid(). When the child detects that the grandchild
-# has finished, it writes to a pipe that’s included in
-# the parent’s select() for this purpose.
-# </rant>
-
-class ExternalCommand
- attr_accessor :out, :err
- attr_reader :status
-
- def initialize(cmd, *args)
- @cmd = cmd
- @args = args
-
- # Strings to collect stdout and stderr from the child process
- # These may be replaced by the caller, to append to existing strings.
- @out = ""
- @err = ""
- @fin = ""
- end
-
- def run()
- # Pipes for parent-child communication
- @out_read, @out_write = IO::pipe
- @err_read, @err_write = IO::pipe
- @fin_read, @fin_write = IO::pipe
-
- @pid = fork do
- # Here we’re in the child process.
- child_process
- end
-
- # Here we’re in the parent process.
- parent_process
-
- return self
- end
-
- private
-
- def child_process()
- # Reopen stdout and stderr to point at the pipes
- STDOUT.reopen(@out_write)
- STDERR.reopen(@err_write)
-
- # Close all the filehandles other than the ones we intend to use.
- ObjectSpace.each_object(IO) do |fh|
- fh.close unless (
- [STDOUT, STDERR, @fin_write].include?(fh) || fh.closed?)
- end
-
- Process::waitpid(fork { grandchild_process })
- @fin_write.puts($?.exitstatus.to_s)
-
- exit! 0
- end
-
- def grandchild_process()
- exec(@cmd, *@args)
-
- # This is only reached if the exec fails
- @err_write.print("Failed to exec: #{[@cmd, *@args].join(' ')}")
- exit! 99
- end
-
- def parent_process()
- # Close the writing ends of the pipes
- @out_write.close
- @err_write.close
- @fin_write.close
-
- @fhs = {@out_read => @out, @err_read => @err, @fin_read => @fin}
-
- while @fin.empty?
- ok = read_data
- if !ok
- raise "select() timed out even with a nil (infinite) timeout"
- end
- end
-
- while read_data(0)
- # Pull out any data that’s left in the pipes
- end
-
- Process::waitpid(@pid)
- @status = @fin.to_i
- @out_read.close
- @err_read.close
- end
-
- def read_data(timeout=nil)
- ready_array = IO.select(@fhs.keys, [], [], timeout)
- return false if ready_array.nil?
- ready_array[0].each do |fh|
- begin
- @fhs[fh] << fh.readpartial(8192)
- rescue EOFError
- @fhs.delete fh
- end
- end
- return true
- end
-end
diff --git a/lib/public_body_categories.rb b/lib/public_body_categories.rb
index 844e14e67..21a021d39 100644
--- a/lib/public_body_categories.rb
+++ b/lib/public_body_categories.rb
@@ -6,14 +6,39 @@
#
# $Id: public_body_categories.rb,v 1.1 2009-09-14 14:45:48 francis Exp $
-module PublicBodyCategories
+class PublicBodyCategories
+
+ attr_reader :with_description, :with_headings, :tags, :by_tag, :singular_by_tag
+
+ def initialize(categories)
+ @with_headings = categories
+ # Arranged in different ways for different sorts of displaying
+ @with_description = @with_headings.select() { |a| a.instance_of?(Array) }
+ @tags = @with_description.map() { |a| a[0] }
+ @by_tag = Hash[*@with_description.map() { |a| a[0..1] }.flatten]
+ @singular_by_tag = Hash[*@with_description.map() { |a| [a[0],a[2]] }.flatten]
+ end
- CATEGORIES_WITH_HEADINGS = []
-
- # Arranged in different ways for different sorts of displaying
- CATEGORIES_WITH_DESCRIPTION = CATEGORIES_WITH_HEADINGS.select() { |a| a.instance_of?(Array) }
- CATEGORIES = CATEGORIES_WITH_DESCRIPTION.map() { |a| a[0] }
- CATEGORIES_BY_TAG = Hash[*CATEGORIES_WITH_DESCRIPTION.map() { |a| a[0..1] }.flatten]
- CATEGORY_SINGULAR_BY_TAG = Hash[*CATEGORIES_WITH_DESCRIPTION.map() { |a| [a[0],a[2]] }.flatten]
-end
+ def PublicBodyCategories.get
+ load_categories() if @@CATEGORIES.nil?
+ @@CATEGORIES[I18n.locale.to_s] || @@CATEGORIES[I18n.default_locale.to_s] || PublicBodyCategories.new([])
+ end
+ # Called from the data files themselves
+ def PublicBodyCategories.add(locale, categories)
+ @@CATEGORIES[locale.to_s] = PublicBodyCategories.new(categories)
+ end
+
+ private
+ @@CATEGORIES = nil
+
+ def PublicBodyCategories.load_categories()
+ @@CATEGORIES = {} if @@CATEGORIES.nil?
+ I18n.available_locales.each do |locale|
+ begin
+ load "public_body_categories_#{locale}.rb"
+ rescue MissingSourceFile
+ end
+ end
+ end
+end \ No newline at end of file
diff --git a/lib/public_body_categories_en.rb b/lib/public_body_categories_en.rb
index 93183d397..5fe762357 100644
--- a/lib/public_body_categories_en.rb
+++ b/lib/public_body_categories_en.rb
@@ -6,88 +6,78 @@
#
# $Id: public_body_categories.rb,v 1.1 2009-09-14 14:45:48 francis Exp $
-module PublicBodyCategories
-
- CATEGORIES_WITH_HEADINGS = [
- "Miscellaneous",
- [ "other", "Miscellaneous", "miscellaneous" ],
- _("Central government"),
- [ "department", "Ministerial departments", "a ministerial department" ],
- [ "non_ministerial_department", "Non-ministerial departments", "a non-ministerial department" ],
- [ "executive_agency", "Executive agencies", "an executive agency" ],
- [ "government_office", "Government offices for the regions", "a government office for the regions" ],
- [ "advisory_committee", "Advisory committees", "an advisory committee" ],
- [ "awc", "Agricultural wages committees", "an agriculatural wages committee" ],
- [ "adhac", "Agricultural dwelling house advisory committees", "an agriculatural dwelling house advisory committee" ],
- [ "newdeal", "New Deal for Communities partnership", "a New Deal for Communities partnership" ],
- _("Local and regional"),
- [ "local_council", "Local councils", "a local council" ],
- [ "parish_council", "Town and Parish councils", "a town or parish council"],
- [ "housing_association", "Housing associations", "a housing association"],
- [ "almo", "Housing ALMOs", "a housing ALMO"],
- [ "municipal_bank", "Municipal bank", "a municipal bank"],
- [ "nsbody", "North/south bodies", "a north/south body"],
- [ "pbo", "Professional buying organisations", "a professional buying organisation"],
- [ "regional_assembly", "Regional assemblies", "a regional assembly"],
- [ "rda", "Regional development agencies", "a regional development agency" ],
- "Education",
- [ "university", "Universities", "a university" ],
- [ "university_college", "University colleges", "a university college" ],
- [ "cambridge_college", "Cambridge colleges", "a Cambridge college" ],
- [ "durham_college", "Durham colleges", "a Durham college" ],
- [ "oxford_college", "Oxford colleges", "an Oxford college or permanent private hall" ],
- [ "york_college", "York colleges", "a college of the University of York" ],
- [ "university_owned_company", "University owned companies", "a university owned company" ],
- [ "hei", "Higher education institutions", "a higher educational institution" ],
- [ "fei", "Further education institutions", "a further educational institution" ],
- [ "school", "Schools", "a school" ],
- [ "research_council", "Research councils", "a research council" ],
- [ "lib_board", "Education and library boards", "an education and library board" ],
- [ "rbc", "Regional Broadband Consortia", "a Regional Broadband Consortium" ],
- "Environment",
- [ "npa", "National park authorities", "a national park authority" ],
- [ "rpa", "Regional park authorities", "a regional park authority" ],
- [ "sea_fishery_committee", "Sea fisheries committees", "a sea fisheries committee" ],
- [ "watercompanies", "Water companies", "a water company" ],
- [ "idb", "Internal drainage boards", "an internal drainage board" ],
- [ "rfdc", "Regional flood defence committees", "a regional flood defence committee" ],
- [ "wda", "Waste disposal authorities", "a waste disposal authority" ],
- [ "zoo", "Zoos", "a zoo" ],
- "Health",
- [ "nhstrust", "NHS trusts", "an NHS trust" ],
- [ "pct", "Primary care trusts", "a primary care trust" ],
- [ "nhswales", "NHS in Wales", "part of the NHS in Wales" ],
- [ "nhsni", "NHS in Northern Ireland", "part of the NHS in Northern Ireland" ],
- [ "hscr", "Health / social care", "Relating to health / social care" ],
- [ "pha", "Port health authorities", "a port health authority"],
- [ "sha", "Strategic health authorities", "a strategic health authority" ],
- [ "specialha", "Special health authorities", "a special health authority" ],
- "Media and culture",
- [ "media", "Media", "a media organisation" ],
- [ "rcc", "Cultural consortia", "a cultural consortium"],
- [ "museum", "Museums and galleries", "a museum or gallery" ],
- "Military and security services",
- [ "military_college", "Military colleges", "a military college" ],
- [ "security_services", "Security services", "a security services body" ],
- "Emergency services and the courts",
- [ "police", "Police forces", "a police force" ],
- [ "police_authority", "Police authorities", "a police authority" ],
- [ "dpp", "District policing partnerships", "a district policing partnership" ],
- [ "fire_service", "Fire and rescue services", "a fire and rescue service" ],
- [ "prob_board", "Probation boards", "a probation board" ],
- [ "rules_committee", "Rules commitees", "a rules committee" ],
- [ "tribunal", "Tribunals", "a tribunal"],
- "Transport",
- [ "npte", "Passenger transport executives", "a passenger transport executive" ],
- [ "port_authority", "Port authorities", "a port authority" ],
- [ "scp", "Safety Camera Partnerships", "a safety camera partnership" ],
- [ "srp", "Safer Roads Partnership", "a safer roads partnership" ]
- ]
-
- # Arranged in different ways for different sorts of displaying
- CATEGORIES_WITH_DESCRIPTION = CATEGORIES_WITH_HEADINGS.select() { |a| a.instance_of?(Array) }
- CATEGORIES = CATEGORIES_WITH_DESCRIPTION.map() { |a| a[0] }
- CATEGORIES_BY_TAG = Hash[*CATEGORIES_WITH_DESCRIPTION.map() { |a| a[0..1] }.flatten]
- CATEGORY_SINGULAR_BY_TAG = Hash[*CATEGORIES_WITH_DESCRIPTION.map() { |a| [a[0],a[2]] }.flatten]
-end
-
+PublicBodyCategories.add(:en, [
+ "Miscellaneous",
+ [ "other", "Miscellaneous", "miscellaneous" ],
+ "Central government",
+ [ "department", "Ministerial departments", "a ministerial department" ],
+ [ "non_ministerial_department", "Non-ministerial departments", "a non-ministerial department" ],
+ [ "executive_agency", "Executive agencies", "an executive agency" ],
+ [ "government_office", "Government offices for the regions", "a government office for the regions" ],
+ [ "advisory_committee", "Advisory committees", "an advisory committee" ],
+ [ "awc", "Agricultural wages committees", "an agriculatural wages committee" ],
+ [ "adhac", "Agricultural dwelling house advisory committees", "an agriculatural dwelling house advisory committee" ],
+ [ "newdeal", "New Deal for Communities partnership", "a New Deal for Communities partnership" ],
+ "Local and regional",
+ [ "local_council", "Local councils", "a local council" ],
+ [ "parish_council", "Town and Parish councils", "a town or parish council"],
+ [ "housing_association", "Housing associations", "a housing association"],
+ [ "almo", "Housing ALMOs", "a housing ALMO"],
+ [ "municipal_bank", "Municipal bank", "a municipal bank"],
+ [ "nsbody", "North/south bodies", "a north/south body"],
+ [ "pbo", "Professional buying organisations", "a professional buying organisation"],
+ [ "regional_assembly", "Regional assemblies", "a regional assembly"],
+ [ "rda", "Regional development agencies", "a regional development agency" ],
+ "Education",
+ [ "university", "Universities", "a university" ],
+ [ "university_college", "University colleges", "a university college" ],
+ [ "cambridge_college", "Cambridge colleges", "a Cambridge college" ],
+ [ "durham_college", "Durham colleges", "a Durham college" ],
+ [ "oxford_college", "Oxford colleges", "an Oxford college or permanent private hall" ],
+ [ "york_college", "York colleges", "a college of the University of York" ],
+ [ "university_owned_company", "University owned companies", "a university owned company" ],
+ [ "hei", "Higher education institutions", "a higher educational institution" ],
+ [ "fei", "Further education institutions", "a further educational institution" ],
+ [ "school", "Schools", "a school" ],
+ [ "research_council", "Research councils", "a research council" ],
+ [ "lib_board", "Education and library boards", "an education and library board" ],
+ [ "rbc", "Regional Broadband Consortia", "a Regional Broadband Consortium" ],
+ "Environment",
+ [ "npa", "National park authorities", "a national park authority" ],
+ [ "rpa", "Regional park authorities", "a regional park authority" ],
+ [ "sea_fishery_committee", "Sea fisheries committees", "a sea fisheries committee" ],
+ [ "watercompanies", "Water companies", "a water company" ],
+ [ "idb", "Internal drainage boards", "an internal drainage board" ],
+ [ "rfdc", "Regional flood defence committees", "a regional flood defence committee" ],
+ [ "wda", "Waste disposal authorities", "a waste disposal authority" ],
+ [ "zoo", "Zoos", "a zoo" ],
+ "Health",
+ [ "nhstrust", "NHS trusts", "an NHS trust" ],
+ [ "pct", "Primary care trusts", "a primary care trust" ],
+ [ "nhswales", "NHS in Wales", "part of the NHS in Wales" ],
+ [ "nhsni", "NHS in Northern Ireland", "part of the NHS in Northern Ireland" ],
+ [ "hscr", "Health / social care", "Relating to health / social care" ],
+ [ "pha", "Port health authorities", "a port health authority"],
+ [ "sha", "Strategic health authorities", "a strategic health authority" ],
+ [ "specialha", "Special health authorities", "a special health authority" ],
+ "Media and culture",
+ [ "media", "Media", "a media organisation" ],
+ [ "rcc", "Cultural consortia", "a cultural consortium"],
+ [ "museum", "Museums and galleries", "a museum or gallery" ],
+ "Military and security services",
+ [ "military_college", "Military colleges", "a military college" ],
+ [ "security_services", "Security services", "a security services body" ],
+ "Emergency services and the courts",
+ [ "police", "Police forces", "a police force" ],
+ [ "police_authority", "Police authorities", "a police authority" ],
+ [ "dpp", "District policing partnerships", "a district policing partnership" ],
+ [ "fire_service", "Fire and rescue services", "a fire and rescue service" ],
+ [ "prob_board", "Probation boards", "a probation board" ],
+ [ "rules_committee", "Rules commitees", "a rules committee" ],
+ [ "tribunal", "Tribunals", "a tribunal"],
+ "Transport",
+ [ "npte", "Passenger transport executives", "a passenger transport executive" ],
+ [ "port_authority", "Port authorities", "a port authority" ],
+ [ "scp", "Safety Camera Partnerships", "a safety camera partnership" ],
+ [ "srp", "Safer Roads Partnership", "a safer roads partnership" ]
+])
diff --git a/lib/world_foi_websites.rb b/lib/world_foi_websites.rb
new file mode 100644
index 000000000..24845437a
--- /dev/null
+++ b/lib/world_foi_websites.rb
@@ -0,0 +1,40 @@
+class WorldFOIWebsites
+ def self.world_foi_websites
+ world_foi_websites = [
+ {:name => "WhatDoTheyKnow?",
+ :country_name => _("United Kingdom"),
+ :country_iso_code => "GB",
+ :url => "http://www.whatdotheyknow.com"},
+ {:name => "Informata Zyrtare",
+ :country_name => _("Kosovo"),
+ :country_iso_code => "XK",
+ :url => "http://informatazyrtare.org"},
+ {:name => "Ask The EU",
+ :country_name => _("European Union"),
+ :country_iso_code => "",
+ :url => "http://asktheu.org"},
+ {:name => "MuckRock.com",
+ :country_name => _("United States of America"),
+ :country_iso_code => "US",
+ :url => "http://www.muckrock.com"},
+ {:name => "FYI",
+ :country_name => _("New Zealand"),
+ :country_iso_code => "NZ",
+ :url => "http://fyi.org.nz"},
+ {:name => "Frag den Staat",
+ :country_name => _("Germany"),
+ :country_iso_code => "DE",
+ :url => "http://fragdenstaat.de"},
+ {:name => "Acceso Intelligente",
+ :country_name => _("Chile"),
+ :country_iso_code => "CL",
+ :url => "accesointeligente.org"}]
+ return world_foi_websites
+ end
+
+ def self.by_code(code)
+ result = self.world_foi_websites.find{|x| x[:country_iso_code].downcase == code.downcase}
+ return result
+ end
+end
+