Beispiel #1
0
 def readTMPrefs(self):
     """readTMPrefs reads the textmate preferences file and constructs a python dictionary.
     The keys that are important for latex are as follows:
     latexAutoView = 0
     latexEngine = pdflatex
     latexEngineOptions = "-interaction=nonstopmode -file-line-error-style"
     latexUselatexmk = 0
     latexViewer = Skim
     """
     # ugly as this is it is the only way I have found so far to convert a binary plist file into something
     # decent in Python without requiring the PyObjC module.  I would prefer to use popen but
     # plutil apparently tries to do something to /dev/stdout which causes an error message to be appended
     # to the output.
     #
     plDict = {}
     if haspyobjc:
         plDict = NSDictionary.dictionaryWithContentsOfFile_(
             os.environ["HOME"] + "/Library/Preferences/" +
             TM_PREFERENCE_FILE)
     else:  # TODO remove all this once everyone is on leopard
         os.system("plutil -convert xml1 \"$HOME/Library/Preferences/" +
                   TM_PREFERENCE_FILE + "\" -o /tmp/tmltxprefs1.plist")
         null_tt = "".join([chr(i) for i in range(256)])
         non_printables = null_tt.translate(null_tt, string.printable)
         plist_str = open('/tmp/tmltxprefs1.plist').read()
         plist_str = plist_str.translate(null_tt, non_printables)
         try:
             plDict = plistlib.readPlistFromString(plist_str)
         except:
             print '<p class="error">There was a problem reading the preferences file, continuing with defaults</p>'
         try:
             os.remove("/tmp/tmltxprefs1.plist")
         except:
             print '<p class="error">Problem removing temporary prefs file</p>'
     return plDict
Beispiel #2
0
 def readTMPrefs(self):
     """readTMPrefs reads the textmate preferences file and constructs a python dictionary.
     The keys that are important for latex are as follows:
     latexAutoView = 0
     latexEngine = pdflatex
     latexEngineOptions = "-interaction=nonstopmode -file-line-error-style"
     latexUselatexmk = 0
     latexViewer = Skim
     """
     # ugly as this is it is the only way I have found so far to convert a binary plist file into something
     # decent in Python without requiring the PyObjC module.  I would prefer to use popen but
     # plutil apparently tries to do something to /dev/stdout which causes an error message to be appended
     # to the output.
     #
     plDict = {}
     if haspyobjc:
         plDict = NSDictionary.dictionaryWithContentsOfFile_(os.environ["HOME"]+"/Library/Preferences/" + TM_PREFERENCE_FILE)
     else:   # TODO remove all this once everyone is on leopard
         os.system("plutil -convert xml1 \"$HOME/Library/Preferences/"+TM_PREFERENCE_FILE+"\" -o /tmp/tmltxprefs1.plist")
         null_tt = "".join([chr(i) for i in range(256)])
         non_printables = null_tt.translate(null_tt, string.printable)
         plist_str = open('/tmp/tmltxprefs1.plist').read()
         plist_str = plist_str.translate(null_tt,non_printables)
         try:
             plDict = plistlib.readPlistFromString(plist_str)
         except:
             print '<p class="error">There was a problem reading the preferences file, continuing with defaults</p>'
         try:
             os.remove("/tmp/tmltxprefs1.plist")
         except:
             print '<p class="error">Problem removing temporary prefs file</p>'
     return plDict
Beispiel #3
0
 def readTMPrefs(self):
     """readTMPrefs reads the textmate preferences file and constructs a python dictionary.
     The keys that are important for latex are as follows:
     latexAutoView = 0
     latexEngine = pdflatex
     latexEngineOptions = "-interaction=nonstopmode -file-line-error-style"
     latexUselatexmk = 0
     latexViewer = Skim
     """
     # ugly as this is it is the only way I have found so far to convert a binary plist file into something
     # decent in Python without requiring the PyObjC module.  I would prefer to use popen but
     # plutil apparently tries to do something to /dev/stdout which causes an error message to be appended
     # to the output.
     #
     plDict = {}
     if haspyobjc:
         plDict = Foundation.NSDictionary.dictionaryWithContentsOfFile_(
             os.environ["HOME"] + "/Library/Preferences/com.macromates.textmate.plist"
         )
     else:  # TODO remove all this once everyone is on leopard
         os.system(
             'plutil -convert xml1 "$HOME/Library/Preferences/com.macromates.textmate.plist" -o /tmp/tmltxprefs1.plist'
         )
         plist_str = open("/tmp/tmltxprefs1.plist", "rt").read()
         try:
             # python 2
             null_tt = "".join([chr(i) for i in range(256)])
             non_printables = null_tt.translate(null_tt, string.printable)
             plist_str = plist_str.translate(null_tt, non_printables)
         except TypeError:
             # python 3
             non_printables = [chr(i) for i in range(256) if chr(i) not in string.printable]
             null_tt = dict(zip(non_printables, len(non_printables) * [None]))
             plist_str = plist_str.translate(null_tt)
         try:
             # wrapper around string to make it a file object
             plDict = plistlib.readPlistFromString(plist_str.encode("utf-8"))
         except ZeroDivisionError:
             print('<p class="error">There was a problem reading the preferences file, continuing with defaults</p>')
         try:
             os.remove("/tmp/tmltxprefs1.plist")
         except:
             print('<p class="error">Problem removing temporary prefs file</p>')
     return plDict