Then run:
-```sh
+```console
$ bin/gunicorn -k flask_sockets.worker sirius.server:app -b 0.0.0.0:5002 -w 1
```
an "encryption_key_required". In that case we connect the device to
the claim code via the hardware-xor and send back the correct
encryption key.
+
+## Creating fake printers
+
+Resetting the actual hardware all the time gets a bit tiresome so
+there's a fake command that creates unclaimed fake little printers:
+
+```console
+$ ./manage.py fake printer
+[...]
+Created printer
+ address: 602d48d344b746f5
+ DB id: 8
+ secret: 66a596840f
+ claim code: 5oop-e9dp-hh7v-fjqo
+```
+
+Functionally there is no difference between resetting and creating a
+new printer so we don't distinguish between the two.
os.environ[name] = value
from sirius.web import webapp
+from sirius.fake import commands as fake_commands
from flask.ext.script import Manager, Shell
from flask.ext.migrate import Migrate, MigrateCommand
return dict(app=app, db=webapp.db)
manager.add_command("shell", Shell(make_context=make_shell_context))
manager.add_command('db', MigrateCommand)
+manager.add_command('fake', fake_commands.fake_manager)
@manager.command
-"""Fake a few printer interactions for testing.
-"""
-import os
-
-from flask.ext import script
-from sirius.models import hardware
-from sirius.coding import bitshuffle
-
-def sub_opts(app, **kwargs):
- pass
-
-fake_manager = script.Manager(sub_opts, usage="Fake printer interactions.")
-
-@fake_manager.command
-def create_printer():
- device_address = os.urandom(8).encode('hex')
- xor = bitshuffle.hardware_xor_from_device_address(device_address)
-
- claim_code = ''
-
- hardware.Printer(
- )
--- /dev/null
+"""Fake a few printer interactions for testing.
+"""
+from __future__ import print_function
+
+import os
+
+from flask.ext import script
+from sirius.models import hardware
+from sirius.models.db import db
+from sirius.coding import bitshuffle
+from sirius.coding import claiming
+
+def sub_opts(app, **kwargs):
+ pass
+
+fake_manager = script.Manager(sub_opts, usage="Fake printer interactions.")
+
+@fake_manager.command
+def printer():
+ device_address = os.urandom(8).encode('hex')
+ xor = bitshuffle.hardware_xor_from_device_address(device_address)
+ secret = os.urandom(5).encode('hex')
+
+ cc = claiming.encode(xor, int(secret, 16))
+ printer = hardware.Printer(
+ device_address=device_address,
+ hardware_xor=xor,
+ )
+ db.session.add(printer)
+ db.session.commit()
+
+ print('Created printer')
+ print(' address: {}'.format(device_address))
+ print(' DB id: {}'.format(printer.id))
+ print(' secret: {}'.format(secret))
+ print(' xor: {}'.format(xor))
+ print(' claim code: {}'.format(cc))
def api_v1_connection(ws):
protocol_loop.accept(ws)
- logger.info('Creating app.')
+ logger.debug('Creating app.')
return app