def newshp(self, task): """Tiles a shapefile specified in the task and registers metadata with GAE. Arguments: task - an item from the queue expected to have shapfile path """ # Validates task: if task is None: logging.warn('newshp task was None') del self.g.QUEUED_LAYERS[task[self.g.Q_ITEM_FULL_PATH]] return if not task.has_key(self.g.Q_ITEM_FULL_PATH): logging.warn('newshp task does not have %s' % self.g.Q_ITEM_FULL_PATH) del self.g.QUEUED_LAYERS[task[self.g.Q_ITEM_FULL_PATH]] return fullpath = task[self.g.Q_ITEM_FULL_PATH] if fullpath is None or len(fullpath.strip()) == 0: logging.warn('newshp task has invalid path ' % fullpath) del self.g.QUEUED_LAYERS[task[self.g.Q_ITEM_FULL_PATH]] return logging.info('Starting new task') # Executes the job layer = None try: layer = Layer(fullpath, self.g.TILE_DIR, self.g.ERR_DIR, self.g.SRC_DIR, self.g.DST_DIR, self.g.MAP_XML, self.g.TILE_URL, self.g.LAYER_URL, self.g.VALID_ID_SERVICE_URL, zoom=self.g.TILE_MAX_ZOOM) logging.info('Layer created: ' + fullpath) layer.totiles(self.g) logging.info('Layers tiled in ' + self.g.TILE_DIR) logging.info('Layer metadata getting registered...') layer.register() logging.info('Layer getting cleaned up...') layer.cleanup() except (SpeciesIdError), e: logging.info('SpeciesIdError ' + fullpath) id = Layer.idfrompath(fullpath)[0] logging.warn('id=' + id) err_dir = self.g.ERR_DIR src_dir = self.g.SRC_DIR err_dir = os.path.join(err_dir, 'animalia/species') # Copies to errors directory: for file in os.listdir(src_dir): if file.startswith(id): shutil.copy2(os.path.join(src_dir, file), err_dir) # Removes from source directory: for file in os.listdir(src_dir): if file.startswith(id): os.remove(os.path.join(src_dir, file))