Rename the project #5
30
README.rst
30
README.rst
@ -1,8 +1,10 @@
|
|||||||
python-chordpro
|
igitar
|
||||||
===============
|
===============
|
||||||
|
|
||||||
``python-chordpro`` is a ChordPro parser, written in Python. The main difference between this module
|
**igitar** *[ee-gee-tahr]* isiXhosa, meaning guitar
|
||||||
and other similar libraries is that ``python-chordpro`` parses ChordPro files down to the syllable
|
|
||||||
|
``igitar`` is a ChordPro parser, written in Python. The main difference between this module
|
||||||
|
and other similar libraries is that ``igitar`` parses ChordPro files down to the syllable
|
||||||
level, enabling finer-grained control of the formatted output.
|
level, enabling finer-grained control of the formatted output.
|
||||||
|
|
||||||
.. warning::
|
.. warning::
|
||||||
@ -13,16 +15,18 @@ level, enabling finer-grained control of the formatted output.
|
|||||||
Installation
|
Installation
|
||||||
------------
|
------------
|
||||||
|
|
||||||
You can use ``pip`` to install ``python-chordpro``::
|
You can use ``pip`` to install ``igitar``:
|
||||||
|
|
||||||
$ pip install python-chordpro
|
.. code-block:: shell-session
|
||||||
|
|
||||||
|
$ pip install igitar
|
||||||
|
|
||||||
Example Usage
|
Example Usage
|
||||||
-------------
|
-------------
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
from chordpro import Song
|
from igitar import Song
|
||||||
|
|
||||||
song = Song('path/to/song.chordpro')
|
song = Song('path/to/song.chordpro')
|
||||||
|
|
||||||
@ -32,11 +36,11 @@ Example Usage
|
|||||||
Rendering
|
Rendering
|
||||||
---------
|
---------
|
||||||
|
|
||||||
``python-chordpro`` comes with two renders, HTML and Text.
|
``igitar`` comes with two renders, HTML and Text.
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
from chordpro.renderers.html import render
|
from igitar.renderers.html import render
|
||||||
|
|
||||||
print(render(song))
|
print(render(song))
|
||||||
|
|
||||||
@ -44,14 +48,16 @@ Rendering
|
|||||||
Command Line Interface
|
Command Line Interface
|
||||||
----------------------
|
----------------------
|
||||||
|
|
||||||
``python-chordpro`` also ships with a built-in command line interface which will read a ChordPro
|
``igitar`` also ships with a built-in command line interface which will read a ChordPro
|
||||||
file and then render it using either the text or HTML renderer.
|
file and then render it using either the text or HTML renderer.
|
||||||
|
|
||||||
For example::
|
For example:
|
||||||
|
|
||||||
$ python-chordpro path/to/song.chordpro -f text -o song.txt
|
.. code-block:: shell-session
|
||||||
|
|
||||||
|
$ igitar path/to/song.chordpro -f text -o song.txt
|
||||||
|
|
||||||
License
|
License
|
||||||
-------
|
-------
|
||||||
|
|
||||||
``python-chordpro`` is licensed under the MIT license. See the LICENSE file for more information.
|
``igitar`` is licensed under the MIT license. See the LICENSE file for more information.
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
[metadata]
|
[metadata]
|
||||||
name = python-chordpro
|
name = igitar
|
||||||
author = Raoul Snyman
|
author = Raoul Snyman
|
||||||
author_email = raoul@snyman.info
|
author_email = raoul@snyman.info
|
||||||
description = A ChordPro parser, written in Python
|
description = A ChordPro parser, written in Python
|
||||||
long_description = file:README.rst
|
long_description = file:README.rst
|
||||||
long_description_content_type = text/x-rst
|
long_description_content_type = text/x-rst
|
||||||
url = https://git.snyman.info/raoul/python-chordpro
|
url = https://git.snyman.info/raoul/igitar
|
||||||
license = MIT
|
license = MIT
|
||||||
classifiers =
|
classifiers =
|
||||||
Development Status :: 3 - Alpha
|
Development Status :: 3 - Alpha
|
||||||
@ -38,7 +38,7 @@ where = src
|
|||||||
|
|
||||||
[options.entry_points]
|
[options.entry_points]
|
||||||
console_scripts =
|
console_scripts =
|
||||||
python-chordpro = chordpro.cli:main
|
igitar = igitar.cli:main
|
||||||
|
|
||||||
[bdist_wheel]
|
[bdist_wheel]
|
||||||
universal = 1
|
universal = 1
|
||||||
|
@ -1 +0,0 @@
|
|||||||
from chordpro.base import Song # noqa
|
|
@ -1,2 +0,0 @@
|
|||||||
from chordpro.cli import main
|
|
||||||
main()
|
|
@ -1,41 +0,0 @@
|
|||||||
from argparse import ArgumentParser
|
|
||||||
|
|
||||||
from chordpro.base import Song
|
|
||||||
from chordpro.renderers.html import render as html_render, get_options as html_get_options
|
|
||||||
from chordpro.renderers.text import render as text_render
|
|
||||||
|
|
||||||
|
|
||||||
def get_args():
|
|
||||||
"""Parse the command line arguments"""
|
|
||||||
parser = ArgumentParser()
|
|
||||||
parser.add_argument('input', metavar='FILENAME', help='Input ChordPro file')
|
|
||||||
parser.add_argument('-o', '--output', metavar='FILENAME', help='Output to a file')
|
|
||||||
parser.add_argument('-f', '--format', metavar='FORMAT', choices=['html', 'text'], default='html',
|
|
||||||
help='Output format')
|
|
||||||
parser.add_argument('-p', '--param', metavar='KEY=VALUE', action='append', help='Parameter to send to renderer')
|
|
||||||
return parser.parse_args()
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
|
||||||
"""The command line entrypoint"""
|
|
||||||
args = get_args()
|
|
||||||
render_params = {kv.split('=')[0]: kv.split('=')[-1] for kv in args.param} if args.param else {}
|
|
||||||
# Prepare the params
|
|
||||||
for key, value in render_params.items():
|
|
||||||
if value.lower() == "true":
|
|
||||||
render_params[key] = True
|
|
||||||
elif value.lower() == "false":
|
|
||||||
render_params[key] = False
|
|
||||||
elif value.isdigit():
|
|
||||||
render_params[key] = int(value)
|
|
||||||
|
|
||||||
song = Song(args.input)
|
|
||||||
if args.format == 'text':
|
|
||||||
output = text_render(song, **render_params)
|
|
||||||
else:
|
|
||||||
output = html_render(song, **render_params)
|
|
||||||
if args.output:
|
|
||||||
with open(args.output, 'w') as html_file:
|
|
||||||
html_file.write(output)
|
|
||||||
else:
|
|
||||||
print(output)
|
|
1
src/igitar/__init__.py
Normal file
1
src/igitar/__init__.py
Normal file
@ -0,0 +1 @@
|
|||||||
|
from igitar.base import Song # noqa
|
2
src/igitar/__main__.py
Normal file
2
src/igitar/__main__.py
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
from igitar.cli import main
|
||||||
|
main()
|
@ -1,7 +1,7 @@
|
|||||||
from hyphen import Hyphenator
|
from hyphen import Hyphenator
|
||||||
|
|
||||||
from chordpro.constants import BRIDGE_MARKER, CHORD_WORD, CHORUS_MARKER, DIRECTIVE, END_OF, \
|
from igitar.constants import BRIDGE_MARKER, CHORD_WORD, CHORUS_MARKER, DIRECTIVE, END_OF, KNOWN_DIRECTIVES, START_OF, \
|
||||||
KNOWN_DIRECTIVES, START_OF, VERSE_MARKER
|
VERSE_MARKER
|
||||||
|
|
||||||
HYPHEN_CACHE = {}
|
HYPHEN_CACHE = {}
|
||||||
SYLLABLE_EXCEPTIONS = {
|
SYLLABLE_EXCEPTIONS = {
|
@ -1,6 +1,6 @@
|
|||||||
import re
|
import re
|
||||||
|
|
||||||
from chordpro.constants import CHORD_SUFFIXES, ENGLISH_NOTES, GERMAN_NOTES, NEOLATIN_NOTES
|
from igitar.constants import CHORD_SUFFIXES, ENGLISH_NOTES, GERMAN_NOTES, NEOLATIN_NOTES
|
||||||
|
|
||||||
_chord_cache = {}
|
_chord_cache = {}
|
||||||
_line_cache = {}
|
_line_cache = {}
|
67
src/igitar/cli.py
Normal file
67
src/igitar/cli.py
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
from argparse import ArgumentParser
|
||||||
|
|
||||||
|
from igitar.base import Song
|
||||||
|
from igitar.renderers.html import render as html_render, get_options as html_get_options
|
||||||
|
from igitar.renderers.text import render as text_render, get_options as text_get_options
|
||||||
|
|
||||||
|
|
||||||
|
def get_args():
|
||||||
|
"""Parse the command line arguments"""
|
||||||
|
parser = ArgumentParser()
|
||||||
|
subparsers = parser.add_subparsers(title='commands', dest='command')
|
||||||
|
|
||||||
|
subparsers.add_parser('list', aliases=['list-commands', 'l'], help='List the commands available')
|
||||||
|
subparsers.add_parser('html', aliases=['html-params', 'h'], help='List the parameters available for HTML rendering')
|
||||||
|
subparsers.add_parser('text', aliases=['text-params', 't'], help='List the parameters available for text rendering')
|
||||||
|
|
||||||
|
parser_render = subparsers.add_parser('render', aliases=['r'], help='Render a ChordPro file to HTML or text')
|
||||||
|
parser_render.add_argument('input', metavar='FILENAME', help='Input ChordPro file')
|
||||||
|
parser_render.add_argument('-o', '--output', metavar='FILENAME', help='Output to a file')
|
||||||
|
parser_render.add_argument('-f', '--format', metavar='FORMAT', choices=['html', 'text'], default='html',
|
||||||
|
help='Output format')
|
||||||
|
parser_render.add_argument('-p', '--param', metavar='KEY=VALUE', action='append',
|
||||||
|
help='Parameter to send to renderer')
|
||||||
|
return parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
"""The command line entrypoint"""
|
||||||
|
args = get_args()
|
||||||
|
if args.command in ['list', 'list-commands', 'l']:
|
||||||
|
print('Commands')
|
||||||
|
print('')
|
||||||
|
print(' list List all available commands')
|
||||||
|
print(' render Render a ChordPro file to HTML or text')
|
||||||
|
print(' html List the parameters available for HTML rendering')
|
||||||
|
print(' text List the parameters available for text rendering')
|
||||||
|
elif args.command in ['html', 'html-params', 'h']:
|
||||||
|
print('HTML parameters')
|
||||||
|
print('')
|
||||||
|
for param, details in html_get_options().items():
|
||||||
|
print(' {:<12} {}'.format(param, details['description']))
|
||||||
|
elif args.command in ['text', 'text-params', 't']:
|
||||||
|
print('Text parameters')
|
||||||
|
print('')
|
||||||
|
for param, details in text_get_options().items():
|
||||||
|
print(' {:<12} {}'.format(param, details['description']))
|
||||||
|
elif args.command == 'render':
|
||||||
|
render_params = {kv.split('=')[0]: kv.split('=')[-1] for kv in args.param} if args.param else {}
|
||||||
|
# Prepare the params
|
||||||
|
for key, value in render_params.items():
|
||||||
|
if value.lower() == "true":
|
||||||
|
render_params[key] = True
|
||||||
|
elif value.lower() == "false":
|
||||||
|
render_params[key] = False
|
||||||
|
elif value.isdigit():
|
||||||
|
render_params[key] = int(value)
|
||||||
|
|
||||||
|
song = Song(args.input)
|
||||||
|
if args.format == 'text':
|
||||||
|
output = text_render(song, **render_params)
|
||||||
|
else:
|
||||||
|
output = html_render(song, **render_params)
|
||||||
|
if args.output:
|
||||||
|
with open(args.output, 'w') as output_file:
|
||||||
|
output_file.write(output)
|
||||||
|
else:
|
||||||
|
print(output)
|
@ -1,6 +1,13 @@
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
|
|
||||||
|
TEXT_OPTIONS = {}
|
||||||
|
|
||||||
|
|
||||||
|
def get_options(group=None):
|
||||||
|
return TEXT_OPTIONS
|
||||||
|
|
||||||
|
|
||||||
def render(song, verse_upper=False):
|
def render(song, verse_upper=False):
|
||||||
"""Render a song to a text file"""
|
"""Render a song to a text file"""
|
||||||
nl = os.linesep
|
nl = os.linesep
|
Loading…
Reference in New Issue
Block a user