From 12799b9ddd0ab1bb34cb1aa433d5d24ad8dec1ba Mon Sep 17 00:00:00 2001 From: Tom Willemse Date: Sat, 17 Aug 2013 21:18:07 +0200 Subject: [PATCH] Add hypoctl script Will be used to control certain server-side aspects of hypo. --- hypo.hy | 4 ++-- hypoctl | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 2 deletions(-) create mode 100755 hypoctl diff --git a/hypo.hy b/hypo.hy index 05fa858..8053488 100755 --- a/hypo.hy +++ b/hypo.hy @@ -137,7 +137,7 @@ If no lexer is found fallback onto the text lexer." (setv web.ctx.status (str "201 Created")) (+ web.ctx.home "/" *prefix* (get h 0) "\n")))]]) -(when (= __name__ "__main__") - (let ((sys.argv (slice sys.argv 1)) +(defun hypo-start [argv] + (let ((sys.argv (cdr (cdr sys.argv))) (app (web.application urls (globals)))) (.run app))) diff --git a/hypoctl b/hypoctl new file mode 100755 index 0000000..40a69a5 --- /dev/null +++ b/hypoctl @@ -0,0 +1,56 @@ +#!/usr/bin/env hy +;; Hypo -- Quickly share stuff +;; Copyright (C) 2013 Tom Willemse + +;; Hypo is free software: you can redistribute it and/or modify it +;; under the terms of the GNU Affero General Public License as +;; published by the Free Software Foundation, either version 3 of the +;; License, or (at your option) any later version. + +;; Hypo is distributed in the hope that it will be useful, but WITHOUT +;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General +;; Public License for more details. + +;; You should have received a copy of the GNU Affero General Public +;; License along with Hypo. If not, see . + +(import pycommand sys web os + [hypo [hypo-start]]) + +(try (import [config [*]]) + (catch [ImportError] + (print "Please copy the config.example.hy to config.hy and set" + "the values to your preference.") + (sys.exit 1))) + +(def db + (kwapply (web.database) + {"dbn" "postgres" "user" *dbuser* "pw" *dbpw* "db" *dbname*})) + +(defun hypo-purge [argv] + (db.delete "hfile" "TRUE") + (foreach [f (os.listdir "files/")] + (os.remove (os.path.join "files" f)))) + +(defclass hypoctl-command (pycommand.CommandBase) + [[usagestr "usage: hypoctl [