Coverage for gramex\license.py: 82%

# Coverage for gramex\license.py : 82%

## 33 statements 28 run 5 missing 0 excluded 2 partial

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

1 import os

2 import six

3 import time

4 import uuid

5 import gramex

6 from gramex.config import variables

7 from gramex.cache import SQLiteStore

8

9

10# gramex.license.EULA has the wording of the end user license agreement

11 EULA = '''

12-------------------------------------------------------------------------

13 Read the license agreement at https://learn.gramener.com/guide/license/

14'''

15# All license information is captured in this store.

16 store = SQLiteStore(path=os.path.join(variables['GRAMEXDATA'], 'license.db'), table='license')

17

18

19 def 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)

26

27

28 def 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')

46

47

48 def reject():

49 '''

50 Rejects the license.

51 '''

52 store.dump('accepted', False)

53 store.flush()

54 gramex.console('Gramex license rejected')

55

56

57'''

58 This section may implement different strategies to uniquely identify machines.

59

60 http://serialsense.com/blog/2011/02/generating-unique-machine-ids/

61 http://stackoverflow.com/questions/2461141/get-a-unique-computer-id-in-python-on-windows-and-linux

62'''

63

64

65 def mac_id():

66 return uuid.getnode()

67

68

69 def cpu_id():

70 raise NotImplementedError('CPU ID not yet implemented')

71

72

73 def bios_id():

74 raise NotImplementedError('BIOS ID not yet implemented')