mirror of https://github.com/patacrep/patacrep.git
oliverpool
8 years ago
committed by
GitHub
30 changed files with 236 additions and 131 deletions
@ -0,0 +1,13 @@ |
|||
"""Common functions for patatools""" |
|||
|
|||
import argparse |
|||
import os |
|||
|
|||
def existing_file(name): |
|||
"""Check that argument is an existing, readable file name. |
|||
|
|||
Return the argument for convenience. |
|||
""" |
|||
if os.path.isfile(name) and os.access(name, os.R_OK): |
|||
return name |
|||
raise argparse.ArgumentTypeError("Cannot read file '{}'.".format(name)) |
@ -0,0 +1,70 @@ |
|||
"""Perform operations on songbook content.""" |
|||
|
|||
import argparse |
|||
import logging |
|||
import os |
|||
import sys |
|||
import textwrap |
|||
import yaml |
|||
|
|||
from patacrep.songbook import open_songbook |
|||
from patacrep.build import Songbook |
|||
from .. import existing_file |
|||
|
|||
LOGGER = logging.getLogger("patatools.content") |
|||
|
|||
def commandline_parser(): |
|||
"""Return a command line parser.""" |
|||
|
|||
parser = argparse.ArgumentParser( |
|||
prog="patatools content", |
|||
description="Operations related to the content of a songbook.", |
|||
formatter_class=argparse.RawTextHelpFormatter, |
|||
) |
|||
|
|||
subparsers = parser.add_subparsers() |
|||
subparsers.required = True |
|||
|
|||
content_items = subparsers.add_parser( |
|||
"items", |
|||
description="Display the content items of a songbook.", |
|||
help="Return the content items.", |
|||
) |
|||
content_items.add_argument( |
|||
'songbook', |
|||
metavar="SONGBOOK", |
|||
help=textwrap.dedent("""Songbook file to be used to look for content items."""), |
|||
type=existing_file, |
|||
) |
|||
content_items.set_defaults(command=do_content_items) |
|||
|
|||
return parser |
|||
|
|||
def do_content_items(namespace): |
|||
"""Execute the `patatools content items` command.""" |
|||
config = open_songbook(namespace.songbook) |
|||
config['_cache'] = True |
|||
config['_error'] = "fix" |
|||
songbook = Songbook(config, config['_outputname']) |
|||
_, content_items = songbook.get_content_items() |
|||
yaml_dir = os.path.dirname(os.path.abspath(namespace.songbook)) |
|||
ref_dir = os.path.join(yaml_dir, 'songs') |
|||
content_items = [ |
|||
normalize_song_path(item.to_dict(), ref_dir) |
|||
for item in content_items |
|||
] |
|||
sys.stdout.write(yaml.safe_dump(content_items, allow_unicode=True, default_flow_style=False)) |
|||
|
|||
def normalize_song_path(file_entry, ref_dir): |
|||
"""Normalize the 'song' value, relative to ref_dir""" |
|||
if 'song' in file_entry: |
|||
file_entry['song'] = os.path.relpath(file_entry['song'], ref_dir) |
|||
return file_entry |
|||
|
|||
def main(args): |
|||
"""Main function: run from command line.""" |
|||
options = commandline_parser().parse_args(args[1:]) |
|||
options.command(options) |
|||
|
|||
if __name__ == "__main__": |
|||
main(sys.argv) |
@ -1 +1 @@ |
|||
- "{'customname:': ''}" |
|||
- customname: '' |
@ -1 +1 @@ |
|||
- customname: |
|||
- customname: '' |
@ -1 +1 @@ |
|||
- "{'customzippedname:': ''}" |
|||
- customzippedname: '' |
|||
|
@ -1 +1 @@ |
|||
- customzippedname: |
|||
- customzippedname: '' |
|||
|
@ -1 +1 @@ |
|||
- subdir/chordpro.csg |
|||
- song: datadir/songs/subdir/chordpro.csg |
@ -1,2 +1,2 @@ |
|||
- subdir/chordpro.csg |
|||
- exsong.sg |
|||
- song: datadir/songs/subdir/chordpro.csg |
|||
- song: datadir/songs/exsong.sg |
Binary file not shown.
@ -1 +1 @@ |
|||
- chordpro.csg |
|||
- song: datadir/songs/chordpro.csg |
@ -1,6 +1,6 @@ |
|||
- exsong.sg |
|||
- chordpro.csg |
|||
- subdir/chordpro.csg |
|||
- chordpro.csg |
|||
- subdir/chordpro.csg |
|||
- exsong.sg |
|||
- song: datadir/songs/exsong.sg |
|||
- song: datadir/songs/chordpro.csg |
|||
- song: datadir/songs/subdir/chordpro.csg |
|||
- song: datadir/songs/chordpro.csg |
|||
- song: datadir/songs/subdir/chordpro.csg |
|||
- song: datadir/songs/exsong.sg |
@ -1,11 +1,13 @@ |
|||
- section{First Section!} |
|||
- section{Named section} |
|||
- section[section_short_name]{Section with short name} |
|||
- section*{Section* with short name} |
|||
- part{part section test} |
|||
- chapter{chapter section test} |
|||
- section{section section test} |
|||
- subsection{subsection section test} |
|||
- subsubsection{subsubsection section test} |
|||
- paragraph{paragraph section test} |
|||
- subparagraph{subparagraph section test} |
|||
- section: First Section! |
|||
- section: Named section |
|||
- section: |
|||
name: Section with short name |
|||
short: section_short_name |
|||
- section*: Section* with short name |
|||
- part: part section test |
|||
- chapter: chapter section test |
|||
- section: section section test |
|||
- subsection: subsection section test |
|||
- subsubsection: subsubsection section test |
|||
- paragraph: paragraph section test |
|||
- subparagraph: subparagraph section test |
@ -1,4 +1,12 @@ |
|||
- setcounter{songnum}{101} |
|||
- setcounter{songnum}{1} |
|||
- setcounter{songnum}{5} |
|||
- setcounter{counter_name}{-1} |
|||
- setcounter: |
|||
name: songnum |
|||
value: 101 |
|||
- setcounter: |
|||
name: songnum |
|||
value: 1 |
|||
- setcounter: |
|||
name: songnum |
|||
value: 5 |
|||
- setcounter: |
|||
name: counter_name |
|||
value: -1 |
@ -1,4 +1,4 @@ |
|||
- exsong.sg |
|||
- texsong.tsg |
|||
- chordpro.csg |
|||
- subdir/chordpro.csg |
|||
- song: datadir/songs/exsong.sg |
|||
- song: datadir/songs/texsong.tsg |
|||
- song: datadir/songs/chordpro.csg |
|||
- song: datadir/songs/subdir/chordpro.csg |
@ -1,6 +1,6 @@ |
|||
- songsection{Traditional} |
|||
- exsong.sg |
|||
- songchapter{English} |
|||
- texsong.tsg |
|||
- chordpro.csg |
|||
- exsong.sg |
|||
- songsection: Traditional |
|||
- song: datadir/songs/exsong.sg |
|||
- songchapter: English |
|||
- song: datadir/songs/texsong.tsg |
|||
- song: datadir/songs/chordpro.csg |
|||
- song: datadir/songs/exsong.sg |
@ -1,27 +1,27 @@ |
|||
- section{Title} |
|||
- "@TEST_FOLDER@/datadir_sort/path1_title1_author1.csg" |
|||
- "@TEST_FOLDER@/datadir_sort/path1_title1_author2.csg" |
|||
- "@TEST_FOLDER@/datadir_sort/path2_title1_author1.csg" |
|||
- "@TEST_FOLDER@/datadir_sort/path2_title1_author2.csg" |
|||
- "@TEST_FOLDER@/datadir_sort/path1_title2_author1.csg" |
|||
- "@TEST_FOLDER@/datadir_sort/path1_title2_author2.csg" |
|||
- "@TEST_FOLDER@/datadir_sort/path2_title2_author1.csg" |
|||
- "@TEST_FOLDER@/datadir_sort/path2_title2_author2.csg" |
|||
- section{Author, Title} |
|||
- "@TEST_FOLDER@/datadir_sort/path1_title1_author1.csg" |
|||
- "@TEST_FOLDER@/datadir_sort/path2_title1_author1.csg" |
|||
- "@TEST_FOLDER@/datadir_sort/path1_title2_author1.csg" |
|||
- "@TEST_FOLDER@/datadir_sort/path2_title2_author1.csg" |
|||
- "@TEST_FOLDER@/datadir_sort/path1_title1_author2.csg" |
|||
- "@TEST_FOLDER@/datadir_sort/path2_title1_author2.csg" |
|||
- "@TEST_FOLDER@/datadir_sort/path1_title2_author2.csg" |
|||
- "@TEST_FOLDER@/datadir_sort/path2_title2_author2.csg" |
|||
- section{Path, Title} |
|||
- "@TEST_FOLDER@/datadir_sort/path1_title1_author1.csg" |
|||
- "@TEST_FOLDER@/datadir_sort/path1_title1_author2.csg" |
|||
- "@TEST_FOLDER@/datadir_sort/path1_title2_author1.csg" |
|||
- "@TEST_FOLDER@/datadir_sort/path1_title2_author2.csg" |
|||
- "@TEST_FOLDER@/datadir_sort/path2_title1_author1.csg" |
|||
- "@TEST_FOLDER@/datadir_sort/path2_title1_author2.csg" |
|||
- "@TEST_FOLDER@/datadir_sort/path2_title2_author1.csg" |
|||
- "@TEST_FOLDER@/datadir_sort/path2_title2_author2.csg" |
|||
- section: Title |
|||
- song: datadir_sort/path1_title1_author1.csg |
|||
- song: datadir_sort/path1_title1_author2.csg |
|||
- song: datadir_sort/path2_title1_author1.csg |
|||
- song: datadir_sort/path2_title1_author2.csg |
|||
- song: datadir_sort/path1_title2_author1.csg |
|||
- song: datadir_sort/path1_title2_author2.csg |
|||
- song: datadir_sort/path2_title2_author1.csg |
|||
- song: datadir_sort/path2_title2_author2.csg |
|||
- section: Author, Title |
|||
- song: datadir_sort/path1_title1_author1.csg |
|||
- song: datadir_sort/path2_title1_author1.csg |
|||
- song: datadir_sort/path1_title2_author1.csg |
|||
- song: datadir_sort/path2_title2_author1.csg |
|||
- song: datadir_sort/path1_title1_author2.csg |
|||
- song: datadir_sort/path2_title1_author2.csg |
|||
- song: datadir_sort/path1_title2_author2.csg |
|||
- song: datadir_sort/path2_title2_author2.csg |
|||
- section: Path, Title |
|||
- song: datadir_sort/path1_title1_author1.csg |
|||
- song: datadir_sort/path1_title1_author2.csg |
|||
- song: datadir_sort/path1_title2_author1.csg |
|||
- song: datadir_sort/path1_title2_author2.csg |
|||
- song: datadir_sort/path2_title1_author1.csg |
|||
- song: datadir_sort/path2_title1_author2.csg |
|||
- song: datadir_sort/path2_title2_author1.csg |
|||
- song: datadir_sort/path2_title2_author2.csg |
|||
|
@ -1,3 +1,3 @@ |
|||
- test/test_content/datadir/songs/texfile.tex |
|||
- test/test_content/datadir/songs/texfile.tex |
|||
- test/test_content/datadir/songs/texfile.tex |
|||
- tex: test/test_content/datadir/songs/texfile.tex |
|||
- tex: test/test_content/datadir/songs/texfile.tex |
|||
- tex: test/test_content/datadir/songs/texfile.tex |
Loading…
Reference in new issue