Use configuration file

This commit is contained in:
Ales (Shagi) Zabala Alava 2020-11-07 10:30:29 +01:00
parent f06aef8c75
commit a35abdf37e
4 changed files with 74 additions and 36 deletions

View File

@ -6,16 +6,22 @@ name = 'build'
help_text = 'Generate static website'
def options(parser):
def options(parser, config, **kwargs):
parser.add_argument(
'song_folder', help="Folder with the song database.")
'-s', '--song_folder', type=Path,
default=config['global']['song_folder'],
help="Folder with the song database, defaults to {}".format(
config['global']['song_folder']))
parser.add_argument(
'lyrics_file', help="File with the lyrics of the songs.")
'-l', '--lyrics_file', type=Path,
default=config['global']['lyrics_file'],
help="File with the lyrics of the songs, defaults to {}".format(
config['global']['lyrics_file']))
def run(args):
def run(args, **kwargs):
builder = Builder(
Path(args.song_folder),
Path(args.lyrics_file),
Path(args.song_folder).expanduser(),
Path(args.lyrics_file).expanduser(),
)
builder.build()

30
negromate/web/commands/ipfs.py Executable file → Normal file
View File

@ -5,21 +5,28 @@ import urllib.request
name = 'ipfs'
help_text = 'Upload the web to IPFS'
initial_config = {
'api': 'http://negromate.rocks:5001',
'pinfile': '~/.negromate/ipfs.hash',
}
def options(parser):
def options(parser, config, **kwargs):
parser.add_argument(
'song_folder', type=Path,
help="Folder with the song database.")
'-s', '--song_folder', type=Path,
default=config['global']['song_folder'],
help="Folder with the song database, defaults to {}".format(
config['global']['song_folder']))
parser.add_argument(
'-a', '--api', default='http://localhost:5001',
help="IPFS API server, defaults to http://localhost:5001.")
'-a', '--api', default=config[name]['api'],
help="IPFS API server, defaults to {}.".format(config[name]['api']))
parser.add_argument(
'-p', '--pinfile', default='~/.negromate/ipfs.hash', type=Path,
help="file to store the current ipfs hash, defaults to ~/.negromate/ipfs.")
'-p', '--pinfile', default=config[name]['pinfile'], type=Path,
help="file to store the current ipfs hash, defaults to {}".format(
config[name]['pinfile']))
def run(args):
def run(args, **kwargs):
# add to local
command = [
"ipfs",
@ -37,6 +44,13 @@ def run(args):
)
urllib.request.urlopen(url)
# update ipns on server
url = "{}/api/v0/name/publish?arg={}&resolve=yes".format(
args.api,
final_hash,
)
urllib.request.urlopen(url)
# read previous hash and update value
pinfile = args.pinfile.expanduser()
if pinfile.exists():

34
negromate/web/commands/rsync.py Executable file → Normal file
View File

@ -3,28 +3,36 @@ from pathlib import Path
name = 'rsync'
help_text = 'Sincronize the static web with the server'
initial_config = {
'host': 'negromate.rocks',
'user': 'root',
'port': '22',
'destination': "/var/www/html",
}
def options(parser):
def options(parser, config, **kwargs):
parser.add_argument(
'song_folder', type=Path,
help="Folder with the song database.")
'-s', '--song_folder', type=Path,
default=config['global']['song_folder'],
help="Folder with the song database, defaults to {}".format(
config['global']['song_folder']))
parser.add_argument(
'host',
help="Target server.")
'-H', '--host', default=config[name]['host'],
help="Target server, defaults to {}.".format(config[name]['host']))
parser.add_argument(
'-u', '--user', default="root",
help="User in the server, defaults to root.")
'-u', '--user', default=config[name]['user'],
help="User in the server, defaults to {}.".format(config[name]['user']))
parser.add_argument(
'-p', '--port', default=22, type=int,
help="Port of the ssh server, defaults to 22.")
'-p', '--port', default=config[name]['port'], type=int,
help="Port of the ssh server, defaults to {}.".format(config[name]['port']))
parser.add_argument(
'-d', '--destination', default="/var/www/html",
help="Folder of the server, defaults to /var/www/html")
'-d', '--destination', default=config[name]['destination'],
help="Folder of the server, defaults to {}".format(config[name]['destination']))
def run(args):
contents = str(args.song_folder) + '/'
def run(args, **kwargs):
contents = str(args.song_folder.expanduser()) + '/'
destination = "{user}@{host}:{folder}".format(
user=args.user,
host=args.host,

View File

@ -1,26 +1,36 @@
from http.server import test, SimpleHTTPRequestHandler
from functools import partial
from http.server import test, SimpleHTTPRequestHandler
from pathlib import Path
name = 'run'
help_text = 'Start web server to test the website'
initial_config = {
'port': '8000',
'bind': '',
}
def options(parser):
def options(parser, config, **kwargs):
parser.add_argument(
'song_folder', help="Folder with the song database.")
'-s', '--song_folder', type=Path,
default=config['global']['song_folder'],
help="Folder with the song database, defaults to {}".format(
config['global']['song_folder']))
parser.add_argument(
'port', action='store', default=8000, type=int, nargs='?',
help='Specify alternate port [default: 8000]')
'-p', '--port', default=config[name]['port'], type=int,
help='Specify alternate port, defaults to {}'.format(config[name]['port']))
parser.add_argument(
'--bind', '-b', default='', metavar='ADDRESS',
help='Specify alternate bind address [default: all interfaces]')
'--bind', '-b', default=config[name]['bind'], metavar='ADDRESS',
help='Specify alternate bind address, defaults to {}'.format(
config[name]['bind'] or 'all interfaces',
))
def run(args):
def run(args, **kwargs):
Handler = partial(
SimpleHTTPRequestHandler,
directory=args.song_folder,
directory=str(args.song_folder.expanduser()),
)
test(HandlerClass=Handler, port=args.port, bind=args.bind)