ó $&¯Mc@sFdZddlZddlmZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl j jZddljZddljZdZdZdZd„Zd„Zd „Zd „Zd „ZdZdZdZd„Zd„Z d„Z!d„Z"d„Z#d„Z$d„Z%dS(sfeed - routines for generating RFC 4287 Atom feeds for packaging server At present, the pkg.server.feed module provides a set of routines that, from a catalog, allow the construction of a feed representing the activity within a given time period.iÿÿÿÿN(t serve_filesapplication/atom+xmlsfeed.xmls%Y-%m-%dT%H:%M:%SZcCs |jtƒS(saReturns a string representing a datetime object formatted according to RFC 3339. (tstrftimet RFC3339_FMT(tts((s5/usr/lib/python2.7/vendor-packages/pkg/server/feed.pytdt_to_rfc3339_str4scCs tjtj|tƒdd!ŒS(svReturns a datetime object representing 'ts_str', which should be in the format specified by RFC 3339. ii(tdatetimettimetstrptimeR(tts_str((s5/usr/lib/python2.7/vendor-packages/pkg/server/feed.pytrfc3339_str_to_dt:scCs2d|j|jƒjdƒtj|jƒƒfS(ssGenerates a 'tag' uri compliant with RFC 4151. Visit http://www.taguri.org/ for more information. s tag:%s,%s:%ss%Y-%m-%d(t publishert get_timestampRturllibtunquotet get_url_path(tf((s5/usr/lib/python2.7/vendor-packages/pkg/server/feed.pytfmri_to_taguri@s cCst|dƒdS(soThis function performs general initialization work that is needed for feeds to work correctly. N(t __clear_cachetNone(tdepot((s5/usr/lib/python2.7/vendor-packages/pkg/server/feed.pytinitHscCs|jdƒ}tjƒ}|j|jjddƒƒ|j|ƒ|j|ƒ|jdƒ}|jdtj ƒƒ|jddƒ|j|ƒ|jdƒ}tjƒ}t j tj ƒƒd d !\} } | j d d ƒd } d | |j dƒ| f} |j| ƒ|j|ƒ|j|ƒ|jdƒ} tjƒ} | jt |ƒƒ| j| ƒ|j| ƒ|jdƒ}tjƒ}|j|jjddƒƒ|j|ƒ|j|ƒ|jdƒ}tjƒ}|j|jjddƒƒ|j|ƒ|j|ƒdS(sêThis function attaches the necessary RSS/Atom feed elements needed to provide title, author and contact information to the provided xmini document object using the provided feed object and update time. ttitletpkg_buit feed_nametlinkthreftreltselftidiit:is tag:%s,%s:%ss%Y-%m-%dtupdatedticont feed_icontlogot feed_logoN(t createElementtxminitTexttreplaceWholeTexttcfgt get_propertyt appendChildt setAttributetcherrypyturlturlparsetsplitRR(Rtdoctfeedt update_tsttttitltitittnetloctpathttagtututtlt((s5/usr/lib/python2.7/vendor-packages/pkg/server/feed.pyt set_titlePs@     "           tAddeds%s was added to the repository.tRemoveds#%s was removed from the repository.tUpdatedsF%s, a new version of an existing package, was added to the repository.cCs/|jdƒ}|\}}}} tjƒ} | jt|ƒƒ|jdƒ} | j| ƒ|j| ƒ|tjjkr¥||kr–t \} } qÒt \} } n-|tjj krÆt \} } n d} d} |jdƒ}tjƒ}|jdj | |j ƒgƒƒ|j|ƒ|j|ƒ|jdƒ}tjƒ}|jt|ƒƒ|j|ƒ|j|ƒtj|dtjt|ƒƒƒ}|jd ƒ}|jd d ƒ|jd |ƒ|j|ƒ| |}tjƒ}|j|ƒ|jd ƒ}|j|ƒ|j|ƒ|j|ƒdS(smEach transaction is an entry. We have non-trivial content, so we can omit summary elements. tentryRsUnknown Operations!%s was changed in the repository.Rt Rs info/0/%sRRt alternateRtcontentN(R#R$R%R&RR)tcatalogt CatalogUpdatetADDt update_optadd_optREMOVEtjoint get_pkg_stemRtmisct get_rel_pathR tquotetstrR*(trequestR/R0RAtfirsttetpfmritop_typetop_timetmetadataR5teidtop_titlet op_contenttetitleR3teuR;te_uriR4t content_texttcotec((s5/usr/lib/python2.7/vendor-packages/pkg/server/feed.pytadd_transactionˆsL     "            c Cs°|j|ƒ}|j|kr"gStƒ}xn|jjƒD]]\}}|jddƒd}|dkroq;n|d}||kr‹q;n|j|ƒq;W|s¦gSt|ƒS(s£Returns a list of the CatalogUpdate files that contain the changes that have been made to the catalog since the specified UTC datetime object 'ts'.t.itCs last-modified(t get_catalogt last_modifiedtsettupdatest iteritemsR.taddtsorted( trepoRtpubtcRgtnametmdatatlocaletulog_lm((s5/usr/lib/python2.7/vendor-packages/pkg/server/feed.pytget_updates_neededÏs    c sw|jjddƒ}t|dƒ\}}|dd}|tjd|d|ƒ}tjƒ} | jddƒ} | jd dƒ|j j |ƒ‰t || | ˆj ƒ| j | ƒi‰‡‡fd †} x”tt|j ||ƒƒD]w} tj| d ˆjƒ} xV| jƒD]H}|d }|d }||krBqnt|| | || |ƒƒqWqëW| j|ƒdS(sƒGenerate new Atom document for current updates. The cached feed file is written to depot.tmp_root/CACHE_FILENAME. Rt feed_windowii<tdaystsecondsshttp://www.w3.org/2005/AtomR0txmlnscsŒ|jƒ}|ˆkr ˆ|SxHˆj|jƒD]4\}}x$|D]\}}|ˆ|jƒs%s was added to the repository.(R?s#%s was removed from the repository.(R@sF%s, a new version of an existing package, was added to the repository.(&t__doc__R+tcherrypy.lib.staticRR¤RR™RŽR’RR R-txml.dom.minidomtdomtminidomR$t pkg.catalogREtpkg.miscRMR´RRRR RRR=RIt remove_opRHRaRrRR‘RR­R¶(((s5/usr/lib/python2.7/vendor-packages/pkg/server/feed.pyts>              3 G # =  3