diff options
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/comment-backfill | 21 | ||||
-rwxr-xr-x | bin/cron-wrapper | 6 | ||||
-rwxr-xr-x | bin/emptyhomes/canonicalise-eha (renamed from bin/canonicalise-eha) | 0 | ||||
-rwxr-xr-x | bin/emptyhomes/make_welsh_po (renamed from bin/make_emptyhomes_welsh_po) | 12 | ||||
-rwxr-xr-x | bin/fetch-comments | 7 | ||||
-rwxr-xr-x | bin/fetch-comments-24hs | 10 | ||||
-rw-r--r-- | bin/fiksgatami/export-norwegian-contacts (renamed from bin/export-norwegian-contacts) | 0 | ||||
-rwxr-xr-x | bin/fiksgatami/load-norwegian-contacts (renamed from bin/load-norwegian-contacts) | 0 | ||||
-rwxr-xr-x | bin/fixmystreet.com/canonicalise-csv (renamed from bin/canonicalise-csv) | 0 | ||||
-rwxr-xr-x | bin/fixmystreet.com/generate_council_location (renamed from bin/generate_council_location) | 0 | ||||
-rwxr-xr-x | bin/fixmystreet.com/import-categories (renamed from bin/import-categories) | 0 | ||||
-rwxr-xr-x | bin/fixmystreet.com/load-contacts (renamed from bin/load-contacts) | 0 | ||||
-rwxr-xr-x | bin/fixmystreet.com/populate_bing_cache (renamed from bin/populate_bing_cache) | 0 | ||||
-rwxr-xr-x | bin/fixmystreet.com/rotate-photos (renamed from bin/rotate-photos) | 0 | ||||
-rwxr-xr-x | bin/fixmystreet.com/showcouncilrates (renamed from bin/showcouncilrates) | 0 | ||||
-rwxr-xr-x | bin/fixmystreet.com/update-areas (renamed from bin/update-areas) | 0 | ||||
-rwxr-xr-x | bin/fixmystreet.com/update-send-questionnaire (renamed from bin/update-send-questionnaire) | 0 | ||||
-rwxr-xr-x | bin/geocode | 11 | ||||
-rwxr-xr-x | bin/gettext-nget-patch | 2 | ||||
-rwxr-xr-x | bin/handlemail | 3 | ||||
-rwxr-xr-x | bin/install-as-user | 8 | ||||
-rwxr-xr-x | bin/kasabi | 234 | ||||
-rwxr-xr-x | bin/make_css | 5 | ||||
-rwxr-xr-x | bin/make_css_watch | 9 | ||||
-rwxr-xr-x | bin/make_po | 4 | ||||
-rwxr-xr-x | bin/open311-populate-service-list | 8 | ||||
-rwxr-xr-x | bin/open311-update-reports | 10 | ||||
-rwxr-xr-x | bin/problem-creation-graph | 11 | ||||
-rwxr-xr-x | bin/problems-filed-graph | 11 | ||||
-rwxr-xr-x | bin/run-tests | 37 | ||||
-rwxr-xr-x | bin/send-alerts | 7 | ||||
-rwxr-xr-x | bin/send-comments | 7 | ||||
-rwxr-xr-x | bin/send-questionnaires | 7 | ||||
-rwxr-xr-x | bin/send-reports | 7 | ||||
-rw-r--r-- | bin/site-specific-install.sh | 2 | ||||
-rwxr-xr-x | bin/test-wrapper | 35 | ||||
-rwxr-xr-x | bin/update-all-reports | 7 | ||||
-rwxr-xr-x | bin/update-schema | 18 | ||||
-rwxr-xr-x | bin/zerotb/import_clinic_list.pl (renamed from bin/zerotb_import_clinic_list.pl) | 0 | ||||
-rwxr-xr-x | bin/zurich/geocode | 45 | ||||
-rwxr-xr-x | bin/zurich/overdue-alert (renamed from bin/zurich-overdue-alert) | 9 |
41 files changed, 182 insertions, 371 deletions
diff --git a/bin/comment-backfill b/bin/comment-backfill deleted file mode 100755 index e296d7756..000000000 --- a/bin/comment-backfill +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/env perl - -use strict; -use warnings; -require 5.8.0; -use DateTime; - -use FixMyStreet::App; - -use Open311; -use Open311::GetServiceRequestUpdates; - -my $start_time = DateTime->now->subtract( days => 1, hours => 1 ); -my $end_time = DateTime->now; - -my $updates = Open311::GetServiceRequestUpdates->new( - start_date => $start_time, - end_date => $end_time, -); - -$updates->fetch; diff --git a/bin/cron-wrapper b/bin/cron-wrapper index 127fd8d8a..c75f0289b 100755 --- a/bin/cron-wrapper +++ b/bin/cron-wrapper @@ -1,8 +1,10 @@ #!/usr/bin/env perl BEGIN { # set all the paths to the perl code - use FindBin; - require "$FindBin::Bin/../setenv.pl"; + use File::Basename qw(dirname); + use File::Spec; + my $d = dirname(File::Spec->rel2abs($0)); + require "$d/../setenv.pl"; } exec { $ARGV[0] } @ARGV or die $!; diff --git a/bin/canonicalise-eha b/bin/emptyhomes/canonicalise-eha index 1030982fa..1030982fa 100755 --- a/bin/canonicalise-eha +++ b/bin/emptyhomes/canonicalise-eha diff --git a/bin/make_emptyhomes_welsh_po b/bin/emptyhomes/make_welsh_po index f4f6850d6..568ccdcde 100755 --- a/bin/make_emptyhomes_welsh_po +++ b/bin/emptyhomes/make_welsh_po @@ -1,15 +1,17 @@ -#!/usr/bin/perl -w +#!/usr/bin/env perl + use strict; +use warnings; # Given a translation of the Empty Homes version of the FixMyStreet .po file, # fix it all up to go direct from FixMyStreet -> EH translation. use POSIX; use FindBin; -use lib "$FindBin::Bin/../perllib"; +use lib "$FindBin::Bin/../../perllib"; use PoChange; -chdir("$FindBin::Bin/../locale"); +chdir("$FindBin::Bin/../../locale"); # First read in translation and match up. open(INPO, 'cy_GB.UTF-8/LC_MESSAGES/EmptyHomes.po') or die $!; @@ -51,7 +53,7 @@ mkdir("cy_GB.UTF-8/LC_MESSAGES"); open(MAINPO, 'FixMyStreet.po') or die; open(OUTPO, ">cy_GB.UTF-8/LC_MESSAGES/FixMyStreet-EmptyHomes.po") or die; -print OUTPO "# AUTOMATICALLY GENERATED by make_emptyhomes_welsh_po, do not edit\n\n"; +print OUTPO "# AUTOMATICALLY GENERATED by make_welsh_po, do not edit\n\n"; my $buffer = ""; my $start = 0; @@ -60,7 +62,7 @@ while(<MAINPO>) { s/#, fuzzy/#/; } if (m/"Last-Translator: FULL NAME/) { - $_ = '"Last-Translator: mysociety/bin/make_emptyhomes_po\\n"'."\n"; + $_ = '"Last-Translator: mysociety/bin/emptyhomes/make_welsh_po\\n"'."\n"; } if (m/"PO-Revision-Date: YEAR-MO-DA/) { my $time = POSIX::strftime("%Y-%m-%d %H:%M%z", localtime(time())); diff --git a/bin/fetch-comments b/bin/fetch-comments index a276433e4..4eb9def14 100755 --- a/bin/fetch-comments +++ b/bin/fetch-comments @@ -8,6 +8,13 @@ use strict; use warnings; require 5.8.0; +BEGIN { + use File::Basename qw(dirname); + use File::Spec; + my $d = dirname(File::Spec->rel2abs($0)); + require "$d/../setenv.pl"; +} + use FixMyStreet::App; use CronFns; my ($verbose, $nomail) = CronFns::options(); diff --git a/bin/fetch-comments-24hs b/bin/fetch-comments-24hs index 602383d40..27853bcc1 100755 --- a/bin/fetch-comments-24hs +++ b/bin/fetch-comments-24hs @@ -7,9 +7,17 @@ use strict; use warnings; +require 5.8.0; + +BEGIN { + use File::Basename qw(dirname); + use File::Spec; + my $d = dirname(File::Spec->rel2abs($0)); + require "$d/../setenv.pl"; +} + use DateTime; use DateTime::Format::W3CDTF; -require 5.8.0; use FixMyStreet::App; use CronFns; diff --git a/bin/export-norwegian-contacts b/bin/fiksgatami/export-norwegian-contacts index 0209c6512..0209c6512 100644 --- a/bin/export-norwegian-contacts +++ b/bin/fiksgatami/export-norwegian-contacts diff --git a/bin/load-norwegian-contacts b/bin/fiksgatami/load-norwegian-contacts index b73778848..b73778848 100755 --- a/bin/load-norwegian-contacts +++ b/bin/fiksgatami/load-norwegian-contacts diff --git a/bin/canonicalise-csv b/bin/fixmystreet.com/canonicalise-csv index c0a7fc60b..c0a7fc60b 100755 --- a/bin/canonicalise-csv +++ b/bin/fixmystreet.com/canonicalise-csv diff --git a/bin/generate_council_location b/bin/fixmystreet.com/generate_council_location index c7aea8074..c7aea8074 100755 --- a/bin/generate_council_location +++ b/bin/fixmystreet.com/generate_council_location diff --git a/bin/import-categories b/bin/fixmystreet.com/import-categories index e9008b93f..e9008b93f 100755 --- a/bin/import-categories +++ b/bin/fixmystreet.com/import-categories diff --git a/bin/load-contacts b/bin/fixmystreet.com/load-contacts index b18699db1..b18699db1 100755 --- a/bin/load-contacts +++ b/bin/fixmystreet.com/load-contacts diff --git a/bin/populate_bing_cache b/bin/fixmystreet.com/populate_bing_cache index 17c8911d0..17c8911d0 100755 --- a/bin/populate_bing_cache +++ b/bin/fixmystreet.com/populate_bing_cache diff --git a/bin/rotate-photos b/bin/fixmystreet.com/rotate-photos index 7b8109d65..7b8109d65 100755 --- a/bin/rotate-photos +++ b/bin/fixmystreet.com/rotate-photos diff --git a/bin/showcouncilrates b/bin/fixmystreet.com/showcouncilrates index 1dacae597..1dacae597 100755 --- a/bin/showcouncilrates +++ b/bin/fixmystreet.com/showcouncilrates diff --git a/bin/update-areas b/bin/fixmystreet.com/update-areas index a8cc01769..a8cc01769 100755 --- a/bin/update-areas +++ b/bin/fixmystreet.com/update-areas diff --git a/bin/update-send-questionnaire b/bin/fixmystreet.com/update-send-questionnaire index 7a231b919..7a231b919 100755 --- a/bin/update-send-questionnaire +++ b/bin/fixmystreet.com/update-send-questionnaire diff --git a/bin/geocode b/bin/geocode index 254cf1578..2559f7a3c 100755 --- a/bin/geocode +++ b/bin/geocode @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/bin/env perl =head1 NAME @@ -6,8 +6,6 @@ geocode - commandline tool to test geocoders =head1 SYNOPSIS - $ eval `perl setenv.pl`, or call with bin/cron-wrapper - $ bin/geocode --geocoder=Bing --cobrand=bromley "Glebe Rd" # ... if your conf/general.yml supplies GEOCODER: @@ -24,6 +22,13 @@ use strict; use warnings; require 5.8.0; +BEGIN { + use File::Basename qw(dirname); + use File::Spec; + my $d = dirname(File::Spec->rel2abs($0)); + require "$d/../setenv.pl"; +} + use Data::Dumper; use Pod::Usage; use feature 'say'; diff --git a/bin/gettext-nget-patch b/bin/gettext-nget-patch index 5ebd8bbcb..92b687552 100755 --- a/bin/gettext-nget-patch +++ b/bin/gettext-nget-patch @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/bin/env perl # # xgettext doesn't deal with TT files, but xgettext.pl doesn't find nget()s, sigh. # This will find the nget()s and output a .po file excerpt. diff --git a/bin/handlemail b/bin/handlemail index 8bc016241..5d4ac753c 100755 --- a/bin/handlemail +++ b/bin/handlemail @@ -1,4 +1,4 @@ -#!/usr/bin/perl -w +#!/usr/bin/env perl # # handlemail: # Handle an individual incoming mail message. @@ -14,6 +14,7 @@ my $rcsid = ''; $rcsid .= '$Id: handlemail,v 1.2 2009-02-11 11:04:48 matthew Exp $'; use strict; +use warnings; require 5.8.0; # Horrible boilerplate to set up appropriate library paths. diff --git a/bin/install-as-user b/bin/install-as-user index ef97a41b3..0e1c151fb 100755 --- a/bin/install-as-user +++ b/bin/install-as-user @@ -127,15 +127,15 @@ then psql -U "$UNIX_USER" "$DB_NAME" < "$REPOSITORY"/db/alert_types.sql psql -U "$UNIX_USER" "$DB_NAME" < "$REPOSITORY"/db/generate_secret.sql else - bin/cron-wrapper update-schema --commit + bin/update-schema --commit fi echo $DONE_MSG # Generate po and mo files (these invocations taken from Kagee's script): echo "Creating locale .mo files" -bin/cron-wrapper bin/make_po FixMyStreet-EmptyHomes -bin/cron-wrapper bin/make_emptyhomes_welsh_po +bin/make_po FixMyStreet-EmptyHomes +bin/emptyhomes/make_welsh_po commonlib/bin/gettext-makemo FixMyStreet echo $DONE_MSG -bin/cron-wrapper update-all-reports +bin/update-all-reports diff --git a/bin/kasabi b/bin/kasabi deleted file mode 100755 index 456b2f4d1..000000000 --- a/bin/kasabi +++ /dev/null @@ -1,234 +0,0 @@ -#!/usr/bin/env python - -import sys -import datetime -import json -import os.path -import re -import urllib -import yaml - -import pytassium -import psycopg2 -import psycopg2.extras -from rdfchangesets import BatchChangeSet -from rdflib.namespace import XSD - -# Set up data access -config = yaml.load(open(os.path.abspath(os.path.join(os.path.dirname(__file__), '../conf/general.yml')))) -dataset = pytassium.Dataset('fixmystreet', config['KASABI_API_KEY']) -db = psycopg2.connect( "host='{host}' dbname='{name}' user='{user}' password='{password}'".format( - host=config['FMS_DB_HOST'], - name=config['FMS_DB_NAME'], - user=config['FMS_DB_USER'], - password=config['FMS_DB_PASS'] -)) -cursor = db.cursor(cursor_factory=psycopg2.extras.RealDictCursor) -report_cursor = db.cursor(cursor_factory=psycopg2.extras.RealDictCursor) - -def main(): - - # Check the status of our dataset - response, status = dataset.status() - if response.status not in range(200, 300) or status['storageMode'] == 'read-only': - # We can't import anything, so let's not bother - sys.exit() - - # Fetch reports that have changed since last update in dataset - response, data = dataset.select('select (max(?lastupdate) as ?max) where { ?report <http://data.kasabi.com/dataset/fixmystreet/def/lastUpdate> ?lastupdate }') - max_lastUpdate = data[1][0]['max'] - query = """ - SELECT id, latitude, longitude, used_map, council, - category, title, detail, (photo IS NOT NULL) as photo, - confirmed, lastupdate, whensent, state - FROM problem - WHERE state not in ('unconfirmed', 'partial') - """ - if len(sys.argv) > 1 and sys.argv[1].isdigit(): - cursor.execute("%s AND id=%%s" % query, (sys.argv[1],)) - else: - cursor.execute("%s AND lastupdate > %%s ORDER BY lastupdate" % query, (str(max_lastUpdate),)) - - for report in cursor: - changeset = FixMyStreetChangeSet(dataset) - if report['state'] == 'hidden': - # If the report has been hidden, just remove it - changeset.remove_report(report) - else: - - # Canonicalise some values - report['latitude'] = round(report['latitude'], 6) # <10cm - report['longitude'] = round(report['longitude'], 6) - report['title'] = tidy_string(report['title']) - report['detail'] = tidy_string(report['detail']) - report['confirmed'] = report['confirmed'].replace(microsecond=0).isoformat() # Don't want microseconds - report['lastupdate'] = report['lastupdate'].replace(microsecond=0).isoformat() - report['council'] = sorted(re.sub('\|.*', '', report['council'] or '').split(',')) # Remove missing councils - - # Fetch updates to note state changes - states = [ { 'state': 'confirmed', 'time': report['confirmed'] } ] - report_cursor.execute(""" - SELECT id, mark_fixed, mark_open, problem_state, confirmed - FROM comment - WHERE problem_id=%s AND state='confirmed' - ORDER BY created - """, (report['id'], )) - for update in report_cursor: - t = update['confirmed'].replace(microsecond=0).isoformat() - if update['problem_state']: - states.append( { 'state': update['problem_state'], 'time': t } ) - elif update['mark_fixed']: - states.append( { 'state': 'fixed - user', 'time': t } ) - elif update['mark_open']: - states.append( { 'state': 'confirmed', 'time': t } ) - - # Remove and then re-add the report - changeset.remove_report(report) - changeset.add_report(report, states) - changeset.apply() - -# Escape double quotes and backslashes, remove carriage returns -def tidy_string(s): - return s.replace('\r', '').replace('\\', '\\\\').replace('"', r'\"') - -class FixMyStreetChangeSet(object): - """Something that hosts either or both of a BatchChangeSet and a Turtle - string for sending to Kasabi. Changes are done by removing all triples - and then readding the report.""" - _changeset = None - data = '' - - def __init__(self, dataset): - self.dataset = dataset - - def __str__(self): - return unicode(self).encode('utf-8') - - def __unicode__(self): - g = self.changeset.getGraph() - data = g.serialize(format='xml') - return "Changeset:\n" + data + "\nNew data:\n" + self.data - - @property - def changeset(self): - if not self._changeset: - self._changeset = BatchChangeSet() - self._changeset.setChangeReason("Report updates") - self._changeset.setCreatorName("FixMyStreet") - return self._changeset - - def apply(self): - if len(self.changeset.changesets): - #response, data = self.dataset.apply_changeset(self.changeset) - # XXX Do everything the above call does, but additionally escape carriage returns to prevent 409 error - api = self.dataset.get_api('update') - g = self.changeset.getGraph() - data = g.serialize(format='xml') - data = data.replace('\r', ' ') - response, data = api.client.request(api.uri, "POST", body=data, headers={"accept" : "*/*", 'content-type':'application/vnd.talis.changeset+xml', 'X_KASABI_APIKEY':api.apikey}) - if response.status not in range(200, 300): - print 'Error:', response.status, response.reason, data - if self.data: - response, data = self.dataset.store_data(self.data, media_type='text/turtle') - if response.status not in range(200, 300): - print 'Error:', response.status, response.reason, data - - def remove_report(self, report): - uri = 'http://data.kasabi.com/dataset/fixmystreet/report/{id}'.format(**report) - response, data = self.dataset.select('select ?p ?o where {{ <{0}> ?p ?o }}'.format(uri)) - for row in data[1]: - # Need to set the datatype correctly for the lastUpdate - if str(row['p']) == 'http://data.kasabi.com/dataset/fixmystreet/def/lastUpdate': - row['o'].datatype = XSD.dateTime - # Delete the referenced statuses - if re.match('http://data.kasabi.com/dataset/fixmystreet/report/\d+/status/\d+$', unicode(row['o'])): - uri2 = unicode(row['o']) - response2, data2 = self.dataset.select('select ?p ?o where {{ <{0}> ?p ?o }}'.format(uri2)) - for row2 in data2[1]: - self.changeset.remove(uri2, row2['p'], row2['o']) - self.changeset.remove(uri, row['p'], row['o']) - - def add_report(self, report, states): - # Work out the update states - c = 0 - state_data = { 'refs': '', 'objs': '' } - for state in states: - state_data['refs'] += ' ; fixmystreet:status <http://data.kasabi.com/dataset/fixmystreet/report/{id}/status/{c}>\n'.format(id=report['id'], c=c) - obj = re.sub('[ -]', '', ' '.join(x.capitalize() for x in state['state'].split())) - if obj == 'Confirmed': obj = 'Open' - state_data['objs'] += """<http://data.kasabi.com/dataset/fixmystreet/report/{id}/status/{c}> a fixmystreet:{state}Status - ; event:time <http://reference.data.gov.uk/id/gregorian-instant/{time}> - . -""".format( id=report['id'], c=c, state=obj, time=state['time'] ) - # ; rdfs:label - c += 1 - - # Get info for the councils - council_data = { 'sentTo': '', 'areaNames': [] } - for council in report['council']: - if not council: continue - js = json.load(urllib.urlopen('http://mapit.mysociety.org/area/{0}'.format(council))) - os_id = int(js['codes']['unit_id']) + 7000000000000000 - if report['whensent']: - council_data['sentTo'] += ' ; fixmystreet:sentTo <http://data.ordnancesurvey.co.uk/id/{os_id}>\n'.format(os_id=os_id) - council_data['areaNames'].append(js['name']) - council_data.setdefault('firstCouncil', council) - council_data['areaNames'] = ' / '.join(council_data['areaNames']) - council_data.setdefault('firstCouncil', '0') - -# easting/northing - - self.data += ''' -@prefix fixmystreet: <http://data.kasabi.com/dataset/fixmystreet/def/> . -@prefix dct: <http://purl.org/dc/terms/> . -@prefix event: <http://purl.org/NET/c4dm/event.owl#> . -@prefix geo: <http://www.w3.org/2003/01/geo/wgs84_pos#> . -@prefix xsd: <http://www.w3.org/2001/XMLSchema#> . -@prefix skos: <http://www.w3.org/2004/02/skos/core#> . -@prefix foaf: <http://xmlns.com/foaf/0.1/> . -@prefix georss: <http://www.georss.org/georss/> . -@prefix owl: <http://www.w3.org/2002/07/owl#> . - -<http://data.kasabi.com/dataset/fixmystreet/report/{id}> a fixmystreet:Report - ; fixmystreet:location <http://data.kasabi.com/dataset/fixmystreet/location/geo/point/{latitude}/{longitude}> - ; dct:description """{detail}""" - ; dct:title "{title}" -{photo_url} -{state_data[refs]} -{council_data[sentTo]} - ; fixmystreet:category <http://data.kasabi.com/dataset/fixmystreet/category/{council_data[firstCouncil]}/{category_uri}> - ; fixmystreet:lastUpdate "{lastupdate}"^^xsd:dateTime - ; foaf:page <http://www.fixmystreet.com/report/{id}> - . - -<http://data.kasabi.com/dataset/fixmystreet/location/geo/point/{latitude}/{longitude}> a fixmystreet:Location - ; geo:lat "{latitude}" - ; geo:long "{longitude}" - ; georss:point "{latitude} {longitude}" - . - -<http://data.kasabi.com/dataset/fixmystreet/location/geo/point/{latitude}/{longitude}> - owl:sameAs <http://rdfize.com/geo/point/{latitude}/{longitude}> - . -{state_data[objs]} -<http://data.kasabi.com/dataset/fixmystreet/category/{council_data[firstCouncil]}/{category_uri}> a skos:Concept - ; skos:prefLabel "{category}" - ; skos:altLabel "{category} in {council_data[areaNames]}" - . - '''.format( - photo_url = ' ; foaf:depiction <http://www.fixmystreet.com/photo/{id}.jpeg>'.format(**report) if report['photo'] else '', - state_data = state_data, - council_data = council_data, - category_uri = report['category'].lower().replace(' ', '-'), - **report - ) - -# ; skos:broader <http://data.kasabi.com/dataset/fixmystreet/category/street-lights> - -# this category is the broadest highlevel street light category -#<http://data.kasabi.com/dataset/fixmystreet/category/street-lights> a skos:Concept -# ; skos:prefLabel "Street lights" -# . - -main() - diff --git a/bin/make_css b/bin/make_css index a8afafb27..3a1fca1a7 100755 --- a/bin/make_css +++ b/bin/make_css @@ -11,13 +11,14 @@ COMPASS=compass SASS=sass -PARENT=$(cd `dirname $0`/../.. && pwd) +DIR=$(cd "$(dirname "$0")" && pwd -P) +PARENT=$(cd "$DIR"/../.. && pwd) if [ -f "$PARENT/gem-bin/compass" ]; then COMPASS=$PARENT/gem-bin/compass SASS=$PARENT/gem-bin/sass fi -DIRECTORY=$(cd `dirname $0`/../web && pwd) +DIRECTORY=$(cd "$DIR"/../web && pwd) DIRS=${@:-`find $DIRECTORY -name "*.scss" -exec dirname {} \; | uniq`} diff --git a/bin/make_css_watch b/bin/make_css_watch index 63a27a35e..2ae287429 100755 --- a/bin/make_css_watch +++ b/bin/make_css_watch @@ -1,7 +1,16 @@ #!/usr/bin/env perl + use strict; use warnings; use feature 'say'; + +BEGIN { + use File::Basename qw(dirname); + use File::Spec; + my $d = dirname(File::Spec->rel2abs($0)); + require "$d/../setenv.pl"; +} + use Cwd qw(abs_path); use File::ChangeNotify; use File::Find::Rule; diff --git a/bin/make_po b/bin/make_po index ad1fc1a89..a5b145ecb 100755 --- a/bin/make_po +++ b/bin/make_po @@ -1,5 +1,7 @@ -#!/usr/bin/perl -w +#!/usr/bin/env perl + use strict; +use warnings; # Generates a version of .po file, which is a translation # into a language the same as English, with replacement as specified in PoChange diff --git a/bin/open311-populate-service-list b/bin/open311-populate-service-list index be1ace3b9..11f9005a5 100755 --- a/bin/open311-populate-service-list +++ b/bin/open311-populate-service-list @@ -2,6 +2,14 @@ use strict; use warnings; + +BEGIN { + use File::Basename qw(dirname); + use File::Spec; + my $d = dirname(File::Spec->rel2abs($0)); + require "$d/../setenv.pl"; +} + use FixMyStreet::App; use Open311::PopulateServiceList; use Getopt::Long::Descriptive; diff --git a/bin/open311-update-reports b/bin/open311-update-reports index 3b77fef89..6a1c894d7 100755 --- a/bin/open311-update-reports +++ b/bin/open311-update-reports @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/bin/env perl # # This script utilises the standard Open311 way of getting updates on reports # (by fetching all reports for a body and looking for updates). If possible, @@ -8,6 +8,14 @@ use strict; use warnings; + +BEGIN { + use File::Basename qw(dirname); + use File::Spec; + my $d = dirname(File::Spec->rel2abs($0)); + require "$d/../setenv.pl"; +} + use Open311::GetUpdates; use FixMyStreet::App; diff --git a/bin/problem-creation-graph b/bin/problem-creation-graph index e1b6f2cc4..c3d10f934 100755 --- a/bin/problem-creation-graph +++ b/bin/problem-creation-graph @@ -10,13 +10,18 @@ use strict; use warnings; require 5.8.0; -use FindBin; +BEGIN { + use File::Basename qw(dirname); + use File::Spec; + my $d = dirname(File::Spec->rel2abs($0)); + chdir "$d/.."; + require "$d/../setenv.pl"; +} + use File::Temp qw(tempfile); use FixMyStreet::App; -chdir("$FindBin::Bin/../"); - my %config = ( gplot_output => "set terminal png font 'Vera.ttf' 9 size 1200,400", extension => '.png', diff --git a/bin/problems-filed-graph b/bin/problems-filed-graph index d3e132f8e..abfe0cf1a 100755 --- a/bin/problems-filed-graph +++ b/bin/problems-filed-graph @@ -10,13 +10,18 @@ use strict; use warnings; require 5.8.0; -use FindBin; +BEGIN { + use File::Basename qw(dirname); + use File::Spec; + my $d = dirname(File::Spec->rel2abs($0)); + chdir "$d/.."; + require "$d/../setenv.pl"; +} + use File::Temp qw(tempfile); use FixMyStreet::App; -chdir("$FindBin::Bin/../"); - my %config = ( gplot_output => "set terminal png font 'Vera.ttf' 9 size 1200,600", extension => '.png', diff --git a/bin/run-tests b/bin/run-tests new file mode 100755 index 000000000..612a13628 --- /dev/null +++ b/bin/run-tests @@ -0,0 +1,37 @@ +#!/usr/bin/env perl +use strict; use warnings; + +BEGIN { + use File::Basename qw(dirname); + use File::Spec; + my $d = dirname(File::Spec->rel2abs($0)); + require "$d/../setenv.pl"; +} + +use FixMyStreet::TestAppProve; + +=head1 NAME + +bin/run-tests - spin up a clean database and configuration for tests + +=head1 USAGE + + bin/run-tests t/ # runs prove -r t/ (recursively, saving state) + bin/run-tests --state=failed # runs just failing tests + # delete .prove to reset + + bin/run-tests t/foo.t # runs with prove -v (single test) + +By default we use conf/general.yml-example as the template, and spin up a fresh +Postgres cluster and database. We can override this by doing: + + bin/run-tests --config=general.mycobrand.yml + bin/run-tests --db-config=general.yml # e.g. use your current DB settings + bin/run-tests --all-config=general.yml # e.g. use your current DB settings + +(NB: passing --state=save automagically is experimental, and will be removed if +it turns out to be annoying.) + +=cut + +FixMyStreet::TestAppProve->run(@ARGV); diff --git a/bin/send-alerts b/bin/send-alerts index 00c5426bc..94f7d5509 100755 --- a/bin/send-alerts +++ b/bin/send-alerts @@ -10,6 +10,13 @@ use strict; use warnings; require 5.8.0; +BEGIN { + use File::Basename qw(dirname); + use File::Spec; + my $d = dirname(File::Spec->rel2abs($0)); + require "$d/../setenv.pl"; +} + use CGI; # XXX use CronFns; diff --git a/bin/send-comments b/bin/send-comments index 2192f674c..2d6b525b5 100755 --- a/bin/send-comments +++ b/bin/send-comments @@ -13,6 +13,13 @@ use strict; use warnings; require 5.8.0; +BEGIN { + use File::Basename qw(dirname); + use File::Spec; + my $d = dirname(File::Spec->rel2abs($0)); + require "$d/../setenv.pl"; +} + use Digest::MD5; use Encode; use CronFns; diff --git a/bin/send-questionnaires b/bin/send-questionnaires index 7ed3c87c2..93d58ed77 100755 --- a/bin/send-questionnaires +++ b/bin/send-questionnaires @@ -10,6 +10,13 @@ use strict; use warnings; require 5.8.0; +BEGIN { + use File::Basename qw(dirname); + use File::Spec; + my $d = dirname(File::Spec->rel2abs($0)); + require "$d/../setenv.pl"; +} + use CGI; # XXX Awkward kludge use Encode; use CronFns; diff --git a/bin/send-reports b/bin/send-reports index 16296dc5b..3c6f26cdb 100755 --- a/bin/send-reports +++ b/bin/send-reports @@ -10,6 +10,13 @@ use strict; use warnings; require 5.8.0; +BEGIN { + use File::Basename qw(dirname); + use File::Spec; + my $d = dirname(File::Spec->rel2abs($0)); + require "$d/../setenv.pl"; +} + use CGI; # XXX use CronFns; diff --git a/bin/site-specific-install.sh b/bin/site-specific-install.sh index 3d01be469..de75d45ae 100644 --- a/bin/site-specific-install.sh +++ b/bin/site-specific-install.sh @@ -66,4 +66,4 @@ fi echo Installation complete - you should now be able to view the site at: echo http://$HOST/ echo Or you can run the tests by switching to the "'$UNIX_USER'" user and -echo running: $REPOSITORY/bin/cron-wrapper prove -r t +echo running: $REPOSITORY/bin/run-tests t diff --git a/bin/test-wrapper b/bin/test-wrapper deleted file mode 100755 index 9cb1791a1..000000000 --- a/bin/test-wrapper +++ /dev/null @@ -1,35 +0,0 @@ -#!/usr/bin/env perl -use strict; use warnings; - -BEGIN { - use FindBin; - require "$FindBin::Bin/../setenv.pl"; -} - -use FixMyStreet::TestAppProve; - -=head1 NAME - -bin/test-wrapper - spin up a clean database and configuration for tests - -=head1 USAGE - - bin/test-wrapper t/ # runs prove -r t/ (recursively, saving state) - bin/test-wrapper --state=failed # runs just failing tests - # delete .prove to reset - - bin/test-wrapper t/foo.t # runs with prove -v (single test) - -By default we use conf/general.yml-example as the template, and spin up a fresh -Postgres cluster and database. We can override this by doing: - - bin/test-wrapper --config=general.mycobrand.yml - bin/test-wrapper --db-config=general.yml # e.g. use your current DB settings - bin/test-wrapper --all-config=general.yml # e.g. use your current DB settings - -(NB: passing --state=save automagically is experimental, and will be removed if -it turns out to be annoying.) - -=cut - -FixMyStreet::TestAppProve->run(@ARGV); diff --git a/bin/update-all-reports b/bin/update-all-reports index f4d6113cb..f6cd34210 100755 --- a/bin/update-all-reports +++ b/bin/update-all-reports @@ -10,6 +10,13 @@ use strict; use warnings; require 5.8.0; +BEGIN { + use File::Basename qw(dirname); + use File::Spec; + my $d = dirname(File::Spec->rel2abs($0)); + require "$d/../setenv.pl"; +} + use FixMyStreet::App; use File::Path (); use File::Slurp; diff --git a/bin/update-schema b/bin/update-schema index 30fc1396b..ce193f29c 100755 --- a/bin/update-schema +++ b/bin/update-schema @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/bin/env perl =head1 NAME @@ -31,9 +31,13 @@ backup of your database before running. use strict; use warnings; -# Horrible boilerplate to set up appropriate library paths. -use FindBin; -use lib "$FindBin::Bin/../commonlib/perllib"; +my $bin_dir; +BEGIN { + use File::Basename qw(dirname); + use File::Spec; + $bin_dir = dirname(File::Spec->rel2abs($0)); + require "$bin_dir/../setenv.pl"; +} use mySociety::Config; use mySociety::DBHandle qw(dbh); @@ -41,7 +45,7 @@ use mySociety::MaPit; use Getopt::Long; use Pod::Usage; -mySociety::Config::set_file("$FindBin::Bin/../conf/general"); +mySociety::Config::set_file("$bin_dir/../conf/general"); my %args = ( Name => mySociety::Config::get('FMS_DB_NAME'), User => mySociety::Config::get('FMS_DB_USER'), @@ -115,7 +119,7 @@ if ($upgrade) { if ($version) { die "Not currently implemented"; } - for my $path (glob("$FindBin::Bin/../db/schema_*")) { + for my $path (glob("$bin_dir/../db/schema_*")) { my ($name) = $path =~ /schema_(.*)\.sql$/; next if $name le $current_version; next if $name =~ /$current_version-/; # For number only match @@ -146,7 +150,7 @@ if ($upgrade) { if ($downgrade) { my %downgrades; - for my $path (glob("$FindBin::Bin/../db/downgrade_*")) { + for my $path (glob("$bin_dir/../db/downgrade_*")) { my ($from, $to) = $path =~ /downgrade_(.*)---(.*)\.sql$/; next unless $from eq $current_version; $downgrades{$to} = $path; diff --git a/bin/zerotb_import_clinic_list.pl b/bin/zerotb/import_clinic_list.pl index 359a63925..359a63925 100755 --- a/bin/zerotb_import_clinic_list.pl +++ b/bin/zerotb/import_clinic_list.pl diff --git a/bin/zurich/geocode b/bin/zurich/geocode deleted file mode 100755 index 9482b27e6..000000000 --- a/bin/zurich/geocode +++ /dev/null @@ -1,45 +0,0 @@ -#!/usr/bin/perl - -=head1 NAME - -zurich/geocode - commandline tool to test the Zurich geocoder - -=head1 SYNOPSIS - - # Firstly: - ## copy the GEOCODER config from a current Zurich conf to your conf/general.yml - $ eval `perl setenv.pl` - - $ bin/zurich/geocode Magnus - - # ... output from geocoder - -This can be used to test the results of, e.g. - - https://www.zueriwieneu.ch/ajax/geocode?term=Magnus - -but without the caching which FixMyStreet applies, and passing on any 500 -errors from the server. - -=cut - -use strict; -use warnings; -require 5.8.0; - - -use Data::Dumper; -use feature 'say'; - -use FixMyStreet; -use FixMyStreet::App; -use FixMyStreet::Geocode::Zurich; - -# TODO use FixMyStreet::override_config to get data from conf/general.yml.zurich if available -my $geocoder = FixMyStreet->config('GEOCODER') - or die "No GEOCODER config -- please copy appropriate Zurich conf to conf/general.yml"; - -my $c = FixMyStreet::App->new(); -my $s = join ' ', @ARGV; - -say Dumper( FixMyStreet::Geocode::Zurich::string( $s, $c ) ); diff --git a/bin/zurich-overdue-alert b/bin/zurich/overdue-alert index c09aef1e2..4a8fea830 100755 --- a/bin/zurich-overdue-alert +++ b/bin/zurich/overdue-alert @@ -1,6 +1,6 @@ #!/usr/bin/env perl -# zurich-overdue-alert: +# zurich/overdue-alert: # Send email alerts to administrators for overdue admin activities. # # Copyright (c) 2012 UK Citizens Online Democracy. All rights reserved. @@ -10,6 +10,13 @@ use strict; use warnings; require 5.8.0; +BEGIN { + use File::Basename qw(dirname); + use File::Spec; + my $d = dirname(File::Spec->rel2abs($0)); + require "$d/../setenv.pl"; +} + use DateTime; use CronFns; use FixMyStreet::App; |