From 4820293f900cc7eba1cbc44f6dcf0fcbb301d298 Mon Sep 17 00:00:00 2001 From: Louis Date: Thu, 5 Nov 2015 13:21:12 +0100 Subject: [PATCH 01/19] Improve get_subdirs signature --- patacrep/songs/__init__.py | 10 +++++----- patacrep/songs/chordpro/__init__.py | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/patacrep/songs/__init__.py b/patacrep/songs/__init__.py index 129c8045..f2f5f6c9 100644 --- a/patacrep/songs/__init__.py +++ b/patacrep/songs/__init__.py @@ -192,11 +192,11 @@ class Song: """ raise NotImplementedError() - def get_datadirs(self, subdir=None): - """Return an iterator of existing datadirs (with eventually a subdir) + def iter_datadirs(self, *subpath): + """Return an iterator of existing datadirs (with an optionnal subpath) """ for directory in self.config['datadir']: - fullpath = os.path.join(directory, subdir) + fullpath = os.path.join(directory, *subpath) if os.path.isdir(fullpath): yield fullpath @@ -255,7 +255,7 @@ class Song: return self.search_file( filename, ['', '.jpg', '.png'], - datadirs=self.get_datadirs('img'), + datadirs=self.iter_datadirs('img'), ) def search_partition(self, filename): @@ -263,7 +263,7 @@ class Song: return self.search_file( filename, ['', '.ly'], - datadirs=self.get_datadirs('scores'), + datadirs=self.iter_datadirs('scores'), ) def unprefixed_title(title, prefixes): diff --git a/patacrep/songs/chordpro/__init__.py b/patacrep/songs/chordpro/__init__.py index 513977f6..ce688379 100644 --- a/patacrep/songs/chordpro/__init__.py +++ b/patacrep/songs/chordpro/__init__.py @@ -50,7 +50,7 @@ class ChordproSong(Song): jinjaenv = Environment(loader=ChoiceLoader([ FileSystemLoader( - self.get_datadirs(os.path.join("templates", self.output_language)) + self.iter_datadirs("templates", self.output_language) ), FileSystemLoader( pkg_datapath('ast_templates', 'chordpro', self.output_language) From e835beedb5b27d234086dde712ce1d9b3c52ab1b Mon Sep 17 00:00:00 2001 From: Louis Date: Thu, 5 Nov 2015 13:38:27 +0100 Subject: [PATCH 02/19] Move templates used ir chordpro conversion Closer #150 --- .../chordpro/chordpro/content_chord | 0 .../chordpro/chordpro/content_chordlist | 0 .../chordpro/chordpro/content_comment | 0 .../chordpro/chordpro/content_define | 0 .../chordpro/chordpro/content_endofline | 0 .../chordpro/chordpro/content_error | 0 .../chordpro/chordpro/content_guitar_comment | 0 .../chordpro/chordpro/content_image | 0 .../chordpro/chordpro/content_line | 0 .../chordpro/chordpro/content_newline | 0 .../chordpro/chordpro/content_partition | 0 .../chordpro/chordpro/content_space | 0 .../chordpro/chordpro/content_tablature | 0 .../chordpro/chordpro/content_verse | 0 .../chordpro/chordpro/content_word | 0 .../data/{ast_templates => }/chordpro/chordpro/song | 0 .../{ast_templates => }/chordpro/chordpro/song_body | 0 .../{ast_templates => }/chordpro/chordpro/song_header | 0 .../{ast_templates => }/chordpro/html/content_chord | 0 .../chordpro/html/content_chordlist | 0 .../{ast_templates => }/chordpro/html/content_comment | 0 .../{ast_templates => }/chordpro/html/content_define | 0 .../chordpro/html/content_define_list | 0 .../chordpro/html/content_endofline | 0 .../{ast_templates => }/chordpro/html/content_error | 0 .../chordpro/html/content_guitar_comment | 0 .../{ast_templates => }/chordpro/html/content_image | 0 .../{ast_templates => }/chordpro/html/content_line | 0 .../chordpro/html/content_metadata_cover | 0 .../{ast_templates => }/chordpro/html/content_newline | 0 .../chordpro/html/content_partition | 0 .../{ast_templates => }/chordpro/html/content_space | 0 .../chordpro/html/content_tablature | 0 .../{ast_templates => }/chordpro/html/content_verse | 0 .../{ast_templates => }/chordpro/html/content_word | 0 patacrep/data/{ast_templates => }/chordpro/html/song | 0 .../data/{ast_templates => }/chordpro/html/song_body | 0 .../{ast_templates => }/chordpro/html/song_header | 0 .../{ast_templates => }/chordpro/latex/content_chord | 0 .../chordpro/latex/content_chordlist | 0 .../chordpro/latex/content_comment | 0 .../{ast_templates => }/chordpro/latex/content_define | 0 .../chordpro/latex/content_endofline | 0 .../{ast_templates => }/chordpro/latex/content_error | 0 .../chordpro/latex/content_guitar_comment | 0 .../{ast_templates => }/chordpro/latex/content_image | 0 .../{ast_templates => }/chordpro/latex/content_line | 0 .../chordpro/latex/content_newline | 0 .../chordpro/latex/content_partition | 0 .../{ast_templates => }/chordpro/latex/content_space | 0 .../chordpro/latex/content_tablature | 0 .../{ast_templates => }/chordpro/latex/content_verse | 0 .../{ast_templates => }/chordpro/latex/content_word | 0 patacrep/data/{ast_templates => }/chordpro/latex/song | 0 .../data/{ast_templates => }/chordpro/latex/song_body | 0 patacrep/songs/chordpro/__init__.py | 11 +++-------- test/test_chordpro/test_parser.py | 3 ++- 57 files changed, 5 insertions(+), 9 deletions(-) rename patacrep/data/{ast_templates => }/chordpro/chordpro/content_chord (100%) rename patacrep/data/{ast_templates => }/chordpro/chordpro/content_chordlist (100%) rename patacrep/data/{ast_templates => }/chordpro/chordpro/content_comment (100%) rename patacrep/data/{ast_templates => }/chordpro/chordpro/content_define (100%) rename patacrep/data/{ast_templates => }/chordpro/chordpro/content_endofline (100%) rename patacrep/data/{ast_templates => }/chordpro/chordpro/content_error (100%) rename patacrep/data/{ast_templates => }/chordpro/chordpro/content_guitar_comment (100%) rename patacrep/data/{ast_templates => }/chordpro/chordpro/content_image (100%) rename patacrep/data/{ast_templates => }/chordpro/chordpro/content_line (100%) rename patacrep/data/{ast_templates => }/chordpro/chordpro/content_newline (100%) rename patacrep/data/{ast_templates => }/chordpro/chordpro/content_partition (100%) rename patacrep/data/{ast_templates => }/chordpro/chordpro/content_space (100%) rename patacrep/data/{ast_templates => }/chordpro/chordpro/content_tablature (100%) rename patacrep/data/{ast_templates => }/chordpro/chordpro/content_verse (100%) rename patacrep/data/{ast_templates => }/chordpro/chordpro/content_word (100%) rename patacrep/data/{ast_templates => }/chordpro/chordpro/song (100%) rename patacrep/data/{ast_templates => }/chordpro/chordpro/song_body (100%) rename patacrep/data/{ast_templates => }/chordpro/chordpro/song_header (100%) rename patacrep/data/{ast_templates => }/chordpro/html/content_chord (100%) rename patacrep/data/{ast_templates => }/chordpro/html/content_chordlist (100%) rename patacrep/data/{ast_templates => }/chordpro/html/content_comment (100%) rename patacrep/data/{ast_templates => }/chordpro/html/content_define (100%) rename patacrep/data/{ast_templates => }/chordpro/html/content_define_list (100%) rename patacrep/data/{ast_templates => }/chordpro/html/content_endofline (100%) rename patacrep/data/{ast_templates => }/chordpro/html/content_error (100%) rename patacrep/data/{ast_templates => }/chordpro/html/content_guitar_comment (100%) rename patacrep/data/{ast_templates => }/chordpro/html/content_image (100%) rename patacrep/data/{ast_templates => }/chordpro/html/content_line (100%) rename patacrep/data/{ast_templates => }/chordpro/html/content_metadata_cover (100%) rename patacrep/data/{ast_templates => }/chordpro/html/content_newline (100%) rename patacrep/data/{ast_templates => }/chordpro/html/content_partition (100%) rename patacrep/data/{ast_templates => }/chordpro/html/content_space (100%) rename patacrep/data/{ast_templates => }/chordpro/html/content_tablature (100%) rename patacrep/data/{ast_templates => }/chordpro/html/content_verse (100%) rename patacrep/data/{ast_templates => }/chordpro/html/content_word (100%) rename patacrep/data/{ast_templates => }/chordpro/html/song (100%) rename patacrep/data/{ast_templates => }/chordpro/html/song_body (100%) rename patacrep/data/{ast_templates => }/chordpro/html/song_header (100%) rename patacrep/data/{ast_templates => }/chordpro/latex/content_chord (100%) rename patacrep/data/{ast_templates => }/chordpro/latex/content_chordlist (100%) rename patacrep/data/{ast_templates => }/chordpro/latex/content_comment (100%) rename patacrep/data/{ast_templates => }/chordpro/latex/content_define (100%) rename patacrep/data/{ast_templates => }/chordpro/latex/content_endofline (100%) rename patacrep/data/{ast_templates => }/chordpro/latex/content_error (100%) rename patacrep/data/{ast_templates => }/chordpro/latex/content_guitar_comment (100%) rename patacrep/data/{ast_templates => }/chordpro/latex/content_image (100%) rename patacrep/data/{ast_templates => }/chordpro/latex/content_line (100%) rename patacrep/data/{ast_templates => }/chordpro/latex/content_newline (100%) rename patacrep/data/{ast_templates => }/chordpro/latex/content_partition (100%) rename patacrep/data/{ast_templates => }/chordpro/latex/content_space (100%) rename patacrep/data/{ast_templates => }/chordpro/latex/content_tablature (100%) rename patacrep/data/{ast_templates => }/chordpro/latex/content_verse (100%) rename patacrep/data/{ast_templates => }/chordpro/latex/content_word (100%) rename patacrep/data/{ast_templates => }/chordpro/latex/song (100%) rename patacrep/data/{ast_templates => }/chordpro/latex/song_body (100%) diff --git a/patacrep/data/ast_templates/chordpro/chordpro/content_chord b/patacrep/data/chordpro/chordpro/content_chord similarity index 100% rename from patacrep/data/ast_templates/chordpro/chordpro/content_chord rename to patacrep/data/chordpro/chordpro/content_chord diff --git a/patacrep/data/ast_templates/chordpro/chordpro/content_chordlist b/patacrep/data/chordpro/chordpro/content_chordlist similarity index 100% rename from patacrep/data/ast_templates/chordpro/chordpro/content_chordlist rename to patacrep/data/chordpro/chordpro/content_chordlist diff --git a/patacrep/data/ast_templates/chordpro/chordpro/content_comment b/patacrep/data/chordpro/chordpro/content_comment similarity index 100% rename from patacrep/data/ast_templates/chordpro/chordpro/content_comment rename to patacrep/data/chordpro/chordpro/content_comment diff --git a/patacrep/data/ast_templates/chordpro/chordpro/content_define b/patacrep/data/chordpro/chordpro/content_define similarity index 100% rename from patacrep/data/ast_templates/chordpro/chordpro/content_define rename to patacrep/data/chordpro/chordpro/content_define diff --git a/patacrep/data/ast_templates/chordpro/chordpro/content_endofline b/patacrep/data/chordpro/chordpro/content_endofline similarity index 100% rename from patacrep/data/ast_templates/chordpro/chordpro/content_endofline rename to patacrep/data/chordpro/chordpro/content_endofline diff --git a/patacrep/data/ast_templates/chordpro/chordpro/content_error b/patacrep/data/chordpro/chordpro/content_error similarity index 100% rename from patacrep/data/ast_templates/chordpro/chordpro/content_error rename to patacrep/data/chordpro/chordpro/content_error diff --git a/patacrep/data/ast_templates/chordpro/chordpro/content_guitar_comment b/patacrep/data/chordpro/chordpro/content_guitar_comment similarity index 100% rename from patacrep/data/ast_templates/chordpro/chordpro/content_guitar_comment rename to patacrep/data/chordpro/chordpro/content_guitar_comment diff --git a/patacrep/data/ast_templates/chordpro/chordpro/content_image b/patacrep/data/chordpro/chordpro/content_image similarity index 100% rename from patacrep/data/ast_templates/chordpro/chordpro/content_image rename to patacrep/data/chordpro/chordpro/content_image diff --git a/patacrep/data/ast_templates/chordpro/chordpro/content_line b/patacrep/data/chordpro/chordpro/content_line similarity index 100% rename from patacrep/data/ast_templates/chordpro/chordpro/content_line rename to patacrep/data/chordpro/chordpro/content_line diff --git a/patacrep/data/ast_templates/chordpro/chordpro/content_newline b/patacrep/data/chordpro/chordpro/content_newline similarity index 100% rename from patacrep/data/ast_templates/chordpro/chordpro/content_newline rename to patacrep/data/chordpro/chordpro/content_newline diff --git a/patacrep/data/ast_templates/chordpro/chordpro/content_partition b/patacrep/data/chordpro/chordpro/content_partition similarity index 100% rename from patacrep/data/ast_templates/chordpro/chordpro/content_partition rename to patacrep/data/chordpro/chordpro/content_partition diff --git a/patacrep/data/ast_templates/chordpro/chordpro/content_space b/patacrep/data/chordpro/chordpro/content_space similarity index 100% rename from patacrep/data/ast_templates/chordpro/chordpro/content_space rename to patacrep/data/chordpro/chordpro/content_space diff --git a/patacrep/data/ast_templates/chordpro/chordpro/content_tablature b/patacrep/data/chordpro/chordpro/content_tablature similarity index 100% rename from patacrep/data/ast_templates/chordpro/chordpro/content_tablature rename to patacrep/data/chordpro/chordpro/content_tablature diff --git a/patacrep/data/ast_templates/chordpro/chordpro/content_verse b/patacrep/data/chordpro/chordpro/content_verse similarity index 100% rename from patacrep/data/ast_templates/chordpro/chordpro/content_verse rename to patacrep/data/chordpro/chordpro/content_verse diff --git a/patacrep/data/ast_templates/chordpro/chordpro/content_word b/patacrep/data/chordpro/chordpro/content_word similarity index 100% rename from patacrep/data/ast_templates/chordpro/chordpro/content_word rename to patacrep/data/chordpro/chordpro/content_word diff --git a/patacrep/data/ast_templates/chordpro/chordpro/song b/patacrep/data/chordpro/chordpro/song similarity index 100% rename from patacrep/data/ast_templates/chordpro/chordpro/song rename to patacrep/data/chordpro/chordpro/song diff --git a/patacrep/data/ast_templates/chordpro/chordpro/song_body b/patacrep/data/chordpro/chordpro/song_body similarity index 100% rename from patacrep/data/ast_templates/chordpro/chordpro/song_body rename to patacrep/data/chordpro/chordpro/song_body diff --git a/patacrep/data/ast_templates/chordpro/chordpro/song_header b/patacrep/data/chordpro/chordpro/song_header similarity index 100% rename from patacrep/data/ast_templates/chordpro/chordpro/song_header rename to patacrep/data/chordpro/chordpro/song_header diff --git a/patacrep/data/ast_templates/chordpro/html/content_chord b/patacrep/data/chordpro/html/content_chord similarity index 100% rename from patacrep/data/ast_templates/chordpro/html/content_chord rename to patacrep/data/chordpro/html/content_chord diff --git a/patacrep/data/ast_templates/chordpro/html/content_chordlist b/patacrep/data/chordpro/html/content_chordlist similarity index 100% rename from patacrep/data/ast_templates/chordpro/html/content_chordlist rename to patacrep/data/chordpro/html/content_chordlist diff --git a/patacrep/data/ast_templates/chordpro/html/content_comment b/patacrep/data/chordpro/html/content_comment similarity index 100% rename from patacrep/data/ast_templates/chordpro/html/content_comment rename to patacrep/data/chordpro/html/content_comment diff --git a/patacrep/data/ast_templates/chordpro/html/content_define b/patacrep/data/chordpro/html/content_define similarity index 100% rename from patacrep/data/ast_templates/chordpro/html/content_define rename to patacrep/data/chordpro/html/content_define diff --git a/patacrep/data/ast_templates/chordpro/html/content_define_list b/patacrep/data/chordpro/html/content_define_list similarity index 100% rename from patacrep/data/ast_templates/chordpro/html/content_define_list rename to patacrep/data/chordpro/html/content_define_list diff --git a/patacrep/data/ast_templates/chordpro/html/content_endofline b/patacrep/data/chordpro/html/content_endofline similarity index 100% rename from patacrep/data/ast_templates/chordpro/html/content_endofline rename to patacrep/data/chordpro/html/content_endofline diff --git a/patacrep/data/ast_templates/chordpro/html/content_error b/patacrep/data/chordpro/html/content_error similarity index 100% rename from patacrep/data/ast_templates/chordpro/html/content_error rename to patacrep/data/chordpro/html/content_error diff --git a/patacrep/data/ast_templates/chordpro/html/content_guitar_comment b/patacrep/data/chordpro/html/content_guitar_comment similarity index 100% rename from patacrep/data/ast_templates/chordpro/html/content_guitar_comment rename to patacrep/data/chordpro/html/content_guitar_comment diff --git a/patacrep/data/ast_templates/chordpro/html/content_image b/patacrep/data/chordpro/html/content_image similarity index 100% rename from patacrep/data/ast_templates/chordpro/html/content_image rename to patacrep/data/chordpro/html/content_image diff --git a/patacrep/data/ast_templates/chordpro/html/content_line b/patacrep/data/chordpro/html/content_line similarity index 100% rename from patacrep/data/ast_templates/chordpro/html/content_line rename to patacrep/data/chordpro/html/content_line diff --git a/patacrep/data/ast_templates/chordpro/html/content_metadata_cover b/patacrep/data/chordpro/html/content_metadata_cover similarity index 100% rename from patacrep/data/ast_templates/chordpro/html/content_metadata_cover rename to patacrep/data/chordpro/html/content_metadata_cover diff --git a/patacrep/data/ast_templates/chordpro/html/content_newline b/patacrep/data/chordpro/html/content_newline similarity index 100% rename from patacrep/data/ast_templates/chordpro/html/content_newline rename to patacrep/data/chordpro/html/content_newline diff --git a/patacrep/data/ast_templates/chordpro/html/content_partition b/patacrep/data/chordpro/html/content_partition similarity index 100% rename from patacrep/data/ast_templates/chordpro/html/content_partition rename to patacrep/data/chordpro/html/content_partition diff --git a/patacrep/data/ast_templates/chordpro/html/content_space b/patacrep/data/chordpro/html/content_space similarity index 100% rename from patacrep/data/ast_templates/chordpro/html/content_space rename to patacrep/data/chordpro/html/content_space diff --git a/patacrep/data/ast_templates/chordpro/html/content_tablature b/patacrep/data/chordpro/html/content_tablature similarity index 100% rename from patacrep/data/ast_templates/chordpro/html/content_tablature rename to patacrep/data/chordpro/html/content_tablature diff --git a/patacrep/data/ast_templates/chordpro/html/content_verse b/patacrep/data/chordpro/html/content_verse similarity index 100% rename from patacrep/data/ast_templates/chordpro/html/content_verse rename to patacrep/data/chordpro/html/content_verse diff --git a/patacrep/data/ast_templates/chordpro/html/content_word b/patacrep/data/chordpro/html/content_word similarity index 100% rename from patacrep/data/ast_templates/chordpro/html/content_word rename to patacrep/data/chordpro/html/content_word diff --git a/patacrep/data/ast_templates/chordpro/html/song b/patacrep/data/chordpro/html/song similarity index 100% rename from patacrep/data/ast_templates/chordpro/html/song rename to patacrep/data/chordpro/html/song diff --git a/patacrep/data/ast_templates/chordpro/html/song_body b/patacrep/data/chordpro/html/song_body similarity index 100% rename from patacrep/data/ast_templates/chordpro/html/song_body rename to patacrep/data/chordpro/html/song_body diff --git a/patacrep/data/ast_templates/chordpro/html/song_header b/patacrep/data/chordpro/html/song_header similarity index 100% rename from patacrep/data/ast_templates/chordpro/html/song_header rename to patacrep/data/chordpro/html/song_header diff --git a/patacrep/data/ast_templates/chordpro/latex/content_chord b/patacrep/data/chordpro/latex/content_chord similarity index 100% rename from patacrep/data/ast_templates/chordpro/latex/content_chord rename to patacrep/data/chordpro/latex/content_chord diff --git a/patacrep/data/ast_templates/chordpro/latex/content_chordlist b/patacrep/data/chordpro/latex/content_chordlist similarity index 100% rename from patacrep/data/ast_templates/chordpro/latex/content_chordlist rename to patacrep/data/chordpro/latex/content_chordlist diff --git a/patacrep/data/ast_templates/chordpro/latex/content_comment b/patacrep/data/chordpro/latex/content_comment similarity index 100% rename from patacrep/data/ast_templates/chordpro/latex/content_comment rename to patacrep/data/chordpro/latex/content_comment diff --git a/patacrep/data/ast_templates/chordpro/latex/content_define b/patacrep/data/chordpro/latex/content_define similarity index 100% rename from patacrep/data/ast_templates/chordpro/latex/content_define rename to patacrep/data/chordpro/latex/content_define diff --git a/patacrep/data/ast_templates/chordpro/latex/content_endofline b/patacrep/data/chordpro/latex/content_endofline similarity index 100% rename from patacrep/data/ast_templates/chordpro/latex/content_endofline rename to patacrep/data/chordpro/latex/content_endofline diff --git a/patacrep/data/ast_templates/chordpro/latex/content_error b/patacrep/data/chordpro/latex/content_error similarity index 100% rename from patacrep/data/ast_templates/chordpro/latex/content_error rename to patacrep/data/chordpro/latex/content_error diff --git a/patacrep/data/ast_templates/chordpro/latex/content_guitar_comment b/patacrep/data/chordpro/latex/content_guitar_comment similarity index 100% rename from patacrep/data/ast_templates/chordpro/latex/content_guitar_comment rename to patacrep/data/chordpro/latex/content_guitar_comment diff --git a/patacrep/data/ast_templates/chordpro/latex/content_image b/patacrep/data/chordpro/latex/content_image similarity index 100% rename from patacrep/data/ast_templates/chordpro/latex/content_image rename to patacrep/data/chordpro/latex/content_image diff --git a/patacrep/data/ast_templates/chordpro/latex/content_line b/patacrep/data/chordpro/latex/content_line similarity index 100% rename from patacrep/data/ast_templates/chordpro/latex/content_line rename to patacrep/data/chordpro/latex/content_line diff --git a/patacrep/data/ast_templates/chordpro/latex/content_newline b/patacrep/data/chordpro/latex/content_newline similarity index 100% rename from patacrep/data/ast_templates/chordpro/latex/content_newline rename to patacrep/data/chordpro/latex/content_newline diff --git a/patacrep/data/ast_templates/chordpro/latex/content_partition b/patacrep/data/chordpro/latex/content_partition similarity index 100% rename from patacrep/data/ast_templates/chordpro/latex/content_partition rename to patacrep/data/chordpro/latex/content_partition diff --git a/patacrep/data/ast_templates/chordpro/latex/content_space b/patacrep/data/chordpro/latex/content_space similarity index 100% rename from patacrep/data/ast_templates/chordpro/latex/content_space rename to patacrep/data/chordpro/latex/content_space diff --git a/patacrep/data/ast_templates/chordpro/latex/content_tablature b/patacrep/data/chordpro/latex/content_tablature similarity index 100% rename from patacrep/data/ast_templates/chordpro/latex/content_tablature rename to patacrep/data/chordpro/latex/content_tablature diff --git a/patacrep/data/ast_templates/chordpro/latex/content_verse b/patacrep/data/chordpro/latex/content_verse similarity index 100% rename from patacrep/data/ast_templates/chordpro/latex/content_verse rename to patacrep/data/chordpro/latex/content_verse diff --git a/patacrep/data/ast_templates/chordpro/latex/content_word b/patacrep/data/chordpro/latex/content_word similarity index 100% rename from patacrep/data/ast_templates/chordpro/latex/content_word rename to patacrep/data/chordpro/latex/content_word diff --git a/patacrep/data/ast_templates/chordpro/latex/song b/patacrep/data/chordpro/latex/song similarity index 100% rename from patacrep/data/ast_templates/chordpro/latex/song rename to patacrep/data/chordpro/latex/song diff --git a/patacrep/data/ast_templates/chordpro/latex/song_body b/patacrep/data/chordpro/latex/song_body similarity index 100% rename from patacrep/data/ast_templates/chordpro/latex/song_body rename to patacrep/data/chordpro/latex/song_body diff --git a/patacrep/songs/chordpro/__init__.py b/patacrep/songs/chordpro/__init__.py index ce688379..fa05b3dd 100644 --- a/patacrep/songs/chordpro/__init__.py +++ b/patacrep/songs/chordpro/__init__.py @@ -48,14 +48,9 @@ class ChordproSong(Song): "content": self.cached['song'].content, } - jinjaenv = Environment(loader=ChoiceLoader([ - FileSystemLoader( - self.iter_datadirs("templates", self.output_language) - ), - FileSystemLoader( - pkg_datapath('ast_templates', 'chordpro', self.output_language) - ), - ])) + jinjaenv = Environment(loader=FileSystemLoader( + self.iter_datadirs("chordpro", self.output_language) + )) jinjaenv.filters['search_image'] = self.search_image jinjaenv.filters['search_partition'] = self.search_partition jinjaenv.filters['lang2babel'] = lang2babel diff --git a/test/test_chordpro/test_parser.py b/test/test_chordpro/test_parser.py index f0e94290..f542a203 100644 --- a/test/test_chordpro/test_parser.py +++ b/test/test_chordpro/test_parser.py @@ -7,7 +7,7 @@ import os import unittest from pkg_resources import resource_filename -from patacrep import files +from patacrep import files, __DATADIR__ from patacrep.build import DEFAULT_CONFIG from patacrep.encoding import open_read @@ -41,6 +41,7 @@ class FileTest(unittest.TestCase, metaclass=dynamic.DynamicTest): if 'datadir' not in cls.config: cls.config['datadir'] = [] cls.config['datadir'].append(resource_filename(__name__, 'datadir')) + cls.config['datadir'].append(__DATADIR__) cls.song_plugins = files.load_plugins( datadirs=cls.config['datadir'], From 72efad78905b3fb58e07394ba76fdc2aea6296f7 Mon Sep 17 00:00:00 2001 From: Louis Date: Thu, 5 Nov 2015 13:42:50 +0100 Subject: [PATCH 03/19] Fix data location --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 023201eb..36d24e55 100755 --- a/setup.py +++ b/setup.py @@ -22,7 +22,7 @@ setup( ], setup_requires=["hgtools"], package_data={'patacrep': [ - 'data/ast_templates/*/*/*', + 'data/chordpro/*/*', 'data/img/*', 'data/latex/*', 'data/templates/*', From 08e5e000b71b70137c163293d7c3e2e8f27e21aa Mon Sep 17 00:00:00 2001 From: Louis Date: Thu, 5 Nov 2015 18:24:14 +0100 Subject: [PATCH 04/19] Add a '--cache' option --- patacrep/songbook/__main__.py | 16 ++++++++++++++++ patacrep/songs/__init__.py | 4 ++-- patacrep/songs/convert/__main__.py | 17 +++++++---------- patacrep/utils.py | 16 ++++++++++++++++ test/test_compilation/test_compilation.py | 2 +- 5 files changed, 42 insertions(+), 13 deletions(-) diff --git a/patacrep/songbook/__main__.py b/patacrep/songbook/__main__.py index 5713b4a9..7006e16f 100644 --- a/patacrep/songbook/__main__.py +++ b/patacrep/songbook/__main__.py @@ -9,6 +9,7 @@ import textwrap import sys from patacrep.build import SongbookBuilder, DEFAULT_STEPS +from patacrep.utils import yesno from patacrep import __version__ from patacrep import errors import patacrep.encoding @@ -37,6 +38,12 @@ class VerboseAction(argparse.Action): def __call__(self, *_args, **_kwargs): LOGGER.setLevel(logging.DEBUG) +def yesno_type(string): + try: + return yesno(string) + except ValueError as error: + raise argparse.ArgumentTypeError(str(error)) + def argument_parser(args): """Parse arguments""" parser = argparse.ArgumentParser( @@ -68,6 +75,14 @@ def argument_parser(args): """) ) + parser.add_argument( + '--cache', '-c', nargs=1, + help=textwrap.dedent("""\ + Enable song cache. + """), + type=yesno_type, + ) + parser.add_argument( '--steps', '-s', nargs=1, type=str, action=ParseStepsAction, @@ -147,6 +162,7 @@ def main(): datadirs.append(os.path.dirname(os.path.abspath(songbook_path))) songbook['datadir'] = datadirs + songbook['_cache'] = options.cache[0] try: sb_builder = SongbookBuilder(songbook, basename) diff --git a/patacrep/songs/__init__.py b/patacrep/songs/__init__.py index 129c8045..a36c17bc 100644 --- a/patacrep/songs/__init__.py +++ b/patacrep/songs/__init__.py @@ -104,7 +104,7 @@ class Song: self.encoding = config["encoding"] self.config = config - if datadir: + if self.datadir and self.config['_cache']: # Only songs in datadirs are cached self._filehash = hashlib.md5( open(self.fullpath, 'rb').read() @@ -155,7 +155,7 @@ class Song: def _write_cache(self): """If relevant, write a dumbed down version of self to the cache.""" - if self.datadir: + if self.datadir and self.config['_cache']: cached = {} for attribute in self.cached_attributes: cached[attribute] = getattr(self, attribute) diff --git a/patacrep/songs/convert/__main__.py b/patacrep/songs/convert/__main__.py index 6b40dca4..2880cdab 100644 --- a/patacrep/songs/convert/__main__.py +++ b/patacrep/songs/convert/__main__.py @@ -7,24 +7,21 @@ import os import logging import sys -from patacrep.build import DEFAULT_CONFIG from patacrep import files +from patacrep.build import DEFAULT_CONFIG +from patacrep.utils import yesno LOGGER = logging.getLogger(__name__) def __usage(): return "python3 -m patacrep.songs.convert INPUTFORMAT OUTPUTFORMAT FILES" -def yesno(prompt): - while True: - answer = input("{} [yn] ".format(prompt)) - if answer.strip().lower() == "y": - return True - if answer.strip().lower() == "n": - return False - def confirm(destname): - return yesno("File '{}' already exist. Overwrite?".format(destname)) + while True + try: + return yesno(input("File '{}' already exist. Overwrite? [yn] ".format(destname))) + except ValueError: + continue if __name__ == "__main__": if len(sys.argv) < 4: diff --git a/patacrep/utils.py b/patacrep/utils.py index 6d9eab4c..998fe738 100644 --- a/patacrep/utils.py +++ b/patacrep/utils.py @@ -59,3 +59,19 @@ class DictOfDict(UserDict): DictOfDict._update(left[key], right[key]) else: left[key] = right[key] + +def yesno(string): + """Interpret string argument as a boolean. + + May raise `ValueError` if argument cannot be interpreted. + """ + yes_strings = ["y", "yes", "true", "1"] + no_strings = ["n", "no", "false", "0"] + if string.lower() in yes_strings: + return True + if string.lower() in no_strings: + return False + raise ValueError("'{}' is supposed to be one of {}.".format( + string, + ", ".join(["'{}'".format(string) for string in yes_strings + no_strings]), + )) diff --git a/test/test_compilation/test_compilation.py b/test/test_compilation/test_compilation.py index dc07107a..5b76e3e7 100644 --- a/test/test_compilation/test_compilation.py +++ b/test/test_compilation/test_compilation.py @@ -108,7 +108,7 @@ class FileTest(unittest.TestCase, metaclass=dynamic.DynamicTest): @staticmethod def compile_songbook(songbook, steps=None): """Compile songbook, and return the command return code.""" - command = ['python', '-m', 'patacrep.songbook', songbook, '-v'] + command = ['python', '-m', 'patacrep.songbook', '--cache=no', songbook, '-v'] if steps: command.extend(['--steps', steps]) From d076be098a8cefa1182d5bd3e473780a9f74c066 Mon Sep 17 00:00:00 2001 From: Louis Date: Thu, 5 Nov 2015 18:56:29 +0100 Subject: [PATCH 05/19] Add docstring --- patacrep/songbook/__main__.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/patacrep/songbook/__main__.py b/patacrep/songbook/__main__.py index 7006e16f..523cae07 100644 --- a/patacrep/songbook/__main__.py +++ b/patacrep/songbook/__main__.py @@ -39,6 +39,10 @@ class VerboseAction(argparse.Action): LOGGER.setLevel(logging.DEBUG) def yesno_type(string): + """Interpret argument as a "yes" or a "no". + + Raise `argparse.ArgumentTypeError` if string cannot be analysed. + """ try: return yesno(string) except ValueError as error: From efb36b38152a86137ec39a7b32edb375605f4e90 Mon Sep 17 00:00:00 2001 From: Oliverpool Date: Fri, 6 Nov 2015 11:28:12 +0100 Subject: [PATCH 06/19] Recursively discover data files or the setup --- patacrep/files.py | 9 +++++---- setup.py | 13 ++++++------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/patacrep/files.py b/patacrep/files.py index 1116c8b0..2f8ea8cd 100644 --- a/patacrep/files.py +++ b/patacrep/files.py @@ -12,24 +12,25 @@ from patacrep import utils LOGGER = logging.getLogger(__name__) -def recursive_find(root_directory, extensions): +def recursive_find(root_directory, extensions=None): """Recursively find files with the given extensions, from a root_directory. Return a list of files matching those conditions. Arguments: - - `extensions`: list of accepted extensions. + - `extensions`: list of accepted extensions (None means every file). - `root_directory`: root directory of the search. """ if not os.path.isdir(root_directory): return [] matches = [] - pattern = re.compile(r'.*\.({})$'.format('|'.join(extensions))) + if extensions: + pattern = re.compile(r'.*\.({})$'.format('|'.join(extensions))) with chdir(root_directory): for root, __ignored, filenames in os.walk(os.curdir): for filename in filenames: - if pattern.match(filename): + if not extensions or pattern.match(filename): matches.append(os.path.join(root, filename)) return matches diff --git a/setup.py b/setup.py index 36d24e55..8d8717d6 100755 --- a/setup.py +++ b/setup.py @@ -4,10 +4,14 @@ $ python setup.py install """ -from patacrep import __version__ +from patacrep import __version__, __DATADIR__, files from setuptools import setup, find_packages +# List the data files +data_files = files.recursive_find(__DATADIR__) +data_files = ["data/" + d for d in data_files] + setup( name='patacrep', version=__version__, @@ -21,12 +25,7 @@ setup( "unidecode", "jinja2", "chardet", "ply", ], setup_requires=["hgtools"], - package_data={'patacrep': [ - 'data/chordpro/*/*', - 'data/img/*', - 'data/latex/*', - 'data/templates/*', - ]}, + package_data={'patacrep': data_files}, entry_points={ 'console_scripts': [ "songbook = patacrep.songbook.__main__:main", From c7551d7456f7eec487e10c6610798089ae909365 Mon Sep 17 00:00:00 2001 From: Oliverpool Date: Fri, 6 Nov 2015 11:30:48 +0100 Subject: [PATCH 07/19] Move the chordpro templates --- .../data/{ => templates/songs}/chordpro/chordpro/content_chord | 0 .../{ => templates/songs}/chordpro/chordpro/content_chordlist | 0 .../{ => templates/songs}/chordpro/chordpro/content_comment | 0 .../data/{ => templates/songs}/chordpro/chordpro/content_define | 0 .../{ => templates/songs}/chordpro/chordpro/content_endofline | 0 .../data/{ => templates/songs}/chordpro/chordpro/content_error | 0 .../songs}/chordpro/chordpro/content_guitar_comment | 0 .../data/{ => templates/songs}/chordpro/chordpro/content_image | 0 .../data/{ => templates/songs}/chordpro/chordpro/content_line | 0 .../{ => templates/songs}/chordpro/chordpro/content_newline | 0 .../{ => templates/songs}/chordpro/chordpro/content_partition | 0 .../data/{ => templates/songs}/chordpro/chordpro/content_space | 0 .../{ => templates/songs}/chordpro/chordpro/content_tablature | 0 .../data/{ => templates/songs}/chordpro/chordpro/content_verse | 0 .../data/{ => templates/songs}/chordpro/chordpro/content_word | 0 patacrep/data/{ => templates/songs}/chordpro/chordpro/song | 0 patacrep/data/{ => templates/songs}/chordpro/chordpro/song_body | 0 .../data/{ => templates/songs}/chordpro/chordpro/song_header | 0 patacrep/data/{ => templates/songs}/chordpro/html/content_chord | 0 .../data/{ => templates/songs}/chordpro/html/content_chordlist | 0 .../data/{ => templates/songs}/chordpro/html/content_comment | 0 .../data/{ => templates/songs}/chordpro/html/content_define | 0 .../{ => templates/songs}/chordpro/html/content_define_list | 0 .../data/{ => templates/songs}/chordpro/html/content_endofline | 0 patacrep/data/{ => templates/songs}/chordpro/html/content_error | 0 .../{ => templates/songs}/chordpro/html/content_guitar_comment | 0 patacrep/data/{ => templates/songs}/chordpro/html/content_image | 0 patacrep/data/{ => templates/songs}/chordpro/html/content_line | 0 .../{ => templates/songs}/chordpro/html/content_metadata_cover | 0 .../data/{ => templates/songs}/chordpro/html/content_newline | 0 .../data/{ => templates/songs}/chordpro/html/content_partition | 0 patacrep/data/{ => templates/songs}/chordpro/html/content_space | 0 .../data/{ => templates/songs}/chordpro/html/content_tablature | 0 patacrep/data/{ => templates/songs}/chordpro/html/content_verse | 0 patacrep/data/{ => templates/songs}/chordpro/html/content_word | 0 patacrep/data/{ => templates/songs}/chordpro/html/song | 0 patacrep/data/{ => templates/songs}/chordpro/html/song_body | 0 patacrep/data/{ => templates/songs}/chordpro/html/song_header | 0 .../data/{ => templates/songs}/chordpro/latex/content_chord | 0 .../data/{ => templates/songs}/chordpro/latex/content_chordlist | 0 .../data/{ => templates/songs}/chordpro/latex/content_comment | 0 .../data/{ => templates/songs}/chordpro/latex/content_define | 0 .../data/{ => templates/songs}/chordpro/latex/content_endofline | 0 .../data/{ => templates/songs}/chordpro/latex/content_error | 0 .../{ => templates/songs}/chordpro/latex/content_guitar_comment | 0 .../data/{ => templates/songs}/chordpro/latex/content_image | 0 patacrep/data/{ => templates/songs}/chordpro/latex/content_line | 0 .../data/{ => templates/songs}/chordpro/latex/content_newline | 0 .../data/{ => templates/songs}/chordpro/latex/content_partition | 0 .../data/{ => templates/songs}/chordpro/latex/content_space | 0 .../data/{ => templates/songs}/chordpro/latex/content_tablature | 0 .../data/{ => templates/songs}/chordpro/latex/content_verse | 0 patacrep/data/{ => templates/songs}/chordpro/latex/content_word | 0 patacrep/data/{ => templates/songs}/chordpro/latex/song | 0 patacrep/data/{ => templates/songs}/chordpro/latex/song_body | 0 patacrep/songs/chordpro/__init__.py | 2 +- 56 files changed, 1 insertion(+), 1 deletion(-) rename patacrep/data/{ => templates/songs}/chordpro/chordpro/content_chord (100%) rename patacrep/data/{ => templates/songs}/chordpro/chordpro/content_chordlist (100%) rename patacrep/data/{ => templates/songs}/chordpro/chordpro/content_comment (100%) rename patacrep/data/{ => templates/songs}/chordpro/chordpro/content_define (100%) rename patacrep/data/{ => templates/songs}/chordpro/chordpro/content_endofline (100%) rename patacrep/data/{ => templates/songs}/chordpro/chordpro/content_error (100%) rename patacrep/data/{ => templates/songs}/chordpro/chordpro/content_guitar_comment (100%) rename patacrep/data/{ => templates/songs}/chordpro/chordpro/content_image (100%) rename patacrep/data/{ => templates/songs}/chordpro/chordpro/content_line (100%) rename patacrep/data/{ => templates/songs}/chordpro/chordpro/content_newline (100%) rename patacrep/data/{ => templates/songs}/chordpro/chordpro/content_partition (100%) rename patacrep/data/{ => templates/songs}/chordpro/chordpro/content_space (100%) rename patacrep/data/{ => templates/songs}/chordpro/chordpro/content_tablature (100%) rename patacrep/data/{ => templates/songs}/chordpro/chordpro/content_verse (100%) rename patacrep/data/{ => templates/songs}/chordpro/chordpro/content_word (100%) rename patacrep/data/{ => templates/songs}/chordpro/chordpro/song (100%) rename patacrep/data/{ => templates/songs}/chordpro/chordpro/song_body (100%) rename patacrep/data/{ => templates/songs}/chordpro/chordpro/song_header (100%) rename patacrep/data/{ => templates/songs}/chordpro/html/content_chord (100%) rename patacrep/data/{ => templates/songs}/chordpro/html/content_chordlist (100%) rename patacrep/data/{ => templates/songs}/chordpro/html/content_comment (100%) rename patacrep/data/{ => templates/songs}/chordpro/html/content_define (100%) rename patacrep/data/{ => templates/songs}/chordpro/html/content_define_list (100%) rename patacrep/data/{ => templates/songs}/chordpro/html/content_endofline (100%) rename patacrep/data/{ => templates/songs}/chordpro/html/content_error (100%) rename patacrep/data/{ => templates/songs}/chordpro/html/content_guitar_comment (100%) rename patacrep/data/{ => templates/songs}/chordpro/html/content_image (100%) rename patacrep/data/{ => templates/songs}/chordpro/html/content_line (100%) rename patacrep/data/{ => templates/songs}/chordpro/html/content_metadata_cover (100%) rename patacrep/data/{ => templates/songs}/chordpro/html/content_newline (100%) rename patacrep/data/{ => templates/songs}/chordpro/html/content_partition (100%) rename patacrep/data/{ => templates/songs}/chordpro/html/content_space (100%) rename patacrep/data/{ => templates/songs}/chordpro/html/content_tablature (100%) rename patacrep/data/{ => templates/songs}/chordpro/html/content_verse (100%) rename patacrep/data/{ => templates/songs}/chordpro/html/content_word (100%) rename patacrep/data/{ => templates/songs}/chordpro/html/song (100%) rename patacrep/data/{ => templates/songs}/chordpro/html/song_body (100%) rename patacrep/data/{ => templates/songs}/chordpro/html/song_header (100%) rename patacrep/data/{ => templates/songs}/chordpro/latex/content_chord (100%) rename patacrep/data/{ => templates/songs}/chordpro/latex/content_chordlist (100%) rename patacrep/data/{ => templates/songs}/chordpro/latex/content_comment (100%) rename patacrep/data/{ => templates/songs}/chordpro/latex/content_define (100%) rename patacrep/data/{ => templates/songs}/chordpro/latex/content_endofline (100%) rename patacrep/data/{ => templates/songs}/chordpro/latex/content_error (100%) rename patacrep/data/{ => templates/songs}/chordpro/latex/content_guitar_comment (100%) rename patacrep/data/{ => templates/songs}/chordpro/latex/content_image (100%) rename patacrep/data/{ => templates/songs}/chordpro/latex/content_line (100%) rename patacrep/data/{ => templates/songs}/chordpro/latex/content_newline (100%) rename patacrep/data/{ => templates/songs}/chordpro/latex/content_partition (100%) rename patacrep/data/{ => templates/songs}/chordpro/latex/content_space (100%) rename patacrep/data/{ => templates/songs}/chordpro/latex/content_tablature (100%) rename patacrep/data/{ => templates/songs}/chordpro/latex/content_verse (100%) rename patacrep/data/{ => templates/songs}/chordpro/latex/content_word (100%) rename patacrep/data/{ => templates/songs}/chordpro/latex/song (100%) rename patacrep/data/{ => templates/songs}/chordpro/latex/song_body (100%) diff --git a/patacrep/data/chordpro/chordpro/content_chord b/patacrep/data/templates/songs/chordpro/chordpro/content_chord similarity index 100% rename from patacrep/data/chordpro/chordpro/content_chord rename to patacrep/data/templates/songs/chordpro/chordpro/content_chord diff --git a/patacrep/data/chordpro/chordpro/content_chordlist b/patacrep/data/templates/songs/chordpro/chordpro/content_chordlist similarity index 100% rename from patacrep/data/chordpro/chordpro/content_chordlist rename to patacrep/data/templates/songs/chordpro/chordpro/content_chordlist diff --git a/patacrep/data/chordpro/chordpro/content_comment b/patacrep/data/templates/songs/chordpro/chordpro/content_comment similarity index 100% rename from patacrep/data/chordpro/chordpro/content_comment rename to patacrep/data/templates/songs/chordpro/chordpro/content_comment diff --git a/patacrep/data/chordpro/chordpro/content_define b/patacrep/data/templates/songs/chordpro/chordpro/content_define similarity index 100% rename from patacrep/data/chordpro/chordpro/content_define rename to patacrep/data/templates/songs/chordpro/chordpro/content_define diff --git a/patacrep/data/chordpro/chordpro/content_endofline b/patacrep/data/templates/songs/chordpro/chordpro/content_endofline similarity index 100% rename from patacrep/data/chordpro/chordpro/content_endofline rename to patacrep/data/templates/songs/chordpro/chordpro/content_endofline diff --git a/patacrep/data/chordpro/chordpro/content_error b/patacrep/data/templates/songs/chordpro/chordpro/content_error similarity index 100% rename from patacrep/data/chordpro/chordpro/content_error rename to patacrep/data/templates/songs/chordpro/chordpro/content_error diff --git a/patacrep/data/chordpro/chordpro/content_guitar_comment b/patacrep/data/templates/songs/chordpro/chordpro/content_guitar_comment similarity index 100% rename from patacrep/data/chordpro/chordpro/content_guitar_comment rename to patacrep/data/templates/songs/chordpro/chordpro/content_guitar_comment diff --git a/patacrep/data/chordpro/chordpro/content_image b/patacrep/data/templates/songs/chordpro/chordpro/content_image similarity index 100% rename from patacrep/data/chordpro/chordpro/content_image rename to patacrep/data/templates/songs/chordpro/chordpro/content_image diff --git a/patacrep/data/chordpro/chordpro/content_line b/patacrep/data/templates/songs/chordpro/chordpro/content_line similarity index 100% rename from patacrep/data/chordpro/chordpro/content_line rename to patacrep/data/templates/songs/chordpro/chordpro/content_line diff --git a/patacrep/data/chordpro/chordpro/content_newline b/patacrep/data/templates/songs/chordpro/chordpro/content_newline similarity index 100% rename from patacrep/data/chordpro/chordpro/content_newline rename to patacrep/data/templates/songs/chordpro/chordpro/content_newline diff --git a/patacrep/data/chordpro/chordpro/content_partition b/patacrep/data/templates/songs/chordpro/chordpro/content_partition similarity index 100% rename from patacrep/data/chordpro/chordpro/content_partition rename to patacrep/data/templates/songs/chordpro/chordpro/content_partition diff --git a/patacrep/data/chordpro/chordpro/content_space b/patacrep/data/templates/songs/chordpro/chordpro/content_space similarity index 100% rename from patacrep/data/chordpro/chordpro/content_space rename to patacrep/data/templates/songs/chordpro/chordpro/content_space diff --git a/patacrep/data/chordpro/chordpro/content_tablature b/patacrep/data/templates/songs/chordpro/chordpro/content_tablature similarity index 100% rename from patacrep/data/chordpro/chordpro/content_tablature rename to patacrep/data/templates/songs/chordpro/chordpro/content_tablature diff --git a/patacrep/data/chordpro/chordpro/content_verse b/patacrep/data/templates/songs/chordpro/chordpro/content_verse similarity index 100% rename from patacrep/data/chordpro/chordpro/content_verse rename to patacrep/data/templates/songs/chordpro/chordpro/content_verse diff --git a/patacrep/data/chordpro/chordpro/content_word b/patacrep/data/templates/songs/chordpro/chordpro/content_word similarity index 100% rename from patacrep/data/chordpro/chordpro/content_word rename to patacrep/data/templates/songs/chordpro/chordpro/content_word diff --git a/patacrep/data/chordpro/chordpro/song b/patacrep/data/templates/songs/chordpro/chordpro/song similarity index 100% rename from patacrep/data/chordpro/chordpro/song rename to patacrep/data/templates/songs/chordpro/chordpro/song diff --git a/patacrep/data/chordpro/chordpro/song_body b/patacrep/data/templates/songs/chordpro/chordpro/song_body similarity index 100% rename from patacrep/data/chordpro/chordpro/song_body rename to patacrep/data/templates/songs/chordpro/chordpro/song_body diff --git a/patacrep/data/chordpro/chordpro/song_header b/patacrep/data/templates/songs/chordpro/chordpro/song_header similarity index 100% rename from patacrep/data/chordpro/chordpro/song_header rename to patacrep/data/templates/songs/chordpro/chordpro/song_header diff --git a/patacrep/data/chordpro/html/content_chord b/patacrep/data/templates/songs/chordpro/html/content_chord similarity index 100% rename from patacrep/data/chordpro/html/content_chord rename to patacrep/data/templates/songs/chordpro/html/content_chord diff --git a/patacrep/data/chordpro/html/content_chordlist b/patacrep/data/templates/songs/chordpro/html/content_chordlist similarity index 100% rename from patacrep/data/chordpro/html/content_chordlist rename to patacrep/data/templates/songs/chordpro/html/content_chordlist diff --git a/patacrep/data/chordpro/html/content_comment b/patacrep/data/templates/songs/chordpro/html/content_comment similarity index 100% rename from patacrep/data/chordpro/html/content_comment rename to patacrep/data/templates/songs/chordpro/html/content_comment diff --git a/patacrep/data/chordpro/html/content_define b/patacrep/data/templates/songs/chordpro/html/content_define similarity index 100% rename from patacrep/data/chordpro/html/content_define rename to patacrep/data/templates/songs/chordpro/html/content_define diff --git a/patacrep/data/chordpro/html/content_define_list b/patacrep/data/templates/songs/chordpro/html/content_define_list similarity index 100% rename from patacrep/data/chordpro/html/content_define_list rename to patacrep/data/templates/songs/chordpro/html/content_define_list diff --git a/patacrep/data/chordpro/html/content_endofline b/patacrep/data/templates/songs/chordpro/html/content_endofline similarity index 100% rename from patacrep/data/chordpro/html/content_endofline rename to patacrep/data/templates/songs/chordpro/html/content_endofline diff --git a/patacrep/data/chordpro/html/content_error b/patacrep/data/templates/songs/chordpro/html/content_error similarity index 100% rename from patacrep/data/chordpro/html/content_error rename to patacrep/data/templates/songs/chordpro/html/content_error diff --git a/patacrep/data/chordpro/html/content_guitar_comment b/patacrep/data/templates/songs/chordpro/html/content_guitar_comment similarity index 100% rename from patacrep/data/chordpro/html/content_guitar_comment rename to patacrep/data/templates/songs/chordpro/html/content_guitar_comment diff --git a/patacrep/data/chordpro/html/content_image b/patacrep/data/templates/songs/chordpro/html/content_image similarity index 100% rename from patacrep/data/chordpro/html/content_image rename to patacrep/data/templates/songs/chordpro/html/content_image diff --git a/patacrep/data/chordpro/html/content_line b/patacrep/data/templates/songs/chordpro/html/content_line similarity index 100% rename from patacrep/data/chordpro/html/content_line rename to patacrep/data/templates/songs/chordpro/html/content_line diff --git a/patacrep/data/chordpro/html/content_metadata_cover b/patacrep/data/templates/songs/chordpro/html/content_metadata_cover similarity index 100% rename from patacrep/data/chordpro/html/content_metadata_cover rename to patacrep/data/templates/songs/chordpro/html/content_metadata_cover diff --git a/patacrep/data/chordpro/html/content_newline b/patacrep/data/templates/songs/chordpro/html/content_newline similarity index 100% rename from patacrep/data/chordpro/html/content_newline rename to patacrep/data/templates/songs/chordpro/html/content_newline diff --git a/patacrep/data/chordpro/html/content_partition b/patacrep/data/templates/songs/chordpro/html/content_partition similarity index 100% rename from patacrep/data/chordpro/html/content_partition rename to patacrep/data/templates/songs/chordpro/html/content_partition diff --git a/patacrep/data/chordpro/html/content_space b/patacrep/data/templates/songs/chordpro/html/content_space similarity index 100% rename from patacrep/data/chordpro/html/content_space rename to patacrep/data/templates/songs/chordpro/html/content_space diff --git a/patacrep/data/chordpro/html/content_tablature b/patacrep/data/templates/songs/chordpro/html/content_tablature similarity index 100% rename from patacrep/data/chordpro/html/content_tablature rename to patacrep/data/templates/songs/chordpro/html/content_tablature diff --git a/patacrep/data/chordpro/html/content_verse b/patacrep/data/templates/songs/chordpro/html/content_verse similarity index 100% rename from patacrep/data/chordpro/html/content_verse rename to patacrep/data/templates/songs/chordpro/html/content_verse diff --git a/patacrep/data/chordpro/html/content_word b/patacrep/data/templates/songs/chordpro/html/content_word similarity index 100% rename from patacrep/data/chordpro/html/content_word rename to patacrep/data/templates/songs/chordpro/html/content_word diff --git a/patacrep/data/chordpro/html/song b/patacrep/data/templates/songs/chordpro/html/song similarity index 100% rename from patacrep/data/chordpro/html/song rename to patacrep/data/templates/songs/chordpro/html/song diff --git a/patacrep/data/chordpro/html/song_body b/patacrep/data/templates/songs/chordpro/html/song_body similarity index 100% rename from patacrep/data/chordpro/html/song_body rename to patacrep/data/templates/songs/chordpro/html/song_body diff --git a/patacrep/data/chordpro/html/song_header b/patacrep/data/templates/songs/chordpro/html/song_header similarity index 100% rename from patacrep/data/chordpro/html/song_header rename to patacrep/data/templates/songs/chordpro/html/song_header diff --git a/patacrep/data/chordpro/latex/content_chord b/patacrep/data/templates/songs/chordpro/latex/content_chord similarity index 100% rename from patacrep/data/chordpro/latex/content_chord rename to patacrep/data/templates/songs/chordpro/latex/content_chord diff --git a/patacrep/data/chordpro/latex/content_chordlist b/patacrep/data/templates/songs/chordpro/latex/content_chordlist similarity index 100% rename from patacrep/data/chordpro/latex/content_chordlist rename to patacrep/data/templates/songs/chordpro/latex/content_chordlist diff --git a/patacrep/data/chordpro/latex/content_comment b/patacrep/data/templates/songs/chordpro/latex/content_comment similarity index 100% rename from patacrep/data/chordpro/latex/content_comment rename to patacrep/data/templates/songs/chordpro/latex/content_comment diff --git a/patacrep/data/chordpro/latex/content_define b/patacrep/data/templates/songs/chordpro/latex/content_define similarity index 100% rename from patacrep/data/chordpro/latex/content_define rename to patacrep/data/templates/songs/chordpro/latex/content_define diff --git a/patacrep/data/chordpro/latex/content_endofline b/patacrep/data/templates/songs/chordpro/latex/content_endofline similarity index 100% rename from patacrep/data/chordpro/latex/content_endofline rename to patacrep/data/templates/songs/chordpro/latex/content_endofline diff --git a/patacrep/data/chordpro/latex/content_error b/patacrep/data/templates/songs/chordpro/latex/content_error similarity index 100% rename from patacrep/data/chordpro/latex/content_error rename to patacrep/data/templates/songs/chordpro/latex/content_error diff --git a/patacrep/data/chordpro/latex/content_guitar_comment b/patacrep/data/templates/songs/chordpro/latex/content_guitar_comment similarity index 100% rename from patacrep/data/chordpro/latex/content_guitar_comment rename to patacrep/data/templates/songs/chordpro/latex/content_guitar_comment diff --git a/patacrep/data/chordpro/latex/content_image b/patacrep/data/templates/songs/chordpro/latex/content_image similarity index 100% rename from patacrep/data/chordpro/latex/content_image rename to patacrep/data/templates/songs/chordpro/latex/content_image diff --git a/patacrep/data/chordpro/latex/content_line b/patacrep/data/templates/songs/chordpro/latex/content_line similarity index 100% rename from patacrep/data/chordpro/latex/content_line rename to patacrep/data/templates/songs/chordpro/latex/content_line diff --git a/patacrep/data/chordpro/latex/content_newline b/patacrep/data/templates/songs/chordpro/latex/content_newline similarity index 100% rename from patacrep/data/chordpro/latex/content_newline rename to patacrep/data/templates/songs/chordpro/latex/content_newline diff --git a/patacrep/data/chordpro/latex/content_partition b/patacrep/data/templates/songs/chordpro/latex/content_partition similarity index 100% rename from patacrep/data/chordpro/latex/content_partition rename to patacrep/data/templates/songs/chordpro/latex/content_partition diff --git a/patacrep/data/chordpro/latex/content_space b/patacrep/data/templates/songs/chordpro/latex/content_space similarity index 100% rename from patacrep/data/chordpro/latex/content_space rename to patacrep/data/templates/songs/chordpro/latex/content_space diff --git a/patacrep/data/chordpro/latex/content_tablature b/patacrep/data/templates/songs/chordpro/latex/content_tablature similarity index 100% rename from patacrep/data/chordpro/latex/content_tablature rename to patacrep/data/templates/songs/chordpro/latex/content_tablature diff --git a/patacrep/data/chordpro/latex/content_verse b/patacrep/data/templates/songs/chordpro/latex/content_verse similarity index 100% rename from patacrep/data/chordpro/latex/content_verse rename to patacrep/data/templates/songs/chordpro/latex/content_verse diff --git a/patacrep/data/chordpro/latex/content_word b/patacrep/data/templates/songs/chordpro/latex/content_word similarity index 100% rename from patacrep/data/chordpro/latex/content_word rename to patacrep/data/templates/songs/chordpro/latex/content_word diff --git a/patacrep/data/chordpro/latex/song b/patacrep/data/templates/songs/chordpro/latex/song similarity index 100% rename from patacrep/data/chordpro/latex/song rename to patacrep/data/templates/songs/chordpro/latex/song diff --git a/patacrep/data/chordpro/latex/song_body b/patacrep/data/templates/songs/chordpro/latex/song_body similarity index 100% rename from patacrep/data/chordpro/latex/song_body rename to patacrep/data/templates/songs/chordpro/latex/song_body diff --git a/patacrep/songs/chordpro/__init__.py b/patacrep/songs/chordpro/__init__.py index fa05b3dd..0be23592 100644 --- a/patacrep/songs/chordpro/__init__.py +++ b/patacrep/songs/chordpro/__init__.py @@ -49,7 +49,7 @@ class ChordproSong(Song): } jinjaenv = Environment(loader=FileSystemLoader( - self.iter_datadirs("chordpro", self.output_language) + self.iter_datadirs("templates", "songs", "chordpro", self.output_language) )) jinjaenv.filters['search_image'] = self.search_image jinjaenv.filters['search_partition'] = self.search_partition From bdef0b1e010533de06d40b466bad98c9ad183334 Mon Sep 17 00:00:00 2001 From: Louis Date: Fri, 6 Nov 2015 19:43:31 +0100 Subject: [PATCH 08/19] Add a default value for the '--cache' option When option is given several times, use the last argument provided --- patacrep/songbook/__main__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/patacrep/songbook/__main__.py b/patacrep/songbook/__main__.py index 523cae07..004f3e95 100644 --- a/patacrep/songbook/__main__.py +++ b/patacrep/songbook/__main__.py @@ -85,6 +85,7 @@ def argument_parser(args): Enable song cache. """), type=yesno_type, + default=[True], ) parser.add_argument( @@ -126,7 +127,7 @@ def main(): options = argument_parser(sys.argv[1:]) - songbook_path = options.book[0] + songbook_path = options.book[-1] if os.path.exists(songbook_path + ".sb") and not os.path.exists(songbook_path): songbook_path += ".sb" From df2f9bfea927d84ca3cfa98a1139c9010e6a08c4 Mon Sep 17 00:00:00 2001 From: Louis Date: Sat, 7 Nov 2015 05:32:30 +0100 Subject: [PATCH 09/19] [test] Ensure tex and control files are read as UTF8 References #155 --- test/test_compilation/test_compilation.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/test/test_compilation/test_compilation.py b/test/test_compilation/test_compilation.py index 3af70d19..0444efa2 100644 --- a/test/test_compilation/test_compilation.py +++ b/test/test_compilation/test_compilation.py @@ -9,7 +9,6 @@ import sys import subprocess import unittest -from patacrep.encoding import open_read from patacrep.files import path2posix from .. import dynamic # pylint: disable=unused-import @@ -64,8 +63,8 @@ class FileTest(unittest.TestCase, metaclass=dynamic.DynamicTest): raise unittest.SkipTest('No control file for {}'.format(songbook)) tex = "{}.tex".format(base) - with open_read(control) as expectfile: - with open_read(tex) as latexfile: + with open(control, mode="r", encoding="utf8") as expectfile: + with open(tex, mode="r", encoding="utf8") as latexfile: expected = expectfile.read().strip() expected = expected.replace( "@TEST_FOLDER@", From a8dd19fe2794aca3a622c9c6f4f145659753947c Mon Sep 17 00:00:00 2001 From: Oliverpool Date: Sat, 7 Nov 2015 09:21:55 +0100 Subject: [PATCH 10/19] pattern should always be defined --- patacrep/files.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/patacrep/files.py b/patacrep/files.py index 2f8ea8cd..a204f8e7 100644 --- a/patacrep/files.py +++ b/patacrep/files.py @@ -25,12 +25,15 @@ def recursive_find(root_directory, extensions=None): return [] matches = [] - if extensions: + if extensions is None: + pattern = re.compile('.*') + else: pattern = re.compile(r'.*\.({})$'.format('|'.join(extensions))) + with chdir(root_directory): for root, __ignored, filenames in os.walk(os.curdir): for filename in filenames: - if not extensions or pattern.match(filename): + if pattern.match(filename): matches.append(os.path.join(root, filename)) return matches From a0c3e83e2f2ba7ca8df8b2255ccf0a3f134cbe82 Mon Sep 17 00:00:00 2001 From: Oliverpool Date: Sat, 7 Nov 2015 11:27:51 +0100 Subject: [PATCH 11/19] Detect file encoding with a priority list --- patacrep/encoding.py | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/patacrep/encoding.py b/patacrep/encoding.py index fd58fc2f..4cecd11a 100644 --- a/patacrep/encoding.py +++ b/patacrep/encoding.py @@ -16,15 +16,32 @@ def open_read(filename, mode='r', encoding=None): If `encoding` is set, use it as the encoding (do not guess). """ if encoding is None: - with open(filename, 'rb') as file: - fileencoding = chardet.detect(file.read())['encoding'] - else: - fileencoding = encoding + encoding = detect_encoding(filename) with codecs.open( filename, mode=mode, - encoding=fileencoding, + encoding=encoding, errors='replace', ) as fileobject: yield fileobject + +def detect_encoding(filename): + """Return the most likely encoding of the file + """ + encodings = ['utf-8', 'windows-1250', 'windows-1252'] + for e in encodings: + try: + fh = codecs.open(filename, 'r', encoding=e) + fh.readlines() + fh.seek(0) + except UnicodeDecodeError: + pass + else: + if e != 'utf-8': + print('Opening `%s` with `%s` encoding' % (filename, e)) + return e + finally: + fh.close() + + raise Exception('Not suitable encoding found for {}'.format(filename)) From ac2363ca37cd7d61467da2db01a62d8cc9788dda Mon Sep 17 00:00:00 2001 From: Oliverpool Date: Sat, 7 Nov 2015 11:31:29 +0100 Subject: [PATCH 12/19] Correct encoding of control file --- test/test_compilation/syntax.tex.control | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_compilation/syntax.tex.control b/test/test_compilation/syntax.tex.control index 2794e2fa..6f213ef2 100644 --- a/test/test_compilation/syntax.tex.control +++ b/test/test_compilation/syntax.tex.control @@ -92,7 +92,7 @@ guitar, \selectlanguage{english} -\beginsong{Song with Sharp in musicnote}[ +\beginsong{Song with Sharp in musicnote}[ by={ }, ] From d483c87d8b2bc4fb6f43ec119db27a7ec5c19029 Mon Sep 17 00:00:00 2001 From: Oliverpool Date: Sat, 7 Nov 2015 11:37:00 +0100 Subject: [PATCH 13/19] chardet package is not required anymore --- Requirements.txt | 1 - patacrep/encoding.py | 1 - setup.py | 2 +- 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/Requirements.txt b/Requirements.txt index 1673cecb..1fd1ebb8 100644 --- a/Requirements.txt +++ b/Requirements.txt @@ -1,4 +1,3 @@ ply Jinja2==2.7.3 -chardet==2.2.1 unidecode>=0.04.16 diff --git a/patacrep/encoding.py b/patacrep/encoding.py index 4cecd11a..20783111 100644 --- a/patacrep/encoding.py +++ b/patacrep/encoding.py @@ -1,7 +1,6 @@ """Dealing with encoding problems.""" import codecs -import chardet import logging import contextlib diff --git a/setup.py b/setup.py index 023201eb..85979a31 100755 --- a/setup.py +++ b/setup.py @@ -18,7 +18,7 @@ setup( packages=find_packages(exclude=["test*"]), license="GPLv2 or any later version", install_requires=[ - "unidecode", "jinja2", "chardet", "ply", + "unidecode", "jinja2", "ply", ], setup_requires=["hgtools"], package_data={'patacrep': [ From 46ceecd1c01d19b3c824e07872fad8d6d5e182f7 Mon Sep 17 00:00:00 2001 From: Oliverpool Date: Sat, 7 Nov 2015 11:39:49 +0100 Subject: [PATCH 14/19] Improve variable names (pylint) --- patacrep/encoding.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/patacrep/encoding.py b/patacrep/encoding.py index 20783111..9f0018da 100644 --- a/patacrep/encoding.py +++ b/patacrep/encoding.py @@ -29,18 +29,18 @@ def detect_encoding(filename): """Return the most likely encoding of the file """ encodings = ['utf-8', 'windows-1250', 'windows-1252'] - for e in encodings: + for encoding in encodings: try: - fh = codecs.open(filename, 'r', encoding=e) - fh.readlines() - fh.seek(0) + filehandler = codecs.open(filename, 'r', encoding=encoding) + filehandler.readlines() + filehandler.seek(0) except UnicodeDecodeError: pass else: - if e != 'utf-8': - print('Opening `%s` with `%s` encoding' % (filename, e)) - return e + if encoding != 'utf-8': + print('Opening `%s` with `%s` encoding' % (filename, encoding)) + return encoding finally: - fh.close() + filehandler.close() raise Exception('Not suitable encoding found for {}'.format(filename)) From b220d6d36aa6b215dba11b67462107dbce41308c Mon Sep 17 00:00:00 2001 From: Oliverpool Date: Sat, 7 Nov 2015 11:39:59 +0100 Subject: [PATCH 15/19] Improve exception type --- patacrep/encoding.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/patacrep/encoding.py b/patacrep/encoding.py index 9f0018da..d38daf60 100644 --- a/patacrep/encoding.py +++ b/patacrep/encoding.py @@ -43,4 +43,4 @@ def detect_encoding(filename): finally: filehandler.close() - raise Exception('Not suitable encoding found for {}'.format(filename)) + raise UnicodeDecodeError('Not suitable encoding found for {}'.format(filename)) From 8e95c829b2f573802ade8a772efe311008d762e0 Mon Sep 17 00:00:00 2001 From: Oliverpool Date: Sat, 7 Nov 2015 12:23:59 +0100 Subject: [PATCH 16/19] Verbose is only for Continuous Integration --- test/test_compilation/test_compilation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_compilation/test_compilation.py b/test/test_compilation/test_compilation.py index f2c6d09c..a095dbfb 100644 --- a/test/test_compilation/test_compilation.py +++ b/test/test_compilation/test_compilation.py @@ -111,7 +111,7 @@ class FileTest(unittest.TestCase, metaclass=dynamic.DynamicTest): @staticmethod def compile_songbook(songbook, steps=None): """Compile songbook, and return the command return code.""" - command = [sys.executable, '-m', 'patacrep.songbook', '--cache=no', songbook, '-v'] + command = [sys.executable, '-m', 'patacrep.songbook', '--cache=no', songbook] if steps: command.extend(['--steps', steps]) From 4c63e6fe707cba64494fb0e2d0048bf374403b28 Mon Sep 17 00:00:00 2001 From: Oliverpool Date: Sat, 7 Nov 2015 12:59:15 +0100 Subject: [PATCH 17/19] Use logger instead of print --- patacrep/encoding.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/patacrep/encoding.py b/patacrep/encoding.py index d38daf60..189db9a3 100644 --- a/patacrep/encoding.py +++ b/patacrep/encoding.py @@ -38,7 +38,7 @@ def detect_encoding(filename): pass else: if encoding != 'utf-8': - print('Opening `%s` with `%s` encoding' % (filename, encoding)) + LOGGER.info('Opening `%s` with `%s` encoding' % (filename, encoding)) return encoding finally: filehandler.close() From d3046339d1633c399eac26fb8aed460acffb2a2f Mon Sep 17 00:00:00 2001 From: Oliverpool Date: Sat, 7 Nov 2015 13:53:40 +0100 Subject: [PATCH 18/19] pylint - use format for string formatting --- patacrep/encoding.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/patacrep/encoding.py b/patacrep/encoding.py index 189db9a3..1ed15b94 100644 --- a/patacrep/encoding.py +++ b/patacrep/encoding.py @@ -38,7 +38,7 @@ def detect_encoding(filename): pass else: if encoding != 'utf-8': - LOGGER.info('Opening `%s` with `%s` encoding' % (filename, encoding)) + LOGGER.info('Opening `{}` with `{}` encoding'.format(filename, encoding)) return encoding finally: filehandler.close() From f22b726484f12292d91bf711c77a55456476c7b3 Mon Sep 17 00:00:00 2001 From: Oliverpool Date: Sat, 7 Nov 2015 14:14:56 +0100 Subject: [PATCH 19/19] Correct Exception for unknown encoding --- patacrep/encoding.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/patacrep/encoding.py b/patacrep/encoding.py index 1ed15b94..3f1512cf 100644 --- a/patacrep/encoding.py +++ b/patacrep/encoding.py @@ -42,5 +42,4 @@ def detect_encoding(filename): return encoding finally: filehandler.close() - - raise UnicodeDecodeError('Not suitable encoding found for {}'.format(filename)) + raise UnicodeError('Not suitable encoding found for {}'.format(filename))