Skip to content

Commit

Permalink
[REF] Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
sylvainc committed Feb 27, 2015
1 parent 4d1dc98 commit 5e0fa13
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 33 deletions.
56 changes: 31 additions & 25 deletions pywebdriver/plugins/escpos_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,31 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
###############################################################################
meta = {
'name': "ESCPOS Printer",
'description': """This plugin add the support of ESCPOS Printer for your
pywebdriver""",
'require_pip': ['pyxmlescpos'],
'require_debian': [],
}

from pif import get_public_ip
from pywebdriver import app, config, drivers
from netifaces import interfaces, ifaddresses, AF_INET
from flask_cors import cross_origin
from flask import request, jsonify
from flask import request, jsonify, render_template
from base_driver import ThreadDriver, check
import simplejson
import usb.core

meta = {
'name': "ESCPOS Printer",
'description': """This plugin add the support of ESCPOS Printer for your
pywebdriver""",
'require_pip': ['pyxmlescpos'],
'require_debian': [],
}

try:
from xmlescpos.printer import Usb
from xmlescpos.supported_devices import device_list
except:
installed=False
except ImportError:
installed = False
print 'ESCPOS: xmlescpos python library not installed'
else:
installed=True
class ESCPOSDriver(ThreadDriver, Usb):
""" ESCPOS Printer Driver class for pywebdriver """

Expand Down Expand Up @@ -155,21 +156,26 @@ def printstatus(self,eprint):
)
self.receipt(msg)

drivers['escpos'] = ESCPOSDriver(app.config)
driver = ESCPOSDriver(app.config)
drivers['escpos'] = driver
installed=True

@app.route(
'/hw_proxy/print_xml_receipt',
methods=['POST', 'GET', 'PUT', 'OPTIONS'])
@cross_origin(headers=['Content-Type'])
def print_xml_receipt_json():
""" For Odoo 8.0+"""

@app.route(
'/hw_proxy/print_xml_receipt',
methods=['POST', 'GET', 'PUT', 'OPTIONS'])
@cross_origin(headers=['Content-Type'])
def print_xml_receipt_json():
""" For Odoo 8.0+"""
driver.open_printer()
receipt = request.json['params']['receipt']
driver.push_task('receipt', receipt)

if 'escpos' not in drivers:
return jsonify(jsonrpc='2.0', result=False)
return jsonify(jsonrpc='2.0', result=True)

driver = drivers['escpos']
driver.open_printer()
receipt = request.json['params']['receipt']
driver.push_task('receipt', receipt)
@app.route('/print_status.html', methods=['GET'])
@cross_origin()
def print_status_http():
driver.push_task('printstatus')
return render_template('print_status.html')

return jsonify(jsonrpc='2.0', result=True)
7 changes: 0 additions & 7 deletions pywebdriver/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,6 @@ def index_http():
return render_template('index.html')


@app.route('/print_status.html', methods=['GET'])
@cross_origin()
def print_status_http():
drivers['escpos'].push_task('printstatus')
return render_template('print_status.html')


@app.route('/status.html', methods=['GET'])
@cross_origin()
def status_http():
Expand Down
3 changes: 2 additions & 1 deletion pywebdriverd
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ def main():
port = config.getint('flask', 'port')
debug = config.getboolean('flask', 'debug')
if config.getboolean('application', 'print_status_start'):
drivers['escpos'].push_task('printstatus')
if 'escpos' in drivers:
drivers['escpos'].push_task('printstatus')
app.run(host=host, port=port, debug=debug)

# Run application
Expand Down

0 comments on commit 5e0fa13

Please sign in to comment.