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' help_text = 'Generate static website'
def options(parser): def options(parser, config, **kwargs):
parser.add_argument( 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( 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( builder = Builder(
Path(args.song_folder), Path(args.song_folder).expanduser(),
Path(args.lyrics_file), Path(args.lyrics_file).expanduser(),
) )
builder.build() builder.build()

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

@ -5,21 +5,28 @@ import urllib.request
name = 'ipfs' name = 'ipfs'
help_text = 'Upload the web to 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( parser.add_argument(
'song_folder', type=Path, '-s', '--song_folder', type=Path,
help="Folder with the song database.") default=config['global']['song_folder'],
help="Folder with the song database, defaults to {}".format(
config['global']['song_folder']))
parser.add_argument( parser.add_argument(
'-a', '--api', default='http://localhost:5001', '-a', '--api', default=config[name]['api'],
help="IPFS API server, defaults to http://localhost:5001.") help="IPFS API server, defaults to {}.".format(config[name]['api']))
parser.add_argument( parser.add_argument(
'-p', '--pinfile', default='~/.negromate/ipfs.hash', type=Path, '-p', '--pinfile', default=config[name]['pinfile'], type=Path,
help="file to store the current ipfs hash, defaults to ~/.negromate/ipfs.") help="file to store the current ipfs hash, defaults to {}".format(
config[name]['pinfile']))
def run(args): def run(args, **kwargs):
# add to local # add to local
command = [ command = [
"ipfs", "ipfs",
@ -37,6 +44,13 @@ def run(args):
) )
urllib.request.urlopen(url) 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 # read previous hash and update value
pinfile = args.pinfile.expanduser() pinfile = args.pinfile.expanduser()
if pinfile.exists(): 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' name = 'rsync'
help_text = 'Sincronize the static web with the server' 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( parser.add_argument(
'song_folder', type=Path, '-s', '--song_folder', type=Path,
help="Folder with the song database.") default=config['global']['song_folder'],
help="Folder with the song database, defaults to {}".format(
config['global']['song_folder']))
parser.add_argument( parser.add_argument(
'host', '-H', '--host', default=config[name]['host'],
help="Target server.") help="Target server, defaults to {}.".format(config[name]['host']))
parser.add_argument( parser.add_argument(
'-u', '--user', default="root", '-u', '--user', default=config[name]['user'],
help="User in the server, defaults to root.") help="User in the server, defaults to {}.".format(config[name]['user']))
parser.add_argument( parser.add_argument(
'-p', '--port', default=22, type=int, '-p', '--port', default=config[name]['port'], type=int,
help="Port of the ssh server, defaults to 22.") help="Port of the ssh server, defaults to {}.".format(config[name]['port']))
parser.add_argument( parser.add_argument(
'-d', '--destination', default="/var/www/html", '-d', '--destination', default=config[name]['destination'],
help="Folder of the server, defaults to /var/www/html") help="Folder of the server, defaults to {}".format(config[name]['destination']))
def run(args): def run(args, **kwargs):
contents = str(args.song_folder) + '/' contents = str(args.song_folder.expanduser()) + '/'
destination = "{user}@{host}:{folder}".format( destination = "{user}@{host}:{folder}".format(
user=args.user, user=args.user,
host=args.host, host=args.host,

View File

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