Changeset 227

Show
Ignore:
Timestamp:
05/26/09 14:51:09 (3 years ago)
Author:
david
Message:

updated w/ working versions of S5

Files:
1 modified

Legend:

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

    r225 r227  
    5353fqsubdomain         = 'http://%s' %(subdomain) 
    5454tmpfile_name        = 'tempfile' 
    55  
    5655 
    5756def DebugOutput(function, words): 
     
    108107                 'search_icon.gif', 
    109108                 's5_icon.jpg', 
     109                 'base.css', 
     110                 's5_slides.css', 
     111                 's5_outline.css', 
     112                 's5_print.css', 
     113                 's5_opera.css', 
     114                 's5_slides.js', 
    110115                 'spinner.gif', 
    111116                 'sitemap', 
     
    117122                  'headerBackground.png', 
    118123                  'topNavBackground.png',] 
    119                                  
    120      
     124 
    121125    for file in add_files: 
    122126        if file == 'index.html': 
     
    376380    fileobj.close() 
    377381     
    378     tmpfobj = open(tmpfile_name, 'w') 
     382    tmpfile = tmpfile_name + filename.split('/')[-1] 
     383     
     384     
     385    tmpfobj = open(tmpfile, 'w') 
    379386    path_to_file = os.path.dirname(filename) 
    380387    path_to_file = path_to_file.replace('/','/') 
     
    392399    #remove completely, as it breaks relative pathing for local browsing 
    393400    for tag in soup.findAll('base'): 
    394         soup.base.extract() 
     401        soup.base.extract()     
    395402         
    396  
    397403    for tag in soup.head.findAll('link'): 
    398404        if tag.has_key('rel'): 
     
    413419            #handle root url case 
    414420            href = href.replace(fqsubdomain, rel_path) 
    415             tag['href'] = href 
    416              
     421            tag['href'] = href             
    417422     
    418423    #replace style tags subdomain  
     
    426431    #replace script tags subdomain  
    427432    for tag in soup.head.findAll('script'): 
    428         if fqsubdomain in tag.contents[0]: 
    429             #remove domain             
    430             tag.contents[0].replaceWith(tag.contents[0].replace(fqsubdomain, rel_path)) 
    431             #replace %20 
    432             tag.contents[0].replaceWith(tag.contents[0].replace('%20','_')) 
    433  
    434  
    435     for key, value in modifiers.items(): 
    436         #HANDLE IMAGES 
    437         for tag in soup.findAll('img'):             
    438             if tag.has_key('src'): 
    439                 src = tag['src'] 
    440                 #remove http://DOMAIN/ and replace w/ rel_path 
    441                 tag['src'] = src.replace(fqsubdomain + '/', rel_path) 
    442  
     433        if tag.has_key('src'):             
     434            if fqsubdomain in tag['src']: 
     435                #remove domain  
     436                src = tag['src'].replace(fqsubdomain, rel_path) 
     437                #replace %20 
     438                src = src.replace('%20', '_') 
     439            tag['src'] = src 
     440 
     441    #image handler 
     442    for tag in soup.findAll('img'):             
     443        doc_action_icons = ['print_icon.gif', 
     444                            'rss_icon.gif', 
     445                            'document_icon.gif', 
     446                            's5_icon.jpg', 
     447                            'bookmarklets.gif'] 
     448        if tag.has_key('src'): 
     449            src = tag['src'] 
     450            #remove http://DOMAIN/ and replace w/ rel_path 
     451            tag['src'] = src.replace(fqsubdomain + '/', rel_path) 
     452             
     453            for icon in doc_action_icons: 
     454                if icon == src: 
     455                    tag['src'] = src.replace(icon, rel_path + icon)                     
    443456  
    444457    #Rebuild links to zip file download to always point to course, since there is no acquisition 
     
    455468  
    456469  
    457     for link in soup.findAll('a'): 
    458      
     470    for link in soup.findAll('a'):         
    459471        if link.has_key('href'): 
    460472            href = link['href'] 
     
    478490                elif 'front-page' in href: 
    479491                    href = href.replace('front-page/', '') 
     492                #download skinless_view 
     493                elif href.endswith('skinless_view'): 
     494                    source = href 
     495                    target = href.replace('/skinless_view', '.skinless.html')                   
     496                    target = target.replace(fqsubdomain + '/', '') 
     497                    href = '%s%s' % (rel_path, target) 
     498                    DownloadResource(source, target) 
     499                #download presentation view 
     500                elif href.endswith('presentation_view'): 
     501                    source = href 
     502                    target = href.replace('/presentation_view', '.presentation.html')                   
     503                    target = target.replace(fqsubdomain + '/', '') 
     504                    href = '%s%s' % (rel_path, target) 
     505                    DownloadResource(source, target) 
     506                    new_file_anz, new_file = ModifyForStaticHTML('./%s' % target, modifiers, folder_list) 
     507                     
     508                 
    480509                #rewrite links to zip file downloads of courses 
    481510                for folder in folder_list: 
     
    484513                        if debug_mode >= 4: 
    485514                            DebugOutput('ModifyForStaticHTML -3', href) 
     515 
    486516            #remove odd  courselist/rss on front page 
    487517            elif 'courselist/rss' == href: 
     
    493523            # append .html for links of documents if they do not end in .htm or .html 
    494524            for page in html_pages: 
    495                 if page in href: 
     525                if href.endswith(page): 
    496526                    if '.htm' not in href: 
    497527                        href = href.replace(page, page + '.html') 
    498528            link['href'] = href 
    499529 
    500  
    501  
    502530    tmpfobj.write(soup.prettify()) 
    503531    tmpfobj.close() 
    504532     
    505533    os.remove(filename) 
    506     os.rename(tmpfile_name, filename) 
     534    os.rename(tmpfile, filename) 
    507535    return new_file_anz, new_file 
    508536 
     
    523551folder_list = FindFilesToModify() 
    524552 
     553#Modify presentation.html files? 
     554 
     555#Modify RDF files? 
     556 
    525557# Create file sitemap.xml.gz 
    526558#CreateSearchSitemap(folder_list)