From 56d703d522503f7da5da22c6f44639566f5caee1 Mon Sep 17 00:00:00 2001 From: Andrey Vertiprahov Date: Wed, 28 Sep 2022 17:54:18 +0500 Subject: [PATCH 1/4] Format change-ip script. --- core/cdag/tx.py | 2 +- core/profile/base.py | 2 +- scripts/deploy/change-ip.py | 30 +++++++++++++++++++++--------- services/classifier/xrulelookup.py | 4 +++- 4 files changed, 26 insertions(+), 12 deletions(-) diff --git a/core/cdag/tx.py b/core/cdag/tx.py index 899bc91490..821531ad16 100644 --- a/core/cdag/tx.py +++ b/core/cdag/tx.py @@ -6,7 +6,7 @@ # ---------------------------------------------------------------------- # Python modules -from typing import Any, Dict, Optional +from typing import Any, Dict # NOC modules from .typing import ValueType diff --git a/core/profile/base.py b/core/profile/base.py index 572094630f..614f81e096 100644 --- a/core/profile/base.py +++ b/core/profile/base.py @@ -182,7 +182,7 @@ class BaseProfile(object, metaclass=BaseProfileMetaclass): NB: Sending logic is implemented in *commands* script Examples: - "^.+\\" -- treat trailing backspace as continuation + rf"^.+\\" -- treat trailing backspace as continuation "banner\s+login\s+(\S+)" -- continue until matched group """ diff --git a/scripts/deploy/change-ip.py b/scripts/deploy/change-ip.py index 5ee57c73f5..0eb73787e4 100755 --- a/scripts/deploy/change-ip.py +++ b/scripts/deploy/change-ip.py @@ -50,21 +50,31 @@ ALL_PATHS = [ TELEGRAF_PG, TELEGRAF_MG, TELEGRAF_NG, - PGBOUNCER + PGBOUNCER, ] + def take_postgresql_version(): distr_family = guess_system_type() ver = "" if distr_family == "deb": - sp = subprocess.run(['dpkg-query -W -f=\'${package} ${status}\n\' postgresql-*|grep "install ok installed" | ' - 'grep -Po "(\\d.?\\d+)"|sort -u'], stdout=subprocess.PIPE, shell=True) - ver = str(sp.stdout.decode('utf-8')).rstrip('\n') + sp = subprocess.run( + [ + "dpkg-query -W -f='${package} ${status}\n' postgresql-*|grep \"install ok installed\" | " + 'grep -Po "(\\d.?\\d+)"|sort -u' + ], + stdout=subprocess.PIPE, + shell=True, + ) + ver = str(sp.stdout.decode("utf-8")).rstrip("\n") return ver if distr_family == "rpm": - sp = subprocess.run(['yum list installed postgresql* | ' - 'grep -Po \'postgresql\\K\\d*(?=-server)\''], stdout=subprocess.PIPE, shell=True) - ver = str(sp.stdout.decode('utf-8')).rstrip('\n') + sp = subprocess.run( + ["yum list installed postgresql* | " "grep -Po 'postgresql\\K\\d*(?=-server)'"], + stdout=subprocess.PIPE, + shell=True, + ) + ver = str(sp.stdout.decode("utf-8")).rstrip("\n") if ver == "96": ver = "9.6" return ver @@ -74,8 +84,10 @@ def take_postgresql_version(): def guess_system_type(): """Trys to figure out what system do we have, deb or rpm like""" - stream = os.popen('grep "^NAME=" /etc/os-release |cut -d "=" -f 2 | sed -e \'s/^"//\' -e \'s/"$//\'') - output = stream.read().rstrip('\n') + stream = os.popen( + 'grep "^NAME=" /etc/os-release |cut -d "=" -f 2 | sed -e \'s/^"//\' -e \'s/"$//\'' + ) + output = stream.read().rstrip("\n") if "Ubuntu" in output or "Debian GNU/Linux" in output: distr_fam = "deb" diff --git a/services/classifier/xrulelookup.py b/services/classifier/xrulelookup.py index 6b871d3d30..42d27abe7d 100644 --- a/services/classifier/xrulelookup.py +++ b/services/classifier/xrulelookup.py @@ -17,7 +17,9 @@ import sre_parse try: import esmre as esm except (ModuleNotFoundError, ImportError): - raise NotImplementedError("XRuleLookup needed ESMRE library for worked. Please, install it from pip") + raise NotImplementedError( + "XRuleLookup needed ESMRE library for worked. Please, install it from pip" + ) import bitarray # NOC modules -- GitLab From 117244a51db2172a239433ff4a4f98b501e84ca5 Mon Sep 17 00:00:00 2001 From: Andrey Vertiprahov Date: Wed, 28 Sep 2022 17:55:58 +0500 Subject: [PATCH 2/4] Fix flake. --- core/profile/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/profile/base.py b/core/profile/base.py index 614f81e096..387af59807 100644 --- a/core/profile/base.py +++ b/core/profile/base.py @@ -183,7 +183,7 @@ class BaseProfile(object, metaclass=BaseProfileMetaclass): Examples: rf"^.+\\" -- treat trailing backspace as continuation - "banner\s+login\s+(\S+)" -- continue until matched group + rf"banner\s+login\s+(\S+)" -- continue until matched group """ pattern_mml_end = None -- GitLab From dd08f82b1452c8776e885104f11eb1294a5897c7 Mon Sep 17 00:00:00 2001 From: Andrey Vertiprahov Date: Wed, 28 Sep 2022 17:57:22 +0500 Subject: [PATCH 3/4] Fix flake2 --- core/profile/base.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/profile/base.py b/core/profile/base.py index 387af59807..8070d155c6 100644 --- a/core/profile/base.py +++ b/core/profile/base.py @@ -182,8 +182,8 @@ class BaseProfile(object, metaclass=BaseProfileMetaclass): NB: Sending logic is implemented in *commands* script Examples: - rf"^.+\\" -- treat trailing backspace as continuation - rf"banner\s+login\s+(\S+)" -- continue until matched group + r"^.+\\" -- treat trailing backspace as continuation + r"banner\s+login\s+(\S+)" -- continue until matched group """ pattern_mml_end = None -- GitLab From 8498cfe2a06522f8582e811fbe5d48fa46e4c8d9 Mon Sep 17 00:00:00 2001 From: Andrey Vertiprahov Date: Wed, 28 Sep 2022 18:00:04 +0500 Subject: [PATCH 4/4] Fix flake 3. --- core/profile/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/profile/base.py b/core/profile/base.py index 8070d155c6..346a6cbdc5 100644 --- a/core/profile/base.py +++ b/core/profile/base.py @@ -183,7 +183,7 @@ class BaseProfile(object, metaclass=BaseProfileMetaclass): Examples: r"^.+\\" -- treat trailing backspace as continuation - r"banner\s+login\s+(\S+)" -- continue until matched group + r"banner\s+login\s+(\S+)" -- continue until matched group # noqa: W605 """ pattern_mml_end = None -- GitLab