Changeset 3478 in products for quintagroup.plonegooglesitemaps/branches/two_request/utils.py
- Timestamp:
- Jul 27, 2012 2:35:19 PM (12 years ago)
- File:
-
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
quintagroup.plonegooglesitemaps/branches/two_request/utils.py
r3460 r3478 11 11 _marker = [] 12 12 13 13 14 14 def searchAndReplace(string, what, withs): 15 15 """Emulate sed command s/""" 16 #TODO: Better solution would be to compile 17 #'what' and 'withs' 16 18 res = re.sub(what, withs, string) 17 19 return res 18 20 OPERATORS = {'s': searchAndReplace, } 19 21 22 def urlFilter(url, operations): 23 """ Method dedicated to filter url according with operations """ 24 for operator, what, withs in operations: 25 url = OPERATORS[operator](url, what, withs.replace("\\", "")) 26 return url 20 27 21 def applyOperations(objects, operations): 22 """Parse Operations """ 23 operations = [OPERATIONS_PARSE.match(op).groups() for op in operations] 24 result = {} 28 def getUrlsObjects(objects): 29 """Method dedicated to get url for each object""" 30 results = set() 25 31 for ob in objects: 26 32 url = _marker … … 29 35 if url in [Missing_Value, _marker]: 30 36 url = ICanonicalLink(ob.getObject()).canonical_link 31 for operator, what, withs in operations:32 url = OPERATORS[operator](url, what, withs.replace("\\", ""))33 37 #TODO: Remove or replace following condition 34 38 #it is senseless in the case we need intelligent 35 39 #result set. Better condition would be to place 36 40 #freshest brain into result 37 if url in result .keys():41 if url in results: 38 42 continue 39 43 #TODO: replace brain with only data necessary to 40 44 #generate sitemap 45 results.add(url) 46 yield url, ob 47 48 def applyOperations(objects, operations): 49 """Parse Operations""" 50 operations = [OPERATIONS_PARSE.match(op).groups() for op in operations] 51 result = {} 52 for url, ob in getUrlsObjects(objects): 53 url = urlFilter(url, operations) 41 54 result[url] = ob 42 55 return result 43 44 56 45 57 def additionalURLs(context):
Note: See TracChangeset
for help on using the changeset viewer.