# Path: fabsetup/fabutils.py
# def task(func, *args, **kwargs):
#     '''Composition of decorator functions for inherent self-documentation on
#     task execution.
# 
#     On execution, each task prints out its name and its first docstring line.
#     '''
#     prefix = '\n# '
#     tail = '\n'
#     return fabric.api.task(
#         print_full_name(color=magenta,
#                         prefix=prefix,
#                         tail=tail)(print_doc1(func)),
#         *args,
#         **kwargs)
# 
# Path: fabsetup/fabutils.py
# def subtask(*args, **kwargs):
#     '''Decorator which prints out the name of the decorated function on
#     execution.
#     '''
#     depth = kwargs.get('depth', 2)
#     prefix = kwargs.get('prefix', '\n' + '#' * depth + ' ')
#     tail = kwargs.get('tail', '\n')
#     doc1 = kwargs.get('doc1', False)
#     color = kwargs.get('color', cyan)
# 
#     def real_decorator(func):
#         if doc1:
#             return print_full_name(color=color, prefix=prefix,
#                                    tail=tail)(print_doc1(func))
#         return print_full_name(color=color, prefix=prefix, tail=tail)(func)
# 
#     invoked = bool(not args or kwargs)
#     if not invoked:
#         # invoke decorator function which returns the wrapper function
#         return real_decorator(func=args[0])
#     return real_decorator
# 
# def run(*args, **kwargs):
#     func, kwargs = _func(kwargs)
#     return func(*args, **kwargs)
# 
# def print_msg(msg):
#     if msg is not None:
#         print(cyan(flo('{msg}')))
# 
# Path: fabsetup/utils.py
# def flo(string):
#     '''Return the string given by param formatted with the callers locals.'''
#     callers_locals = {}
#     frame = inspect.currentframe()
#     try:
#         outerframe = frame.f_back
#         callers_locals = outerframe.f_locals
#     finally:
#         del frame
#     return string.format(**callers_locals)


from os.path import dirname, join
from fabsetup.fabutils import task
from fabsetup.fabutils import subtask, run, print_msg
from fabsetup.utils import flo
            ├── lrs2lrf
            ├── markdown-calibre
            ├── resources
            └── web2disk
    '''
    install_calibre(instdir='~/bin/calibre-bin')


@subtask
def install_calibre(instdir):
    inst_parent = dirname(instdir)
    inst_tmp = join(inst_parent, 'calibre-tmp')

    run(flo('mkdir -p {inst_tmp}'),
        msg='### assure, inst base-dir exists\n')

    run(flo('wget -nv -O- '
            'https://raw.githubusercontent.com/kovidgoyal/calibre/master/setup/'
            'linux-installer.py | '
            'python -c "import sys; '
            'main=lambda x,y:sys.stderr.write(\'Download failed\\n\'); '
            'exec(sys.stdin.read()); main(\'{inst_tmp}\', True)"'),
        msg='\n### download and run calibre installer script\n')

    # calibre-installer installs into {inst_tmp}/calibre/; needs to be moved
    print_msg('\n### replace old install (if exists) by new installation\n')
    run(flo('rm -rf  {instdir}'))
    run(flo('mv  {inst_tmp}/calibre  {instdir}'))
    run(flo('rmdir  {inst_tmp}'))


# Path: fabsetup/fabutils.py
# def task(func, *args, **kwargs):
#     '''Composition of decorator functions for inherent self-documentation on
#     task execution.
# 
#     On execution, each task prints out its name and its first docstring line.
#     '''
#     prefix = '\n# '
#     tail = '\n'
#     return fabric.api.task(
#         print_full_name(color=magenta,
#                         prefix=prefix,
#                         tail=tail)(print_doc1(func)),
#         *args,
#         **kwargs)
# 
# Path: fabsetup/fabutils.py
# def subtask(*args, **kwargs):
#     '''Decorator which prints out the name of the decorated function on
#     execution.
#     '''
#     depth = kwargs.get('depth', 2)
#     prefix = kwargs.get('prefix', '\n' + '#' * depth + ' ')
#     tail = kwargs.get('tail', '\n')
#     doc1 = kwargs.get('doc1', False)
#     color = kwargs.get('color', cyan)
# 
#     def real_decorator(func):
#         if doc1:
#             return print_full_name(color=color, prefix=prefix,
#                                    tail=tail)(print_doc1(func))
#         return print_full_name(color=color, prefix=prefix, tail=tail)(func)
# 
#     invoked = bool(not args or kwargs)
#     if not invoked:
#         # invoke decorator function which returns the wrapper function
#         return real_decorator(func=args[0])
#     return real_decorator
# 
# def run(*args, **kwargs):
#     func, kwargs = _func(kwargs)
#     return func(*args, **kwargs)
# 
# def print_msg(msg):
#     if msg is not None:
#         print(cyan(flo('{msg}')))
# 
# Path: fabsetup/utils.py
# def flo(string):
#     '''Return the string given by param formatted with the callers locals.'''
#     callers_locals = {}
#     frame = inspect.currentframe()
#     try:
#         outerframe = frame.f_back
#         callers_locals = outerframe.f_locals
#     finally:
#         del frame
#     return string.format(**callers_locals)


# Path: fabsetup/fabfile/setup/calibre.py
from os.path import dirname, join
from fabsetup.fabutils import task
from fabsetup.fabutils import subtask, run, print_msg
from fabsetup.utils import flo

            ├── lrs2lrf
            ├── markdown-calibre
            ├── resources
            └── web2disk
    '''
    install_calibre(instdir='~/bin/calibre-bin')


@subtask
def install_calibre(instdir):
    inst_parent = dirname(instdir)
    inst_tmp = join(inst_parent, 'calibre-tmp')

    run(flo('mkdir -p {inst_tmp}'),
        msg='### assure, inst base-dir exists\n')

    run(flo('wget -nv -O- '
            'https://raw.githubusercontent.com/kovidgoyal/calibre/master/setup/'
            'linux-installer.py | '
            'python -c "import sys; '
            'main=lambda x,y:sys.stderr.write(\'Download failed\\n\'); '
            'exec(sys.stdin.read()); main(\'{inst_tmp}\', True)"'),
        msg='\n### download and run calibre installer script\n')

    # calibre-installer installs into {inst_tmp}/calibre/; needs to be moved
    print_msg('\n### replace old install (if exists) by new installation\n')
    run(flo('rm -rf  {instdir}'))
    run(flo('mv  {inst_tmp}/calibre  {instdir}'))
    run(flo('rmdir  {inst_tmp}'))


    run(flo('ln -snf  {instdir}/calibre  ~/bin/calibre'),