From 08aa70bd13da704ca5ab59ad056db29406a7cb70 Mon Sep 17 00:00:00 2001 From: Louis Date: Sun, 16 Nov 2014 17:38:13 +0100 Subject: [PATCH] Simplification de l'installateur --- MANIFEST.in | 2 + patacrep/songbook.py | 155 ++++++++++++++++++++++++++++++++++++++++++ readme.md | 7 -- setup.py | 91 +++++++++++-------------- songbook | 156 ++----------------------------------------- stdeb.cfg | 6 -- 6 files changed, 200 insertions(+), 217 deletions(-) create mode 100644 MANIFEST.in create mode 100755 patacrep/songbook.py delete mode 100644 stdeb.cfg diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 00000000..bca3a82b --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,2 @@ +include LICENSE NEWS readme.md Requirements.txt stdeb.cfg +recursive-include patacrep/data * diff --git a/patacrep/songbook.py b/patacrep/songbook.py new file mode 100755 index 00000000..e3bcf555 --- /dev/null +++ b/patacrep/songbook.py @@ -0,0 +1,155 @@ +#! /usr/bin/env python3 +# -*- coding: utf-8 -*- + +"""Command line tool to compile songbooks using the songbook library.""" + +import argparse +import json +import locale +import logging +import os.path +import textwrap +import sys + +from patacrep.build import SongbookBuilder, DEFAULT_STEPS +from patacrep import __version__ +from patacrep import errors +from patacrep import encoding + +# Logging configuration +logging.basicConfig(level=logging.INFO) +LOGGER = logging.getLogger() + +# pylint: disable=too-few-public-methods +class ParseStepsAction(argparse.Action): + """Argparse action to split a string into a list.""" + def __call__(self, __parser, namespace, values, __option_string=None): + if not getattr(namespace, self.dest): + setattr(namespace, self.dest, []) + setattr( + namespace, + self.dest, + ( + getattr(namespace, self.dest) + + [value.strip() for value in values[0].split(',')] + ), + ) + +class VerboseAction(argparse.Action): + """Set verbosity level with option --verbose.""" + def __call__(self, *_args, **_kwargs): + LOGGER.setLevel(logging.DEBUG) + +def argument_parser(args): + """Parse arguments""" + parser = argparse.ArgumentParser(description="A song book compiler") + + parser.add_argument('--version', help='Show version', action='version', + version='%(prog)s ' + __version__) + + parser.add_argument('book', nargs=1, help=textwrap.dedent("""\ + Book to compile. + """)) + + parser.add_argument('--datadir', '-d', nargs='+', type=str, action='append', + help=textwrap.dedent("""\ + Data location. Expected (not necessarily required) + subdirectories are 'songs', 'img', 'latex', 'templates'. + """)) + + parser.add_argument('--verbose', '-v', nargs=0, action=VerboseAction, + help=textwrap.dedent("""\ + Show details about the compilation process. + """)) + + parser.add_argument('--steps', '-s', nargs=1, type=str, + action=ParseStepsAction, + help=textwrap.dedent("""\ + Steps to run. Default is "{steps}". + Available steps are: + "tex" produce .tex file from templates; + "pdf" compile .tex file; + "sbx" compile index files; + "clean" remove temporary files; + any string beginning with '%%' (in this case, it will be run + in a shell). Several steps (excepted the custom shell + command) can be combinend in one --steps argument, as a + comma separated string. + """.format(steps=','.join(DEFAULT_STEPS))), + default=None, + ) + + options = parser.parse_args(args) + + return options + + +def main(): + """Main function:""" + + # set script locale to match user's + try: + locale.setlocale(locale.LC_ALL, '') + except locale.Error as error: + # Locale is not installed on user's system, or wrongly configured. + LOGGER.error("Locale error: {}\n".format(str(error))) + + options = argument_parser(sys.argv[1:]) + + songbook_path = options.book[0] + + basename = os.path.basename(songbook_path)[:-3] + + songbook_file = None + try: + songbook_file = encoding.open_read(songbook_path) + songbook = json.load(songbook_file) + except Exception as error: # pylint: disable=broad-except + LOGGER.error(error) + LOGGER.error("Error while loading file '{}'.".format(songbook_path)) + sys.exit(1) + finally: + if songbook_file: + songbook_file.close() + + # Gathering datadirs + datadirs = [] + if options.datadir: + # Command line options + datadirs += [item[0] for item in options.datadir] + if 'datadir' in songbook: + # .sg file + if isinstance(songbook['datadir'], str): + songbook['datadir'] = [songbook['datadir']] + datadirs += [ + os.path.join( + os.path.dirname(os.path.abspath(songbook_path)), + path + ) + for path in songbook['datadir'] + ] + # Default value + datadirs.append(os.path.dirname(os.path.abspath(songbook_path))) + + songbook['datadir'] = datadirs + + try: + sb_builder = SongbookBuilder(songbook, basename) + sb_builder.unsafe = True + + sb_builder.build_steps(options.steps) + except errors.SongbookError as error: + LOGGER.error(error) + if LOGGER.level >= logging.INFO: + LOGGER.error( + "Running again with option '-v' may give more information." + ) + sys.exit(1) + except KeyboardInterrupt: + LOGGER.warning("Aborted by user.") + sys.exit(1) + + sys.exit(0) + +if __name__ == '__main__': + main() diff --git a/readme.md b/readme.md index ed4b1860..c97fef12 100644 --- a/readme.md +++ b/readme.md @@ -38,13 +38,6 @@ Look for existing songbook files in `/books/`. For example: > /songbook /books/songbook_en.sb > songbook_en.pdf -# Quick and dirty deb packages - -Install `python3-stdeb`, then: - -> python3 setup.py --command-packages=stdeb.command bdist_deb -> sudo dpkg -i deb_dist/python3-patacrep_-1_all.deb - # Documentation - Compiled, but may be outdated: http://www.patacrep.com/data/documents/doc_en.pdf diff --git a/setup.py b/setup.py index 7810c5ca..34705187 100755 --- a/setup.py +++ b/setup.py @@ -6,57 +6,42 @@ $ python setup.py install """ from patacrep import __version__ -from setuptools import setup - -import sys -import os -import site - - -SETUP = {"name": 'patacrep', - "version": __version__, - "description": 'Songbook compilation chain', - "author": 'The Songbook team', - "author_email": 'crep@team-on-fire.com', - "url": 'https://github.com/patacrep/patacrep', - "packages": ['patacrep', 'patacrep.content', 'patacrep.latex'], - "license": "GPLv2 or any later version", - "scripts": ['songbook'], - "requires": [ - "argparse", "codecs", "distutils", "fnmatch", "glob", "json", - "locale", "logging", "os", "re", "subprocess", "sys", - "textwrap", "unidecode", "jinja2", "chardet" - ], - "install_requires": [ - "argparse", "unidecode", "jinja2", "chardet", "ply" +from setuptools import setup, find_packages + +setup( + name='patacrep', + version=__version__, + description='Songbook compilation chain', + author='The Songbook team', + author_email='crep@team-on-fire.com', + url='https://github.com/patacrep/patacrep', + packages=find_packages(), + license="GPLv2 or any later version", + requires=[ + "argparse", "codecs", "distutils", "fnmatch", "glob", "json", + "locale", "logging", "os", "re", "subprocess", "sys", + "textwrap", "unidecode", "jinja2", "chardet" + ], + install_requires=[ + "argparse", "unidecode", "jinja2", "chardet", "ply" + ], + include_package_data=True, + entry_points={ + 'console_scripts': [ + "songbook = patacrep.songbook:main", ], - "package_data": {'patacrep': [ 'data/latex/*', - 'data/templates/*', - 'data/examples/*.sb', - 'data/examples/*/*.sg', - 'data/examples/*/*.ly', - 'data/examples/*/*.jpg', - 'data/examples/*/*.png', - 'data/examples/*/*.png', - 'data/examples/*/*/header']}, - "classifiers": [ - "Environment :: Console", - "License :: OSI Approved :: GNU General Public License v2 or later (GPLv2+)", - "Natural Language :: English", - "Operating System :: POSIX :: Linux", - "Operating System :: Microsoft :: Windows", - "Operating System :: MacOS :: MacOS X", - "Programming Language :: Python :: 2.7", - "Programming Language :: Python :: 3.3", - "Programming Language :: Python :: 3.4", - "Topic :: Utilities", - ], - "platforms": ["GNU/Linux", "Windows", "MacOsX"] -} - -if sys.platform.startswith('win32'): - from shutil import copy - copy("songbook", "songbook.py") - SETUP["scripts"] = ['songbook.py'] - -setup(**SETUP) + }, + classifiers=[ + "Environment :: Console", + "License :: OSI Approved :: GNU General Public License v2 or later (GPLv2+)", + "Natural Language :: English", + "Operating System :: POSIX :: Linux", + "Operating System :: Microsoft :: Windows", + "Operating System :: MacOS :: MacOS X", + "Programming Language :: Python :: 2.7", + "Programming Language :: Python :: 3.3", + "Programming Language :: Python :: 3.4", + "Topic :: Utilities", + ], + platforms=["GNU/Linux", "Windows", "MacOsX"] +) diff --git a/songbook b/songbook index e3bcf555..80e12f88 100755 --- a/songbook +++ b/songbook @@ -1,155 +1,9 @@ #! /usr/bin/env python3 -# -*- coding: utf-8 -*- -"""Command line tool to compile songbooks using the songbook library.""" - -import argparse -import json -import locale -import logging -import os.path -import textwrap -import sys - -from patacrep.build import SongbookBuilder, DEFAULT_STEPS -from patacrep import __version__ -from patacrep import errors -from patacrep import encoding - -# Logging configuration -logging.basicConfig(level=logging.INFO) -LOGGER = logging.getLogger() - -# pylint: disable=too-few-public-methods -class ParseStepsAction(argparse.Action): - """Argparse action to split a string into a list.""" - def __call__(self, __parser, namespace, values, __option_string=None): - if not getattr(namespace, self.dest): - setattr(namespace, self.dest, []) - setattr( - namespace, - self.dest, - ( - getattr(namespace, self.dest) - + [value.strip() for value in values[0].split(',')] - ), - ) - -class VerboseAction(argparse.Action): - """Set verbosity level with option --verbose.""" - def __call__(self, *_args, **_kwargs): - LOGGER.setLevel(logging.DEBUG) - -def argument_parser(args): - """Parse arguments""" - parser = argparse.ArgumentParser(description="A song book compiler") - - parser.add_argument('--version', help='Show version', action='version', - version='%(prog)s ' + __version__) - - parser.add_argument('book', nargs=1, help=textwrap.dedent("""\ - Book to compile. - """)) - - parser.add_argument('--datadir', '-d', nargs='+', type=str, action='append', - help=textwrap.dedent("""\ - Data location. Expected (not necessarily required) - subdirectories are 'songs', 'img', 'latex', 'templates'. - """)) - - parser.add_argument('--verbose', '-v', nargs=0, action=VerboseAction, - help=textwrap.dedent("""\ - Show details about the compilation process. - """)) - - parser.add_argument('--steps', '-s', nargs=1, type=str, - action=ParseStepsAction, - help=textwrap.dedent("""\ - Steps to run. Default is "{steps}". - Available steps are: - "tex" produce .tex file from templates; - "pdf" compile .tex file; - "sbx" compile index files; - "clean" remove temporary files; - any string beginning with '%%' (in this case, it will be run - in a shell). Several steps (excepted the custom shell - command) can be combinend in one --steps argument, as a - comma separated string. - """.format(steps=','.join(DEFAULT_STEPS))), - default=None, - ) - - options = parser.parse_args(args) +# Do not edit this file. This file is just a helper file for development test. +# It is not part of the distributed software. - return options - - -def main(): - """Main function:""" - - # set script locale to match user's - try: - locale.setlocale(locale.LC_ALL, '') - except locale.Error as error: - # Locale is not installed on user's system, or wrongly configured. - LOGGER.error("Locale error: {}\n".format(str(error))) - - options = argument_parser(sys.argv[1:]) - - songbook_path = options.book[0] - - basename = os.path.basename(songbook_path)[:-3] - - songbook_file = None - try: - songbook_file = encoding.open_read(songbook_path) - songbook = json.load(songbook_file) - except Exception as error: # pylint: disable=broad-except - LOGGER.error(error) - LOGGER.error("Error while loading file '{}'.".format(songbook_path)) - sys.exit(1) - finally: - if songbook_file: - songbook_file.close() - - # Gathering datadirs - datadirs = [] - if options.datadir: - # Command line options - datadirs += [item[0] for item in options.datadir] - if 'datadir' in songbook: - # .sg file - if isinstance(songbook['datadir'], str): - songbook['datadir'] = [songbook['datadir']] - datadirs += [ - os.path.join( - os.path.dirname(os.path.abspath(songbook_path)), - path - ) - for path in songbook['datadir'] - ] - # Default value - datadirs.append(os.path.dirname(os.path.abspath(songbook_path))) - - songbook['datadir'] = datadirs - - try: - sb_builder = SongbookBuilder(songbook, basename) - sb_builder.unsafe = True - - sb_builder.build_steps(options.steps) - except errors.SongbookError as error: - LOGGER.error(error) - if LOGGER.level >= logging.INFO: - LOGGER.error( - "Running again with option '-v' may give more information." - ) - sys.exit(1) - except KeyboardInterrupt: - LOGGER.warning("Aborted by user.") - sys.exit(1) - - sys.exit(0) +"""Command line tool to compile songbooks using the songbook library.""" -if __name__ == '__main__': - main() +from patacrep.songbook import main +main() diff --git a/stdeb.cfg b/stdeb.cfg deleted file mode 100644 index ed8a5bed..00000000 --- a/stdeb.cfg +++ /dev/null @@ -1,6 +0,0 @@ -[DEFAULT] -Depends: python3-jinja2, python3-pkg-resources, python3-chardet, python3-unidecode, texlive-latex-base, texlive-latex-recommended, texlive-latex-extra, lilypond, texlive-fonts-recommended -Recommends: texlive-lang-english, texlive-lang-french, texlive-lang-portuguese, texlive-lang-spanish, texlive-fonts-extra -X-Python3-Version: -Section: tex -