zebra-day 0.0.37__py3-none-any.whl → 2.0.0__py3-none-any.whl

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 (173) hide show
  1. zebra_day/__init__.py +35 -0
  2. zebra_day/bin/__init__.py +0 -0
  3. zebra_day/cli/__init__.py +240 -0
  4. zebra_day/cli/cognito.py +121 -0
  5. zebra_day/cli/gui.py +338 -0
  6. zebra_day/cli/printer.py +168 -0
  7. zebra_day/cli/template.py +176 -0
  8. zebra_day/cmd_mgr.py +35 -0
  9. zebra_day/etc/Monoid-Regular-HalfTight-Dollar-0-1-l.ttf +0 -0
  10. zebra_day/etc/label_styles/blank.zpl +0 -0
  11. zebra_day/etc/label_styles/cornersStripOf4Squares_1inX1in.zpl +55 -0
  12. zebra_day/etc/label_styles/corners_1inX2in.zpl +28 -0
  13. zebra_day/etc/label_styles/corners_20cmX30cm.zpl +6 -0
  14. zebra_day/etc/label_styles/corners_smallTube.zpl +7 -0
  15. zebra_day/etc/label_styles/corners_unspecifiedDimensions.zpl +15 -0
  16. zebra_day/etc/label_styles/generic_2inX1in.zpl +21 -0
  17. zebra_day/etc/label_styles/plate_1inX0.25in.zpl +9 -0
  18. zebra_day/etc/label_styles/plate_1inX0.25inHD.zpl +9 -0
  19. zebra_day/etc/label_styles/smallTubeWdotHD_prod.zpl +8 -0
  20. zebra_day/etc/label_styles/smallTubeWdot_corners.zpl +7 -0
  21. zebra_day/etc/label_styles/smallTubeWdot_prod.zpl +8 -0
  22. zebra_day/etc/label_styles/smallTubeWdot_prodAlt1.zpl +6 -0
  23. zebra_day/etc/label_styles/smallTubeWdot_prodAlt1b.zpl +3 -0
  24. zebra_day/etc/label_styles/smallTubeWdot_prodV2.zpl +8 -0
  25. zebra_day/etc/label_styles/smallTubeWdot_reagent.zpl +29 -0
  26. zebra_day/etc/label_styles/stripOf4Squares_1inX1in.zpl +32 -0
  27. zebra_day/etc/label_styles/test_800dX800dCoordinateArray.zpl +1 -0
  28. zebra_day/etc/label_styles/tmps/.hold +0 -0
  29. zebra_day/etc/label_styles/tmps/tmp_zpl_templates.here +0 -0
  30. zebra_day/etc/label_styles/tube_20mmX30mmA.zpl +7 -0
  31. zebra_day/etc/label_styles/tube_2inX0.3in.zpl +15 -0
  32. zebra_day/etc/label_styles/tube_2inX0.5in.zpl +15 -0
  33. zebra_day/etc/label_styles/tube_2inX0.5inHD.zpl +15 -0
  34. zebra_day/etc/label_styles/tube_2inX1in.zpl +25 -0
  35. zebra_day/etc/label_styles/tube_2inX1inHD.zpl +22 -0
  36. zebra_day/etc/label_styles/tube_2inX1inHDv3.zpl +21 -0
  37. zebra_day/etc/old_printer_config/.hold +0 -0
  38. zebra_day/etc/old_printer_config/2026-02-01_01:50:25.022846_printer_config.json +1 -0
  39. zebra_day/etc/old_printer_config/2026-02-01_01:50:25.033657_printer_config.json +1 -0
  40. zebra_day/etc/old_printer_config/2026-02-01_01:50:25.039597_printer_config.json +3 -0
  41. zebra_day/etc/old_printer_config/2026-02-01_01:50:25.047295_printer_config.json +1 -0
  42. zebra_day/etc/old_printer_config/2026-02-01_01:50:25.055804_printer_config.json +1 -0
  43. zebra_day/etc/old_printer_config/2026-02-01_01:50:25.061337_printer_config.json +3 -0
  44. zebra_day/etc/old_printer_config/2026-02-01_01:51:24.073326_printer_config.json +1 -0
  45. zebra_day/etc/old_printer_config/2026-02-01_01:51:24.081950_printer_config.json +1 -0
  46. zebra_day/etc/old_printer_config/2026-02-01_01:51:24.088251_printer_config.json +3 -0
  47. zebra_day/etc/old_printer_config/2026-02-01_01:51:24.096501_printer_config.json +1 -0
  48. zebra_day/etc/old_printer_config/2026-02-01_01:51:24.104767_printer_config.json +1 -0
  49. zebra_day/etc/old_printer_config/2026-02-01_01:51:24.110364_printer_config.json +3 -0
  50. zebra_day/etc/old_printer_config/2026-02-01_01:51:24.118239_printer_config.json +1 -0
  51. zebra_day/etc/old_printer_config/2026-02-01_01:51:24.125950_printer_config.json +1 -0
  52. zebra_day/etc/old_printer_config/2026-02-01_01:51:24.349866_printer_config.json +1 -0
  53. zebra_day/etc/old_printer_config/2026-02-01_01:51:24.361085_printer_config.json +3 -0
  54. zebra_day/etc/old_printer_config/2026-02-01_01:51:24.558323_printer_config.json +1 -0
  55. zebra_day/etc/old_printer_config/2026-02-01_01:51:24.565756_printer_config.json +3 -0
  56. zebra_day/etc/old_printer_config/2026-02-01_01:51:29.739070_printer_config.json +16 -0
  57. zebra_day/etc/old_printer_config/2026-02-01_01:51:29.753796_printer_config.json +1 -0
  58. zebra_day/etc/old_printer_config/2026-02-01_01:51:29.760201_printer_config.json +3 -0
  59. zebra_day/etc/old_printer_config/2026-02-01_01:51:29.768747_printer_config.json +1 -0
  60. zebra_day/etc/old_printer_config/2026-02-01_01:51:29.775312_printer_config.json +3 -0
  61. zebra_day/etc/old_printer_config/2026-02-01_01:51:29.782533_printer_config.json +1 -0
  62. zebra_day/etc/old_printer_config/2026-02-01_01:51:29.789287_printer_config.json +1 -0
  63. zebra_day/etc/old_printer_config/2026-02-01_01:51:29.794230_printer_config.json +3 -0
  64. zebra_day/etc/old_printer_config/2026-02-01_01:51:29.800021_printer_config.json +5 -0
  65. zebra_day/etc/printer_config.json +4 -0
  66. zebra_day/etc/printer_config.template.json +24 -0
  67. zebra_day/etc/tmp_printers0.json +5 -0
  68. zebra_day/etc/tmp_printers120.json +10 -0
  69. zebra_day/etc/tmp_printers145.json +10 -0
  70. zebra_day/etc/tmp_printers207.json +10 -0
  71. zebra_day/etc/tmp_printers374.json +5 -0
  72. zebra_day/etc/tmp_printers383.json +5 -0
  73. zebra_day/etc/tmp_printers450.json +5 -0
  74. zebra_day/etc/tmp_printers469.json +10 -0
  75. zebra_day/etc/tmp_printers485.json +10 -0
  76. zebra_day/etc/tmp_printers504.json +5 -0
  77. zebra_day/etc/tmp_printers531.json +10 -0
  78. zebra_day/etc/tmp_printers540.json +10 -0
  79. zebra_day/etc/tmp_printers542.json +10 -0
  80. zebra_day/etc/tmp_printers552.json +10 -0
  81. zebra_day/etc/tmp_printers608.json +5 -0
  82. zebra_day/etc/tmp_printers657.json +5 -0
  83. zebra_day/etc/tmp_printers715.json +10 -0
  84. zebra_day/etc/tmp_printers838.json +5 -0
  85. zebra_day/etc/tmp_printers839.json +5 -0
  86. zebra_day/etc/tmp_printers933.json +5 -0
  87. zebra_day/etc/tmp_printers957.json +5 -0
  88. zebra_day/etc/tmp_printers972.json +10 -0
  89. zebra_day/exceptions.py +88 -0
  90. zebra_day/files/.hold +0 -0
  91. zebra_day/files/blank_preview.png +0 -0
  92. zebra_day/files/corners_20cmX30cm_preview.png +0 -0
  93. zebra_day/files/generic_2inX1in_preview.png +0 -0
  94. zebra_day/files/hold +0 -0
  95. zebra_day/files/test_png_12020.png +0 -0
  96. zebra_day/files/test_png_12352.png +0 -0
  97. zebra_day/files/test_png_15472.png +0 -0
  98. zebra_day/files/test_png_17696.png +0 -0
  99. zebra_day/files/test_png_23477.png +0 -0
  100. zebra_day/files/test_png_24493.png +0 -0
  101. zebra_day/files/test_png_28157.png +0 -0
  102. zebra_day/files/test_png_30069.png +0 -0
  103. zebra_day/files/test_png_35832.png +0 -0
  104. zebra_day/files/test_png_36400.png +0 -0
  105. zebra_day/files/test_png_40816.png +0 -0
  106. zebra_day/files/test_png_47791.png +0 -0
  107. zebra_day/files/test_png_47799.png +0 -0
  108. zebra_day/files/test_png_49564.png +0 -0
  109. zebra_day/files/test_png_53848.png +0 -0
  110. zebra_day/files/test_png_55588.png +0 -0
  111. zebra_day/files/test_png_58809.png +0 -0
  112. zebra_day/files/test_png_62542.png +0 -0
  113. zebra_day/files/test_png_67242.png +0 -0
  114. zebra_day/files/test_png_89893.png +0 -0
  115. zebra_day/files/test_png_91597.png +0 -0
  116. zebra_day/files/test_png_93633.png +0 -0
  117. zebra_day/files/tmpbjo3k7q1.png +0 -0
  118. zebra_day/files/tmpigtr4pwy.png +0 -0
  119. zebra_day/files/tube_20mmX30mmA_preview.png +0 -0
  120. zebra_day/files/zpl_label_tube_2inX1in_2026-02-01_01:51:24.370964.png +0 -0
  121. zebra_day/logging_config.py +74 -0
  122. zebra_day/logs/.hold +0 -0
  123. zebra_day/logs/print_requests.log +2 -0
  124. zebra_day/paths.py +143 -0
  125. zebra_day/print_mgr.py +557 -117
  126. zebra_day/static/datschund.css +140 -0
  127. zebra_day/static/datschund.png +0 -0
  128. zebra_day/static/daylily.png +0 -0
  129. zebra_day/static/favicon.svg +20 -0
  130. zebra_day/static/general.css +99 -0
  131. zebra_day/static/js/zebra_modern.js +172 -0
  132. zebra_day/static/lsmc.css +354 -0
  133. zebra_day/static/moon.jpeg +0 -0
  134. zebra_day/static/oakland.css +197 -0
  135. zebra_day/static/petrichor.css +150 -0
  136. zebra_day/static/popday_daylily.css +140 -0
  137. zebra_day/static/style.css +183 -0
  138. zebra_day/static/triangles.css +122 -0
  139. zebra_day/static/tron.css +277 -0
  140. zebra_day/static/zebra_modern.css +771 -0
  141. zebra_day/static/zebras.css +176 -0
  142. zebra_day/templates/modern/base.html +98 -0
  143. zebra_day/templates/modern/config.html +141 -0
  144. zebra_day/templates/modern/config_backups.html +59 -0
  145. zebra_day/templates/modern/config_editor.html +95 -0
  146. zebra_day/templates/modern/config_new.html +93 -0
  147. zebra_day/templates/modern/dashboard.html +160 -0
  148. zebra_day/templates/modern/print_request.html +145 -0
  149. zebra_day/templates/modern/print_result.html +88 -0
  150. zebra_day/templates/modern/printer_detail.html +244 -0
  151. zebra_day/templates/modern/printers.html +144 -0
  152. zebra_day/templates/modern/save_result.html +46 -0
  153. zebra_day/templates/modern/template_editor.html +175 -0
  154. zebra_day/templates/modern/templates.html +122 -0
  155. zebra_day/web/__init__.py +9 -0
  156. zebra_day/web/app.py +248 -0
  157. zebra_day/web/auth.py +172 -0
  158. zebra_day/web/middleware.py +159 -0
  159. zebra_day/web/routers/__init__.py +2 -0
  160. zebra_day/web/routers/api.py +313 -0
  161. zebra_day/web/routers/ui.py +636 -0
  162. zebra_day/zpl_renderer.py +273 -0
  163. zebra_day-2.0.0.dist-info/METADATA +847 -0
  164. zebra_day-2.0.0.dist-info/RECORD +168 -0
  165. {zebra_day-0.0.37.dist-info → zebra_day-2.0.0.dist-info}/WHEEL +1 -1
  166. zebra_day-2.0.0.dist-info/entry_points.txt +4 -0
  167. zebra_day/bin/scan_for_networed_zebra_printers.py +0 -23
  168. zebra_day/bin/te.py +0 -905
  169. zebra_day/bin/zserve.py +0 -620
  170. zebra_day-0.0.37.dist-info/METADATA +0 -1177
  171. zebra_day-0.0.37.dist-info/RECORD +0 -10
  172. {zebra_day-0.0.37.dist-info → zebra_day-2.0.0.dist-info/licenses}/LICENSE +0 -0
  173. {zebra_day-0.0.37.dist-info → zebra_day-2.0.0.dist-info}/top_level.txt +0 -0
zebra_day/bin/zserve.py DELETED
@@ -1,620 +0,0 @@
1
- import cherrypy
2
- import os
3
- import sys
4
- import time
5
- from datetime import datetime, timedelta, date
6
- import pytz
7
- import yaml
8
- import json
9
- import tempfile
10
-
11
- import zebra_day.print_mgr as zdpm
12
-
13
- FILES_DIR = "zebra_day/etc/label_styles"
14
-
15
- ENVCHECK = os.environ.get('ZDAY','skip') # Start zserve.py like: export ZDAY=somestring && python zebra_day/bin/zserve.py and the index (for now) will not load unless you send along the same string with the HTTP request using the envcheck variable. If not detected, set to skip and this is not checked. NOTE! This is hugely crude and something much better needs to be done before anything here is exposed routinely in the wild. A quick improvement coming soon, session level auth and so on.
16
-
17
- class Zserve(object):
18
-
19
- def __init__(self):
20
- self.zp = zdpm.zpl()
21
- self.css_file = "zebra_day/static/style.css"
22
- try:
23
- ipcmd = "(ip addr show | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1' || ifconfig | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1') 2>/dev/null"
24
- print(ipcmd)
25
- self.ip = os.popen(ipcmd).readline().rstrip()
26
- self.ip_root = ".".join(self.ip.split('.')[:-1])
27
- except Exception as e:
28
- self.ip = '192.168.1.0' # FAILS
29
- self.ip_root = '192.168.1' # FAILS
30
-
31
-
32
- @cherrypy.expose
33
- def chg_ui_style(self,css_file=None):
34
-
35
- if css_file not in [None]:
36
- self.css_file = "zebra_day/static/"+css_file
37
- raise cherrypy.HTTPRedirect("/")
38
-
39
- ret_html = "<h1>Change The Zebra Day UI Style</h1><ul><small><a href=/>home</a></small><br><ul><hr><br><ul>Available Style CSS Files:<br><ul>"
40
- for i in sorted(os.listdir('zebra_day/static')):
41
- if i.endswith('.css'):
42
- ret_html += f"<li><a href=chg_ui_style?css_file={i} >{i}</a>"
43
- ret_html += "</ul></ul></ul>"
44
-
45
- return self.wrap_content(ret_html)
46
-
47
-
48
- @cherrypy.expose
49
- def probe_network_for_zebra_printers(self, ip_stub="192.168.1", scan_wait="0.25"):
50
- ret_html = f"<h1>Probing {ip_stub} For Zebra Printers</h1><br><a href=printer_status>BACK TO THE NETWORK ZEBRA REPORT</a><ul><hr><ul>"
51
- try:
52
- self.detected_printer_ips = {}
53
- except Exception as e:
54
- self.detected_printer_ips = {}
55
-
56
- res = os.popen(f"zebra_day/bin/scan_for_networed_zebra_printers_curl.sh {ip_stub} {scan_wait}")
57
- for i in res.readlines():
58
- ii = i.rstrip()
59
- sl = ii.split('|')
60
- if len(sl) > 1:
61
- zp = sl[0]
62
- ip = sl[1]
63
- model = sl[2]
64
- serial = sl[3]
65
- status = sl[4]
66
- self.detected_printer_ips[ip] = [model, serial, status]
67
- ret_html = ret_html + f"""
68
- <li>{zp} ::: <a href={ip} target=new>{ip}</a> ::: {model} ::: {serial} ::: {status}"""
69
-
70
- self._restart()
71
-
72
- return self.wrap_content(ret_html)
73
-
74
-
75
- @cherrypy.expose
76
- def list_prior_printer_config_files(self):
77
- ret_html = """
78
- <h1> Saved Printer Config JSON Files</h1><ul><small><a href=/>home</a></small><br><ul><hr><ul>
79
- If you wish to restore from one of these files, download the one you'd like, open in a text editor, then copy the contents of the file into <a href=view_pstation_json>the printers json editing form</a> and save a new json file. <br><ul><i><small>note: the existing file will have a backup created and accessible here</small></i>.<br><br><ul><hr><br>
80
- <ul>"""
81
-
82
- bkup_d = "zebra_day/etc/old_printer_config/"
83
-
84
- for i in sorted(os.listdir(bkup_d)):
85
- bkup_fn = f"{bkup_d}{i}"
86
- ret_html = ret_html + f"<li><a href={bkup_fn} >{bkup_fn}</a>"
87
-
88
- return self.wrap_content(ret_html)
89
-
90
-
91
- @cherrypy.expose
92
- def clear_printers_json(self):
93
- self.zp.clear_printers_json()
94
- ret_html = "printers json file has been cleared.<br><a href=/>home</a>"
95
- self._restart()
96
- return self.wrap_content(ret_html)
97
-
98
-
99
- @cherrypy.expose
100
- def probe_zebra_printers_add_to_printers_json(self, ip_stub="192.168.1", scan_wait="0.25",lab="scan-results"):
101
-
102
- self.zp.probe_zebra_printers_add_to_printers_json(ip_stub=ip_stub, scan_wait=scan_wait ,lab=lab)
103
-
104
- ret_html = "<a href=/>home</a><br><br><br>New Json Object:" + str(self.zp.printers)
105
- return self.wrap_content(ret_html)
106
-
107
-
108
- @cherrypy.expose
109
- def printer_status(self,lab="scan-results"):
110
-
111
- if lab not in self.zp.printers['labs']:
112
- return f"ERROR-- there is no record for this lab, {lab} in the printers.json. Please go <a href=/>home</a> and check the printers.json record to confirm it is valid. If necessary, you may clear the json and re-build it from a network scan."
113
-
114
- printer_deets = {}
115
- ret_html = f"<h1>Printer Status Summary For {lab}</h1><small><a href=/>BACK HOME</a></small><br><ul><hr>Scan Network For Zebra Printers : <form action=probe_network_for_zebra_printers id='myForm' > Network Stub To Scan : <input type=text name=ip_stub value='{self.ip_root}' class='navigational-link' > Scan Wait(s)<input type=text name=scan_wait value='0.25'><input type=submit></form><br><ul><table border=1 ><tr><th>Printer Name</th><th>Printer IP</th><th>Label Style</th><th>Status on Network</th></tr>"
116
-
117
- pips = {}
118
- try:
119
- pips = self.detected_printer_ips.copy()
120
- except Exception as e:
121
- self.detected_printer_ips = {}
122
-
123
-
124
- for pname in self.zp.printers['labs'][lab]:
125
- pip = self.zp.printers['labs'][lab][pname]['ip_address']
126
- if pip in self.detected_printer_ips:
127
- del(pips[pip])
128
-
129
- printer_deets[pname] = [pip, "<small><a href=edit_zpl >available zpl templates here</a></small>"] # "...".join(self.zp.printers['labs'][lab][pname]['label_zpl_styles'])]
130
- print(pname, pip)
131
- cres = os.popen(f"curl -m 4 {pip}").readlines()
132
- for ci in cres:
133
- if len(ci.split('Status:')) > 1:
134
- printer_deets[pname].append(ci)
135
-
136
- ptype = ''
137
- for pret in printer_deets:
138
- try:
139
- pip2 = printer_deets[pret][0]
140
-
141
- pip2a = f"{self.zp.printers['labs'][lab][pret]['model']} / {self.zp.printers['labs'][lab][pret]['serial']}" # "" if pip2 not in self.detected_printer_ips else " / ".join(self.detected_printer_ips[pip2])
142
- ptype = printer_deets[pret][1]
143
- pconnect = printer_deets[pret][2]
144
- serial = self.zp.printers['labs'][lab][pret]['serial'].replace(' ','_')
145
- model = self.zp.printers['labs'][lab][pret]['model']
146
- ret_html = ret_html + f'<tr><td>{pret}<br><small>{pip2a}</small></td><td><a href=http://{pip2} target=pcheck>{pip2}</a><br><br><small><a target=pl href="_print_label?lab={lab}&printer={pret}&printer_ip={pip2}&label_zpl_style=labware_2inX1in&uid_barcode={pip2}&alt_a={model}&alt_b={serial}&alt_c={pret}&alt_d={lab}" >print-test-label</a></small></td><td>{ptype}</td><td>{pconnect} <small>if state=PAUSED, each printer has a specific pause/unpause button, not one of the menu buttons, which is likely flashing and needs to be pressed</small></td></tr>'
147
- except Exception as e:
148
- print(e)
149
- ret_html = ret_html + f"<tr><td>{pret}</td><td><a href=http://{pip2} target=pcheck>{pip2}</a></td><td>{ptype}<br></td><td>UNABLE TO CONNECT</td></tr>"
150
-
151
- zaddl = ""
152
- for zi in pips:
153
- zaddl = zaddl + f"<li>{zi} :: {pips[zi]}"
154
-
155
- ret_html = ret_html + "</table></ul><h3>Detected, But Not Configured, Zebra Printers</h3><small>you must scan the network before this will present info</small><ul>" + zaddl + "</ul></ul>"
156
-
157
- return self.wrap_content(ret_html)
158
-
159
-
160
- @cherrypy.expose
161
- def index(self,envcheck='skip'):
162
- if envcheck != ENVCHECK:
163
- #client_ip = cherrypy.request.remote.ip
164
- os.system('sleep 31')
165
- return ''
166
-
167
- llinks = ""
168
- try:
169
- for lb in self.zp.printers['labs'].keys():
170
- llinks = llinks + f"<li><a href=printer_status?lab={lb} > {lb} Zebra Printer Status </a>"
171
- except Exception as e:
172
- llinks = llinks + "<li> no labs found. try scanning and resetting printers.json"
173
-
174
- llinks = llinks + "<li> __end__ </ul>"
175
-
176
- ret_html = """
177
- <h1>Daylily Zebra Printer And Print Request Manager</h1><ul><small>ip address detected :: """+self.ip+"""</small>
178
- <hr><ul>
179
- <hr>
180
- <h2>Zebra Printer Fleet Status, By Site</h2>
181
- <ul>detected sites:
182
- <ul><ul>"""+llinks+"""</ul><br></ul>
183
- <hr>
184
- <h2>Zebra Printer JSON Config</h2>
185
- <ul>this json file defines the zebra printers available to the package
186
- <ul><ul>
187
- <li><a href=view_pstation_json >view and edit json</a>
188
- <br>
189
- <br><li><small>scan network for new zebra printers, and add to printers.json config used by this package <form id='myForm'action=probe_zebra_printers_add_to_printers_json >Enter IP Root To Scan: <input type=text value='"""+self.ip_root+"""' name=ip_stub > <input type=submit></form> </small><li><a href=list_prior_printer_config_files>view backed up printers json config files</a> </ul><br>
190
- </ul></ul>
191
- <hr>
192
- <h2>Send Print Requests</h2>
193
- <ul>to accessible zebra printers
194
- <ul><ul>
195
- <li><a href=send_print_request>manually compose & send print request</a>
196
- </ul><br>
197
- </ul></ul>
198
- <hr><h2>Edit Label Templates</h2>
199
- <ul>modify existing templates, create new templates, preview changes & test print new designs
200
- <ul><ul>
201
- <li><a href=edit_zpl>edit zpl files</a></ul><br>
202
- </ul></ul>
203
- <hr><h2>Github Docs</h2>
204
- <ul>for this and other daylily repos
205
- <ul><ul><small>
206
- <li><a href=https://github.com/Daylily-Informatics/zebra_day >zebra_day</a>
207
- <li><a href=https://github.com/Daylily-Informatics/fedex_tracking_day >fedex_tracking_day</a>
208
- <li><a href=https://github.com/Daylily-Informatics/yaml_config_day >yaml_config_day</a>
209
- </small>
210
- </ul></ul>
211
- </ul></ul></ul>
212
- <small> <a href=chg_ui_style style='position: fixed; bottom: 0; right: 0;padding: 10px; text-decoration:none;' id="bottomRightLink">change ui style</a></small>
213
- """
214
-
215
- return self.wrap_content(ret_html)
216
-
217
-
218
- @cherrypy.expose
219
- def send_print_request(self):
220
- ret_html = ""
221
-
222
- for lab in sorted(self.zp.printers['labs']):
223
- ret_html = ret_html + f"<h1>Lab {lab}</h1><small><a href=/>home</a><br><ul><hr><ul>"
224
- for printer in sorted(self.zp.printers['labs'][lab]):
225
- pip = self.zp.printers['labs'][lab][printer]['ip_address']
226
- plab = self.zp.printers['labs'][lab][printer]['label_zpl_styles']
227
- ret_html = ret_html + f"<li>{printer} .. {pip}<ul>"
228
- for plabi in sorted(plab):
229
- ret_html = ret_html + f"<li>{plabi} ----- <a href=build_print_request?lab='{lab}'&printer='{printer}'&printer_ip='{pip}'&label_zpl_style='{plabi}'>PRINT THIS TYPE</a>"
230
- ret_html = ret_html + "</ul><br>"
231
-
232
- return self.wrap_content(ret_html)
233
-
234
-
235
- @cherrypy.expose
236
- def build_print_request(self, lab, printer, printer_ip='', label_zpl_style='',content='', filename='',ftag=''):
237
-
238
- if label_zpl_style in ['','None', None] and filename not in ['','None',None]:
239
- label_zpl_style = filename.split('.zpl')[0]
240
-
241
- ret_html = f"""
242
- <h1>Send Label Print Request</h1>
243
- <ul><small><a href=/>home</a></small><hr><ul>
244
- <h3>{lab} .. {printer} .. {printer_ip} .. {label_zpl_style}</h3><ul><hr><ul>
245
- """
246
-
247
- ret_html = ret_html + """
248
- <form action=_print_label>
249
- <li>UID for Barcode : <input type=text name=uid_barcode ></input><br>
250
- <li>ALT-A : <input type=text name=alt_a ></input><br>
251
- <li>ALT-B : <input type=text name=alt_b ></input><br>
252
- <li>ALT-C : <input type=text name=alt_c ></input><br>
253
- <li>ALT-D : <input type=text name=alt_d ></input><br>
254
- <li>ALT-E : <input type=text name=alt_e ></input><br>
255
- <li>ALT-F : <input type=text name=alt_f ></input><br>
256
- """
257
- ret_html = ret_html + f"""
258
- Override Lab: <input type=text name=lab value={lab} ><br>
259
- Override Printer: <input type=text name=printer value={printer} ><br>
260
- Override IP: <input type=text name=printer_ip value={printer_ip} ><br>
261
- Over-Ride label_style_zpl: <input type=text name=label_zpl_style value={label_zpl_style} ><br>
262
- <input type=submit>
263
- </form>
264
- """
265
-
266
- return self.wrap_content(ret_html)
267
-
268
-
269
- @cherrypy.expose
270
- def _print_label(self, lab, printer, printer_ip='', label_zpl_style='', uid_barcode='', alt_a='', alt_b='', alt_c='', alt_d='', alt_e='', alt_f=''):
271
- client_ip = cherrypy.request.remote.ip
272
-
273
- ret_s = self.zp.print_zpl(lab=lab ,printer_name=printer, label_zpl_style=label_zpl_style, uid_barcode=uid_barcode, alt_a=alt_a, alt_b=alt_b, alt_c=alt_c, alt_d=alt_d, alt_e=alt_e, alt_f=alt_f, client_ip=client_ip)
274
-
275
- full_url = cherrypy.url() + f"?lab={lab}&printer={printer}&printer_ip={printer_ip}&label_zpl_style={label_zpl_style}&uid_barcode={uid_barcode}&alt_a={alt_a}&alt_b={alt_b}&alt_c={alt_c}&alt_d={alt_d}&alt_e={alt_e}&alt_f={alt_f}"
276
-
277
- addl_html = f"<h2>Zday Label Print Request Sent</h2><ul>The URL for this print request(which you can edit and use incurl) is: {full_url}<hr><ul>SUCCESS, LABEL PRINTED<br><ul>"
278
- if len(ret_s.split('.png')) > 1:
279
- addl_html = f"<a href=/>home</a><br><br>SUCCESFULLY CREATED PNG<br><img src={ret_s}><br>"
280
- ret_html = addl_html + "<a href=/>home</a>"
281
- return self.wrap_content(ret_html)
282
-
283
-
284
- @cherrypy.expose
285
- def _restart(self):
286
- os.system(f"touch zebra_day/bin/zserve.py")
287
- os.system('sleep 4')
288
- ret_html = 'server restarted'
289
- return self.wrap_content(ret_html)
290
-
291
-
292
- @cherrypy.expose
293
- def dl_bin_file(self, fn=None):
294
-
295
- # Set the content type and disposition headers for the file
296
- cherrypy.response.headers['Content-Type'] = 'image/png'
297
- cherrypy.response.headers['Content-Disposition'] = f'attachment; filename="{fn}"'
298
-
299
- # Open and serve the PNG file as a static file
300
- try:
301
- with open(fn, 'rb') as f:
302
- return f.read()
303
- except FileNotFoundError:
304
- return "File not found."
305
-
306
-
307
- @cherrypy.expose
308
- def view_pstation_json(self, error_msg=None):
309
-
310
- with open(self.zp.printers_filename, 'r') as f:
311
- data = json.load(f)
312
- error_display = f'<p style="color:red;">{error_msg}</p>' if error_msg else ''
313
- ret_html = f"""
314
- <br><a href=/>home</a><br>
315
- {error_display}
316
- <form action="save_pstation_json" method="post">
317
- <textarea name="json_data" rows="45" cols="50">{json.dumps(data, indent=4)}</textarea><br>
318
- <input type="submit" value="Save New Printers Config Json & Make Active">
319
- </form>
320
- <ul><ul><hr>
321
- <li><a href=list_prior_printer_config_files>view backed up printers json config files</a>
322
- <ul><Ul>
323
- <hr><hr>
324
- <li>!! <a href=reset_pstation_json>Restore Printer Settings From Default JSON (THIS WILL DELETE YOUR CURRENT FILE!!)</a>
325
- <ul><ul>
326
- <hr><hr><hr>
327
- <li>!! <a href=clear_printers_json>CLEAR contents of current printers.json file !!!! This Cannot Be Undone</a>
328
-
329
- """
330
-
331
- return self.wrap_content(ret_html)
332
-
333
-
334
- @cherrypy.expose
335
- def reset_pstation_json(self):
336
- self.zp.replace_printer_json_from_template()
337
- ret_html = "Done. <a href=/>home</a>."
338
- ret_html = ret_html + "<br>server is restarted? " + self._restart()
339
- return self.wrap_content(ret_html)
340
-
341
-
342
- @cherrypy.expose
343
- def save_pstation_json(self, json_data):
344
- rec_date = str(datetime.now()).replace(' ','_')
345
- bkup_pconfig_fn = f"zebra_day/etc/old_printer_config/{rec_date}_printer_config.json"
346
-
347
- os.system(f"cp {self.zp.printers_filename} {bkup_pconfig_fn}")
348
-
349
- try:
350
- data = json.loads(json_data)
351
- with open(self.zp.printers_filename, 'w') as f:
352
- json.dump(data, f, indent=4)
353
- self.zp.load_printer_json(json_file=self.zp.printers_filename)
354
- self._restart()
355
- return "JSON saved successfully!<br><br>Print Stations Updated.<br><br><a href=/>home</a><br><br><a href=view_pstation_json>open current print station json</a>"
356
- except json.JSONDecodeError as e:
357
- return self.view_pstation_json(error_msg=str(e))
358
-
359
-
360
- @cherrypy.expose
361
- def edit_zpl(self):
362
- files = [f for f in os.listdir(FILES_DIR) if os.path.isfile(os.path.join(FILES_DIR, f))]
363
-
364
- file_links = ['<a href="/edit?filename={}">{}</a>'.format(f, f) for f in files]
365
-
366
- filest = [ft for ft in os.listdir(FILES_DIR+'/tmps/') if os.path.isfile(os.path.join(FILES_DIR+'/tmps/', ft))]
367
-
368
- file_linkst = ['<a href="/edit?dtype=tmps&filename={}">{}</a>'.format(ft, ft) for ft in filest]
369
-
370
- ret_html = """
371
- <a href=/>home</a><br><ul>
372
- To specify a template to use (via the programatic API or <a href=send_print_request>this GUI</a>), use the file name string (not including the path prefix) and remove the trailing '.zpl'. ie: test_2inX1in' <br><ul><hr><br>stable ZPL templates<br>
373
- <ul>
374
- {}
375
- </ul>
376
-
377
- <br><br><hr><br>draft ZPL templates<ul> {} </ul>
378
- """.format("<li>" + "</li><li>".join(file_links) + "</li>", "<li>" + "</li><li>".join(file_linkst) + "</li>")
379
-
380
- return self.wrap_content(ret_html)
381
-
382
-
383
- @cherrypy.expose
384
- def qqqxxx(self):
385
- self.labs_dict = self.zp.printers
386
- labs = self.labs_dict["labs"].keys()
387
-
388
- html = """<html>
389
- <head>
390
- <script>
391
- function populatePrinters() {
392
- var lab = document.getElementById("labsDropdown").value;
393
- var printersDropdown = document.getElementById("printersDropdown");
394
- printersDropdown.innerHTML = "";
395
- var labs = """ + str(self.labs_dict["labs"]) + """;
396
- for (var printer in labs[lab]) {
397
- var option = document.createElement("option");
398
- option.text = printer;
399
- option.value = printer;
400
- printersDropdown.add(option);
401
- }
402
- }
403
- </script>
404
- </head>
405
- <body>
406
- <form>
407
- <select id="labsDropdown" onchange="populatePrinters()">
408
- <option value="">Select Lab</option>"""
409
-
410
- for lab in labs:
411
- html += f'<option value="{lab}">{lab}</option>'
412
-
413
- html += """
414
- </select>
415
- <select id="printersDropdown">
416
- <option value="">Select Printer</option>
417
- </select>
418
- </form>
419
- </body>
420
- </html>"""
421
-
422
- return html
423
-
424
-
425
- @cherrypy.expose
426
- def edit(self, filename=None, dtype=''):
427
- if not filename:
428
- return "No file selected"
429
-
430
- filepath = os.path.join(FILES_DIR + '/' + dtype + '/', filename)
431
-
432
- with open(filepath, 'r') as file:
433
- content = file.read()
434
-
435
- self.labs_dict = self.zp.printers
436
- labs = self.labs_dict["labs"].keys()
437
-
438
- ll = ""
439
- for lab in labs:
440
- ll += f'<option value="{lab}">{lab}</option>'
441
-
442
-
443
- return """<html>
444
- <head>
445
- <link rel="stylesheet" href="""+self.css_file+""">
446
- <script>
447
- function populatePrinters() {
448
- var lab = document.getElementById("labsDropdown").value;
449
- var printersDropdown = document.getElementById("printersDropdown");
450
- printersDropdown.innerHTML = "";
451
- var labs = """ + str(self.labs_dict["labs"]) + """;
452
- for (var printer in labs[lab]) {
453
- var option = document.createElement("option");
454
- option.text = printer;
455
- option.value = printer;
456
- printersDropdown.add(option);
457
- }
458
- }
459
- </script>
460
- </head>
461
- <body>
462
- <h2>Editing: """+filename+"""</h2><small><ul><hr><a href=/>home</a> /// <a href=edit_zpl >back to label list</a> /// <a href=https://labelary.com/zpl.html target=x >zpl intro</a></small><br>
463
- <table border=1><tr><td style="vertical-align: top;" >
464
- <form method="post" action="/save" id="textForm">
465
- <textarea name="content" rows="30" cols="40">{cont}</textarea><br/>
466
- <input type="hidden" name="filename" value="{fn}">
467
- TMP File Tag (added to new file name): <input type=text name=ftag value=na >
468
- <input type="submit" value="Save Temp File">
469
- <hr>
470
- <input type="button" value="Render PNG Of ZPL Label" onclick="submitToPNGrenderer();">
471
- <hr>
472
- <b>choose a 'Lab' and 'Printer' to test print to</b><select id="labsDropdown" name=lab onchange="populatePrinters()">
473
- <option value="">Select Lab</option>{ll}
474
- </select>
475
- <select id="printersDropdown" name=printer>
476
- <option value="">Select Printer</option>
477
- </select>
478
- <input type="button" value="Test Print To Local Zebra" onclick="submitToRealPrint();">
479
- </form><br>
480
- </td><td>
481
- <div style="border: 1;" id="pngContainer"></div>
482
- <ul><h3>How To Use This Tool</h3>
483
- <small><a href=https://labelary.com/viewer.html target=labels>For More On ZPL (docs and tools)</a></small><ul>
484
- <ul><li>Load existing ZPL format files, make edits and preview the effects by producing a PNG.
485
- <li>When you wish to save a ZPL format you have worked on here, click 'Save As Temp'. This will use the original ZPL file name to create a timestamped new file with your changes saved to it, the new file name will contain the TAG you specify. <b>THE ORIGINAL FILE IS NOT CHANGED OR DELETED</b>.
486
- <li><a href=edit_zpl >Your New File Appears Here</a>
487
- <li>To print using this ZPL template to a printer available on your network, <a href=send_print_request >navigate to available printers</a>. When you arrive at the <b>build_print_request</b> form for a specific printer, you are able to enter in any of the format replacement values specified in the ZPL you created. <b>important</b>, new ZPL files are not default available to use for printing. However, you can override the label_style_zpl value to select a different ZPL file. Valid strings for label_style_zpl are the label style zpl file name, minus the .zpl extension, and no path. So, for 'plate_1inX0.25in.zpl' you would enter 'plate_1inX0.25in' to use this zpl format. For any non-default ZPL template files which have been created, the same process applies. Given a draft ZPL file created on this page, ie: 'tube_2inX1in.2023-10-22_05:25:05.004018.zpl', you may use this template by trimming off the .zpl and entering 'tube_2inX1in.2023-10-22_05:25:05.004018'.
488
- </ul>
489
- <li>A good way to proceed when designing a new label. Use the labely tool to generate your ZPL. Create a zpl template file here with the format wildcards added. Test using this ZPL, with format substitutions, on the printers you will be using you new template on.
490
-
491
- <li> <b>When A ZPL File Is Ready For Wider Use...</b> For now, the file needs to be manually moved to a permanent ZPL file name. A tool to do this will be available everntually.
492
- </ul>
493
-
494
- <h3>ZPL Template Wildcards</h3>
495
- This tool is a very simple interface to tinker with the overall features of a ZPL label. You may add format wildcards to the ZPL you edit here, but this interface does not execute format replacement of the ZPL previews generated.
496
- <ul><hr>
497
- The templates used by this system provide for a set of format wildcards which can be embedded in the ZPL specification file, and values inserted with each new print request. Not all ZPL formats support all format replacements. The preview pdf generation on this page will not template any values in. To use a zpl template, and specify format replacement values, <a href=send_print_request >use this interface</a>. <br>The wildcards supported:
498
- <ul>
499
- <li>{{uid_barcode}} = This will be encoded as the scannable barcode and presented in human readable form (at least for all default label templates)
500
- <li>{{alt_a}} = the 'alt_*' wildcards are placehoders for additional information that may be presented beyond the . These alt_* fields may be used howeever you like with your ZPL templates.
501
- <li>{{alt_b}} = <a href=send_print_request >use this interface to test sending wildcards to ZPL templates.</a>
502
- <li>... through {{alt_f}}
503
- </ul></ul>
504
- </td></tr></table>
505
-
506
- <script>
507
- function submitToLocPrint() {{
508
- var form = document.getElementById('textForm'); var formData = new FormData(form);
509
-
510
- fetch('/build_print_request', {{
511
- method: 'POST',
512
- body: formData
513
- }})}}
514
- </script>
515
- <script>
516
- function submitToRealPrint() {{
517
- var form = document.getElementById('textForm');
518
- form.action = '/build_print_request';
519
- form.submit();
520
- }}
521
- </script>
522
- </script>
523
- <script>
524
- function submitToPNGrenderer() {{
525
- var form = document.getElementById('textForm');
526
- var formData = new FormData(form);
527
-
528
- fetch('/png_renderer', {{
529
- method: 'POST',
530
- body: formData
531
- }})
532
- .then(response => response.text()) // Treat the response as plain text
533
- .then(pngPath => {{
534
- const pngImage = document.createElement('img');
535
- pngImage.src = pngPath;
536
- const container = document.getElementById('pngContainer');
537
- container.innerHTML = ''; // Clear previous images if any
538
- container.appendChild(pngImage);
539
- }})
540
- .catch(error => {{
541
- console.error('Error:', error);
542
- }});
543
-
544
- event.preventDefault(); // Prevent form from actually submitting and refreshing page
545
- }}
546
-
547
- </script>
548
- </body>
549
- </html>
550
- """.format(cont=content, fn=filename,ll=ll)
551
-
552
- @cherrypy.expose
553
- def png_renderer(self,filename,content,lab='',printer='', ftag=''):
554
-
555
- png_tmp_f = tempfile.NamedTemporaryFile(suffix='.png', dir='zebra_day/files', delete=False).name
556
-
557
- self.zp.generate_label_png(content,png_fn=png_tmp_f)
558
-
559
- return "zebra_day/files/" + png_tmp_f.split('/')[-1]
560
-
561
-
562
-
563
- @cherrypy.expose
564
- def save(self, filename, content, lab='',printer='', ftag=''):
565
- rec_date = str(datetime.now()).replace(' ','_')
566
-
567
- tfn = filename.replace('.zpl',f'.{ftag}.{rec_date}.zpl')
568
-
569
- temp_filepath = os.path.join(FILES_DIR, 'tmps/', tfn)
570
-
571
- with open(temp_filepath, 'w') as file:
572
- file.write(content)
573
-
574
- ret_html = "Changes saved to temp file! <br>You may either: (<a href=edit_zpl >go back to the zpl file list</a>) -or- (<a href='/'>go home</a>)"
575
-
576
- return self.wrap_content(ret_html)
577
-
578
-
579
- def wrap_content(self, content):
580
- header = f"""
581
- <html>
582
- <head>
583
- <link rel="stylesheet" href="{self.css_file}">
584
- </head>
585
- <body>
586
- <div id="spinner" class="spinner-hidden">
587
- <div class="loader"></div>
588
- </div>
589
- """
590
-
591
- footer = """
592
- <script>
593
- document.getElementById('myForm').addEventListener('submit', function(event) {
594
- // When the form is submitted, show the spinner
595
- document.getElementById('spinner').classList.remove('spinner-hidden');
596
-
597
- // The actual submission will proceed, and the new page will start loading.
598
- // As the new page loads, the current page (and spinner) will be unloaded.
599
- });
600
- </script>
601
- </body>
602
- </html>
603
- """
604
-
605
- return header + content + footer
606
-
607
-
608
- if __name__ == '__main__':
609
- cw_dir = os.path.abspath('.')
610
- cherrypy.config.update( {
611
- 'tools.staticdir.on': True,
612
- 'tools.staticdir.dir': cw_dir,
613
- 'server.socket_host': '0.0.0.0',
614
- 'server.socket_port': 8118,
615
- 'server.thread_pool' : 20,
616
- 'server.socket_queue_size': 20,
617
- 'tools.sessions.on': True,
618
- 'tools.sessions.timeout': 199, # Session timeout in minutes
619
- })
620
- cherrypy.quickstart(Zserve(),'/')