Use negromate.commands entry_point
This commit is contained in:
parent
d7f9017abd
commit
f06aef8c75
|
@ -1,44 +0,0 @@
|
|||
import argparse
|
||||
import sys
|
||||
|
||||
from . import run, build, thumbnail, rsync, ipfs
|
||||
|
||||
|
||||
def main():
|
||||
"""
|
||||
Build parser for all the commands and launch appropiate command.
|
||||
|
||||
Each command must be a module with at least the following members:
|
||||
|
||||
* name: String with the command name. Will be used for
|
||||
argparse subcommand.
|
||||
* help_text: String with the help text.
|
||||
* options: Function to build the parser of the command. Takes
|
||||
one parametter, the argparser parser instance for this
|
||||
subcommand.
|
||||
* run: Function that runs the actual command. Takes one
|
||||
parametter, the Namespace with the arguments.
|
||||
"""
|
||||
commands = [
|
||||
build,
|
||||
run,
|
||||
thumbnail,
|
||||
rsync,
|
||||
ipfs,
|
||||
]
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.set_defaults(command=None)
|
||||
subparsers = parser.add_subparsers()
|
||||
for command in commands:
|
||||
command_parser = subparsers.add_parser(command.name, help=command.help_text)
|
||||
command_parser.set_defaults(command=command.name)
|
||||
command.options(command_parser)
|
||||
|
||||
args = parser.parse_args()
|
||||
if args.command is None:
|
||||
parser.print_usage()
|
||||
else:
|
||||
for command in commands:
|
||||
if args.command == command.name:
|
||||
command.run(args)
|
|
@ -1,22 +0,0 @@
|
|||
from pathlib import Path
|
||||
|
||||
from negromate.songs.utils import generate_cover, generate_thumbnail
|
||||
|
||||
name = 'thumbnail'
|
||||
help_text = 'Generate cover and thumbnail for a video.'
|
||||
|
||||
|
||||
def options(parser):
|
||||
parser.add_argument(
|
||||
'video', help="Video of the song.", type=Path)
|
||||
parser.add_argument(
|
||||
'second', type=int,
|
||||
help='Take snapshot at this second.')
|
||||
|
||||
|
||||
def run(args):
|
||||
video = args.video
|
||||
cover = video.parent / 'cover.jpg'
|
||||
thumbnail = video.parent / 'thumb.jpg'
|
||||
generate_cover(video, cover, args.second)
|
||||
generate_thumbnail(cover, thumbnail)
|
|
@ -23,11 +23,14 @@ python_requires = >= 3.4
|
|||
install_requires =
|
||||
Jinja2
|
||||
ass ==0.4.4
|
||||
negromate.songs ==1.0
|
||||
negromate.songs ==1.1
|
||||
|
||||
[options.entry_points]
|
||||
console_scripts =
|
||||
negromate-web = negromate.web.commands:main
|
||||
negromate.commands =
|
||||
build = negromate.web.commands.build
|
||||
run = negromate.web.commands.run
|
||||
rsync = negromate.web.commands.rsync
|
||||
ipfs = negromate.web.commands.ipfs
|
||||
|
||||
[bdist_wheel]
|
||||
# This flag says to generate wheels that support both Python 2 and Python
|
||||
|
|
Loading…
Reference in New Issue