colony-print 0.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. colony-print-0.2.0/PKG-INFO +89 -0
  2. colony-print-0.2.0/README.md +62 -0
  3. colony-print-0.2.0/setup.cfg +7 -0
  4. colony-print-0.2.0/setup.py +63 -0
  5. colony-print-0.2.0/src/colony_print/__init__.py +10 -0
  6. colony-print-0.2.0/src/colony_print/controllers/__init__.py +12 -0
  7. colony-print-0.2.0/src/colony_print/controllers/base.py +7 -0
  8. colony-print-0.2.0/src/colony_print/controllers/document.py +79 -0
  9. colony-print-0.2.0/src/colony_print/controllers/node.py +126 -0
  10. colony-print-0.2.0/src/colony_print/controllers/printer.py +33 -0
  11. colony-print-0.2.0/src/colony_print/main.py +25 -0
  12. colony-print-0.2.0/src/colony_print/node.py +75 -0
  13. colony-print-0.2.0/src/colony_print/printing/__init__.py +12 -0
  14. colony-print-0.2.0/src/colony_print/printing/binie/__init__.py +10 -0
  15. colony-print-0.2.0/src/colony_print/printing/binie/exceptions.py +36 -0
  16. colony-print-0.2.0/src/colony_print/printing/binie/system.py +32 -0
  17. colony-print-0.2.0/src/colony_print/printing/binie/visitor.py +561 -0
  18. colony-print-0.2.0/src/colony_print/printing/common/__init__.py +6 -0
  19. colony-print-0.2.0/src/colony_print/printing/common/base.py +65 -0
  20. colony-print-0.2.0/src/colony_print/printing/manager/__init__.py +15 -0
  21. colony-print-0.2.0/src/colony_print/printing/manager/ast.py +98 -0
  22. colony-print-0.2.0/src/colony_print/printing/manager/exceptions.py +36 -0
  23. colony-print-0.2.0/src/colony_print/printing/manager/parser.py +237 -0
  24. colony-print-0.2.0/src/colony_print/printing/manager/system.py +108 -0
  25. colony-print-0.2.0/src/colony_print/printing/manager/visitor.py +95 -0
  26. colony-print-0.2.0/src/colony_print/printing/pdf/__init__.py +10 -0
  27. colony-print-0.2.0/src/colony_print/printing/pdf/exceptions.py +62 -0
  28. colony-print-0.2.0/src/colony_print/printing/pdf/system.py +34 -0
  29. colony-print-0.2.0/src/colony_print/printing/pdf/visitor.py +839 -0
  30. colony-print-0.2.0/src/colony_print/static/example/js/main.js +112 -0
  31. colony-print-0.2.0/src/colony_print/static/example/print.html +17 -0
  32. colony-print-0.2.0/src/colony_print/static/example/xml/hello.xml +8 -0
  33. colony-print-0.2.0/src/colony_print/static/example/xml/money_sale_slip.xml +148 -0
  34. colony-print-0.2.0/src/colony_print.egg-info/PKG-INFO +89 -0
  35. colony-print-0.2.0/src/colony_print.egg-info/SOURCES.txt +38 -0
  36. colony-print-0.2.0/src/colony_print.egg-info/dependency_links.txt +1 -0
  37. colony-print-0.2.0/src/colony_print.egg-info/not-zip-safe +1 -0
  38. colony-print-0.2.0/src/colony_print.egg-info/requires.txt +5 -0
  39. colony-print-0.2.0/src/colony_print.egg-info/top_level.txt +1 -0
@@ -0,0 +1,89 @@
1
+ Metadata-Version: 2.1
2
+ Name: colony-print
3
+ Version: 0.2.0
4
+ Summary: Colony Print Infra-structure
5
+ Home-page: http://colony-print.hive.pt
6
+ Author: Hive Solutions Lda.
7
+ Author-email: development@hive.pt
8
+ License: Apache License, Version 2.0
9
+ Description: # [Colony Print Infra-structure](http://colony-print.hive.pt)
10
+
11
+ Small web app for printing of Colony based documents.
12
+
13
+ This project includes two main components:
14
+
15
+ * The web app end point that allows for XML to Binie conversion `colony_print.controllers`
16
+ * The structure conversion infra-structure (visitors, ast, etc.) `colony_print.printing`
17
+
18
+ ## Installation
19
+
20
+ ### Pre-requisites
21
+
22
+ ```bash
23
+ apt-get install gcc python-dev
24
+ pip install --upgrade appier netius pillow reportlab
25
+ ```
26
+
27
+ ### Run Server
28
+
29
+ ```bash
30
+ pip install colony_print
31
+ python -m colony_print.main
32
+ ```
33
+
34
+ ### Run Node
35
+
36
+ ```bash
37
+ pip install colony_print
38
+ BASE_URL=$BASE_URL \
39
+ SECRET_KEY=$SECRET_KEY \
40
+ NODE_ID=$NODE_ID \
41
+ NODE_NAME=$NODE_NAME \
42
+ NODE_LOCATION=$NODE_LOCATION \
43
+ python -m colony_print.node
44
+ ```
45
+
46
+ ### Fonts
47
+
48
+ To be able to use new fonts (other than the ones provided by the system) one must install them
49
+ into the `/usr/share/fonts/truetype` directory so they are exposed and ready to
50
+ be used by the PDF generation infra-structure. For example calibri is one type of font that should
51
+ be exported to an UNIX machine as it is used by mani colony generated documents.
52
+
53
+ ## Running
54
+
55
+ ```bash
56
+ PORT=8686 \
57
+ PYTHONPATH=$BASE_PATH/colony_print/src python \
58
+ $BASE_PATH/colony_print/src/colony_print/main.py
59
+ ```
60
+
61
+ ## License
62
+
63
+ Colony Print Infra-structure is currently licensed under the [Apache License, Version 2.0](http://www.apache.org/licenses/).
64
+
65
+ ## Build Automation
66
+
67
+ [![Build Status](https://app.travis-ci.com/hivesolutions/colony-print.svg?branch=master)](https://travis-ci.com/github/hivesolutions/colony-print)
68
+ [![Coverage Status](https://coveralls.io/repos/hivesolutions/colony-print/badge.svg?branch=master)](https://coveralls.io/r/hivesolutions/colony-print?branch=master)
69
+ [![PyPi Status](https://img.shields.io/pypi/v/colony-print.svg)](https://pypi.python.org/pypi/colony-print)
70
+ [![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](https://www.apache.org/licenses/)
71
+
72
+ Keywords: colony print native
73
+ Platform: UNKNOWN
74
+ Classifier: Development Status :: 5 - Production/Stable
75
+ Classifier: Topic :: Utilities
76
+ Classifier: License :: OSI Approved :: Apache Software License
77
+ Classifier: Operating System :: OS Independent
78
+ Classifier: Programming Language :: Python
79
+ Classifier: Programming Language :: Python :: 2.6
80
+ Classifier: Programming Language :: Python :: 2.7
81
+ Classifier: Programming Language :: Python :: 3.0
82
+ Classifier: Programming Language :: Python :: 3.1
83
+ Classifier: Programming Language :: Python :: 3.2
84
+ Classifier: Programming Language :: Python :: 3.3
85
+ Classifier: Programming Language :: Python :: 3.4
86
+ Classifier: Programming Language :: Python :: 3.5
87
+ Classifier: Programming Language :: Python :: 3.6
88
+ Classifier: Programming Language :: Python :: 3.7
89
+ Description-Content-Type: text/markdown
@@ -0,0 +1,62 @@
1
+ # [Colony Print Infra-structure](http://colony-print.hive.pt)
2
+
3
+ Small web app for printing of Colony based documents.
4
+
5
+ This project includes two main components:
6
+
7
+ * The web app end point that allows for XML to Binie conversion `colony_print.controllers`
8
+ * The structure conversion infra-structure (visitors, ast, etc.) `colony_print.printing`
9
+
10
+ ## Installation
11
+
12
+ ### Pre-requisites
13
+
14
+ ```bash
15
+ apt-get install gcc python-dev
16
+ pip install --upgrade appier netius pillow reportlab
17
+ ```
18
+
19
+ ### Run Server
20
+
21
+ ```bash
22
+ pip install colony_print
23
+ python -m colony_print.main
24
+ ```
25
+
26
+ ### Run Node
27
+
28
+ ```bash
29
+ pip install colony_print
30
+ BASE_URL=$BASE_URL \
31
+ SECRET_KEY=$SECRET_KEY \
32
+ NODE_ID=$NODE_ID \
33
+ NODE_NAME=$NODE_NAME \
34
+ NODE_LOCATION=$NODE_LOCATION \
35
+ python -m colony_print.node
36
+ ```
37
+
38
+ ### Fonts
39
+
40
+ To be able to use new fonts (other than the ones provided by the system) one must install them
41
+ into the `/usr/share/fonts/truetype` directory so they are exposed and ready to
42
+ be used by the PDF generation infra-structure. For example calibri is one type of font that should
43
+ be exported to an UNIX machine as it is used by mani colony generated documents.
44
+
45
+ ## Running
46
+
47
+ ```bash
48
+ PORT=8686 \
49
+ PYTHONPATH=$BASE_PATH/colony_print/src python \
50
+ $BASE_PATH/colony_print/src/colony_print/main.py
51
+ ```
52
+
53
+ ## License
54
+
55
+ Colony Print Infra-structure is currently licensed under the [Apache License, Version 2.0](http://www.apache.org/licenses/).
56
+
57
+ ## Build Automation
58
+
59
+ [![Build Status](https://app.travis-ci.com/hivesolutions/colony-print.svg?branch=master)](https://travis-ci.com/github/hivesolutions/colony-print)
60
+ [![Coverage Status](https://coveralls.io/repos/hivesolutions/colony-print/badge.svg?branch=master)](https://coveralls.io/r/hivesolutions/colony-print?branch=master)
61
+ [![PyPi Status](https://img.shields.io/pypi/v/colony-print.svg)](https://pypi.python.org/pypi/colony-print)
62
+ [![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](https://www.apache.org/licenses/)
@@ -0,0 +1,7 @@
1
+ [bdist_wheel]
2
+ universal = 1
3
+
4
+ [egg_info]
5
+ tag_build =
6
+ tag_date = 0
7
+
@@ -0,0 +1,63 @@
1
+ #!/usr/bin/python
2
+ # -*- coding: utf-8 -*-
3
+
4
+ import os
5
+ import setuptools
6
+
7
+ setuptools.setup(
8
+ name = "colony-print",
9
+ version = "0.2.0",
10
+ author = "Hive Solutions Lda.",
11
+ author_email = "development@hive.pt",
12
+ description = "Colony Print Infra-structure",
13
+ license = "Apache License, Version 2.0",
14
+ keywords = "colony print native",
15
+ url = "http://colony-print.hive.pt",
16
+ zip_safe = False,
17
+ packages = [
18
+ "colony_print",
19
+ "colony_print.controllers",
20
+ "colony_print.printing",
21
+ "colony_print.printing.binie",
22
+ "colony_print.printing.common",
23
+ "colony_print.printing.manager",
24
+ "colony_print.printing.pdf"
25
+ ],
26
+ test_suite = "colony_print.test",
27
+ package_dir = {
28
+ "" : os.path.normpath("src")
29
+ },
30
+ package_data = {
31
+ "colony_print" : [
32
+ "static/example/*",
33
+ "static/example/js/*",
34
+ "static/example/xml/*"
35
+ ]
36
+ },
37
+ install_requires = [
38
+ "appier",
39
+ "appier-extras",
40
+ "jinja2",
41
+ "pillow",
42
+ "reportlab"
43
+ ],
44
+ classifiers = [
45
+ "Development Status :: 5 - Production/Stable",
46
+ "Topic :: Utilities",
47
+ "License :: OSI Approved :: Apache Software License",
48
+ "Operating System :: OS Independent",
49
+ "Programming Language :: Python",
50
+ "Programming Language :: Python :: 2.6",
51
+ "Programming Language :: Python :: 2.7",
52
+ "Programming Language :: Python :: 3.0",
53
+ "Programming Language :: Python :: 3.1",
54
+ "Programming Language :: Python :: 3.2",
55
+ "Programming Language :: Python :: 3.3",
56
+ "Programming Language :: Python :: 3.4",
57
+ "Programming Language :: Python :: 3.5",
58
+ "Programming Language :: Python :: 3.6",
59
+ "Programming Language :: Python :: 3.7"
60
+ ],
61
+ long_description = open(os.path.join(os.path.dirname(__file__), "README.md"), "rb").read().decode("utf-8"),
62
+ long_description_content_type = "text/markdown"
63
+ )
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/python
2
+ # -*- coding: utf-8 -*-
3
+
4
+ from . import controllers
5
+ from . import printing
6
+ from . import main
7
+
8
+ from .controllers import *
9
+ from .printing import *
10
+ from .main import ColonyPrintApp
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/python
2
+ # -*- coding: utf-8 -*-
3
+
4
+ from . import base
5
+ from . import document
6
+ from . import node
7
+ from . import printer
8
+
9
+ from .base import BaseController
10
+ from .document import DocumentController
11
+ from .node import NodeController
12
+ from .printer import PrinterController
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/python
2
+ # -*- coding: utf-8 -*-
3
+
4
+ import appier
5
+
6
+ class BaseController(appier.Controller):
7
+ pass
@@ -0,0 +1,79 @@
1
+ #!/usr/bin/python
2
+ # -*- coding: utf-8 -*-
3
+
4
+ import base64
5
+
6
+ import appier
7
+
8
+ MIME = dict(
9
+ binie = "text/x-binie",
10
+ pdf = "application/pdf"
11
+ )
12
+ """ Map defining the association between the print
13
+ format naming and the associated base mime type value
14
+ (note that this value may be complemented with base64) """
15
+
16
+ EXAMPLE = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\
17
+ <printing_document name=\"hello_world\" font=\"Calibri\" font_size=\"9\">\
18
+ <paragraph text_align=\"center\">\
19
+ <line><text>Hello World</text></line>\
20
+ </paragraph>\
21
+ </printing_document>"
22
+ """ Example XML string that should display an hello world
23
+ message using the XML printing language """
24
+
25
+ class DocumentController(appier.Controller):
26
+
27
+ def __init__(self, owner, *args, **kwargs):
28
+ appier.Controller.__init__(self, owner, *args, **kwargs)
29
+ self.manager = None
30
+
31
+ @appier.route("/documents/example.<format>", "GET")
32
+ def example(self, format):
33
+ return self.send_print(EXAMPLE, format)
34
+
35
+ @appier.route("/documents.<format>", "POST")
36
+ def convert(self, format):
37
+ # retrieves the current request reference and then
38
+ # uses it to retrieve its "raw" data, that should
39
+ # contain the XML string for the generation of the
40
+ # of binie result and then sends the value for print
41
+ request = self.get_request()
42
+ data = request.get_data()
43
+ return self.send_print(data, format = format)
44
+
45
+ def send_print(self, data, format = "binie"):
46
+ # retrieves the various optional fields for printing
47
+ # and then parses them creating the composite values
48
+ # (should include the size tuple)
49
+ b64 = self.field("base64", False, cast = bool)
50
+ width = self.field("width", 0.0, cast = float)
51
+ height = self.field("height", 0.0, cast = float)
52
+ has_size = width > 0.0 and width > 0.0
53
+
54
+ mime = self.get_mime(format, b64 = base64)
55
+ manager = self.get_manager()
56
+
57
+ data = data
58
+ file = appier.legacy.BytesIO()
59
+ options = dict(name = format, file = file)
60
+ if has_size: options["size"] = (width, height)
61
+
62
+ manager.print_language(data, options)
63
+ value = file.getvalue()
64
+ value = base64.b64encode(value) if b64 else value
65
+
66
+ self.content_type(mime)
67
+ return value
68
+
69
+ def get_mime(self, format, b64 = False):
70
+ mime = MIME.get(format, "application/octet-stream")
71
+ mime = mime + "-base64" if b64 else mime
72
+ return mime
73
+
74
+ def get_manager(self):
75
+ import colony_print
76
+ if self.manager: return self.manager
77
+ self.manager = colony_print.PrintingManager()
78
+ self.manager.load()
79
+ return self.manager
@@ -0,0 +1,126 @@
1
+ #!/usr/bin/python
2
+ # -*- coding: utf-8 -*-
3
+
4
+ import json
5
+ import uuid
6
+
7
+ import appier
8
+
9
+ HELLO_WORLD_B64 = "SGVsbG8gV29ybGQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\
10
+ AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\
11
+ AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\
12
+ AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\
13
+ AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAEAAABAAQAAAA\
14
+ AAAAAAAABDYWxpYnJpAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\
15
+ AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\
16
+ AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\
17
+ AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\
18
+ AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACQAAAAMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\
19
+ AAAAAAAAAwAAABIZWxsbyBXb3JsZAA="
20
+
21
+ class NodeController(appier.Controller):
22
+
23
+ @appier.route("/nodes", "GET", json = True)
24
+ @appier.ensure(token = "admin")
25
+ def list(self):
26
+ return self.owner.nodes
27
+
28
+ @appier.route("/nodes/<str:id>", "POST", json = True)
29
+ @appier.ensure(token = "admin")
30
+ def create(self, id):
31
+ node = appier.get_object()
32
+ self.owner.nodes[id] = node
33
+
34
+ @appier.route("/nodes/<str:id>", "GET", json = True)
35
+ @appier.ensure(token = "admin")
36
+ def show(self, id):
37
+ return self.owner.nodes[id]
38
+
39
+ @appier.route("/nodes/<str:id>/jobs", "GET", json = True)
40
+ @appier.ensure(token = "admin")
41
+ def jobs(self, id):
42
+ self.request.set_content_type("application/json")
43
+ for value in appier.header_a(): yield value
44
+ for value in self.wait_jobs(id): yield value
45
+
46
+ @appier.route("/nodes/<str:id>/jobs_peek", "GET", json = True)
47
+ @appier.ensure(token = "admin")
48
+ def jobs_peek(self, id):
49
+ jobs = self.owner.jobs.get(id, [])
50
+ return jobs
51
+
52
+ @appier.route("/nodes/<str:id>/print", ("GET", "POST"), json = True)
53
+ @appier.ensure(token = "admin")
54
+ def print_default(self, id):
55
+ data_b64 = self.field("data_b64", mandatory = True, not_empty = True)
56
+ name = self.field("name", None)
57
+ name = name or str(uuid.uuid4())
58
+ job = dict(data_b64 = data_b64)
59
+ if name: job["name"] = name
60
+ jobs = self.owner.jobs.get(id, [])
61
+ jobs.append(job)
62
+ self.owner.jobs[id] = jobs
63
+ appier.notify("jobs:%s" % id)
64
+
65
+ @appier.route("/nodes/<str:id>/print", "OPTIONS")
66
+ def print_default_o(self, id):
67
+ return ""
68
+
69
+ @appier.route("/nodes/<str:id>/print_hello", ("GET", "POST"), json = True)
70
+ @appier.ensure(token = "admin")
71
+ def print_hello_default(self, id):
72
+ self.set_field("data_b64", HELLO_WORLD_B64)
73
+ self.set_field("name", "hello_world")
74
+ self.print_default(id)
75
+
76
+ @appier.route("/nodes/<str:id>/printers/print", ("GET", "POST"), json = True)
77
+ @appier.ensure(token = "admin")
78
+ def print_printer_f(self, id):
79
+ printer = self.field("printer")
80
+ return self.print_printer(id, printer)
81
+
82
+ @appier.route("/nodes/<str:id>/printers/print", "OPTIONS")
83
+ def print_printer_of(self, id):
84
+ printer = self.field("printer")
85
+ return self.print_printer_o(id, printer)
86
+
87
+ @appier.route("/nodes/<str:id>/printers/print_hello", ("GET", "POST"), json = True)
88
+ @appier.ensure(token = "admin")
89
+ def print_hello_printer_f(self, id):
90
+ printer = self.field("printer")
91
+ return self.print_hello_printer(id, printer)
92
+
93
+ @appier.route("/nodes/<str:id>/printers/<str:printer>/print", ("GET", "POST"), json = True)
94
+ @appier.ensure(token = "admin")
95
+ def print_printer(self, id, printer):
96
+ data_b64 = self.field("data_b64", mandatory = True, not_empty = True)
97
+ name = self.field("name", None)
98
+ name = name or str(uuid.uuid4())
99
+ job = dict(
100
+ data_b64 = data_b64,
101
+ printer = printer
102
+ )
103
+ if name: job["name"] = name
104
+ jobs = self.owner.jobs.get(id, [])
105
+ jobs.append(job)
106
+ self.owner.jobs[id] = jobs
107
+ appier.notify("jobs:%s" % id)
108
+
109
+ @appier.route("/nodes/<str:id>/printers/<str:printer>/print", "OPTIONS")
110
+ def print_printer_o(self, id, printer):
111
+ return ""
112
+
113
+ @appier.route("/nodes/<str:id>/printers/<str:printer>/print_hello", ("GET", "POST"), json = True)
114
+ @appier.ensure(token = "admin")
115
+ def print_hello_printer(self, id, printer):
116
+ self.set_field("data_b64", HELLO_WORLD_B64)
117
+ self.set_field("name", "hello_world")
118
+ self.print_printer(id, printer)
119
+
120
+ @appier.coroutine
121
+ def wait_jobs(self, id):
122
+ while True:
123
+ jobs = self.owner.jobs.pop(id, [])
124
+ if jobs: break
125
+ for value in appier.wait("jobs:%s" % id): yield value
126
+ yield json.dumps(jobs)
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/python
2
+ # -*- coding: utf-8 -*-
3
+
4
+ import appier
5
+
6
+ class PrinterController(appier.Controller):
7
+
8
+ @appier.route("/printers", "GET", json = True)
9
+ @appier.ensure(token = "admin")
10
+ def list(self):
11
+ return self.npcolony.get_devices()
12
+
13
+ @appier.route("/printers/hello", "GET", json = True)
14
+ @appier.ensure(token = "admin")
15
+ def hello(self):
16
+ self.npcolony.print_hello()
17
+
18
+ @appier.route("/printers/print", "GET", json = True)
19
+ @appier.ensure(token = "admin")
20
+ def print_document_f(self):
21
+ printer = self.field("printer")
22
+ return self.print_document(printer)
23
+
24
+ @appier.route("/printers/<str:printer>/print", ("GET", "POST"), json = True)
25
+ @appier.ensure(token = "admin")
26
+ def print_document(self, printer):
27
+ data_b64 = self.field("data_b64")
28
+ self.npcolony.print_printer_base64(printer, data_b64)
29
+
30
+ @property
31
+ def npcolony(self):
32
+ import npcolony
33
+ return npcolony
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/python
2
+ # -*- coding: utf-8 -*-
3
+
4
+ import appier
5
+ import appier_extras
6
+
7
+ class ColonyPrintApp(appier.APIApp):
8
+
9
+ def __init__(self, *args, **kwargs):
10
+ appier.APIApp.__init__(
11
+ self,
12
+ name = "colony-print",
13
+ parts = (
14
+ appier_extras.AdminPart,
15
+ ),
16
+ *args, **kwargs
17
+ )
18
+ self.nodes = dict()
19
+ self.jobs = dict()
20
+
21
+ if __name__ == "__main__":
22
+ app = ColonyPrintApp()
23
+ app.serve()
24
+ else:
25
+ __path__ = []
@@ -0,0 +1,75 @@
1
+ #!/usr/bin/python
2
+ # -*- coding: utf-8 -*-
3
+
4
+ import time
5
+ import logging
6
+
7
+ import appier
8
+
9
+ BASE_URL = "https://print.bemisc.com/"
10
+
11
+ SLEEP_TIME = 3.0
12
+
13
+ class ColonyPrintNode(object):
14
+
15
+ def __init__(self, sleep_time = SLEEP_TIME):
16
+ self.sleep_time = sleep_time
17
+
18
+ def loop(self):
19
+ logging.basicConfig(
20
+ format = "%(asctime)s [%(levelname)s] %(message)s",
21
+ level = logging.DEBUG
22
+ )
23
+
24
+ base_url = appier.conf("BASE_URL", BASE_URL)
25
+ secret_key = appier.conf("SECRET_KEY", None)
26
+ node_id = appier.conf("NODE_ID", "node")
27
+ node_name = appier.conf("NODE_NAME", "node")
28
+ node_location = appier.conf("NODE_LOCATION", "undefined")
29
+
30
+ headers = dict()
31
+ if secret_key: headers["X-Secret-Key"] = secret_key
32
+
33
+ while True:
34
+ try:
35
+ logging.info("Submitting node information")
36
+ appier.post(
37
+ base_url + "nodes/%s" % node_id,
38
+ data_j = dict(
39
+ name = node_name,
40
+ location = node_location
41
+ ),
42
+ headers = headers
43
+ )
44
+ logging.info("Retrieving jobs for node '%s'" % node_id)
45
+ jobs = appier.get(
46
+ base_url + "nodes/%s/jobs" % node_id,
47
+ headers = headers,
48
+ timeout = 600
49
+ )
50
+ logging.info("Retrieved %d jobs for node '%s'" % (len(jobs), node_id))
51
+ for job in jobs: self.print_job(job)
52
+ except Exception as exception:
53
+ logging.info("Exception while looping '%s'" % str(exception))
54
+ logging.info("Sleeping for %.2f seconds" % self.sleep_time)
55
+ time.sleep(self.sleep_time)
56
+
57
+ def print_job(self, job):
58
+ data_b64 = job["data_b64"]
59
+ name = job.get("name", "undefined")
60
+ printer = job.get("printer", None)
61
+ printer_s = printer if printer else "default"
62
+ logging.info("Printing job '%s' with '%s' printer" % (name, printer_s))
63
+ if printer: self.npcolony.print_printer_base64(printer, data_b64)
64
+ else: self.npcolony.print_base64(data_b64)
65
+
66
+ @property
67
+ def npcolony(self):
68
+ import npcolony
69
+ return npcolony
70
+
71
+ if __name__ == "__main__":
72
+ node = ColonyPrintNode()
73
+ node.loop()
74
+ else:
75
+ __path__ = []
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/python
2
+ # -*- coding: utf-8 -*-
3
+
4
+ from . import binie
5
+ from . import common
6
+ from . import manager
7
+ from . import pdf
8
+
9
+ from .binie import *
10
+ from .common import *
11
+ from .manager import *
12
+ from .pdf import *
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/python
2
+ # -*- coding: utf-8 -*-
3
+
4
+ from . import exceptions
5
+ from . import system
6
+ from . import visitor
7
+
8
+ from .exceptions import PrintingBinieException, InvalidContextInformationName
9
+ from .system import PrintingBinie
10
+ from .visitor import Visitor
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/python
2
+ # -*- coding: utf-8 -*-
3
+
4
+ class PrintingBinieException(Exception):
5
+ """
6
+ The printing binie exception class.
7
+ """
8
+
9
+ message = None
10
+ """ The exception's message """
11
+
12
+ class InvalidContextInformationName(PrintingBinieException):
13
+ """
14
+ The invalid context information name class.
15
+ """
16
+
17
+ def __init__(self, message):
18
+ """
19
+ Constructor of the class.
20
+
21
+ :type message: String
22
+ :param message: The message to be printed.
23
+ """
24
+
25
+ PrintingBinieException.__init__(self)
26
+ self.message = message
27
+
28
+ def __str__(self):
29
+ """
30
+ Returns the string representation of the class.
31
+
32
+ :rtype: String
33
+ :return: The string representation of the class.
34
+ """
35
+
36
+ return "Invalid context information name - %s" % self.message