Skip to content

Commit

Permalink
Fixes for LGTM alerts
Browse files Browse the repository at this point in the history
- classifier for Python version -- force corect lgtm analizer
- deleted unused imports
- fixed mixed imports
- deleted dead code

Signed-off-by: Nemanja Patrnogic <[email protected]>
  • Loading branch information
nemqe committed Nov 4, 2019
1 parent ba5fc96 commit 05ca2c4
Show file tree
Hide file tree
Showing 40 changed files with 147 additions and 181 deletions.
2 changes: 1 addition & 1 deletion data/migrations/deb/1_0_96_to_1_0_97.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from stp_core.common.log import getlogger

from indy_common.util import compose_cmd
from indy_node.utils.node_control_tool import NodeControlTool, TIMEOUT
from indy_node.utils.node_control_tool import TIMEOUT

logger = getlogger()

Expand Down
12 changes: 6 additions & 6 deletions data/migrations/deb/1_3_396_to_1_3_397.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,22 +78,22 @@ def migrate_storage(level_db_dir, rocks_db_dir, db_name, is_db_int_keys):
try:
leveldb_storage = KeyValueStorageLeveldbCls(level_db_dir, db_name, read_only=True)
except Exception:
logger.error(traceback.print_exc())
logger.error(traceback.format_exc())
logger.error("Could not open leveldb storage: {}".format(os.path.join(level_db_dir, db_name)))
return False

try:
rocksdb_storage = KeyValueStorageRocksdbCls(rocks_db_dir, db_name)
except Exception:
logger.error(traceback.print_exc())
logger.error(traceback.format_exc())
logger.error("Could not open rocksdb storage: {}".format(os.path.join(rocks_db_dir, db_name)))
return False

try:
for key, val in leveldb_storage.iterator():
rocksdb_storage.put(bytes(key), bytes(val))
except Exception:
logger.error(traceback.print_exc())
logger.error(traceback.format_exc())
logger.error("Could not put key/value to RocksDB storage '{}'".format(db_name))
return False

Expand Down Expand Up @@ -141,7 +141,7 @@ def migrate_all():
try:
os.mkdir(rocksdb_ledger_dir)
except Exception:
logger.error(traceback.print_exc())
logger.error(traceback.format_exc())
logger.error("Could not create temporary directory for RocksDB-based ledger: {}"
.format(rocksdb_ledger_dir))
return False
Expand All @@ -168,7 +168,7 @@ def migrate_all():
try:
shutil.rmtree(leveldb_ledger_dir)
except Exception:
logger.error(traceback.print_exc())
logger.error(traceback.format_exc())
logger.error("Could not remove LevelDB-based ledger: {}"
.format(leveldb_ledger_dir))
shutil.rmtree(rocksdb_ledger_dir)
Expand All @@ -179,7 +179,7 @@ def migrate_all():
try:
shutil.move(rocksdb_ledger_dir, ledger_dir)
except Exception:
logger.error(traceback.print_exc())
logger.error(traceback.format_exc())
logger.error("Could not rename temporary RocksDB-based ledger from '{}' to '{}'"
.format(rocksdb_ledger_dir, ledger_dir))
shutil.rmtree(rocksdb_ledger_dir)
Expand Down
16 changes: 8 additions & 8 deletions data/migrations/deb/1_3_428_to_1_3_429.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,22 +211,22 @@ def put_into_seq_no_db(txn):
db_dir,
new_seqno_db_name)
except Exception:
logger.error(traceback.print_exc())
logger.error(traceback.format_exc())
logger.error("Could not open new seq_no_db storage")
return False

# open new and old ledgers
try:
src_storage = KeyValueStorageRocksdbIntKeys(db_dir, db_name, read_only=True)
except Exception:
logger.error(traceback.print_exc())
logger.error(traceback.format_exc())
logger.error("Could not open old ledger: {}".format(os.path.join(db_dir, db_name)))
return False

try:
dest_storage = KeyValueStorageRocksdbIntKeys(db_dir, new_db_name)
except Exception:
logger.error(traceback.print_exc())
logger.error(traceback.format_exc())
logger.error("Could not open new ledger: {}".format(os.path.join(db_dir, new_db_name)))
return False

Expand Down Expand Up @@ -256,7 +256,7 @@ def put_into_seq_no_db(txn):
dest_storage.put(key, new_val)

except Exception:
logger.error(traceback.print_exc())
logger.error(traceback.format_exc())
logger.error("Could not put key/value to the new ledger '{}'".format(db_name))
return False

Expand All @@ -269,7 +269,7 @@ def put_into_seq_no_db(txn):
try:
shutil.rmtree(old_path)
except Exception:
logger.error(traceback.print_exc())
logger.error(traceback.format_exc())
logger.error("Could not remove old ledger: {}"
.format(old_path))
return False
Expand All @@ -278,7 +278,7 @@ def put_into_seq_no_db(txn):
try:
shutil.move(new_path, old_path)
except Exception:
logger.error(traceback.print_exc())
logger.error(traceback.format_exc())
logger.error("Could not rename temporary new ledger from '{}' to '{}'"
.format(new_path, old_path))
return False
Expand All @@ -297,14 +297,14 @@ def rename_seq_no_db(db_dir):
try:
shutil.rmtree(old_seqno_path)
except Exception:
logger.error(traceback.print_exc())
logger.error(traceback.format_exc())
logger.error("Could not remove old seq_no_db: {}"
.format(old_seqno_path))
return False
try:
shutil.move(new_seqno_path, old_seqno_path)
except Exception:
logger.error(traceback.print_exc())
logger.error(traceback.format_exc())
logger.error("Could not rename temporary new seq_no_db from '{}' to '{}'"
.format(new_seqno_path, old_seqno_path))
return False
Expand Down
2 changes: 0 additions & 2 deletions data/migrations/deb/1_9_1_to_1_9_2.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import os
import shutil
import subprocess
import sys

from indy_common.config_helper import NodeConfigHelper
from indy_common.config_util import getConfig
Expand Down
1 change: 0 additions & 1 deletion data/migrations/deb/helper_1_0_96_to_1_0_97.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import json
import os
import shutil
import subprocess

from common.serializers.compact_serializer import CompactSerializer
from common.serializers.json_serializer import JsonSerializer
Expand Down
4 changes: 2 additions & 2 deletions indy_common/authorize/auth_constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@ def __str__(self):
error_msg = ""

if self.off_ledger_signature and self.sig_count > 1:
error_msg = "{} signatures of any role (off-ledger included) are required".format(self.sig_count, role)
error_msg = "{} signatures of any role (off-ledger included) are required".format(self.sig_count)
elif self.off_ledger_signature and self.sig_count == 1:
error_msg = "1 signature of any role (off-ledger included) is required".format(self.sig_count, role)
error_msg = "1 signature of any role (off-ledger included) is required"

elif role != 'ALL' and self.need_to_be_owner and self.sig_count > 1:
error_msg = "{} {} signatures are required and needs to be owner".format(self.sig_count, role)
Expand Down
3 changes: 1 addition & 2 deletions indy_common/config.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import os
import logging
from collections import OrderedDict

from indy_common.constants import LOCAL_AUTH_POLICY, CONFIG_LEDGER_AUTH_POLICY
from indy_common.constants import CONFIG_LEDGER_AUTH_POLICY
from plenum.common.constants import ClientBootStrategy, HS_ROCKSDB, KeyValueStorageType
from plenum.config import rocksdb_default_config

Expand Down
5 changes: 2 additions & 3 deletions indy_common/setup_util.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import glob
import os
import shutil
from shutil import copyfile
from shutil import copyfile, copy2

from ledger.genesis_txn.genesis_txn_file_util import genesis_txn_file

Expand Down Expand Up @@ -65,5 +64,5 @@ def setupSampleInvites(self):
files = glob.iglob(os.path.join(sdir, "*.indy"))
for file in files:
if os.path.isfile(file):
shutil.copy2(file, sidir)
copy2(file, sidir)
return self
2 changes: 1 addition & 1 deletion indy_common/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from common.exceptions import PlenumTypeError, PlenumValueError

from plenum.common.constants import TARGET_NYM, NONCE, RAW, ENC, HASH, NAME, \
VERSION, FORCE, ORIGIN, OPERATION_SCHEMA_IS_STRICT, SCHEMA_IS_STRICT
VERSION, FORCE, ORIGIN, OPERATION_SCHEMA_IS_STRICT
from plenum.common.messages.client_request import ClientMessageValidator as PClientMessageValidator
from plenum.common.messages.client_request import ClientOperationField as PClientOperationField
from plenum.common.messages.fields import ConstantField, IdentifierField, \
Expand Down
1 change: 0 additions & 1 deletion indy_node/server/action_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ def __init__(
['ts', 'ev_type'] +
[(self._data_items_prefix + i) for i in self.data._items]
)
pass

def __getattr__(self, name):
try:
Expand Down
10 changes: 3 additions & 7 deletions indy_node/server/client_authn.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,10 @@
from hashlib import sha256

from plenum.common.types import OPERATION
from plenum.common.constants import TXN_TYPE, RAW, ENC, HASH, IDENTIFIER, NYM
from plenum.server.client_authn import NaclAuthNr, CoreAuthNr, CoreAuthMixin
from plenum.common.constants import TXN_TYPE, RAW, ENC, HASH, NYM
from plenum.server.client_authn import NaclAuthNr, CoreAuthMixin

from indy_common.constants import ATTRIB, POOL_UPGRADE, SCHEMA, CLAIM_DEF, \
GET_NYM, GET_ATTR, GET_SCHEMA, GET_CLAIM_DEF, POOL_CONFIG, POOL_RESTART, \
REVOC_REG_DEF, REVOC_REG_ENTRY, \
GET_REVOC_REG_DEF, GET_REVOC_REG, GET_REVOC_REG_DELTA, VALIDATOR_INFO, \
AUTH_RULES, AUTH_RULE, GET_AUTH_RULE
from indy_common.constants import ATTRIB
from indy_node.persistence.idr_cache import IdrCache
from plenum.server.request_handlers.utils import get_request_type, nym_ident_is_dest, get_target_verkey

Expand Down
5 changes: 2 additions & 3 deletions indy_node/server/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@
from indy_common.authorize.auth_constraints import AbstractConstraintSerializer
from indy_node.server.node_bootstrap import NodeBootstrap

# from indy_node.server.action_req_handler import ActionReqHandler
from indy_node.server.validator_info_tool import ValidatorNodeInfoTool

from plenum.common.constants import VERSION, \
ENC, RAW, DOMAIN_LEDGER_ID, CURRENT_PROTOCOL_VERSION, FORCE, POOL_LEDGER_ID, TS_LABEL, ATTRIB_LABEL, IDR_CACHE_LABEL
ENC, RAW, CURRENT_PROTOCOL_VERSION, FORCE, ATTRIB_LABEL, IDR_CACHE_LABEL
from plenum.common.txn_util import get_type, get_payload_data, TxnUtilConfig
from plenum.common.types import f, \
OPERATION
Expand All @@ -19,7 +18,7 @@
from state.pruning_state import PruningState
from indy_common.config_util import getConfig
from indy_common.constants import TXN_TYPE, ATTRIB, DATA, ACTION, \
NODE_UPGRADE, COMPLETE, FAIL, CONFIG_LEDGER_ID, POOL_UPGRADE, POOL_CONFIG, \
NODE_UPGRADE, COMPLETE, FAIL, POOL_UPGRADE, POOL_CONFIG, \
IN_PROGRESS, AUTH_RULE, AUTH_RULES
from indy_common.types import Request, SafeRequest
from indy_common.config_helper import NodeConfigHelper
Expand Down
7 changes: 1 addition & 6 deletions indy_node/server/node_bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,7 @@

from indy_node.server.restarter import Restarter
from indy_node.server.upgrader import Upgrader
from ledger.compact_merkle_tree import CompactMerkleTree
from ledger.genesis_txn.genesis_txn_initiator_from_file import GenesisTxnInitiatorFromFile
from plenum.common.constants import IDR_CACHE_LABEL, ATTRIB_LABEL, NODE_PRIMARY_STORAGE_SUFFIX, \
TS_LABEL
from plenum.common.ledger import Ledger
from plenum.persistence.storage import initStorage
from plenum.common.constants import IDR_CACHE_LABEL, ATTRIB_LABEL
from plenum.server.node_bootstrap import NodeBootstrap as PNodeBootstrap
from plenum.server.request_handlers.get_txn_author_agreement_aml_handler import GetTxnAuthorAgreementAmlHandler
from plenum.server.request_handlers.get_txn_author_agreement_handler import GetTxnAuthorAgreementHandler
Expand Down
4 changes: 2 additions & 2 deletions indy_node/server/node_maintainer.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from abc import ABCMeta, abstractmethod
from collections import deque
from datetime import datetime, timedelta
from typing import Tuple, Callable
from datetime import timedelta
from typing import Callable

from stp_core.common.log import getlogger
from plenum.server.has_action_queue import HasActionQueue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from plenum.common.exceptions import InvalidClientRequest
from plenum.server.database_manager import DatabaseManager
from plenum.server.request_handlers.handler_interfaces.write_request_handler import WriteRequestHandler
from plenum.server.request_handlers.utils import decode_state_value


class AbstractAuthRuleHandler(WriteRequestHandler, metaclass=ABCMeta):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from indy_common.authorize.auth_actions import AuthActionAdd
from indy_common.authorize.auth_request_validator import WriteRequestValidator
from plenum.common.request import Request
from plenum.server.database_manager import DatabaseManager
from plenum.server.request_handlers.txn_author_agreement_aml_handler import TxnAuthorAgreementAmlHandler \
as PTxnAuthorAgreementAmlHandler
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from copy import deepcopy
from json import JSONDecodeError

from common.exceptions import LogicError
from indy_common.authorize.auth_actions import AuthActionEdit, AuthActionAdd
from indy_common.authorize.auth_request_validator import WriteRequestValidator
from indy_common.serialization import attrib_raw_data_serializer
Expand All @@ -12,7 +11,7 @@
from indy_common.state.state_constants import MARKER_ATTR
from indy_node.server.request_handlers.utils import validate_attrib_keys
from plenum.common.constants import DOMAIN_LEDGER_ID, RAW, ENC, HASH, TARGET_NYM
from plenum.common.exceptions import InvalidClientRequest, UnauthorizedClientRequest
from plenum.common.exceptions import InvalidClientRequest

from plenum.common.request import Request
from plenum.common.txn_util import get_type, get_request_data, get_payload_data, get_seq_no, get_txn_time
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from plenum.common.constants import DOMAIN_LEDGER_ID
from plenum.common.exceptions import InvalidClientRequest
from plenum.common.request import Request
from plenum.common.txn_util import get_request_data, get_seq_no, get_txn_time, get_from, get_payload_data
from plenum.common.txn_util import get_seq_no, get_txn_time, get_from, get_payload_data

from plenum.server.database_manager import DatabaseManager
from plenum.server.request_handlers.handler_interfaces.write_request_handler import WriteRequestHandler
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from copy import deepcopy
from typing import Dict, Callable
from typing import Callable

from indy_common.authorize.auth_actions import AuthActionEdit, AuthActionAdd
from indy_common.authorize.auth_request_validator import WriteRequestValidator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
get_txn_schema_version, get_txn_schema_attr_names
from indy_common.state.state_constants import MARKER_SCHEMA
from plenum.common.constants import DOMAIN_LEDGER_ID
from plenum.common.exceptions import InvalidClientRequest

from plenum.common.request import Request
from plenum.common.txn_util import get_request_data, get_from, get_seq_no, get_txn_time
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from common.serializers.serialization import state_roots_serializer, domain_state_serializer
from common.serializers.serialization import domain_state_serializer
from indy_common.authorize.auth_constraints import ConstraintsSerializer
from indy_common.authorize.auth_request_validator import WriteRequestValidator
from indy_common.state import config
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from indy_node.server.request_handlers.domain_req_handlers.revoc_reg_entry_handler import RevocRegEntryHandler
from indy_node.server.request_handlers.utils import StateValue
from plenum.common.constants import DOMAIN_LEDGER_ID
from plenum.common.exceptions import InvalidClientRequest
from plenum.common.request import Request
from plenum.server.database_manager import DatabaseManager
from plenum.server.request_handlers.handler_interfaces.read_request_handler import ReadRequestHandler
Expand Down
14 changes: 4 additions & 10 deletions indy_node/server/restarter.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import os
from collections import deque
from datetime import datetime, timedelta
from datetime import datetime
from functools import partial
from typing import Tuple, Union, Optional, Callable, Dict
from typing import Union

import dateutil.parser
import dateutil.tz
Expand All @@ -12,14 +11,9 @@
NodeControlToolMessage
from indy_node.server.restart_log import RestartLogData, RestartLog
from stp_core.common.log import getlogger
from plenum.common.constants import TXN_TYPE, VERSION, DATA, IDENTIFIER
from plenum.common.types import f
from plenum.server.has_action_queue import HasActionQueue
from plenum.common.constants import TXN_TYPE
from indy_common.constants import ACTION, POOL_RESTART, START, DATETIME, \
CANCEL, JUSTIFICATION, TIMEOUT, REINSTALL, IN_PROGRESS, FORCE, \
RESTART_MESSAGE
from plenum.server import notifier_plugin_manager
from ledger.util import F
CANCEL, TIMEOUT, RESTART_MESSAGE
import asyncio

logger = getlogger()
Expand Down
2 changes: 0 additions & 2 deletions indy_node/server/revocation_strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ def write(self, current_reg_entry, txn):
txn_data[VALUE] = value_from_txn
# contains already changed txn
self.set_to_state(txn)
del txn

@staticmethod
def get_delta(to_dict, from_dict=None):
Expand Down Expand Up @@ -203,7 +202,6 @@ def write(self, current_reg_entry, txn):
txn_data[VALUE] = value_from_txn
# contains already changed txn
self.set_to_state(txn)
del txn

@staticmethod
def get_delta(to_dict, from_dict=None):
Expand Down
Loading

0 comments on commit 05ca2c4

Please sign in to comment.