]> git.aero2k.de Git - sirius.git/commitdiff
Add management command to fake a newly reset little printer calling home.
authorTom Hunger <tehunger@gmail.com>
Wed, 14 Jan 2015 15:42:37 +0000 (15:42 +0000)
committerTom Hunger <tehunger@gmail.com>
Wed, 14 Jan 2015 18:32:02 +0000 (18:32 +0000)
README.md
manage.py
sirius/fake/__init__.py
sirius/fake/commands.py [new file with mode: 0644]
sirius/web/webapp.py

index eaf8e063e213e8163521b4460a8d3ddf741b2b1b..6ffac7995b024d5daf6c49e329b707613875fe26 100644 (file)
--- a/README.md
+++ b/README.md
@@ -5,7 +5,7 @@ First point your bridge at your laptop, port 5002 (or similar).
 
 Then run:
 
-```sh
+```console
 $ bin/gunicorn -k flask_sockets.worker sirius.server:app -b 0.0.0.0:5002 -w 1
 ```
 
@@ -59,3 +59,21 @@ We are also deriving this hardware xor when a device calls home with
 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.
index 828edaaf6ff17a03aa190e5b845f7fd38b40767b..3b9f8b99dace4e826975f21a9aa4c2b05da8c0a2 100755 (executable)
--- a/manage.py
+++ b/manage.py
@@ -9,6 +9,7 @@ if os.path.exists('.env'):
         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
 
@@ -20,6 +21,7 @@ def make_shell_context():
     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
index e922e90265075a188316679e5b402b317fc4bb36..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 100644 (file)
@@ -1,22 +0,0 @@
-"""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(
-    )
diff --git a/sirius/fake/commands.py b/sirius/fake/commands.py
new file mode 100644 (file)
index 0000000..cfdec7c
--- /dev/null
@@ -0,0 +1,37 @@
+"""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))
index 44daa6882b7d221b961d905bd436c3d6f811b6cc..5298a0d5df17b9639bdcc3ba69c03f191efddb43 100644 (file)
@@ -55,5 +55,5 @@ def create_app(config_name):
     def api_v1_connection(ws):
         protocol_loop.accept(ws)
 
-    logger.info('Creating app.')
+    logger.debug('Creating app.')
     return app