def addProcess(self, job, projectdir, zoomLevels, metatile, extent):
		pprint.pprint("-----------")
		path = os.path.realpath(__file__)
			
		# Create mapcache folder if not exist
		if not os.path.exists(projectdir+"/mapcache"):
			os.makedirs(projectdir+"/mapcache")
		
		#If there is a gitignore file, add the mapcache directory
		if os.path.exists(projectdir+"/.gitignore"):
			with open(projectdir+"/.gitignore", "r+") as gitignore:
				lines = gitignore.readlines()
				found = False
				for line in lines:
					if "mapcache" in line:
						found = True
				if not found:	
					gitignore.writelines("mapcache/*")

		jobdir = projectdir+"/mapcache/job-"+job['title']+str(job['id'])
		os.makedirs(jobdir)
		
		inFile = open(path.replace("processManager.py","mapcacheConfig.xml.default"))
		outFile = open(projectdir+"/mapcacheConfig.xml","w")
		replacements = {'<!--SCRIBEUIPATH-->':jobdir, '<!--SCRIBEUITITLE-->':"job-"+job['title']+str(job['id']), '<!--SCRIBEUIMAPFILEPATH-->':projectdir+'/map/'+job['map_name']+'.map'}

		for line in inFile:
			for src, target in replacements.iteritems():
				line = line.replace(src, target)
			outFile.write(line)
		inFile.close()
		outFile.close()
		#start mapcache
		pprint.pprint("Adding new process")
		p = Popen(["mapcache_seed", "-c", projectdir+"/mapcacheConfig.xml", "-t", "default", "-z", zoomLevels, "-M", metatile, "-e",extent], shell=False)
		p.jobid = job['id']
		
		# Lock the processes list before adding data
		self.lock.acquire()
		self.processes.append(p)

		#If thread is finished, start it up
		if self.thread is None or not self.thread.isAlive():
			self.thread = None
			self.thread = self.pollProcesses(self)
			self.thread.start()
		self.lock.release()
		return
    def addProcess(self, job, projectdir, mapfile, zoomLevels, metatile, grid, 
            extent=None, dbconfig=None, jobdir=None, mapserver_url='http://localhost/cgi-bin/mapserv'):
        projectdir = projectdir.rstrip('/')

        pprint.pprint("-----------")
        path = os.path.dirname(os.path.abspath(__file__))

        # Create mapcache folder if not exist
        if not os.path.exists(projectdir+"/mapcache"):
            os.makedirs(projectdir+"/mapcache")
        
        #If there is a gitignore file, add the mapcache directory
        if os.path.exists(projectdir+"/.gitignore"):
            with open(projectdir+"/.gitignore", "r+") as gitignore:
                lines = gitignore.readlines()
                found = False
                for line in lines:
                    if "mapcache" in line:
                        found = True
                if not found:   
                    gitignore.writelines("mapcache/*")

        if not jobdir:
            jobdir = projectdir+"/mapcache/job-"+job.title+str(job.id)
        else:
            jobdir = jobdir.rstrip('/') + '/' + job.title+str(job.id)
        if not os.path.exists(jobdir):
            os.makedirs(jobdir)

        inFile = open(path + "/mapcacheConfig.xml.default")
        outFile = open(jobdir+"/mapcacheConfig.xml","w")
        replacements = {
            '<!--SCRIBEUIPATH-->':jobdir, 
            '<!--SCRIBEUITITLE-->':"job-"+job.title+str(job.id), 
            '<!--SCRIBEUIMAPFILEPATH-->':mapfile,
            '<!--SCRIBEUIMAPSERVER-->':mapserver_url
        }

        for line in inFile:
            for src, target in replacements.iteritems():
                line = line.replace(src, target)
            outFile.write(line)
        inFile.close()
        outFile.close()

        pprint.pprint("Adding new process")
        if extent:
            if extent[0] == '/' and extent[-4:] == '.shp' and os.path.isfile(extent):
                p = Popen(["mapcache_seed", "-c", jobdir+"/mapcacheConfig.xml", "-t", "default", "-z", zoomLevels, "-M", metatile, "-g", grid, "-d", extent], shell=False)
                p.jobid = job.id
            else:
                p = Popen(["mapcache_seed", "-c", jobdir+"/mapcacheConfig.xml", "-t", "default", "-z", zoomLevels, "-M", metatile, "-g", grid, "-e", extent], shell=False)
                p.jobid = job.id

        elif dbconfig:
           #TODO: ADD SUPPORT FOR OTHER DATABASE TYPE
           #ALSO, THIS CODE COULD PROBABLY BE PLACED IN A FUNCTION SOMEWHERE ELSE 
           if dbconfig['type'].lower() == 'postgis':
                connection_string = 'PG:dbname=' + dbconfig['name'] + ' host=' + dbconfig['host'] + ' port=' + dbconfig['port'] + ' user='******'user'];
                if dbconfig['password']:
                    connection_string += ' password='******'password'] 
                else:
                    connection_string = ''

                query_string = dbconfig['query'].rstrip(';')

           #start mapcache
           p = Popen(["mapcache_seed", "-c", jobdir+"/mapcacheConfig.xml", "-t", "default", "-z", zoomLevels, "-M", metatile, "-g", grid, "-d", connection_string, '-s', query_string], shell=False)

           p.jobid = job.id
   
        # Lock the processes list before adding data
        self.lock.acquire()
        self.processes.append(p)

        #If thread is finished, start it up
        if self.thread is None or not self.thread.isAlive():
            self.thread = None
            self.thread = self.pollProcesses(self)
            self.thread.start()
        self.lock.release()
        return
Exemple #3
0
    def addProcess(self,
                   job,
                   projectdir,
                   mapfile,
                   zoomLevels,
                   metatile,
                   grid,
                   extent=None,
                   dbconfig=None,
                   jobdir=None,
                   mapserver_url='http://localhost/cgi-bin/mapserv'):
        projectdir = projectdir.rstrip('/')

        pprint.pprint("-----------")
        path = os.path.dirname(os.path.abspath(__file__))

        # Create mapcache folder if not exist
        if not os.path.exists(projectdir + "/mapcache"):
            os.makedirs(projectdir + "/mapcache")

        #If there is a gitignore file, add the mapcache directory
        if os.path.exists(projectdir + "/.gitignore"):
            with open(projectdir + "/.gitignore", "r+") as gitignore:
                lines = gitignore.readlines()
                found = False
                for line in lines:
                    if "mapcache" in line:
                        found = True
                if not found:
                    gitignore.writelines("mapcache/*")

        if not jobdir:
            jobdir = projectdir + "/mapcache/job-" + job.title + str(job.id)
        else:
            jobdir = jobdir.rstrip('/') + '/' + job.title + str(job.id)
        if not os.path.exists(jobdir):
            os.makedirs(jobdir)

        inFile = open(path + "/mapcacheConfig.xml.default")
        outFile = open(jobdir + "/mapcacheConfig.xml", "w")
        replacements = {
            '<!--SCRIBEUIPATH-->': jobdir,
            '<!--SCRIBEUITITLE-->': "job-" + job.title + str(job.id),
            '<!--SCRIBEUIMAPFILEPATH-->': mapfile,
            '<!--SCRIBEUIMAPSERVER-->': mapserver_url
        }

        for line in inFile:
            for src, target in replacements.iteritems():
                line = line.replace(src, target)
            outFile.write(line)
        inFile.close()
        outFile.close()

        pprint.pprint("Adding new process")
        if extent:
            if extent[0] == '/' and extent[-4:] == '.shp' and os.path.isfile(
                    extent):
                p = Popen([
                    "mapcache_seed", "-c", jobdir + "/mapcacheConfig.xml",
                    "-t", "default", "-z", zoomLevels, "-M", metatile, "-g",
                    grid, "-d", extent
                ],
                          shell=False)
                p.jobid = job.id
            else:
                p = Popen([
                    "mapcache_seed", "-c", jobdir + "/mapcacheConfig.xml",
                    "-t", "default", "-z", zoomLevels, "-M", metatile, "-g",
                    grid, "-e", extent
                ],
                          shell=False)
                p.jobid = job.id

        elif dbconfig:
            #TODO: ADD SUPPORT FOR OTHER DATABASE TYPE
            #ALSO, THIS CODE COULD PROBABLY BE PLACED IN A FUNCTION SOMEWHERE ELSE
            if dbconfig['type'].lower() == 'postgis':
                connection_string = 'PG:dbname=' + dbconfig[
                    'name'] + ' host=' + dbconfig['host'] + ' port=' + dbconfig[
                        'port'] + ' user='******'user']
                if dbconfig['password']:
                    connection_string += ' password='******'password']
                else:
                    connection_string = ''

                query_string = dbconfig['query'].rstrip(';')

            #start mapcache
            p = Popen([
                "mapcache_seed", "-c", jobdir + "/mapcacheConfig.xml", "-t",
                "default", "-z", zoomLevels, "-M", metatile, "-g", grid, "-d",
                connection_string, '-s', query_string
            ],
                      shell=False)

            p.jobid = job.id

        # Lock the processes list before adding data
        self.lock.acquire()
        self.processes.append(p)

        #If thread is finished, start it up
        if self.thread is None or not self.thread.isAlive():
            self.thread = None
            self.thread = self.pollProcesses(self)
            self.thread.start()
        self.lock.release()
        return