testgres.os-ops 0.0.1__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.
@@ -0,0 +1,21 @@
1
+ Metadata-Version: 2.4
2
+ Name: testgres.os_ops
3
+ Version: 0.0.1
4
+ Summary: Testgres subsystem to work with OS
5
+ Home-page: https://github.com/postgrespro/testgres.os_ops
6
+ Author: Postgres Professional
7
+ Author-email: testgres@postgrespro.ru
8
+ License: PostgreSQL
9
+ Keywords: testgres
10
+ Description-Content-Type: text/markdown
11
+ Requires-Dist: psutil
12
+ Requires-Dist: six>=1.9.0
13
+ Requires-Dist: testgres.common==0.0.1
14
+ Dynamic: author
15
+ Dynamic: author-email
16
+ Dynamic: description-content-type
17
+ Dynamic: home-page
18
+ Dynamic: keywords
19
+ Dynamic: license
20
+ Dynamic: requires-dist
21
+ Dynamic: summary
@@ -0,0 +1,10 @@
1
+ [![Build Status](https://api.travis-ci.com/postgrespro/testgres.os_ops.svg?token=HgEMhyw9n7RCQkHCis4T&branch=master)](https://travis-ci.com/github/postgrespro/testgres.os_ops)
2
+
3
+
4
+ # testgres - os_ops
5
+
6
+ Subsystem of testgres to work with OS.
7
+
8
+ ## Authors
9
+
10
+ [Postgres Professional](https://postgrespro.ru/about)
@@ -0,0 +1,11 @@
1
+ [metadata]
2
+ description-file = README.md
3
+
4
+ [flake8]
5
+ ignore = E501
6
+ exclude = .git,__pycache__,env,venv
7
+
8
+ [egg_info]
9
+ tag_build =
10
+ tag_date = 0
11
+
@@ -0,0 +1,28 @@
1
+ try:
2
+ from setuptools import setup
3
+ except ImportError:
4
+ from distutils.core import setup
5
+
6
+ # Basic dependencies
7
+ install_requires = [
8
+ "psutil",
9
+ "six>=1.9.0",
10
+ "testgres.common==0.0.1",
11
+ ]
12
+
13
+ setup(
14
+ version="0.0.1",
15
+ name="testgres.os_ops",
16
+ packages=[
17
+ "testgres.operations",
18
+ ],
19
+ package_dir={"testgres.operations": "src"},
20
+ description='Testgres subsystem to work with OS',
21
+ url='https://github.com/postgrespro/testgres.os_ops',
22
+ long_description_content_type='text/markdown',
23
+ license='PostgreSQL',
24
+ author='Postgres Professional',
25
+ author_email='testgres@postgrespro.ru',
26
+ keywords=['testgres'],
27
+ install_requires=install_requires,
28
+ )
File without changes
@@ -0,0 +1,53 @@
1
+ # coding: utf-8
2
+
3
+ from testgres.common.exceptions import TestgresException
4
+ from testgres.common.exceptions import InvalidOperationException
5
+ import six
6
+
7
+
8
+ class ExecUtilException(TestgresException):
9
+ def __init__(self, message=None, command=None, exit_code=0, out=None, error=None):
10
+ super(ExecUtilException, self).__init__(message)
11
+
12
+ self.message = message
13
+ self.command = command
14
+ self.exit_code = exit_code
15
+ self.out = out
16
+ self.error = error
17
+
18
+ def __str__(self):
19
+ msg = []
20
+
21
+ if self.message:
22
+ msg.append(self.message)
23
+
24
+ if self.command:
25
+ command_s = ' '.join(self.command) if isinstance(self.command, list) else self.command
26
+ msg.append(u'Command: {}'.format(command_s))
27
+
28
+ if self.exit_code:
29
+ msg.append(u'Exit code: {}'.format(self.exit_code))
30
+
31
+ if self.error:
32
+ msg.append(u'---- Error:\n{}'.format(self.error))
33
+
34
+ if self.out:
35
+ msg.append(u'---- Out:\n{}'.format(self.out))
36
+
37
+ return self.convert_and_join(msg)
38
+
39
+ @staticmethod
40
+ def convert_and_join(msg_list):
41
+ # Convert each byte element in the list to str
42
+ str_list = [six.text_type(item, 'utf-8') if isinstance(item, bytes) else six.text_type(item) for item in
43
+ msg_list]
44
+
45
+ # Join the list into a single string with the specified delimiter
46
+ return six.text_type('\n').join(str_list)
47
+
48
+
49
+ __all__ = [
50
+ type(TestgresException).__name__,
51
+ type(InvalidOperationException).__name__,
52
+ type(ExecUtilException).__name__,
53
+ ]
@@ -0,0 +1,55 @@
1
+ import locale
2
+
3
+
4
+ class Helpers:
5
+ @staticmethod
6
+ def _make_get_default_encoding_func():
7
+ # locale.getencoding is added in Python 3.11
8
+ if hasattr(locale, 'getencoding'):
9
+ return locale.getencoding
10
+
11
+ # It must exist
12
+ return locale.getpreferredencoding
13
+
14
+ # Prepared pointer on function to get a name of system codepage
15
+ _get_default_encoding_func = _make_get_default_encoding_func.__func__()
16
+
17
+ @staticmethod
18
+ def GetDefaultEncoding():
19
+ #
20
+ # Original idea/source was:
21
+ #
22
+ # def os_ops.get_default_encoding():
23
+ # if not hasattr(locale, 'getencoding'):
24
+ # locale.getencoding = locale.getpreferredencoding
25
+ # return locale.getencoding() or 'UTF-8'
26
+ #
27
+
28
+ assert __class__._get_default_encoding_func is not None
29
+
30
+ r = __class__._get_default_encoding_func()
31
+
32
+ if r:
33
+ assert r is not None
34
+ assert type(r) == str # noqa: E721
35
+ assert r != ""
36
+ return r
37
+
38
+ # Is it an unexpected situation?
39
+ return 'UTF-8'
40
+
41
+ @staticmethod
42
+ def PrepareProcessInput(input, encoding):
43
+ if not input:
44
+ return None
45
+
46
+ if type(input) == str: # noqa: E721
47
+ if encoding is None:
48
+ return input.encode(__class__.GetDefaultEncoding())
49
+
50
+ assert type(encoding) == str # noqa: E721
51
+ return input.encode(encoding)
52
+
53
+ # It is expected!
54
+ assert type(input) == bytes # noqa: E721
55
+ return input