The new woob repository is here: https://gitlab.com/woob/woob. This gitlab will be removed soon.

The new woob repository is here: https://gitlab.com/woob/woob. This gitlab will be removed soon.

boilerplate.py 2.25 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
#! /usr/bin/env python
# -*- coding: utf-8 -*-

# Copyright(C) 2013-2019      Laurent Bachelier, Sébastien Jean
#
# This file is part of weboob.
#
# weboob is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# weboob is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with weboob. If not, see <http://www.gnu.org/licenses/>.

from __future__ import print_function

import argparse
import os
25
import subprocess
26 27 28 29 30 31 32 33 34 35
import sys
from importlib import import_module

BOILERPLATE_PATH = os.getenv(
    'BOILERPLATE_PATH',
    os.path.realpath(os.path.join(os.path.dirname(__file__), 'boilerplate_data')))

sys.path.append(os.path.dirname(__file__))
sys.path.append(BOILERPLATE_PATH)

36 37
from recipe import Recipe  # NOQA

38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56

def u8(s):
    if isinstance(s, bytes):
        return s.decode('utf-8')
    return s


def gitconfig(entry):
    return u8(subprocess.check_output('git config -z --get %s' % entry, shell=True)[:-1])


def main():
    parser = argparse.ArgumentParser()
    parser.add_argument(
        '-a', '--author',
        default=gitconfig('user.name'), type=u8)
    parser.add_argument(
        '-e', '--email',
        default=gitconfig('user.email'), type=u8)
57 58
    subparsers = parser.add_subparsers(dest='recipe')
    subparsers.required = True
59 60 61

    recipes_module = import_module('recipes', package='boilerplate_data')

62 63 64 65 66 67 68 69
    if hasattr(recipes_module, '__all__'):
        for k in recipes_module.__all__:
            getattr(recipes_module, k).configure_subparser(subparsers)
    else:
        for k in dir(recipes_module):
            print(k)
            if issubclass(getattr(recipes_module, k), Recipe) and not k.startswith('_'):
                getattr(recipes_module, k).configure_subparser(subparsers)
70 71 72

    args = parser.parse_args()

73
    recipe = args.recipe_class(args)
74 75 76 77 78
    recipe.generate()


if __name__ == '__main__':
    main()