Changeset 727 in products for qPloneGoogleSitemaps/trunk/utils.py
- Timestamp:
- Jan 5, 2007 3:11:47 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
qPloneGoogleSitemaps/trunk/utils.py
r55 r727 1 1 from urllib2 import urlopen 2 2 from urllib import quote as urlquote 3 from Products.CMFCore.utils import getToolByName 4 import re 5 import Products.qPloneGoogleSitemaps.config as config 3 4 from Globals import DevelopmentMode 6 5 from OFS.ObjectManager import BadRequestException 7 def ping_google(url): 6 7 from Products.qPloneGoogleSitemaps.config import testing 8 9 def ping_google(url, sitemap_id): 8 10 """Ping sitemap to Google""" 9 sitemap_url = urlquote(url + "/google-sitemaps") 11 if DevelopmentMode: 12 #prevent pinging in debug mode 13 print "Pinging Google ...", url, sitemap_id 14 return 0 15 16 resurl = url + "/" + sitemap_id 17 sitemap_url = urlquote(resurl) 10 18 g = urlopen('http://www.google.com/webmasters/sitemaps/ping?sitemap='+sitemap_url) 11 19 result = g.read() 12 20 g.close() 21 if testing: 22 print "Pinged %s sitemap to google" % resurl 13 23 return 0 14 15 def searchAndReplace(string, what, with):16 """Emulate sed command s/"""17 res = re.sub(what,with,string)18 return res19 20 OPERATORS = {'s': searchAndReplace,}21 22 def applyOperations(objects, operations):23 """Parse Operations """24 parse = re.compile(r"(.?[^\\])/(.*[^\\]|)/(.*[^\\]|)/")25 operations=[parse.match(op).groups() for op in operations]26 result={}27 for ob in objects:28 url = ob.getURL()29 for operator, what, with in operations:30 url = OPERATORS[operator](url, what, with.replace("\\", ""))31 #TODO: Remove or replace following condition32 #it is senseless in the case we need intelligent33 #result set. Better condition would be to place34 #freshest brain into result35 if url in result.keys():36 continue37 #TODO: replace brain with only data necessary to38 #generate sitemap39 result[url]=ob40 return result41 42 def additionalURLs(self):43 """Add URLs to sitemap that arn't objects"""44 res = []45 plone_home = getToolByName(self, 'portal_url').getPortalObject().absolute_url()46 root = self.getPhysicalRoot().absolute_url()47 48 props = getToolByName(self,'portal_properties')49 try:50 URLs = props.googlesitemap_properties.urls51 except AttributeError:52 URLs = []53 54 add_zope = re.compile('^/')55 add_plone= re.compile('^[^http://|https://|\\\]')56 for url in URLs:57 if add_zope.match(url):58 res.append(root+url)59 elif add_plone.match(url):60 res.append(plone_home+'/'+url)61 else:62 res.append(url)63 return res64 65 """workflows & co"""66 def getWorkflowTransitions(self,workflow_id):67 pw = getToolByName(self,'portal_workflow')68 wf = pw.getWorkflowById(workflow_id)69 if not wf:70 return None71 return wf.transitions.values()72 73 def setWorkflowTransitions(self,transitions):74 """set workflow transitions properties"""75 portal_workflow = getToolByName(self, 'portal_workflow')76 transmap = {}77 for key in transitions:78 if key.find('#')>0:79 ids = key.split('#')80 wfid = ids[0]81 if not wfid in transmap.keys():82 transmap[wfid]=[]83 transmap[wfid].append(ids[1])84 for wfid in transmap.keys():85 workflow = portal_workflow.getWorkflowById(wfid)86 if config.ping_googlesitemap not in workflow.scripts.objectIds():87 workflow.scripts.manage_addProduct['ExternalMethod'].manage_addExternalMethod(88 config.ping_googlesitemap,89 'Ping sitemap',90 'qPloneGoogleSitemaps.ping_googlesitemap',91 config.ping_googlesitemap)92 transitions_set = transmap[wfid]93 for transition in workflow.transitions.values():94 trid = transition.id95 tras = transition.after_script_name96 if (tras == '') and (trid in transitions_set):97 #set98 after_script = config.ping_googlesitemap99 elif (tras == config.ping_googlesitemap) and not (trid in transitions_set):100 #reset101 after_script = ''102 else:103 #avoid properties set104 continue105 transition.setProperties(title=transition.title,106 new_state_id=transition.new_state_id,107 after_script_name=after_script,108 actbox_name=transition.actbox_name)
Note: See TracChangeset
for help on using the changeset viewer.