Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf8e717e

Browse files
author
d.kovalenko
committed
Initial import
Direct copy from testgres 34cc7d1d with minimal changes.
1 parent29c4371 commitf8e717e

19 files changed

+3148
-0
lines changed

‎.gitignore‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
*.pyc
2+
*.egg
3+
*.egg-info/
4+
.eggs/
5+
.pytest_cache/
6+
.vscode/
7+
__pycache__/
8+
env/
9+
venv/

‎README.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#testgres - os_ops
2+
3+
Subsystem of testgres to work with OS.
4+
5+
##Authors
6+
7+
[Postgres Professional](https://postgrespro.ru/about)

‎__init__.py‎

Whitespace-only changes.

‎setup.cfg‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[metadata]
2+
description-file = README.md
3+
4+
[flake8]
5+
ignore = E501
6+
exclude = .git,__pycache__,env,venv,testgres/__init__.py

‎setup.py‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
try:
2+
fromsetuptoolsimportsetup
3+
exceptImportError:
4+
fromdistutils.coreimportsetup
5+
6+
setup(
7+
version="0.0.1",
8+
name="testgres.os_ops",
9+
packages=[
10+
"testgres.operations",
11+
],
12+
package_dir={"testgres.operations":"src"},
13+
description='Testgres subsystem to work with OS',
14+
url='https://github.com/postgrespro/testgres.os_ops',
15+
long_description_content_type='text/markdown',
16+
license='PostgreSQL',
17+
author='Postgres Professional',
18+
author_email='testgres@postgrespro.ru',
19+
keywords=['testgres'],
20+
)

‎src/__init__.py‎

Whitespace-only changes.

‎src/exceptions.py‎

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# coding: utf-8
2+
3+
importsix
4+
5+
6+
classTestgresException(Exception):
7+
pass
8+
9+
10+
classExecUtilException(TestgresException):
11+
def__init__(self,message=None,command=None,exit_code=0,out=None,error=None):
12+
super(ExecUtilException,self).__init__(message)
13+
14+
self.message=message
15+
self.command=command
16+
self.exit_code=exit_code
17+
self.out=out
18+
self.error=error
19+
20+
def__str__(self):
21+
msg= []
22+
23+
ifself.message:
24+
msg.append(self.message)
25+
26+
ifself.command:
27+
command_s=' '.join(self.command)ifisinstance(self.command,list)elseself.command,
28+
msg.append(u'Command: {}'.format(command_s))
29+
30+
ifself.exit_code:
31+
msg.append(u'Exit code: {}'.format(self.exit_code))
32+
33+
ifself.error:
34+
msg.append(u'---- Error:\n{}'.format(self.error))
35+
36+
ifself.out:
37+
msg.append(u'---- Out:\n{}'.format(self.out))
38+
39+
returnself.convert_and_join(msg)
40+
41+
@staticmethod
42+
defconvert_and_join(msg_list):
43+
# Convert each byte element in the list to str
44+
str_list= [six.text_type(item,'utf-8')ifisinstance(item,bytes)elsesix.text_type(item)foritemin
45+
msg_list]
46+
47+
# Join the list into a single string with the specified delimiter
48+
returnsix.text_type('\n').join(str_list)
49+
50+
51+
classInvalidOperationException(TestgresException):
52+
pass

‎src/helpers.py‎

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
importlocale
2+
3+
4+
classHelpers:
5+
@staticmethod
6+
def_make_get_default_encoding_func():
7+
# locale.getencoding is added in Python 3.11
8+
ifhasattr(locale,'getencoding'):
9+
returnlocale.getencoding
10+
11+
# It must exist
12+
returnlocale.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+
defGetDefaultEncoding():
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_funcisnotNone
29+
30+
r=__class__._get_default_encoding_func()
31+
32+
ifr:
33+
assertrisnotNone
34+
asserttype(r)==str# noqa: E721
35+
assertr!=""
36+
returnr
37+
38+
# Is it an unexpected situation?
39+
return'UTF-8'
40+
41+
@staticmethod
42+
defPrepareProcessInput(input,encoding):
43+
ifnotinput:
44+
returnNone
45+
46+
iftype(input)==str:# noqa: E721
47+
ifencodingisNone:
48+
returninput.encode(__class__.GetDefaultEncoding())
49+
50+
asserttype(encoding)==str# noqa: E721
51+
returninput.encode(encoding)
52+
53+
# It is expected!
54+
asserttype(input)==bytes# noqa: E721
55+
returninput

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp