#! /usr/bin/env python # -*- coding: UTF-8 -*- """The URL repository module """ # Copyright 2005, 2006 EIAO Consoritum # This program is distributed under the terms of the GNU General # Public License. # # This file is part of the European Internet Accessibility Observatory # (EIAO) # # EIAO is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # EIAO is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with EIAO; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, # MA 02110-1301 USA __owner__ = "Terje Gjosater" __maintainer__ = "Terje Gjosater" __version__ = 0.1 import SOAPpy import sys import urllib import urlparse import sc import random sco = sc.SystemConfiguration() class eiaoassess: """Site URL server command line tool """ def __init__(self): """initialise the class """ self.server = SOAPpy.SOAPProxy(urllib.unquote(sco.siteurlserver)) def usage(): print """Usage: eiaoassess [-h ETLserver] [-p port] [-d] [-r testrun] <-f urllist | -t table | -u URL> Arguments: -h ETLserver Host name of the ETL server that loads this test run. (Default is localhost). -p port Port number of ETL server that loads this test run. (Default is 8890). -d Delete the test run indicated by testrunID. This implies stopping the given crawl by removing all URLs that have been loaded for assessment. If no test run id is given, then the system will prompt if all ongoing test runs should be stopped, and will remove all on confirmation. -r testrun Specify testrun ID to use. (Default is EIAOXXX where XXX is the next test run ID in the URL repository, which is printed on stdout) -f urllist Perform accessibility assessments on URLs from the file urllist. -e table Add URLs to the existing testrun from table or view in the URLRespossitory -t table Perform accessibility assessments on URLs from the table or view table in the URLrepository. -u URL Perform accessibility assessment on the site identified by URL. -i directory Import new URLs (and detetes old) from the URL repository. Directory mush contain one or more .csv-files. These files must end with .csv. """ def checkTestRun(): if not ea.server.finished(): print "WARNING: Site URL server is working on testrun ",ea.server.testrunId() answer="" while 1: print "Do you want to continue (Yes/No)?" answer=raw_input() if "yes" in answer.lower(): break if "no" in answer.lower(): sys.exit(0) else: print "Please answer Yes or No." if __name__ == "__main__": ea=eiaoassess() if len(sys.argv)<=1: usage() sys.exit() etlService = urlparse.urlparse(urllib.unquote(sco.etlserver))[1] try: if ('-h' in sys.argv) or ('--help' in sys.argv) or ('--h' in sys.argv): ea.etlserver = sys.argv[sys.argv.index('-h')+1] else: ea.etlserver=etlService if ':' in ea.etlserver: ea.etlserver = ea.etlserver[:ea.etlserver.find(':')] if '-p' in sys.argv: ea.etlport = sys.argv[sys.argv.index('-p')+1] else: ea.etlport = etlService[etlService.find(':')+1:] print ea.etlserver,ea.etlport #constructing etlserver-string etlserver="http://"+ea.etlserver+":"+ea.etlport+"/" if '-d' in sys.argv: #print sys.argv.index('-d')+1 #print len(sys.argv)-1 if sys.argv.index('-d')+1 <= len(sys.argv)-1: ea.deletetestrun = sys.argv[sys.argv.index('-d')+1] print "Deleting testrun: ", ea.deletetestrun ea.server.removeTestRun(ea.deletetestrun) else: #ask for confirmation and delete all confirmation=raw_input("Remove all scheduled testruns? (y/n) ").lower() if confirmation in ("y","yes"): #remove all ea.server.removeTestRun() print "Removed all testruns" else: print "Cancelled removal of all testruns" if '-r' in sys.argv: ea.testrun = sys.argv[sys.argv.index('-r')+1] else: #come up with a testrunID ea.testrun = None print "Testrun:", ea.testrun #do stuff here if '-f' in sys.argv: # Check if an existing test run runs checkTestRun() ea.urlfile = sys.argv[sys.argv.index('-f')+1] fil=open(ea.urlfile,"r") while 1: data=fil.readlines(100) if data==[]: break reply = ea.server.addURLs(ea.testrun, etlserver, data) if not reply: print "Failed to add URLs to testrun." print ea.server.error() break if reply: print "Testrun successfully added." else: print "Failed to add URLs to testrun." elif'-t' in sys.argv: # Check if an existing test run runs checkTestRun() ea.urltable = sys.argv[sys.argv.index('-t')+1] reply = ea.server.addURLsFromTable(ea.testrun, etlserver, ea.urltable) if reply: print "Testrun successfully added." else: print "Failed to add URLs to testrun." print ea.server.error() elif '-e' in sys.argv: ea.urltable = sys.argv[sys.argv.index('-e')+1] reply = ea.server.addURLsToExistingTestrun(ea.testrun,etlserver,ea.urltable) elif'-u' in sys.argv: # Check if an existing test run runs checkTestRun() ea.url = sys.argv[sys.argv.index('-u')+1] print ea.url reply = ea.server.addURLs(ea.testrun, etlserver, ea.url) if reply: print "Testrun successfully added." else: print "Failed to add URLs to testrun." print ea.server.error() elif '-i' in sys.argv: if raw_input('This will the delete all content of the URL repository and instert the basic URLs. Are you sure you want to do that (y/n). No as default.').lower() in ('y','yes'): directory = sys.argv[sys.argv.index('-i') + 1] import os files = [directory+l for l in os.listdir(directory) if l.endswith('.csv')] random.shuffle(files) if not files: print 'No csv-files found in directory:',directory,'.Please make sure this directory includes at least one csv-file.' else: import urlrep ur=urlrep.URLRepUtils3(sco,deletemodel=True) for f in files: print 'Adding sites from file',f ur.addInitialURLs(f) else: pass except IndexError: usage() sys.exit()