def process(self, user, request, resource, path, meta): """ Gets information about the event and reports it to the Redis pub/sub """ key = "%s.files" % user.get('id') event = Event() type = 'add' if request.method == 'DELETE': type = 'remove' baseUri = '' if request.env.has_key('BASE_URI'): baseUri = request.env['BASE_URI'] uri = request.uri.replace(baseUri,'') if request.method == 'POST': commonString = utils.longestCommonSubstring(uri, path) uri += path.replace(commonString,'') elif request.method in ['COPY','MOVE']: uri = urlparse.urlparse(request.env['HTTP_DESTINATION'])[2] uri = uri.replace(baseUri,'') baseUri = request.uri.replace(baseUri,'').replace(path,'') if baseUri: path = uri.replace(baseUri,'/') else: path = uri meta = None if type!='remove': meta = resource.storageProvider.getMeta(path, user=user) meta = meta[path] timestamp = time.time() data = { 'time': timestamp, 'type': type, # add|remove 'resource': uri, 'meta': meta } event.publish(key, data, timestamp) if request.method == 'MOVE': timestamp = time.time() data = { 'time': timestamp, 'type': 'remove', # add|remove 'resource': request.uri, 'meta': None } event.publish(key, data, timestamp)
def process(self, user, request, resource, path, meta): """ Gets information about the event and reports it to the Redis pub/sub """ key = "%s.files" % user.get('id') event = Event() type = 'add' if request.method == 'DELETE': type = 'remove' baseUri = '' if request.env.has_key('BASE_URI'): baseUri = request.env['BASE_URI'] uri = request.uri.replace(baseUri, '') if request.method == 'POST': commonString = utils.longestCommonSubstring(uri, path) uri += path.replace(commonString, '') elif request.method in ['COPY', 'MOVE']: uri = urlparse.urlparse(request.env['HTTP_DESTINATION'])[2] uri = uri.replace(baseUri, '') baseUri = request.uri.replace(baseUri, '').replace(path, '') if baseUri: path = uri.replace(baseUri, '/') else: path = uri meta = None if type != 'remove': meta = resource.storageProvider.getMeta(path, user=user) meta = meta[path] timestamp = time.time() data = { 'time': timestamp, 'type': type, # add|remove 'resource': uri, 'meta': meta } event.publish(key, data, timestamp) if request.method == 'MOVE': timestamp = time.time() data = { 'time': timestamp, 'type': 'remove', # add|remove 'resource': request.uri, 'meta': None } event.publish(key, data, timestamp)
def staticParts(allTokens): strings = list(set(allTokens.copy())) commonSubstrings = {} for theString in strings: strings.remove(theString) for string in strings: commonSubstring = longestCommonSubstring(theString, string) if commonSubstring not in commonSubstrings: commonSubstrings[commonSubstring] = [] if len(commonSubstring) > 2: if theString not in commonSubstrings[commonSubstring]: commonSubstrings[commonSubstring].append(theString) if string not in commonSubstrings[commonSubstring]: commonSubstrings[commonSubstring].append(string) return commonSubstrings