Changeset 225

Show
Ignore:
Timestamp:
05/22/09 11:04:44 (3 years ago)
Author:
david
Message:

handle links, RSS, courselist, amongst other things

Location:
plone-export/trunk
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • plone-export/trunk/plone-static-export.py

    r206 r225  
    9090                 'bookmarklets.gif', 
    9191                 'bullet.gif', 
    92                  'courselist', 
    9392                 'document_icon.gif', 
    9493                 'eduCommonsDivision.gif', 
     
    105104                 'rss_icon.gif', 
    106105                 'py.png', 
     106                 '@@rss_feeds', 
    107107                 'robots.txt', 
    108108                 'search_icon.gif', 
     
    127127        if file in ['accessibility-info', 'sitemap']: 
    128128            target += '.html' 
    129         if file == 'courselist': 
    130             target += '.html' 
     129        elif file == '@@rss_feeds': 
     130            target = target.replace('@@rss_feeds', 'courselist/@@rss_feeds.html')    
    131131        DownloadResource(source, target) 
    132132     
     
    154154            if not os.path.exists(directory): 
    155155                CreateDirectory(directory) 
    156             DownloadResource(source, target) 
     156            DownloadResource(source, target)           
    157157            if 'portal_css' in line: 
    158158                DownloadCSSImages(source, target, css_images) 
     
    328328    return link, target 
    329329 
    330  
    331  
    332330def FindFilesToModify(): 
    333331    ''' Find files to modify them  ''' 
     
    350348    for root, dirs, files in os.walk('./'): 
    351349        for file in files: 
    352              
    353350            # Files which are looking for changes 
    354351            if file.find('.html') >= 0 or file.find('.htm') >= 0: 
     
    396393    for tag in soup.findAll('base'): 
    397394        soup.base.extract() 
     395         
     396 
     397    for tag in soup.head.findAll('link'): 
     398        if tag.has_key('rel'): 
     399            #find objects with RDF link tags, and download the associated RDF document 
     400            if tag['rel'] == 'alternate': 
     401                if tag['type'] == 'application/rss+xml': 
     402                    href = tag['href'].replace('RSS', 'rss') 
     403                    tag['href'] = href.replace(fqsubdomain, '') 
     404                elif tag['type'] == 'application/rdf+xml':     
     405                    source = tag['href'] 
     406                    rdf_file = tag['href'].replace('/rdf', '.rdf')                   
     407                    target = rdf_file.replace(fqsubdomain + '/', '') 
     408                    tag['href'] = '../%s' % target 
     409                    DownloadResource(source, target) 
     410            #generic URL rewriter 
     411            href = tag['href'] 
     412            href = href.replace(fqsubdomain + '/', rel_path) 
     413            #handle root url case 
     414            href = href.replace(fqsubdomain, rel_path) 
     415            tag['href'] = href 
     416             
    398417     
    399418    #replace style tags subdomain  
     
    423442 
    424443  
     444    #Rebuild links to zip file download to always point to course, since there is no acquisition 
     445    for dl in soup.findAll('dl'): 
     446       if dl.has_key('class'): 
     447           if dl['class'] == 'portlet portletReuseCourse': 
     448               path_parts = dl.dd.a['href'].replace(fqsubdomain + '/', '').split('/') 
     449               zip_path = path_parts[0:2] + path_parts[-1:] 
     450               zip_path = rel_path + string.join(zip_path, '/')                         
     451               dl.dd.a['href'] = zip_path 
     452  
     453    for div in soup.findAll('div', id='portal-personaltools-wrapper'): 
     454        div.extract() 
     455  
     456  
    425457    for link in soup.findAll('a'): 
     458     
    426459        if link.has_key('href'): 
    427460            href = link['href'] 
     
    430463                if href == 'http://demo.educommons.com': 
    431464                    href = '%s/index.html' % href 
     465                # download rss feeds 
     466                elif href.endswith('/rss'): 
     467                    DownloadResource(href, href.replace(fqsubdomain, '')) 
     468                #replace with static url 
     469                elif href.endswith('@@rss'): 
     470                    #rewrite views in rss_feeds.html page, no need to create duplicate copies of RSS feeds 
     471                    if 'courselist' in href: 
     472                        href = replace('courselist/', '') 
     473                    href = href.replace('@@rss', 'rss') 
     474                #convert spaces to _     
    432475                elif '%20' in href: 
    433476                    href = href.replace('%20','_') 
    434                 # change folder links to folder/index.html if link ends in /folder                  
     477                #remove front-page path 
     478                elif 'front-page' in href: 
     479                    href = href.replace('front-page/', '') 
     480                #rewrite links to zip file downloads of courses 
    435481                for folder in folder_list: 
    436482                    if folder in href and href.endswith(folder): 
     
    438484                        if debug_mode >= 4: 
    439485                            DebugOutput('ModifyForStaticHTML -3', href) 
     486            #remove odd  courselist/rss on front page 
     487            elif 'courselist/rss' == href: 
     488                href = href.replace('courselist/', '')                  
    440489                 
    441490            #remove http://DOMAIN/ and replace w/ rel_path 
  • plone-export/trunk/static_export.cpy

    r206 r225  
    1313   for content in context.portal_catalog(portal_type='Course', review_state='Published', sort_order = 'Date'): 
    1414      objects += [content.getURL(),]       
     15     
     16   # Add Courselist folder   
     17   objects += [context.courselist.absolute_url(),] 
    1518 
    1619else: 
     
    6063      objects[obj_url] = obj_url  
    6164 
     65   # Generate list of FSS files 
     66   for content in context.portal_catalog(portal_type='FSSFile', review_state='Published', sort_order = 'Date'): 
     67      obj_url = content.getURL() 
     68      objects[obj_url] = obj_url 
     69                
     70   # Add courselist folder 
     71   obj_url = content.courselist.absolute_url() 
     72   tar_url = '%s/index.html' % obj_url 
     73   objects[obj_url] = tar_url 
     74 
    6275# return the list of objects 
    6376return objects 
    64