ponysay.py: Converted methods which are never called on an instances to class methods.

This commit is contained in:
Michael Schwarz 2014-08-24 18:25:33 +02:00
parent 45b53d6eb0
commit b2e597fdc2

View file

@ -58,7 +58,7 @@ class Ponysay():
## Load extension and configurations via ponysayrc ## Load extension and configurations via ponysayrc
for file in ('$XDG_CONFIG_HOME/ponysay/ponysayrc', '$HOME/.config/ponysay/ponysayrc', '$HOME/.ponysayrc', '/etc/ponysayrc'): for file in ('$XDG_CONFIG_HOME/ponysay/ponysayrc', '$HOME/.config/ponysay/ponysayrc', '$HOME/.ponysayrc', '/etc/ponysayrc'):
file = Ponysay.__parseFile(file) file = self.__parseFile(file)
if (file is not None) and os.path.exists(file): if (file is not None) and os.path.exists(file):
with open(file, 'rb') as ponysayrc: with open(file, 'rb') as ponysayrc:
code = ponysayrc.read().decode('utf8', 'replace') + '\n' code = ponysayrc.read().decode('utf8', 'replace') + '\n'
@ -80,7 +80,7 @@ class Ponysay():
self.linuxvt = ('TERM' in os.environ) and (os.environ['TERM'] == 'linux') self.linuxvt = ('TERM' in os.environ) and (os.environ['TERM'] == 'linux')
# Whether the script is executed as ponythink # Whether the script is executed as ponythink
self.isthink = Ponysay.__isPonythink() self.isthink = self.__isPonythink()
# Whether stdin is piped # Whether stdin is piped
@ -102,24 +102,25 @@ class Ponysay():
# The directories where pony files are stored, ttyponies/ are used if the terminal is Linux VT (also known as TTY) and not with KMS # The directories where pony files are stored, ttyponies/ are used if the terminal is Linux VT (also known as TTY) and not with KMS
self.xponydirs = Ponysay.__getShareDirectories('ponies/') self.xponydirs = self.__getShareDirectories('ponies/')
self.vtponydirs = Ponysay.__getShareDirectories('ttyponies/') self.vtponydirs = self.__getShareDirectories('ttyponies/')
# The directories where pony files are stored, extrattyponies/ are used if the terminal is Linux VT (also known as TTY) and not with KMS # The directories where pony files are stored, extrattyponies/ are used if the terminal is Linux VT (also known as TTY) and not with KMS
self.extraxponydirs = Ponysay.__getShareDirectories('extraponies/') self.extraxponydirs = self.__getShareDirectories('extraponies/')
self.extravtponydirs = Ponysay.__getShareDirectories('extrattyponies/') self.extravtponydirs = self.__getShareDirectories('extrattyponies/')
# The directories where quotes files are stored # The directories where quotes files are stored
self.quotedirs = Ponysay.__getShareDirectories('quotes/') self.quotedirs = self.__getShareDirectories('quotes/')
# The directories where balloon style files are stored # The directories where balloon style files are stored
self.balloondirs = Ponysay.__getShareDirectories('balloons/') self.balloondirs = self.__getShareDirectories('balloons/')
# ucsmap files # ucsmap files
self.ucsmaps = Ponysay.__getShareDirectories('ucsmap/') self.ucsmaps = self.__getShareDirectories('ucsmap/')
def __parseFile(file): @classmethod
def __parseFile(cls, file):
''' '''
Parse a file name encoded with environment variables Parse a file name encoded with environment variables
@ -153,7 +154,8 @@ class Ponysay():
return file return file
def __getShareDirectories(directory): @classmethod
def __getShareDirectories(cls, directory):
''' '''
Gets existing unique /share directories Gets existing unique /share directories
@ -162,7 +164,7 @@ class Ponysay():
''' '''
appendset = set() appendset = set()
rc = [] rc = []
_ponydirs = Ponysay.__share(directory) _ponydirs = cls.__share(directory)
for ponydir in _ponydirs: for ponydir in _ponydirs:
if (ponydir is not None) and os.path.isdir(ponydir) and (ponydir not in appendset): if (ponydir is not None) and os.path.isdir(ponydir) and (ponydir not in appendset):
rc.append(ponydir) rc.append(ponydir)
@ -170,7 +172,8 @@ class Ponysay():
return rc return rc
def __share(file): @classmethod
def __share(cls, file):
''' '''
Gets /share files Gets /share files
@ -182,14 +185,15 @@ class Ponysay():
return None return None
return a + b return a + b
# TODO use only ./ in development mode # TODO use only ./ in development mode
return [cat(Ponysay.__parseFile(item), file) for item in [ return [cat(cls.__parseFile(item), file) for item in [
'$XDG_DATA_HOME/ponysay/', '$XDG_DATA_HOME/ponysay/',
'$HOME/.local/share/ponysay/', '$HOME/.local/share/ponysay/',
'/usr/share/ponysay/' '/usr/share/ponysay/'
]] ]]
def __isPonythink(): @classmethod
def __isPonythink(cls):
''' '''
Check if ponythink is executed Check if ponythink is executed
''' '''