From f7dbe498e966261f94fa62377147c4cdd5a47ea2 Mon Sep 17 00:00:00 2001 From: Filipp Lepalaan Date: Mon, 2 Nov 2020 09:18:24 +0200 Subject: Better --- README.md | 46 ++++++++++++++++++++++++++++++++++++++++++++++ client.py | 27 --------------------------- hello.py | 33 +++++++++++++++++++++++++++++++++ requirements.txt | 2 -- templates/nginx.rst | 6 +++--- 5 files changed, 82 insertions(+), 32 deletions(-) create mode 100644 README.md delete mode 100755 client.py create mode 100755 hello.py diff --git a/README.md b/README.md new file mode 100644 index 0000000..42f3fd0 --- /dev/null +++ b/README.md @@ -0,0 +1,46 @@ +## Introduction + +hello is a boilerplate repository. + +## Requirements + +- nginx with _autoindex_ on and _autoindex_format_ set to _json_ for the repo directory: + + server { + listen 8080; + server_name localhost; + + location / { + root /Users/filipp/Projects/hello/templates; + autoindex on; + autoindex_format json; + } + } + +- the _requests_ HTTP client library (which everyone probably already has installed). _pip install -r requirements.txt_ to install. + +## Setup + +- Put your boilerplate on a web server +- Export an environment variabled called _HELLO_REPO_ which points to the directory that contains your boilerplate templates + + +## Usage + +Run _hello.py_ with boilerplate name or without the name to get a list of available templates + +The boilerplate templates get rendered with all your environment variables as context so feel free to use stuff like $HOME or $PWD or $USER or whatever inside them. + +'Nuff said. + +## FAQ + +- Why not do this as a snippet collection for ? +- I keep switching between 4 different editors so I needed something a bit more universal. + +## License + +Copyright © 2020 Filipp Lepalaan +This work is free. You can redistribute it and/or modify it under the +terms of the Do What The Fuck You Want To Public License, Version 2, +as published by Sam Hocevar. See http://www.wtfpl.net/ for more details. diff --git a/client.py b/client.py deleted file mode 100755 index 28b9c45..0000000 --- a/client.py +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/env python -import os -import sys -import requests - -def main(arg=None): - repo = os.getenv("HELLO_REPO") - assert repo is not None, "No repo configured!" - - templates = [] - for t in requests.get(repo).json(): - templates.append(t['name']) - - if arg is None: - return templates - - if arg in templates: - url = "{0}/{1}".format(repo.rstrip("/"), arg) - template = requests.get(url).text - return template - else: - error = "Template for {0} not found".format(arg) - raise Exception(error) - - -if __name__ == '__main__': - print(main(sys.argv[1])) diff --git a/hello.py b/hello.py new file mode 100755 index 0000000..237d975 --- /dev/null +++ b/hello.py @@ -0,0 +1,33 @@ +#!/usr/bin/env python +import os +import sys +from string import Template + +import requests + +def main(arg=None): + repo = os.getenv("HELLO_REPO") + assert repo is not None, "No repo configured!" + + templates = [] + for t in requests.get(repo).json(): + templates.append(t['name']) + + if arg is None: + return "\n".join(templates) + + if arg in templates: + url = "{0}/{1}".format(repo.rstrip("/"), arg) + template = Template(requests.get(url).text) + return template.substitute(**os.environ) + else: + error = "Template for {0} not found".format(arg) + raise Exception(error) + + +if __name__ == '__main__': + arg = None + if len(sys.argv) > 1: + arg = sys.argv[1] + + print(main(arg)) diff --git a/requirements.txt b/requirements.txt index ed56b80..f229360 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1 @@ requests -fastapi -uvicorn diff --git a/templates/nginx.rst b/templates/nginx.rst index 1fd314d..5923225 100644 --- a/templates/nginx.rst +++ b/templates/nginx.rst @@ -9,15 +9,15 @@ http { include mime.types; default_type application/octet-stream; - sendfile on; - keepalive_timeout 65; + sendfile on; + keepalive_timeout 65; server { listen 8080; server_name localhost; location / { - root html; + root $PWD/public_html; index index.html index.htm; } } -- cgit v1.2.3