Coverage for gramex\license.py : 82%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1import os
2import six
3import time
4import uuid
5import gramex
6from gramex.config import variables
7from gramex.cache import SQLiteStore
10# gramex.license.EULA has the wording of the end user license agreement
11EULA = '''
12-------------------------------------------------------------------------
13Read the license agreement at https://learn.gramener.com/guide/license/
14'''
15# All license information is captured in this store.
16store = SQLiteStore(path=os.path.join(variables['GRAMEXDATA'], 'license.db'), table='license')
19def is_accepted():
20 '''
21 If license was accepted, returns timestamp when license was accepted.
22 If license was never accepted so far, returns None.
23 If license was rejected, returns False.
24 '''
25 return store.load('accepted', default=None)
28def accept(force=False):
29 '''
30 Prints the license.
31 Allows users to accept the license by prompting.
32 If force=True is passed, accepts the license without prompting the user.
33 '''
34 if is_accepted():
35 return
36 gramex.console(EULA)
37 result = 'y' if force else ''
38 while not result: 38 ↛ 39line 38 didn't jump to line 39, because the condition on line 38 was never true
39 result = six.moves.input('Do you accept the license (Y/N): ').strip()
40 if result.lower().startswith('y'): 40 ↛ 45line 40 didn't jump to line 45, because the condition on line 40 was never false
41 store.dump('accepted', time.time())
42 store.flush()
43 gramex.console('Gramex license accepted')
44 else:
45 raise RuntimeError('Gramex license not accepted')
48def reject():
49 '''
50 Rejects the license.
51 '''
52 store.dump('accepted', False)
53 store.flush()
54 gramex.console('Gramex license rejected')
57'''
58This section may implement different strategies to uniquely identify machines.
60http://serialsense.com/blog/2011/02/generating-unique-machine-ids/
61http://stackoverflow.com/questions/2461141/get-a-unique-computer-id-in-python-on-windows-and-linux
62'''
65def mac_id():
66 return uuid.getnode()
69def cpu_id():
70 raise NotImplementedError('CPU ID not yet implemented')
73def bios_id():
74 raise NotImplementedError('BIOS ID not yet implemented')