importfeeds: add relative_to config

This commit is contained in:
Philippe Mongeau 2013-01-22 22:19:20 -05:00
parent a675b907ed
commit ddbae951c0

View file

@ -33,6 +33,7 @@ class ImportFeedsPlugin(BeetsPlugin):
'formats': [],
'm3u_name': u'imported.m3u',
'dir': None,
'relative_to': None,
})
feeds_dir = self.config['dir'].get()
@ -41,6 +42,12 @@ class ImportFeedsPlugin(BeetsPlugin):
if not os.path.exists(syspath(feeds_dir)):
os.makedirs(syspath(feeds_dir))
relative_to = self.config['relative_to'].get()
if relative_to:
self.config['relative_to'] = os.path.expanduser(bytestring_path(relative_to))
else:
self.config['relative_to'] = feeds_dir
def _get_feeds_dir(lib):
"""Given a Library object, return the path to the feeds directory to be
used (either in the library directory or an explicitly configured
@ -77,12 +84,13 @@ def _record_items(lib, basename, items):
"""Records relative paths to the given items for each feed format
"""
feedsdir = config['importfeeds']['dir'].as_filename()
relative_to = config['importfeeds']['relative_to'].as_filename()
formats = config['importfeeds']['formats'].as_str_seq()
paths = []
for item in items:
paths.append(os.path.relpath(
item.path, feedsdir
item.path, relative_to
))
if 'm3u' in formats: