From c4d782613f90120e8c42dccd6f3775d3c4c0b1e0 Mon Sep 17 00:00:00 2001 From: Adrien Beudin Date: Fri, 5 May 2017 16:52:12 +0200 Subject: [PATCH] add new option of prosopopee command --- docs/build.rst | 20 ++++++++++++++++ docs/changelog.rst | 1 + docs/configuration.rst | 13 +++++++++++ docs/install.rst | 4 ++++ prosopopee/prosopopee.py | 49 +++++++++++++++++++++++++++++++++++++++- requirements.txt | 1 + 6 files changed, 87 insertions(+), 1 deletion(-) diff --git a/docs/build.rst b/docs/build.rst index f02b30b..0224659 100644 --- a/docs/build.rst +++ b/docs/build.rst @@ -1,6 +1,9 @@ Build the website ================= +Generate +-------- + **Note: You need to be in an activated virtualenv.** In a folder containing the **root** settings.yaml file, simply do:: @@ -9,3 +12,20 @@ In a folder containing the **root** settings.yaml file, simply do:: A `build` folder will be created in the current directory, containing an index.html, static files (css & js) and pictures. + +Preview +------- + +In a root folder launch this command:: + + prosopopee preview + +After you can check your website on http://localhost:9000 + +Deployment +---------- + +Prosopopee can upload your website with rsync, for do it run:: + + prosopopee deploy + diff --git a/docs/changelog.rst b/docs/changelog.rst index 8ed115e..0d6a839 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -6,6 +6,7 @@ Changelog * Add audio HTML5 player * Update Material theme * Add youtube section + * Add deploy and preview option 0.4 (2016-12-11) diff --git a/docs/configuration.rst b/docs/configuration.rst index 63daf85..237e5e1 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -188,6 +188,19 @@ Optionnal: You need use description and lang key in settings gallery. for more informations about Open Graph http://ogp.me/ +Deployment +~~~~~~~~~~ + +If you wanna configure the deployement of your website by rsync:: + + settings: + deploy: + username: beudbeud (optional need for ssh) + hostname: beudibox.fr (optional need for ssh) + dest: /var/www/surleschemins/build/ + others: --delete-afte (optional) + + Gallery settings.yaml --------------------- diff --git a/docs/install.rst b/docs/install.rst index ba9758b..a04df40 100644 --- a/docs/install.rst +++ b/docs/install.rst @@ -20,6 +20,10 @@ or:: apt-get install libav-tools +The deployment need rsync:: + + apt-get install rsync + Installation in virtualenv -------------------------- diff --git a/prosopopee/prosopopee.py b/prosopopee/prosopopee.py index ed84cf7..d94ed4c 100644 --- a/prosopopee/prosopopee.py +++ b/prosopopee/prosopopee.py @@ -1,8 +1,26 @@ #!/usr/bin/env python +"""Prosopopee. Static site generator for your story. +Usage: + prosopopee.py + prosopopee.py preview + prosopopee.py deploy + prosopopee.py (-h | --help) + prosopopee.py --version +Options: + -h --help Show this screen. + --version Show version. +""" + import os import yaml import shutil +from docopt import docopt + +import SocketServer +import SimpleHTTPServer + +import subprocess from path import Path @@ -500,6 +518,7 @@ def build_index(settings, galleries_cover, templates, gallery_path='', sub_index def main(): + arguments = docopt(__doc__, version='0.5') settings = get_settings() front_page_galleries_cover = [] @@ -510,8 +529,36 @@ def main(): "directory (NOT the settings.yaml in your current directory, but one INSIDE A " "DIRECTORY in your current working directory), you don't have any gallery?") - Path("build").makedirs_p() + if arguments['preview']: + error(Path("build").exists(), "Please build the website before launch preview") + os.chdir('build') + + Handler = SimpleHTTPServer.SimpleHTTPRequestHandler + httpd = SocketServer.TCPServer(("", 9000), Handler) + + print "Start server on http://localhost:9000" + # gracefully handle interrupt here + httpd.serve_forever() + + if arguments['deploy']: + error(os.system("which rsync > /dev/null") == 0, "I can't locate the rsync, " + "please install the 'rsync' package.\n") + error(Path("build").exists(), "Please build the website before launch deployment") + r_username = settings["settings"]["deploy"]["username"] + r_hostname = settings["settings"]["deploy"]["hostname"] + r_dest = settings["settings"]["deploy"]["dest"] + if settings["settings"]["deploy"]["others"]: + r_others = settings["settings"]["deploy"]["others"] + else: + r_others = '' + r_cmd = "rsync -avz --progress %s build/* %s@%s:%s" % (r_others, r_username, r_hostname, r_dest) + print r_cmd + error(os.system(r_cmd) == 0, "deployment failed") + #proc = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, preexec_fn=os.setsid) + return + + Path("build").makedirs_p() theme = settings["settings"].get("theme", "exposure") templates = get_gallery_templates(theme) templates.add_extension('jinja2.ext.with_') diff --git a/requirements.txt b/requirements.txt index aee8cc3..1f92f2e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ jinja2 pyyaml path.py +docopt