diff --git a/negromate/web/commands/__init__.py b/negromate/web/commands/__init__.py index 6edaad3..05cac3b 100644 --- a/negromate/web/commands/__init__.py +++ b/negromate/web/commands/__init__.py @@ -1,7 +1,7 @@ import argparse import sys -from . import run, build, thumbnail +from . import run, build, thumbnail, rsync def main(): @@ -23,9 +23,11 @@ def main(): build, run, thumbnail, + rsync, ] 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) @@ -33,6 +35,9 @@ def main(): command.options(command_parser) args = parser.parse_args() - for command in commands: - if args.command == command.name: - command.run(args) + if args.command is None: + parser.print_usage() + else: + for command in commands: + if args.command == command.name: + command.run(args) diff --git a/negromate/web/commands/rsync.py b/negromate/web/commands/rsync.py new file mode 100755 index 0000000..45579e3 --- /dev/null +++ b/negromate/web/commands/rsync.py @@ -0,0 +1,41 @@ +import subprocess +from pathlib import Path + +name = 'rsync' +help_text = 'Sincronize the static web with the server' + + +def options(parser): + parser.add_argument( + 'song_folder', type=Path, + help="Folder with the song database.") + parser.add_argument( + 'host', + help="Target server.") + parser.add_argument( + '-u', '--user', default="root", + help="User in the server, defaults to root.") + parser.add_argument( + '-p', '--port', default=22, type=int, + help="Port of the ssh server, defaults to 22.") + parser.add_argument( + '-d', '--destination', default="/var/www/html", + help="Folder of the server, defaults to /var/www/html") + + +def run(args): + contents = str(args.song_folder) + '/' + destination = "{user}@{host}:{folder}".format( + user=args.user, + host=args.host, + folder=args.destination, + ) + command = [ + "rsync", + "-av", + '--rsh=ssh -p {}'.format(args.port), + contents, + destination, + ] + print(" ".join(command)) + subprocess.check_call(command) diff --git a/negromate/web/commands/thumbnail.py b/negromate/web/commands/thumbnail.py index 10e381d..31bad79 100644 --- a/negromate/web/commands/thumbnail.py +++ b/negromate/web/commands/thumbnail.py @@ -1,4 +1,3 @@ -import subprocess from pathlib import Path from negromate.songs.utils import generate_cover, generate_thumbnail