From 7118f4be2715a30a8446cc609e0f72dabc5bd973 Mon Sep 17 00:00:00 2001 From: Erik van Blokland Date: Tue, 18 Oct 2011 21:07:55 +0000 Subject: [PATCH] RFPrefs module is ancient. toolsRF is empty. Both can go. git-svn-id: http://svn.robofab.com/branches/ufo3k@423 b5fa9d6c-a76f-4ffd-b3cb-f825fc41095c --- Lib/robofab/tools/rfPrefs.py | 122 ----------------------------------- Lib/robofab/tools/toolsRF.py | 6 -- 2 files changed, 128 deletions(-) delete mode 100755 Lib/robofab/tools/rfPrefs.py delete mode 100755 Lib/robofab/tools/toolsRF.py diff --git a/Lib/robofab/tools/rfPrefs.py b/Lib/robofab/tools/rfPrefs.py deleted file mode 100755 index 440984d0d..000000000 --- a/Lib/robofab/tools/rfPrefs.py +++ /dev/null @@ -1,122 +0,0 @@ -"""A simple module for dealing with preferences that are used by scripts. Based almost entirely on MacPrefs. - -To save some preferences: -myPrefs = RFPrefs(drive/directory/directory/myPrefs.plist) -myPrefs.myString = 'xyz' -myPrefs.myInteger = 1234 -myPrefs.myList = ['a', 'b', 'c'] -myPrefs.myDict = {'a':1, 'b':2} -myPrefs.save() - -To retrieve some preferences: -myPrefs = RFPrefs(drive/directory/directory/myPrefs.plist) -myString = myPrefs.myString -myInteger = myPrefs.myInteger -myList = myPrefs.myList -myDict = myPrefs.myDict - -When using this module within FontLab, it is not necessary to -provide the RFPrefs class with a path. If a path is not given, -it will look for a file in FontLab/RoboFab Data/RFPrefs.plist. -If that file does not exist, it will make it. -""" - -from robofab import RoboFabError -from robofab.plistlib import Plist -from cStringIO import StringIO -import os - -class _PrefObject: - - def __init__(self, dict=None): - if not dict: - self._prefs = {} - else: - self._prefs = dict - - def __len__(self): - return len(self._prefs) - - def __delattr__(self, attr): - if self._prefs.has_key(attr): - del self._prefs[attr] - else: - raise AttributeError, 'delete non-existing instance attribute' - - def __getattr__(self, attr): - if attr == '__members__': - keys = self._prefs.keys() - keys.sort() - return keys - try: - return self._prefs[attr] - except KeyError: - raise AttributeError, attr - - def __setattr__(self, attr, value): - if attr[0] != '_': - self._prefs[attr] = value - else: - self.__dict__[attr] = value - - def asDict(self): - return self._prefs - -class RFPrefs(_PrefObject): - - """The main preferences object to call""" - - def __init__(self, path=None): - from robofab.world import world - self.__path = path - self._prefs = {} - if world.inFontLab: - #we don't have a path, but we know where we can put it - if not path: - from robofab.tools.toolsFL import makeDataFolder - settingsPath = makeDataFolder() - path = os.path.join(settingsPath, 'RFPrefs.plist') - self.__path = path - self._makePrefsFile() - #we do have a path, make sure it exists and load it - else: - self._makePrefsFile() - else: - #no path, raise error - if not path: - raise RoboFabError, "no preferences path defined" - #we do have a path, make sure it exists and load it - else: - self._makePrefsFile() - self._prefs = Plist.fromFile(path) - - def _makePrefsFile(self): - if not os.path.exists(self.__path): - self.save() - - def __getattr__(self, attr): - if attr[0] == '__members__': - keys = self._prefs.keys() - keys.sort() - return keys - try: - return self._prefs[attr] - except KeyError: - raise AttributeError, attr - #if attr[0] != '_': - # self._prefs[attr] = _PrefObject() - # return self._prefs[attr] - #else: - # raise AttributeError, attr - - def save(self): - """save the plist file""" - f = StringIO() - pl = Plist() - for i in self._prefs.keys(): - pl[i] = self._prefs[i] - pl.write(f) - data = f.getvalue() - f = open(self.__path, 'wb') - f.write(data) - f.close() diff --git a/Lib/robofab/tools/toolsRF.py b/Lib/robofab/tools/toolsRF.py deleted file mode 100755 index 01624c5ad..000000000 --- a/Lib/robofab/tools/toolsRF.py +++ /dev/null @@ -1,6 +0,0 @@ -""" - -Module for rf specific tool like code. - -""" -