Skip to content

Commit

Permalink
Merge pull request #35 from SUSE/isbm-py3-typeanno
Browse files Browse the repository at this point in the history
Add more Py3 type annotations
  • Loading branch information
Bo Maryniuk authored May 14, 2019
2 parents ad52adf + a782ac9 commit 2f777d7
Show file tree
Hide file tree
Showing 8 changed files with 137 additions and 111 deletions.
2 changes: 2 additions & 0 deletions .mypyrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[mypy]
mypy_path = ./src/
20 changes: 20 additions & 0 deletions run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,23 @@ source "$venv/bin/activate"
install_deps
ln -s "$(readlink -f .)/src/smdba" $(dirname $(python -c "import pytest as _; print(_.__file__)")) 2>/dev/null
pytest -sv tests

cat <<EOF
==================================== MyPy Tests [start] ===================================
EOF
mypy --config-file ./.mypyrc --strict src/smdba/

if [ $? -ne 0 ]; then
cat <<EOF
=================================== MyPy Tests [finish] ===================================
There are still some issues with static run. Unless this is oraclegate.py, please fix them.
EOF
else
cat <<EOF
Type check seems OK.
EOF
fi
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

setup(
name='SUSE Manager Database Control',
version='1.7.1',
version='1.7.3',
package_dir= {'': 'src'},
package_data={'smdba': ['scenarios/*.scn']},
packages=['smdba'],
Expand Down
22 changes: 11 additions & 11 deletions src/smdba/basegate.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ class BaseGate(metaclass=abc.ABCMeta):

debug = False

def __init__(self):
self.config = {}
self._gate_commands = {}
def __init__(self) -> None:
self.config: typing.Dict[str, typing.Any] = {}
self._gate_commands: typing.Dict[str, typing.Any] = {}

@staticmethod
def is_sm_running() -> bool:
Expand Down Expand Up @@ -61,7 +61,7 @@ def get_scn(name: str) -> typing.TextIO:

return open(scenario, 'r')

def get_scenario_template(self, target: str = 'sqlplus', login: str = None) -> str:
def get_scenario_template(self, target: str = 'sqlplus', login: typing.Optional[str] = None) -> str:
"""
Generate a template for the Oracle SQL*Plus scenario.
Expand Down Expand Up @@ -111,7 +111,7 @@ def get_scenario_template(self, target: str = 'sqlplus', login: str = None) -> s
return '\n'.join(scenario)

def call_scenario(self, scenario: str, target: str = 'sqlplus',
login: str = None, **variables: str) -> typing.Tuple[str, str]:
login: typing.Optional[str] = None, **variables: str) -> typing.Tuple[str, str]:
"""
Call scenario in SQL*Plus.
Returns stdout and stderr.
Expand Down Expand Up @@ -160,7 +160,7 @@ def to_str(value: bytes) -> str:

return out

def syscall(self, command: str, *params: str, input: str = None) -> typing.Tuple[str, str]:
def syscall(self, command: str, *params: str, input: typing.Optional[str] = None) -> typing.Tuple[str, str]:
"""
Call an external system command.
Expand Down Expand Up @@ -214,15 +214,15 @@ def check(self) -> None:
"""

@staticmethod
def size_pretty(size: str, int_only: bool = False, no_whitespace: bool = False) -> str:
def size_pretty(size: typing.Union[str, int, float], int_only: bool = False, no_whitespace: bool = False) -> str:
"""
Make pretty size from bytes to other metrics.
Size: amount (int, long)
"""

_size = float(size)
wsp = "" if no_whitespace else " "
wrap = lambda arg: arg if not int_only else int(round(arg))
wrap: typing.Callable[[float], typing.Union[int, float]] = lambda arg: arg if not int_only else int(round(arg))
sz_ptn = '%.d' if int_only else '%.2f'

if _size >= 0x10000000000:
Expand Down Expand Up @@ -276,7 +276,7 @@ def finish(self) -> None:
"""

@staticmethod
def extract_errors(stdout: str):
def extract_errors(stdout: str) -> str:
"""
Extract errors from the RMAN and SQLPlus.
Based on http://docs.oracle.com/cd/B28359_01/backup.111/b28270/rcmtroub.htm
Expand All @@ -285,7 +285,7 @@ def extract_errors(stdout: str):
if not (stdout + "").strip():
return ""

out: typing.List = []
out: typing.List[str] = []
for line in filter(None, str(stdout).replace("\\n", "\n").split("\n")):
if line.lower().startswith("ora-") or line.lower().startswith("rman-"):
if not line.find("===") > -1:
Expand All @@ -294,7 +294,7 @@ def extract_errors(stdout: str):
return '\n'.join(out)

@staticmethod
def to_stderr(stderr: str):
def to_stderr(stderr: str) -> typing.Optional[bool]:
"""
Format an error output to STDERR and terminate everything at once.
"""
Expand Down
Loading

0 comments on commit 2f777d7

Please sign in to comment.