def mapvisng (request, **kwargs): """ Opens the map vis/edit function :param request: :param kwargs: :return: """ proxy_id = kwargs['proxy_id'] manifest = proxy_core.getManifest(proxy_id) vismode = kwargs['vismode'] # vismode must reflect one of these validmodes = ["modeledit", "mapview", "mapedit", "full"] """ Modes breakdown - Modeler: edits the model of a single map, still requires loading the map (maybe with a few reductions) but does NOT show it. - Mapview: views a single map, can select single elements and make filters but no changes are allowed - Mapedit: edits a single map, can select elements make filters and changes. Can SAVE AS but not load other maps or create new maps - Full: can do everything and allows to load and create as a starting point """ if vismode not in validmodes: raise Exception ("Not a valid mode") else: if vismode != "full": meta_id = kwargs['meta_id'] map_id = kwargs['map_id'] else: meta_id = None map_id = None print "Launching *%s* with context %s/%s/%s" % (vismode, proxy_id, meta_id, map_id) proxy_type = proxy_core.learnProxyTypeAdv(proxy_id, manifest) mapsdata = proxy_core.getMapsSummary(proxy_id) if meta_id != '.create': setmodel = mapsdata[meta_id][map_id]['type'] elif map_id == 'DefaultLine': setmodel = 'LineString' elif map_id == 'DefaultPoint': setmodel = 'Point' proxy_meta = mapsdata.keys() proxy_mapsbymeta = {} for cmeta_id in proxy_meta: proxy_mapsbymeta [cmeta_id] = mapsdata[cmeta_id].keys() print "Proxy maps data: %s " % proxy_mapsbymeta modeldata = getModels() print "Proxy models: %s" % modeldata return render_to_response ('mapvisng.html', {'proxy_id': proxy_id, 'meta_id': meta_id, 'map_id': map_id, 'manifest': SafeString(json.dumps(manifest)), 'mode': vismode, 'proxy_name': manifest['name'], 'proxy_meta': proxy_meta, 'proxy_type': proxy_type, 'mapsbymeta': proxy_mapsbymeta, 'proxy_maps': mapsdata, 'mapsforjs': SafeString(json.dumps(mapsdata)), 'proxy_models': SafeString(json.dumps(modeldata)), 'rawmodels': modeldata, 'maptype': setmodel}, context_instance=RequestContext(request))
def sendProxyManifestFromFile (proxy_id): """ Sends the manifest of a given soft proxy to the main server and returns the response :param proxy_id: :return: """ return sendProxyManifestRaw(proxy_core.getManifest(proxy_id))
def getProxyType (proxy_id): """ Opens the manifest and returns the type of manifest :param proxy_id: :return: """ manifest = proxy_core.getManifest(proxy_id) return learnProxyType(manifest)
def isLinkedProxy (ref_id, ref_name): """ returns whether the reference proxy is linked to another proxy (actually a standalone tool) :return: """ for proxy_cmp in getProxyList(): name_cmp = proxy_core.getManifest(proxy_cmp)['name'] if ref_id != proxy_cmp and name_cmp == ref_name: return True return False
def uiview (request, **kwargs): """ Loads the interface of the standalone tool :param request: :param kwargs: :return: """ proxy_editables = proxy_core.getAllEditables() # we always have a proxy_id since the standalone area is specific to each proxy. proxy_id = kwargs['proxy_id'] try: req_meta_id = kwargs['meta_id'] req_map_id = kwargs['shape_id'] except: req_meta_id = None req_map_id = None manifest = proxy_core.getManifest(proxy_id) proxy_name = manifest['name'] proxy_meta = [] maplist = {} for metadata in manifest['metadata']: meta_id = metadata['name'] proxy_meta.append(meta_id) try: maplist[meta_id] = proxy_editables[proxy_id][meta_id] except: # we can have empty metadata pass #maplist_st = [] maplist_st = os.listdir(os.path.join(proxyconf.baseproxypath, proxy_id, proxyconf.path_standalone)) print proxy_id, proxy_name, proxy_meta, maplist, maplist_st models = getModels() return render_to_response ('fwstui.html', {'proxy_id': proxy_id, 'proxy_name': proxy_name, 'proxy_meta': SafeString(json.dumps(proxy_meta)), 'maps_fider': SafeString(json.dumps(maplist)), 'maps_st': SafeString(json.dumps(maplist_st)), 'models': SafeString(json.dumps(models)), 'manifest': SafeString(json.dumps(manifest)), 'sel_meta': req_meta_id, 'sel_map': req_map_id}, context_instance=RequestContext(request))
def handleFileEvent (eventpath): """ Acts as controller during the whole process of update (and eventual send in case of write/full :param eventpath: path to the changed/added/deleted file on the filesystem :return: """ # our upload dir structure is: # $upload / $proxy_instance / $meta_id / $shape_id.zip # we detect what has actually changed. # It MUST be a zip file or somebody is messing with the dir structure and we must exit and warn about it proxy_id, meta_id, shape_id = proxy_core.verifyUpdateStructure(eventpath) print "Working on file event @ %s/%s/%s" % (proxy_id, meta_id, shape_id) print "w.eventpath %s" % eventpath locker = proxy_lock.ProxyLocker (retries=3, wait=5) upsert = None # Determining if the event is an upsert or a delete if not os.path.exists(eventpath): # delete #proxy_core.handleDelete (proxy_id, meta_id, shape_id) print "Deleting %s/%s/%s" % (proxy_id, meta_id, shape_id) locker.performLocked(proxy_core.handleDelete, proxy_id, meta_id, shape_id) elif zipfile.is_zipfile(eventpath): # upsert # proxy_core.handleUpsert (proxy_id, meta_id, shape_id) print "Updating/Adding %s/%s/%s" % (proxy_id, meta_id, shape_id) locker.performLocked(proxy_core.handleUpsert, proxy_id, meta_id, shape_id) upsert = shape_id else: # wrong file type or directory creation print "Unexpected file type or operation on path %s" % eventpath raise InvalidFSOperationException ("Unexpected file type or operation on path %s" % eventpath) if upsert is not None: shapedata = proxy_core.rebuildShape(proxy_id, meta_id, shape_id, modified=True) #proxy_core.replicateShapeData (shapedata, proxy_id, meta_id, shape_id, modified=True) locker.performLocked(proxy_core.replicateShapeData, shapedata, proxy_id, meta_id, shape_id, modified=True) else: # this is a delete #proxy_core.replicateDelete (proxy_id, meta_id, shape_id) locker.performLocked(proxy_core.replicateDelete, proxy_id, meta_id, shape_id) #no need of locking for this, since it simply adds/updates a file to the /next dir proxy_core.queueForSend(proxy_id, meta_id) #if the server is a write/full server, we launch the server update process proxymanifest = proxy_core.getManifest(proxy_id) if proxymanifest['operations']['write'] == u'full': try: sentok, details = sendUpdatesWrite(proxy_id) if sentok is True: logEvent ("Sent update for proxy %s" % proxy_id) else: logEvent ("Error while sending update for proxy %s: %s" % (proxy_id, details)) except Exception as e: logEvent (e.message, True)