Show
Ignore:
Timestamp:
03/20/11 13:12:05 (4 years ago)
Author:
mbutscher
Message:

branches/stable-2.1:
* Support for URL appendix "prnr" to create a relative link which is

not relocated (modified) when exported as HTML to a different
destination (backported to 2.1 to provide some backward compatibility
to old behavior)

* Bug fixed: Favorite wiki icons may open wrong wiki
* Bug fixed: Misleading error message and bad error handling for

corrupted wiki config file

* Internal: Default maximum length of compatible filename reduced from

250 to 120

branches/mbutscher/work:
* Less jumping around of selection in doc structure window when adding

text (thanks to Christian Ziemski)

* Support for spaces in bracketed URLs
* Option to control type of URL (bracketed or not) on drag&drop
* Support for URL appendix "prnr" to create a relative link which is

not relocated (modified) when exported as HTML to a different
destination

* Option to sort list in "Open Wiki Word" dialog in reverse

alphabetical order

* Shortcuts introduced to move one or more selected logical lines one

line up or down

* Bug fixed: Favorite wiki icons may open wrong wiki
* Bug fixed: Misleading error message and bad error handling for

corrupted wiki config file

* Internal: Deprecated makeRelUrlAbsolute() and makeAbsPathRelUrl() in

PersonalWikiFrame?, call functions in WikiDocument? instead

* Internal: Default maximum length of compatible filename reduced from

250 to 120

* File cleanup now in usable state (orphaned files complete, missing

files need work yet)

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branches/mbutscher/work/lib/pwiki/wikidata/WikiDataManager.py

    r247 r263  
    33 
    44from weakref import WeakValueDictionary 
    5 import os, os.path, time, shutil, traceback 
     5import os, os.path, time, shutil, traceback, ConfigParser 
    66from threading import RLock, Thread, Condition 
    77# from collections import deque 
     
    131131    else: 
    132132        wikiConfigFilename = wikiCombinedFilename 
    133     wikiWord = None 
    134  
    135     while True: 
    136         try: 
    137             # config.read(wikiConfigFile) 
    138             wikiConfig.loadConfig(wikiConfigFilename) 
    139             return wikiConfigFilename, wikiWord 
    140         except Exception, e: 
    141             # try to recover by checking if the parent dir contains the real wiki file 
    142             # if it does the current wiki file must be a wiki word file, so open the 
    143             # real wiki to the wiki word. 
    144 #                 try: 
    145             parentDir = os.path.dirname(os.path.dirname(wikiConfigFilename)) 
    146             if parentDir: 
    147                 try: 
    148                     wikiFiles = [file for file in os.listdir(parentDir) \ 
    149                             if file.endswith(".wiki")] 
    150                     if len(wikiFiles) > 0: 
    151                         wikiWord = os.path.basename(wikiConfigFilename) 
    152                         wikiWord = wikiWord[0 : len(wikiWord) - 5] 
    153  
    154                         # if this is win95 or < the file name could be a 8.3 alias, file~1 for example 
    155                         windows83Marker = wikiWord.find("~") 
    156                         if windows83Marker != -1: 
    157                             wikiWord = wikiWord[0:windows83Marker] 
    158                             matchingFiles = [file for file in wikiFiles \ 
    159                                     if file.lower().startswith(wikiWord)] 
    160                             if matchingFiles: 
    161                                 wikiWord = matchingFiles[0] 
    162                         wikiConfigFilename = os.path.join(parentDir, wikiFiles[0]) 
    163                         continue 
    164                 except (WindowsError, IOError, OSError): 
    165                     # something went wrong -> give up 
    166                     traceback.print_exc() 
    167                     return None, None 
    168  
    169             return None, None 
     133 
     134    try: 
     135        wikiConfig.loadConfig(wikiConfigFilename) 
     136        return wikiConfigFilename, None 
     137    except ConfigParser.ParsingError, e: 
     138        # try to recover by checking if the parent dir contains the real wiki file 
     139        # if it does the current wiki file must be a wiki word file, so open the 
     140        # real wiki to the wiki word. 
     141        wikiWord = None 
     142        parentDir = os.path.dirname(os.path.dirname(wikiConfigFilename)) 
     143        if parentDir: 
     144            try: 
     145                wikiFiles = [file for file in os.listdir(parentDir) \ 
     146                        if file.endswith(".wiki")] 
     147                if len(wikiFiles) > 0: 
     148                    wikiWord = os.path.basename(wikiConfigFilename) 
     149                    wikiWord = wikiWord[0 : len(wikiWord) - 5] 
     150 
     151                    # if this is win95 or < the file name could be a 8.3 alias, file~1 for example 
     152                    windows83Marker = wikiWord.find("~") 
     153                    if windows83Marker != -1: 
     154                        wikiWord = wikiWord[0:windows83Marker] 
     155                        matchingFiles = [file for file in wikiFiles \ 
     156                                if file.lower().startswith(wikiWord)] 
     157                        if matchingFiles: 
     158                            wikiWord = matchingFiles[0] 
     159 
     160                    wikiConfig.loadConfig(os.path.join(parentDir, wikiFiles[0])) 
     161                    return os.path.join(parentDir, wikiFiles[0]), wikiWord 
     162            except: 
     163                pass 
     164 
     165        # Either parent directory couldn't be constructed or something went 
     166        # wrong in parent directory so return initial wikiConfigFilename 
     167        # although the file is obviously corrupted but this is handled by 
     168        # code PersonalWikiFrame.openWiki 
     169        return wikiConfigFilename, None 
     170 
     171    except Exception, e: 
     172        # Something else went wrong (file not present or not accessible) 
     173        traceback.print_exc() 
     174        return None, None 
     175 
    170176     
    171177     
     
    311317        self.writeAccessDenied = False 
    312318 
    313         wikiConfig.loadConfig(wikiConfigFilename) 
     319        try: 
     320            wikiConfig.loadConfig(wikiConfigFilename) 
     321        except ConfigParser.ParsingError, e: 
     322            raise BadConfigurationFileException( 
     323                    _(u"Wiki configuration file is corrupted")) 
    314324 
    315325        # config variables 
     
    733743 
    734744 
    735     def makeRelUrlAbsolute(self, relurl): 
     745    def makeRelUrlAbsolute(self, relurl, addSafe=''): 
    736746        """ 
    737747        Return the absolute file: URL for a rel: URL 
     
    741751        url = u"file:" + urlFromPathname( 
    742752                os.path.abspath(os.path.join(os.path.dirname( 
    743                         self.getWikiConfigPath()), relpath))) 
     753                        self.getWikiConfigPath()), relpath)), addSafe=addSafe) 
    744754 
    745755        return url 
    746756 
    747757 
    748     def makeAbsPathRelUrl(self, absPath): 
     758    def makeAbsPathRelUrl(self, absPath, addSafe=''): 
    749759        """ 
    750760        Return the rel: URL for an absolute file path or None if 
     
    761771            return None 
    762772 
    763         return u"rel://" + urlFromPathname(relPath) 
     773        return u"rel://" + urlFromPathname(relPath, addSafe=addSafe) 
    764774 
    765775