ebs-linuxnode-core 3.2.0__tar.gz → 3.2.2__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 (27) hide show
  1. {ebs-linuxnode-core-3.2.0/ebs_linuxnode_core.egg-info → ebs_linuxnode_core-3.2.2}/PKG-INFO +13 -1
  2. {ebs-linuxnode-core-3.2.0 → ebs_linuxnode_core-3.2.2}/ebs/linuxnode/core/basenode.py +2 -0
  3. {ebs-linuxnode-core-3.2.0 → ebs_linuxnode_core-3.2.2}/ebs/linuxnode/core/http.py +12 -10
  4. {ebs-linuxnode-core-3.2.0 → ebs_linuxnode_core-3.2.2}/ebs/linuxnode/core/log.py +16 -0
  5. ebs_linuxnode_core-3.2.2/ebs/linuxnode/core/tempfs.py +69 -0
  6. {ebs-linuxnode-core-3.2.0 → ebs_linuxnode_core-3.2.2/ebs_linuxnode_core.egg-info}/PKG-INFO +13 -1
  7. {ebs-linuxnode-core-3.2.0 → ebs_linuxnode_core-3.2.2}/ebs_linuxnode_core.egg-info/SOURCES.txt +1 -0
  8. {ebs-linuxnode-core-3.2.0 → ebs_linuxnode_core-3.2.2}/ebs_linuxnode_core.egg-info/requires.txt +1 -0
  9. {ebs-linuxnode-core-3.2.0 → ebs_linuxnode_core-3.2.2}/setup.py +1 -0
  10. {ebs-linuxnode-core-3.2.0 → ebs_linuxnode_core-3.2.2}/.gitignore +0 -0
  11. {ebs-linuxnode-core-3.2.0 → ebs_linuxnode_core-3.2.2}/ebs/__init__.py +0 -0
  12. {ebs-linuxnode-core-3.2.0 → ebs_linuxnode_core-3.2.2}/ebs/linuxnode/__init__.py +0 -0
  13. {ebs-linuxnode-core-3.2.0 → ebs_linuxnode_core-3.2.2}/ebs/linuxnode/core/__init__.py +0 -0
  14. {ebs-linuxnode-core-3.2.0 → ebs_linuxnode_core-3.2.2}/ebs/linuxnode/core/background.py +0 -0
  15. {ebs-linuxnode-core-3.2.0 → ebs_linuxnode_core-3.2.2}/ebs/linuxnode/core/basemixin.py +0 -0
  16. {ebs-linuxnode-core-3.2.0 → ebs_linuxnode_core-3.2.2}/ebs/linuxnode/core/busy.py +0 -0
  17. {ebs-linuxnode-core-3.2.0 → ebs_linuxnode_core-3.2.2}/ebs/linuxnode/core/config.py +0 -0
  18. {ebs-linuxnode-core-3.2.0 → ebs_linuxnode_core-3.2.2}/ebs/linuxnode/core/constants.py +0 -0
  19. {ebs-linuxnode-core-3.2.0 → ebs_linuxnode_core-3.2.2}/ebs/linuxnode/core/nodeid.py +0 -0
  20. {ebs-linuxnode-core-3.2.0 → ebs_linuxnode_core-3.2.2}/ebs/linuxnode/core/resources.py +0 -0
  21. {ebs-linuxnode-core-3.2.0 → ebs_linuxnode_core-3.2.2}/ebs/linuxnode/core/shell.py +0 -0
  22. {ebs-linuxnode-core-3.2.0 → ebs_linuxnode_core-3.2.2}/ebs/linuxnode/db/__init__.py +0 -0
  23. {ebs-linuxnode-core-3.2.0 → ebs_linuxnode_core-3.2.2}/ebs/linuxnode/db/sequence.py +0 -0
  24. {ebs-linuxnode-core-3.2.0 → ebs_linuxnode_core-3.2.2}/ebs_linuxnode_core.egg-info/dependency_links.txt +0 -0
  25. {ebs-linuxnode-core-3.2.0 → ebs_linuxnode_core-3.2.2}/ebs_linuxnode_core.egg-info/top_level.txt +0 -0
  26. {ebs-linuxnode-core-3.2.0 → ebs_linuxnode_core-3.2.2}/example.py +0 -0
  27. {ebs-linuxnode-core-3.2.0 → ebs_linuxnode_core-3.2.2}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ebs-linuxnode-core
3
- Version: 3.2.0
3
+ Version: 3.2.2
4
4
  Summary: Twisted based linux application node core
5
5
  Home-page: https://github.com/ebs-universe/ebs-linuxnode-core
6
6
  Author: Chintalagiri Shashank
@@ -12,3 +12,15 @@ Classifier: Programming Language :: Python
12
12
  Classifier: Programming Language :: Python :: 3
13
13
  Classifier: Programming Language :: Python :: 3.6
14
14
  Classifier: Operating System :: POSIX :: Linux
15
+ Requires-Dist: six
16
+ Requires-Dist: setuptools-scm
17
+ Requires-Dist: appdirs
18
+ Requires-Dist: twisted[tls]
19
+ Requires-Dist: SQLAlchemy
20
+ Requires-Dist: arrow
21
+ Requires-Dist: raspi_system
22
+ Requires-Dist: netifaces
23
+ Requires-Dist: ifcfg
24
+ Requires-Dist: psutil
25
+ Requires-Dist: memory_tempfile
26
+ Requires-Dist: treq
@@ -10,6 +10,7 @@ from .shell import BaseShellMixin
10
10
  from .http import HttpClientMixin
11
11
  from .resources import ResourceManagerMixin
12
12
  from .background import BackgroundCoreMixin
13
+ from .tempfs import TempFSMixin
13
14
 
14
15
 
15
16
  class BaseIoTNode(BackgroundCoreMixin,
@@ -17,6 +18,7 @@ class BaseIoTNode(BackgroundCoreMixin,
17
18
  HttpClientMixin,
18
19
  BaseShellMixin,
19
20
  NodeBusyMixin,
21
+ TempFSMixin,
20
22
  NodeLoggingMixin,
21
23
  NodeIDMixin):
22
24
  _has_gui = False
@@ -181,20 +181,22 @@ class HttpClientMixin(NodeBusyMixin, NodeLoggingMixin, BaseMixin):
181
181
  return url
182
182
 
183
183
  @staticmethod
184
- def _strip_auth(kwargs):
185
- if 'headers' not in kwargs.keys():
186
- return kwargs
187
- if b'Authorization' in kwargs['headers'].keys():
188
- rv = copy.deepcopy(kwargs)
189
- rv['headers'][b'Authorization'] = rv['headers'][b'Authorization'][:10] + b'...'
190
- return rv
191
- return kwargs
184
+ def _sanitize(kwargs):
185
+ response = {k: v for k, v in kwargs.items() if k not in {'_files'}}
186
+ if 'headers' not in response.keys():
187
+ return response
188
+ if b'Authorization' in response['headers'].keys():
189
+ new_headers = copy.deepcopy(response['headers'])
190
+ new_headers[b'Authorization'] = new_headers[b'Authorization'][:10] + b'...'
191
+ response['headers'] = new_headers
192
+ return response
193
+ return response
192
194
 
193
195
  def http_get(self, url, **kwargs):
194
196
  self.log.debug("Executing HTTP GET Request\n"
195
197
  " to URL {url}\n"
196
198
  " with kwargs {kwargs}",
197
- url=url, kwargs=self._strip_auth(kwargs))
199
+ url=url, kwargs=self._sanitize(kwargs))
198
200
  deferred_response = self.http_semaphore.run(
199
201
  self.http_client.get, url, **kwargs
200
202
  )
@@ -211,7 +213,7 @@ class HttpClientMixin(NodeBusyMixin, NodeLoggingMixin, BaseMixin):
211
213
  self.log.debug("Executing HTTP Post Request\n"
212
214
  " to URL {url}\n"
213
215
  " with kwargs {kwargs}",
214
- url=url, kwargs=self._strip_auth(kwargs))
216
+ url=url, kwargs=self._sanitize(kwargs))
215
217
  deferred_response = self.http_semaphore.run(
216
218
  self.http_client.post, url, **kwargs
217
219
  )
@@ -4,6 +4,7 @@ import os
4
4
  import io
5
5
  import sys
6
6
  import time
7
+ import zipfile
7
8
  from twisted import logger
8
9
  from twisted.logger import LogLevel
9
10
  from twisted.logger import LogLevelFilterPredicate
@@ -102,6 +103,21 @@ class NodeLoggingMixin(ConfigMixin, BaseMixin):
102
103
  os.makedirs(user_log_dir(self.appname), exist_ok=True)
103
104
  return user_log_dir(self.appname)
104
105
 
106
+ def log_build_package(self, out_path=None):
107
+ if not out_path:
108
+ ctime = datetime.now().strftime("%Y%m%d%H%M%S")
109
+ out_path = os.path.join('/tmp', f'{self.id}.{ctime}.logs.zip')
110
+
111
+ with zipfile.ZipFile(out_path, 'w', zipfile.ZIP_DEFLATED) as zip_file:
112
+ for root, dirs, files in os.walk(self.log_dir):
113
+ for file_or_dir in files + dirs:
114
+ zip_file.write(
115
+ os.path.join(root, file_or_dir),
116
+ os.path.relpath(os.path.join(root, file_or_dir), self.log_dir)
117
+ )
118
+
119
+ return out_path
120
+
105
121
  def exim_install(self):
106
122
  super(NodeLoggingMixin, self).exim_install()
107
123
  self.exim.register_export('logs', self.log_dir)
@@ -0,0 +1,69 @@
1
+
2
+
3
+ import shutil
4
+ import tempfile
5
+ from memory_tempfile import MemoryTempfile
6
+
7
+ from .basemixin import BaseMixin
8
+ from .log import NodeLoggingMixin
9
+ from .config import ElementSpec
10
+ from .config import ItemSpec
11
+
12
+
13
+ class TempFSMixin(NodeLoggingMixin, BaseMixin):
14
+ def __init__(self, *args, **kwargs):
15
+ super(TempFSMixin, self).__init__(*args, **kwargs)
16
+ self._tempfile = None
17
+ self._tempdir = None
18
+
19
+ def install(self):
20
+ super(TempFSMixin, self).install()
21
+ _elements = {
22
+ 'tmpfs_prefer_memory': ElementSpec('tmpfs', 'memory_prefer', ItemSpec(bool, fallback=True)),
23
+ 'tmpfs_force_memory': ElementSpec('tmpfs', 'memory_force', ItemSpec(bool, fallback=False)),
24
+ 'tmpfs_clean_on_exit': ElementSpec('tmpfs', 'clean_on_exit', ItemSpec(bool, fallback=True)),
25
+ }
26
+ for name, spec in _elements.items():
27
+ self.config.register_element(name, spec)
28
+
29
+ def _tempfile_init(self):
30
+ if self.config.tmpfs_force_memory:
31
+ # TODO This should use MemoryTempfile to find a tmpfs or ramfs path,
32
+ # and fail (throw exception) if a suitable path does not exist.
33
+ # - The assumption is going to be that it will be upto the deployment
34
+ # to ensure a suitable path exists.
35
+ # - Mounting here is not viable due to permission issues
36
+ # - Using pyfilesystem2 is not viable since all users will also need
37
+ # to treat it as a pyfilesystem2 object, and external processes
38
+ # cannot be handed this path.
39
+ raise NotImplementedError
40
+ elif self.config.tmpfs_prefer_memory:
41
+ self._tempfile = MemoryTempfile()
42
+ else:
43
+ self._tempfile = tempfile
44
+
45
+ @property
46
+ def tempfile(self):
47
+ if not self._tempfile:
48
+ self._tempfile_init()
49
+ return self._tempfile
50
+
51
+ @property
52
+ def tempdir(self):
53
+ if not self._tempdir:
54
+ self._tempdir = self.tempfile.mkdtemp()
55
+ return self._tempdir
56
+
57
+ def start(self):
58
+ super().start()
59
+ self.log.debug(f"Using tempfs: {self.tempfile.gettempdir()}")
60
+ self.log.info(f"Using tempdir: {self.tempdir}")
61
+
62
+ def stop(self):
63
+ if self.tempdir:
64
+ if self.config.tmpfs_clean_on_exit:
65
+ self.log.info(f"Cleaning up tempdir: {self.tempdir}")
66
+ shutil.rmtree(self.tempdir)
67
+ else:
68
+ self.log.info(f"Not cleaning up tempdir: {self.tempdir}")
69
+ super().stop()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ebs-linuxnode-core
3
- Version: 3.2.0
3
+ Version: 3.2.2
4
4
  Summary: Twisted based linux application node core
5
5
  Home-page: https://github.com/ebs-universe/ebs-linuxnode-core
6
6
  Author: Chintalagiri Shashank
@@ -12,3 +12,15 @@ Classifier: Programming Language :: Python
12
12
  Classifier: Programming Language :: Python :: 3
13
13
  Classifier: Programming Language :: Python :: 3.6
14
14
  Classifier: Operating System :: POSIX :: Linux
15
+ Requires-Dist: six
16
+ Requires-Dist: setuptools-scm
17
+ Requires-Dist: appdirs
18
+ Requires-Dist: twisted[tls]
19
+ Requires-Dist: SQLAlchemy
20
+ Requires-Dist: arrow
21
+ Requires-Dist: raspi_system
22
+ Requires-Dist: netifaces
23
+ Requires-Dist: ifcfg
24
+ Requires-Dist: psutil
25
+ Requires-Dist: memory_tempfile
26
+ Requires-Dist: treq
@@ -15,6 +15,7 @@ ebs/linuxnode/core/log.py
15
15
  ebs/linuxnode/core/nodeid.py
16
16
  ebs/linuxnode/core/resources.py
17
17
  ebs/linuxnode/core/shell.py
18
+ ebs/linuxnode/core/tempfs.py
18
19
  ebs/linuxnode/db/__init__.py
19
20
  ebs/linuxnode/db/sequence.py
20
21
  ebs_linuxnode_core.egg-info/PKG-INFO
@@ -8,4 +8,5 @@ raspi_system
8
8
  netifaces
9
9
  ifcfg
10
10
  psutil
11
+ memory_tempfile
11
12
  treq
@@ -15,6 +15,7 @@ _requires = [
15
15
  # System
16
16
  'ifcfg',
17
17
  'psutil',
18
+ 'memory_tempfile',
18
19
 
19
20
  # HTTP Client
20
21
  'treq',