changeset 81:9ad8421dafb4 1.1

merge
author Bernhard Herzog <bh@intevation.de>
date Mon, 09 Mar 2015 17:07:48 +0100
parents ae2f4e1c4ab0 (current diff) 3928af61b4ce (diff)
children c9e424850b3c
files
diffstat 8 files changed, 90 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- 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, <bjoern.ricks@intevation.de>
+Copyright (c) 2014, 2015 Intevation GmbH
+Author(s): Björn Ricks <bjoern.ricks@intevation.de>
 
 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal
--- 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"
 
--- /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()
--- 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"),
                  )
--- 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):
 
--- /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 %}
+<h1>Check</h1>
+
+<form role="form" action="" method="POST" enctype="multipart/form-data">
+    <div class="form-group">
+        <label for="files">File</label>
+        <input id="files" type="file" name="file">
+    </div>
+    <button class="btn btn-default" type="submit">Check</button>
+</form>
+{% endblock %}
--- 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 @@
     <li>
     <a href="/merge/">Merge</a>
     </li>
+    <li>
+    <a href="/check/">Check</a>
+    </li>
 </ul>
 {% endblock %}
--- 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 @@
         <label for="files">Files</label>
         <input id="files" type="file" name="files" multiple>
     </div>
-    <button class="btn btn-default" type="submit">Convert</button>
+    <button class="btn btn-default" type="submit">Merge</button>
 </form>
 {% endblock %}
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)