automatic cache clean

This commit is contained in:
Mattias Andrée 2012-08-21 19:35:55 +02:00
parent 194ddff8fa
commit c13ce26768
2 changed files with 25 additions and 2 deletions

1
configure vendored
View file

@ -239,7 +239,6 @@ function makeMakefile()
echo echo
echo 'install-cache:' echo 'install-cache:'
echo -en '\t' ; echo 'if [ -d "/var/cache/ponysay" ]; then rm -r "/var/cache/ponysay"; fi'
echo -en '\t' ; echo 'mkdir -p "$(DESTDIR)/var/cache/ponysay/"' echo -en '\t' ; echo 'mkdir -p "$(DESTDIR)/var/cache/ponysay/"'
echo -en '\t' ; echo 'chmod 777 "$(DESTDIR)/var/cache/ponysay/"' echo -en '\t' ; echo 'chmod 777 "$(DESTDIR)/var/cache/ponysay/"'
echo echo

26
ponysay
View file

@ -24,7 +24,7 @@ from subprocess import Popen, PIPE
''' '''
The version of ponysay The version of ponysay
''' '''
VERSION = '2.2' VERSION = '2.3'
''' '''
@ -533,6 +533,8 @@ class Ponysay():
if not linuxvt: if not linuxvt:
return pony return pony
KMS_VERSION = '1'
env_kms = os.environ['PONYSAY_KMS_PALETTE'] if 'PONYSAY_KMS_PALETTE' in os.environ else None env_kms = os.environ['PONYSAY_KMS_PALETTE'] if 'PONYSAY_KMS_PALETTE' in os.environ else None
if env_kms is None: env_kms = '' if env_kms is None: env_kms = ''
@ -554,6 +556,28 @@ class Ponysay():
if not os.path.isdir(cachedir): if not os.path.isdir(cachedir):
os.makedirs(cachedir) os.makedirs(cachedir)
newversion = False
if not os.path.isfile(cachedir + '/.version'):
newversion = True
else:
cachev = None
try:
cachev = open(cachedir + '/.version', 'r')
if ''.join(cachev.readlines()) == KMS_VERSION:
newversion = True
finally:
if cachev is not None:
cachev.close()
if newversion:
for cached in os.listdir(ponydir):
shutil.rmtree(cachedir + '/' + cached, False)
try:
cachev = open(cachedir + '/.version', 'w+')
cachev.write(KMS_VERSION)
finally:
if cachev is not None:
cachev.close()
kmsponies = cachedir + '/kmsponies/' + palettefile kmsponies = cachedir + '/kmsponies/' + palettefile
kmspony = (kmsponies + pony).replace('//', '/') kmspony = (kmsponies + pony).replace('//', '/')