source: products/qPloneGoogleSitemaps/trunk/browser/utils.py

Last change on this file was 793, checked in by chervol, 13 years ago

add place for EditorProfile?

  • Property svn:eol-style set to native
File size: 1.7 KB
RevLine 
[395]1import re
2
3from DateTime import DateTime
4
5from Products.CMFCore.utils import getToolByName
6import Products.qPloneGoogleSitemaps.config as config
7
8ADD_ZOPE = re.compile('^/')
9ADD_PLONE = re.compile('^[^http://|https://|\\\]')
10OPERATIONS_PARSE = re.compile(r"(.?[^\\])/(.*[^\\]|)/(.*[^\\]|)/")
11
12def searchAndReplace(string, what, with):
13    """Emulate sed command s/"""
14    res = re.sub(what,with,string)
15    return res
16OPERATORS = {'s': searchAndReplace,}
17
18def applyOperations(objects, operations):
19    """Parse Operations """
20    operations=[OPERATIONS_PARSE.match(op).groups() for op in operations]
[402]21    result = {}
[395]22    for ob in objects:
[793]23        if ob.has_key('canonical_path'):
24            url = ob.canonical_path
25        else:
26            url = '/'+'/'.join(ob.getPath().split('/')[2:])
[395]27        for operator, what, with in operations:
28            url = OPERATORS[operator](url, what, with.replace("\\", ""))
29        #TODO: Remove or replace following condition
30        #it is senseless in the case we need intelligent
31        #result set. Better condition would be to place
32        #freshest brain into result
[402]33        if url in result.keys():
[395]34            continue
[402]35        #TODO: replace brain with only data necessary to
36        #generate sitemap
37        result[url]=ob
[395]38    return result
39
40def additionalURLs(context):
41    """Add URLs to sitemap that arn't objects"""
42    res = []
43
44    plone_home = getToolByName(context, 'portal_url')()
45    root = context.getPhysicalRoot().absolute_url()
46    URLs =  context.getUrls()
47
48    for url in URLs:
49        if ADD_ZOPE.match(url):
50            res.append(root+url)
51        elif ADD_PLONE.match(url):
52            res.append(plone_home+'/'+url)
53        else:
54            res.append(url)
55    return res
Note: See TracBrowser for help on using the repository browser.