# HG changeset patch # User Bernhard Herzog # Date 1425917268 -3600 # Node ID 9ad8421dafb43c2df9c11472b51d575c0553aa27 # Parent ae2f4e1c4ab0cc0bce951f1f9665c4fa6da6396f# Parent 3928af61b4cec9ab1c6171df529800ed7c656e00 merge diff -r ae2f4e1c4ab0 -r 9ad8421dafb4 LICENSE --- a/LICENSE Thu Feb 26 12:27:54 2015 +0100 +++ b/LICENSE Mon Mar 09 17:07:48 2015 +0100 @@ -1,6 +1,7 @@ The MIT License (MIT) -Copyright (c) 2014 Björn Ricks, +Copyright (c) 2014, 2015 Intevation GmbH +Author(s): Björn Ricks Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff -r ae2f4e1c4ab0 -r 9ad8421dafb4 README.rst --- a/README.rst Thu Feb 26 12:27:54 2015 +0100 +++ b/README.rst Mon Mar 09 17:07:48 2015 +0100 @@ -24,7 +24,7 @@ PY3O_UNO_SERVER_HOSTNAME = "my.server.url" PY3O_UNO_SERVER_PORT = 4001 -or host and port for the odfcase service:: +or host and port for the odfcast service:: SERVER_NAME = "my.odfcast.url:8500" diff -r ae2f4e1c4ab0 -r 9ad8421dafb4 checkclient.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/checkclient.py Mon Mar 09 17:07:48 2015 +0100 @@ -0,0 +1,38 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import optparse +import sys + +import requests + + +def main(): + usage = "usage: %prog [options] infile" + parser = optparse.OptionParser(usage=usage) + parser.add_option("-s", "--host", default="localhost") + parser.add_option("-p", "--port", default="5000") + (options, args) = parser.parse_args() + + if len(args) < 1: + parser.print_usage() + sys.exit(1) + + url = "http://%s:%s/check/" % (options.host, options.port) + infilename = args[0] + + files = {'file': open(infilename, 'rb')} + + r = requests.post(url, files=files) + + if r.status_code == 200: + print "OK" + else: + print "An error has occured" + print r.status_code, r.headers + print r.text + sys.exit(2) + + +if __name__ == "__main__": + main() diff -r ae2f4e1c4ab0 -r 9ad8421dafb4 odfcast/__init__.py --- a/odfcast/__init__.py Thu Feb 26 12:27:54 2015 +0100 +++ b/odfcast/__init__.py Mon Mar 09 17:07:48 2015 +0100 @@ -12,7 +12,7 @@ if app.config["DEBUG"]: logging.basicConfig(level=logging.DEBUG) -from odfcast.convert import ConvertView, MergeView, TemplateView +from odfcast.convert import ConvertView, MergeView, CheckView, TemplateView app.add_url_rule("/convert/", @@ -25,6 +25,9 @@ app.add_url_rule("/merge/", view_func=MergeView.as_view("merge"), ) +app.add_url_rule("/check/", + view_func=CheckView.as_view("check"), + ) app.add_url_rule("/", view_func=TemplateView.as_view("index", "index.html"), ) diff -r ae2f4e1c4ab0 -r 9ad8421dafb4 odfcast/convert.py --- a/odfcast/convert.py Thu Feb 26 12:27:54 2015 +0100 +++ b/odfcast/convert.py Mon Mar 09 17:07:48 2015 +0100 @@ -232,6 +232,34 @@ return request.args.get("ignore_file_errors", False) or \ request.form.get("ignore_file_errors", False) +class CheckView(MethodView): + + def get(self): + return render_template("check.html") + + def post(self): + log.debug("Checking a PDF document's readiness for merging") + + merger = PdfFileMerger() + + ffile = request.files['file'] + if not ffile.filename: + return ErrorResponse( + "Upload file missing", error_code=101, + details="Please upload a file for conversion", + html_error_code=400) + + try: + merger.append(ffile) + except Exception, e: + log.exception("Error merging file %s" % ffile) + return MergeErrorResponse(details=str(e)) + + merger.close() + + log.debug("PDF document %s checked." % ffile) + return Response("Okay.") + class TemplateView(MethodView): diff -r ae2f4e1c4ab0 -r 9ad8421dafb4 odfcast/templates/check.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/odfcast/templates/check.html Mon Mar 09 17:07:48 2015 +0100 @@ -0,0 +1,13 @@ +{% extends 'base.html' %} + +{% block content %} +

Check

+ +
+
+ + +
+ +
+{% endblock %} diff -r ae2f4e1c4ab0 -r 9ad8421dafb4 odfcast/templates/index.html --- a/odfcast/templates/index.html Thu Feb 26 12:27:54 2015 +0100 +++ b/odfcast/templates/index.html Mon Mar 09 17:07:48 2015 +0100 @@ -8,5 +8,8 @@
  • Merge
  • +
  • + Check +
  • {% endblock %} diff -r ae2f4e1c4ab0 -r 9ad8421dafb4 odfcast/templates/merge.html --- a/odfcast/templates/merge.html Thu Feb 26 12:27:54 2015 +0100 +++ b/odfcast/templates/merge.html Mon Mar 09 17:07:48 2015 +0100 @@ -8,6 +8,6 @@ - + {% endblock %}