sciveo 0.1.15__tar.gz → 0.1.16__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. {sciveo-0.1.15 → sciveo-0.1.16}/PKG-INFO +1 -1
  2. sciveo-0.1.16/sciveo/common/tools/compress.py +26 -0
  3. sciveo-0.1.16/sciveo/common/tools/crypto.py +57 -0
  4. {sciveo-0.1.15 → sciveo-0.1.16}/sciveo/common/tools/daemon.py +17 -0
  5. sciveo-0.1.16/sciveo/common/tools/random.py +22 -0
  6. sciveo-0.1.16/sciveo/version.py +2 -0
  7. {sciveo-0.1.15 → sciveo-0.1.16}/sciveo.egg-info/PKG-INFO +1 -1
  8. {sciveo-0.1.15 → sciveo-0.1.16}/sciveo.egg-info/SOURCES.txt +5 -0
  9. {sciveo-0.1.15 → sciveo-0.1.16}/sciveo.egg-info/requires.txt +1 -0
  10. {sciveo-0.1.15 → sciveo-0.1.16}/setup.py +1 -0
  11. sciveo-0.1.16/test/test_compress.py +16 -0
  12. sciveo-0.1.16/test/test_crypto.py +34 -0
  13. sciveo-0.1.15/sciveo/version.py +0 -2
  14. {sciveo-0.1.15 → sciveo-0.1.16}/README.md +0 -0
  15. {sciveo-0.1.15 → sciveo-0.1.16}/sciveo/__init__.py +0 -0
  16. {sciveo-0.1.15 → sciveo-0.1.16}/sciveo/api/__init__.py +0 -0
  17. {sciveo-0.1.15 → sciveo-0.1.16}/sciveo/api/base.py +0 -0
  18. {sciveo-0.1.15 → sciveo-0.1.16}/sciveo/api/upload.py +0 -0
  19. {sciveo-0.1.15 → sciveo-0.1.16}/sciveo/cli.py +0 -0
  20. {sciveo-0.1.15 → sciveo-0.1.16}/sciveo/common/__init__.py +0 -0
  21. {sciveo-0.1.15 → sciveo-0.1.16}/sciveo/common/configuration.py +0 -0
  22. {sciveo-0.1.15 → sciveo-0.1.16}/sciveo/common/model.py +0 -0
  23. {sciveo-0.1.15 → sciveo-0.1.16}/sciveo/common/optimizers.py +0 -0
  24. {sciveo-0.1.15 → sciveo-0.1.16}/sciveo/common/sampling.py +0 -0
  25. {sciveo-0.1.15 → sciveo-0.1.16}/sciveo/common/tools/__init__.py +0 -0
  26. {sciveo-0.1.15 → sciveo-0.1.16}/sciveo/common/tools/configuration.py +0 -0
  27. {sciveo-0.1.15 → sciveo-0.1.16}/sciveo/common/tools/formating.py +0 -0
  28. {sciveo-0.1.15 → sciveo-0.1.16}/sciveo/common/tools/hardware.py +0 -0
  29. {sciveo-0.1.15 → sciveo-0.1.16}/sciveo/common/tools/logger.py +0 -0
  30. {sciveo-0.1.15 → sciveo-0.1.16}/sciveo/common/tools/synchronized.py +0 -0
  31. {sciveo-0.1.15 → sciveo-0.1.16}/sciveo/common/tools/timers.py +0 -0
  32. {sciveo-0.1.15 → sciveo-0.1.16}/sciveo/content/__init__.py +0 -0
  33. {sciveo-0.1.15 → sciveo-0.1.16}/sciveo/content/dataset.py +0 -0
  34. {sciveo-0.1.15 → sciveo-0.1.16}/sciveo/content/experiment.py +0 -0
  35. {sciveo-0.1.15 → sciveo-0.1.16}/sciveo/content/project.py +0 -0
  36. {sciveo-0.1.15 → sciveo-0.1.16}/sciveo/content/runner.py +0 -0
  37. {sciveo-0.1.15 → sciveo-0.1.16}/sciveo/monitoring/__init__.py +0 -0
  38. {sciveo-0.1.15 → sciveo-0.1.16}/sciveo/monitoring/monitor.py +0 -0
  39. {sciveo-0.1.15 → sciveo-0.1.16}/sciveo/monitoring/network.py +0 -0
  40. {sciveo-0.1.15 → sciveo-0.1.16}/sciveo/monitoring/start.py +0 -0
  41. {sciveo-0.1.15 → sciveo-0.1.16}/sciveo.egg-info/dependency_links.txt +0 -0
  42. {sciveo-0.1.15 → sciveo-0.1.16}/sciveo.egg-info/entry_points.txt +0 -0
  43. {sciveo-0.1.15 → sciveo-0.1.16}/sciveo.egg-info/top_level.txt +0 -0
  44. {sciveo-0.1.15 → sciveo-0.1.16}/setup.cfg +0 -0
  45. {sciveo-0.1.15 → sciveo-0.1.16}/test/test_configuration.py +0 -0
  46. {sciveo-0.1.15 → sciveo-0.1.16}/test/test_monitoring.py +0 -0
  47. {sciveo-0.1.15 → sciveo-0.1.16}/test/test_runner.py +0 -0
  48. {sciveo-0.1.15 → sciveo-0.1.16}/test/test_sampling.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: sciveo
3
- Version: 0.1.15
3
+ Version: 0.1.16
4
4
  Description-Content-Type: text/markdown
5
5
  Provides-Extra: mon
6
6
  Provides-Extra: net
@@ -0,0 +1,26 @@
1
+ import json
2
+ import gzip
3
+ import base64
4
+
5
+ from sciveo.common.tools.logger import *
6
+
7
+
8
+ class CompressJsonData:
9
+ def __init__(self) -> None:
10
+ pass
11
+
12
+ def compress(self, data):
13
+ json_data = json.dumps(data).encode('utf-8')
14
+ compressed_data = gzip.compress(json_data)
15
+ encoded_data = base64.b64encode(compressed_data).decode('utf-8')
16
+ debug(type(self).__name__, "compress", len(json_data), "->", len(encoded_data))
17
+ return encoded_data
18
+
19
+ def decompress(self, encoded_data):
20
+ compressed_data = base64.b64decode(encoded_data)
21
+ decompressed_data = gzip.decompress(compressed_data)
22
+ json_data = decompressed_data.decode('utf-8')
23
+ data = json.loads(json_data)
24
+ debug(type(self).__name__, "decompress", len(encoded_data), "->", len(json_data))
25
+ return data
26
+
@@ -0,0 +1,57 @@
1
+ import json
2
+ import base64
3
+ from Crypto.Cipher import AES
4
+ from Crypto.Random import get_random_bytes
5
+
6
+ from sciveo.common.tools.logger import *
7
+
8
+
9
+ class CryptoJsonData:
10
+ def __init__(self, base64_key=None) -> None:
11
+ if base64_key is None:
12
+ self.gen_key()
13
+ else:
14
+ self.key = base64.b64decode(base64_key)
15
+
16
+ def get_key(self):
17
+ return base64.b64encode(self.key).decode("utf-8")
18
+
19
+ def gen_key(self):
20
+ self.key = get_random_bytes(32)
21
+ return self.get_key()
22
+
23
+ def read_key(self, key_path):
24
+ with open(key_path, 'rb') as fp:
25
+ self.key = fp.read(32)
26
+
27
+ def write_key(self, key_path):
28
+ with open(key_path, 'wb') as fp:
29
+ fp.write(self.key)
30
+
31
+ def encrypt(self, plaintext, mode=AES.MODE_GCM):
32
+ iv = get_random_bytes(12)
33
+ cipher = AES.new(self.key, mode, nonce=iv)
34
+ data_encrypted, auth_tag = cipher.encrypt_and_digest(plaintext.encode())
35
+ return {
36
+ "encrypted": base64.b64encode(data_encrypted).decode("utf-8"),
37
+ "auth_tag": base64.b64encode(auth_tag).decode("utf-8"),
38
+ "iv": base64.b64encode(iv).decode("utf-8")
39
+ }
40
+
41
+ def decrypt(self, cipher_data, mode=AES.MODE_GCM):
42
+ cipher_text = base64.b64decode(cipher_data["encrypted"])
43
+ auth_tag = base64.b64decode(cipher_data["auth_tag"])
44
+ iv = base64.b64decode(cipher_data["iv"])
45
+ cipher = AES.new(self.key, mode, nonce=iv)
46
+ return cipher.decrypt_and_verify(cipher_text, auth_tag).decode("utf-8")
47
+
48
+ def encrypt_json(self, data):
49
+ data = json.dumps(data)
50
+ data = base64.b64encode(data.encode()).decode("utf-8")
51
+ return self.encrypt(data)
52
+
53
+ def decrypt_json(self, encrypted_data):
54
+ data = self.decrypt(encrypted_data)
55
+ data = base64.b64decode(data)
56
+ data = json.loads(data)
57
+ return data
@@ -10,6 +10,7 @@
10
10
  #
11
11
 
12
12
  import threading
13
+ import signal
13
14
  import time
14
15
 
15
16
  from sciveo.common.tools.logger import *
@@ -17,6 +18,22 @@ from sciveo.common.tools.synchronized import ListQueue
17
18
  from sciveo.api.upload import APIFileUploader
18
19
 
19
20
 
21
+ class SignalHandler:
22
+ def __init__(self, daemons):
23
+ self.daemons = daemons
24
+
25
+ signal.signal(signal.SIGINT, self.handler_int)
26
+ signal.signal(signal.SIGUSR1, self.handler_usr1)
27
+
28
+ def handler_int(self, signum, frame):
29
+ info(type(self).__name__, "INT signal received", signum, frame)
30
+ for daemon in self.daemons:
31
+ daemon.stop()
32
+
33
+ def handler_usr1(self, signum, frame):
34
+ info(type(self).__name__, "USR1 signal received", signum, frame)
35
+
36
+
20
37
  class DaemonBase:
21
38
  def __init__(self, num_threads=1, period=0):
22
39
  self.is_running = False
@@ -0,0 +1,22 @@
1
+ import random
2
+ import string
3
+
4
+
5
+ def random_password(length):
6
+ lower = string.ascii_lowercase
7
+ upper = string.ascii_uppercase
8
+ digits = string.digits
9
+ special = '!@#$%&'
10
+
11
+ # Ensure the password contains at least one character from each set
12
+ password = [
13
+ random.choice(lower),
14
+ random.choice(upper),
15
+ random.choice(digits),
16
+ random.choice(special)
17
+ ]
18
+
19
+ all_chars = lower + upper + (2 * digits) + (3 * special)
20
+ password += random.choices(all_chars, k=length - 4)
21
+ random.shuffle(password)
22
+ return ''.join(password)
@@ -0,0 +1,2 @@
1
+
2
+ __version__ = '0.1.16'
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: sciveo
3
- Version: 0.1.15
3
+ Version: 0.1.16
4
4
  Description-Content-Type: text/markdown
5
5
  Provides-Extra: mon
6
6
  Provides-Extra: net
@@ -18,11 +18,14 @@ sciveo/common/model.py
18
18
  sciveo/common/optimizers.py
19
19
  sciveo/common/sampling.py
20
20
  sciveo/common/tools/__init__.py
21
+ sciveo/common/tools/compress.py
21
22
  sciveo/common/tools/configuration.py
23
+ sciveo/common/tools/crypto.py
22
24
  sciveo/common/tools/daemon.py
23
25
  sciveo/common/tools/formating.py
24
26
  sciveo/common/tools/hardware.py
25
27
  sciveo/common/tools/logger.py
28
+ sciveo/common/tools/random.py
26
29
  sciveo/common/tools/synchronized.py
27
30
  sciveo/common/tools/timers.py
28
31
  sciveo/content/__init__.py
@@ -34,7 +37,9 @@ sciveo/monitoring/__init__.py
34
37
  sciveo/monitoring/monitor.py
35
38
  sciveo/monitoring/network.py
36
39
  sciveo/monitoring/start.py
40
+ test/test_compress.py
37
41
  test/test_configuration.py
42
+ test/test_crypto.py
38
43
  test/test_monitoring.py
39
44
  test/test_runner.py
40
45
  test/test_sampling.py
@@ -4,6 +4,7 @@ requests>=0.0.0
4
4
  [all]
5
5
  psutil>=0.0.0
6
6
  netifaces>=0.0.0
7
+ pycryptodome>=0.0.0
7
8
 
8
9
  [mon]
9
10
  psutil>=0.0.0
@@ -32,6 +32,7 @@ setup(
32
32
  'all': [
33
33
  'psutil>=0.0.0',
34
34
  'netifaces>=0.0.0',
35
+ 'pycryptodome>=0.0.0'
35
36
  ]
36
37
  },
37
38
  py_modules=['sciveo'],
@@ -0,0 +1,16 @@
1
+ import unittest
2
+ import json
3
+
4
+ from sciveo.common.tools.compress import *
5
+
6
+
7
+ class TestEncoders(unittest.TestCase):
8
+ def test_compress_json(self):
9
+ zip = CompressJsonData()
10
+ j1 = {"AAA": [1, 2, 3], "BBB": {"CCC": 1, "DDD": 2, "EEE": 3}, "CC": 3}
11
+ j2 = zip.decompress(zip.compress(j1))
12
+ self.assertEqual(json.dumps(j1, sort_keys=True), json.dumps(j2, sort_keys=True))
13
+
14
+
15
+ if __name__ == '__main__':
16
+ unittest.main()
@@ -0,0 +1,34 @@
1
+ import unittest
2
+
3
+ from sciveo.common.tools.crypto import *
4
+
5
+
6
+ class TestCrypto(unittest.TestCase):
7
+ def test_string(self):
8
+ c = CryptoJsonData()
9
+ m1 = "test message string encrypt and decrypt"
10
+ m2 = c.decrypt(c.encrypt(m1))
11
+ self.assertEqual(m1, m2)
12
+
13
+ def test_json(self):
14
+ c = CryptoJsonData()
15
+ j1 = {"A": 1, "B": []}
16
+ j2 = c.decrypt_json(c.encrypt_json(j1))
17
+ self.assertEqual(json.dumps(j1, sort_keys=True), json.dumps(j2, sort_keys=True))
18
+
19
+ def test_big_json(self):
20
+ c = CryptoJsonData()
21
+ j1 = {"test": 1, "L": [1,2,3,4], "W": "A", "B": "C", "D1": {1: 2, 2: 3, 3: 4}, "L2": [[1,2,3], [3,4,5]]}
22
+ j2 = c.decrypt_json(c.encrypt_json(j1))
23
+ self.assertEqual(json.dumps(j1, sort_keys=True), json.dumps(j2, sort_keys=True))
24
+
25
+ def test_key(self):
26
+ key = "OZ1IIdAh3b6h+E7fgIGo33rRsNT8Vg428GVC4FAGZGM="
27
+ c = CryptoJsonData(key)
28
+ m1 = "test message string encrypt and decrypt"
29
+ m2 = c.decrypt(c.encrypt(m1))
30
+ self.assertEqual(m1, m2)
31
+
32
+
33
+ if __name__ == '__main__':
34
+ unittest.main()
@@ -1,2 +0,0 @@
1
-
2
- __version__ = '0.1.15'
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes