aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Tom Willemse2013-08-17 21:18:07 +0200
committerGravatar Tom Willemse2013-08-17 21:18:07 +0200
commit12799b9ddd0ab1bb34cb1aa433d5d24ad8dec1ba (patch)
tree45b931aecdb7c20dec8c49a8b5ecfd8759ff4ad4
parente73ca5556f4aae9a78ef083203352fd334b0aa60 (diff)
downloadhypo-12799b9ddd0ab1bb34cb1aa433d5d24ad8dec1ba.tar.gz
hypo-12799b9ddd0ab1bb34cb1aa433d5d24ad8dec1ba.zip
Add hypoctl script
Will be used to control certain server-side aspects of hypo.
-rwxr-xr-xhypo.hy4
-rwxr-xr-xhypoctl56
2 files changed, 58 insertions, 2 deletions
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 <http://www.gnu.org/licenses/>.
+
+(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 <command> [<args]"]
+ [description "Control hypo"]
+ [run (lambda [self]
+ (cond
+ ((not self.args)
+ (progn (print self.usage) 2))
+ ((= (car self.args) "purge")
+ (hypo-purge (cdr self.args)))
+ ((= (car self.args) "start")
+ (hypo-start (cdr self.args)))
+ (True
+ (print (.format "error: command {0} does not exist"
+ (car self.args))))))]])
+
+(when (= __name__ "__main__")
+ (let ((cmd (hypoctl-command (cdr (cdr sys.argv)))))
+ (if cmd.error
+ (progn (print (.format "error: {0}" cmd.error))
+ (sys.exit 1))
+ (sys.exit (cmd.run)))))