From a35eb0db922367ca5f9b84e86855ea99315f8206 Mon Sep 17 00:00:00 2001 From: j Date: Mon, 19 May 2014 13:09:12 +0200 Subject: [PATCH] filenames --- oml/item/models.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/oml/item/models.py b/oml/item/models.py index 84e4866..cc1c34d 100644 --- a/oml/item/models.py +++ b/oml/item/models.py @@ -474,6 +474,8 @@ class File(db.Model): return os.path.join(prefix, self.path) def move(self): + def format_underscores(string): + return re.sub('^\.|\.$|:|/|\?|<|>', '_', string) prefs = settings.preferences prefix = os.path.join(os.path.expanduser(prefs['libraryPath']), 'Books/') j = self.item.json() @@ -484,12 +486,13 @@ class File(db.Model): author = 'Unknown Author' title = j.get('title', 'Untitled') extension = j['extension'] + if len(title) > 100: title = title[:100] - if author.endswith('.'): - author = author[:-1] + '_' - if author.startswith('.'): - author = '_' + author[1:] + + title = format_underscores(title) + author = format_underscores(author) + filename = '%s.%s' % (title, extension) new_path = os.path.join(author[0].upper(), author, filename) if self.path == new_path: