Merge branch 'release-0.4'

merges hotfix
This commit is contained in:
boyska 2016-12-11 02:37:01 +01:00
commit 8aebeae560
No known key found for this signature in database
GPG key ID: 7395DCAE58289CA9
5 changed files with 41 additions and 3 deletions

View file

@ -60,9 +60,9 @@ copyright = '2015-2016, boyska'
# built documents.
#
# The short X.Y version.
version = '0.4'
version = '0.4.2'
# The full version, including alpha/beta/rc tags.
release = '0.4'
release = '0.4.2'
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.

View file

@ -27,6 +27,7 @@ def get_conf(prefix='LARIGIRA_'):
conf['EVENT_TICK_SECS'] = 30 # period for scheduling events
conf['DEBUG'] = False
conf['LOG_CONFIG'] = False
conf['TMPDIR'] = os.getenv('TMPDIR', '/tmp/')
conf.update(from_envvars(prefix=prefix))
return conf

31
larigira/test_unused.py Normal file
View file

@ -0,0 +1,31 @@
import pytest
from .unused import UnusedCleaner
from .config import get_conf
@pytest.fixture
def unusedcleaner():
return UnusedCleaner(get_conf(prefix='LARIGIRATEST_'))
# this test suite heavily assumes that TMPDIR == /tmp/, which is the default
# indeed. However, the code does not rely on this assumption.
def test_watch_file(unusedcleaner):
# despite not existing, the file is added
unusedcleaner.watch('file:///tmp/gnam')
assert len(unusedcleaner.waiting_removal_files) == 1
assert list(unusedcleaner.waiting_removal_files)[0] == '/tmp/gnam'
def test_watch_path_error(unusedcleaner):
'''paths are not valid thing to watch. URIs only, thanks'''
unusedcleaner.watch('/tmp/foo')
assert len(unusedcleaner.waiting_removal_files) == 0
def test_watch_notmp_error(unusedcleaner):
'''Files not in TMPDIR are not added'''
unusedcleaner.watch('file:///not/in/tmp')
assert len(unusedcleaner.waiting_removal_files) == 0

View file

@ -5,6 +5,7 @@ This component will look for files to be removed. There are some assumptions:
* MPD URIs are parsed, and only file:/// is supported
'''
import os
from os.path import commonpath, normpath
import logging
import mpd
@ -29,6 +30,11 @@ class UnusedCleaner:
if not uri.startswith('file:///'):
return # not a file URI
fpath = uri[len('file://'):]
if 'TMPDIR' in self.conf and self.conf['TMPDIR'] \
and commonpath([self.conf['TMPDIR'], fpath]) != \
normpath(self.conf['TMPDIR']):
self.log.info('Not watching file {}: not in TMPDIR'.format(fpath))
return
if not os.path.exists(fpath):
self.log.warning('a path that does not exist is being monitored')
self.waiting_removal_files.add(fpath)

View file

@ -29,7 +29,7 @@ class PyTest(TestCommand):
sys.exit(errno)
setup(name='larigira',
version='0.4',
version='0.4.2',
description='A radio automation based on MPD',
long_description=read('README.rst'),
author='boyska',