Add rsync command
This commit is contained in:
parent
ccbca5c79d
commit
376f8be080
|
@ -1,7 +1,7 @@
|
||||||
import argparse
|
import argparse
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from . import run, build, thumbnail
|
from . import run, build, thumbnail, rsync
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
@ -23,9 +23,11 @@ def main():
|
||||||
build,
|
build,
|
||||||
run,
|
run,
|
||||||
thumbnail,
|
thumbnail,
|
||||||
|
rsync,
|
||||||
]
|
]
|
||||||
|
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
|
parser.set_defaults(command=None)
|
||||||
subparsers = parser.add_subparsers()
|
subparsers = parser.add_subparsers()
|
||||||
for command in commands:
|
for command in commands:
|
||||||
command_parser = subparsers.add_parser(command.name, help=command.help_text)
|
command_parser = subparsers.add_parser(command.name, help=command.help_text)
|
||||||
|
@ -33,6 +35,9 @@ def main():
|
||||||
command.options(command_parser)
|
command.options(command_parser)
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
if args.command is None:
|
||||||
|
parser.print_usage()
|
||||||
|
else:
|
||||||
for command in commands:
|
for command in commands:
|
||||||
if args.command == command.name:
|
if args.command == command.name:
|
||||||
command.run(args)
|
command.run(args)
|
||||||
|
|
|
@ -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)
|
|
@ -1,4 +1,3 @@
|
||||||
import subprocess
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from negromate.songs.utils import generate_cover, generate_thumbnail
|
from negromate.songs.utils import generate_cover, generate_thumbnail
|
||||||
|
|
Loading…
Reference in New Issue