Beispiel #1
0
    def submitJob(self, xmlFile):
        """ Submits the job specified by file xmlFile to the queue
        and returns the job number.
        """
        print "submitJob"
        connection = psycopg.connect("dbname=%s" % self.dbname, "user=%s" % self.uname)
        mark = connection.cursor()

        sqlstr = "select max(jobNo) from queue;"
        mark.execute(sqlstr)
        records = mark.fetchall()
        lastJobNo = records[0][0]
        if lastJobNo == None:
            lastJobNo = 0
        jobNo = lastJobNo + 1

        # Read the XML file contents to extract the title etc.
        pr = prefs()
        pr.loadPrefs(xmlFile)
        pl = pr.getPrefs()
        origin = pl["origin"]
        (latStr, lonStr) = origin.split(",")
        originLat = float(latStr)
        originLon = float(lonStr)
        title = pl["title"]
        now = datetime.now()

        # Read the XML file into a string to store it in the database
        if not os.path.exists(xmlFile):
            print "Error - File %s does not exist." % xmlFile
            return
        ip = open(xmlFile, "r")
        lines = ip.readlines()
        xmlStr = ""
        for line in lines:
            xmlStr = "%s%s" % (xmlStr, line)
        ip.close

        # Now substitute 'dangerous' characters that will mess up postgreSQL
        substitutions = {"'": "\\'", "\\": "\\"}
        xmlStrSafe = ""
        for n in range(len(xmlStr)):
            ch = xmlStr[n]
            subs = substitutions.get(ch)
            # print "ch=%s, subs=%s" % (ch,subs)
            if subs == None:
                subs = ch
            xmlStrSafe = "%s%s" % (xmlStrSafe, subs)

        # And finally add a new record to the database to be picked up
        # by the queue daemon.
        sqlstr = (
            "insert into queue (status, title, originlat, originlon,"
            "subdate, statusdate, xml) values "
            "( %d, '%s', %f, %f, timestamp'%s', timestamp'%s', '%s');"
            % (self.NOT_STARTED, title, originLat, originLon, now, now, xmlStrSafe)
        )
        mark.execute(sqlstr)
        connection.commit()
Beispiel #2
0
        verbose = False)
    (options,args)=parser.parse_args()
    
    if (options.debug):
        options.verbose = True
        print "options   = %s" % options
        print "arguments = %s" % args


    # print
    # print "Townguide Version %s" % version
    # print
    
    if len(args)==0:
        print "No configuration file specified - using a simple default configuration as an example."
        preferences_list = {'title':'townguide default output',
              'origin':'54.6466,-1.2619',
              'mapsize':'10,12',
              'tilesize':'1000',
              'features':'amenity=school,amenity=pub'}
    else:
        print "Using configuration file %s." % args[0]
        preferences = prefs()
        preferences_list = preferences.loadPrefs(args[0])

    # tg = townguide(54.6466,-1.2619,1000,10,12)
    # townguide_map = townguide(preferences)
    # townguide(preferences)
    townguide(preferences)
    
Beispiel #3
0
    def renderJob(self, jobNo):
        """Execute the specified job number using the townguide renderer.
        """
        print "renderJob(%d)" % jobNo
        self.setJobStatus(jobNo, self.RUNNING)
        connection = psycopg.connect("dbname=%s" % self.dbname, "user=%s" % self.uname)
        mark = connection.cursor()

        sqlstr = "select jobno, renderer,xml from queue where jobno=%d;" % jobNo

        mark.execute(sqlstr)
        recordArr = mark.fetchone()
        renderer = recordArr[1]
        print "Renderer=%d" % renderer
        xmlStr = recordArr[2]
        print "xmlStr = %s" % xmlStr

        jobDir = "%s/%d" % (self.wkdir, jobNo)
        if not os.path.exists(jobDir):
            try:
                os.makedirs(jobDir)
            except:
                print "***********************************************"
                print "odd - got an error making the output directory"
                print "trying to carry on regardless!!!"
                print "***********************************************"

        xmlFile = "%s/townguide.xml" % (jobDir)
        try:
            op = open(xmlFile, "w")
            op.write(xmlStr)
            op.close()
            pr = prefs()
            pr.loadPrefs(xmlFile)
            pl = pr.getPrefs()

            pl["datadir"] = self.datadir
            pl["outdir"] = jobDir
            pl["mapfile"] = self.mapFileName

            print "mapFileName=%s." % self.mapFileName

            #            try:
            # jobLog = open("%s/townguide.log" % (jobDir))
            # queueLog = sys.stdout

            # sys.stdout = jobLog
            # sys.stderr = jobLog

            # if renderer==1:
            #    tg = townguide.townguide(pr)
            # else:
            #    tg = townguide2.townguide(pr)
            tg = townguide.townguide(pr)
            self.setJobStatus(jobNo, self.COMPLETE)
            sys.stdout.flush()
            # sys.stdout = queueLog
            # sys.stderr = queueLog
            # except:
            #    print "Oh No - error opening log file, or townguide failed"
            #    self.setJobStatus(jobNo,self.ERROR)
        except Exception, e:
            print "Oh No - Error processing job number %d" % jobNo
            print "Unexpected error:", sys.exc_info()[0]
            print "%s" % (dir(e))
            print sys.exc_info()
            self.setJobStatus(jobNo, self.ERROR)
Beispiel #4
0
        verbose=False)
    (options,args)=parser.parse_args()
    
    if (options.debug):
        options.verbose = True
        print "options   = %s" % options
        print "arguments = %s" % args


    print
    print "Townguide Version %s" % version
    print
    
    if len(args)==0:
        print "No configuration file specified - using a simple default\
configuration as an example."
        pl = {'title':'townguide default output',
              'origin':'54.6466,-1.2619',
              'mapsize':'10,12',
              'tilesize':'1000',
              'features':'amenity=school,amenity=pub'}
    else:
        print "Using configuration file %s." % args[0]
        pr = prefs()
        pl = pr.loadPrefs(args[0])


    #tg = townguide(54.6466,-1.2619,1000,10,12)
    tg = townguide(pr)