1- #!/usr/bin/env python3
2- # -*- coding: utf_8 -*-
31import base64
42import pathlib
53import subprocess
64import json
75import psutil
86import inspect
97import socket
8+ import sys
9+ import getopt
10+ import os
1011
1112from functools import partial
1213
2324 get_load_avg ,
2425 run_as_root ,
2526 time2human ,
26- timeago ,
27- timestamp2datetime ,
2827 get_timestamp ,
2928 print_table ,
3029 color_print ,
3130 color_text ,
3231 bcolors ,
3332 Dict ,
34- MyPyClass , ip2int
33+ MyPyClass
3534)
3635
3736from mypyconsole .mypyconsole import MyPyConsole
3837from mytoncore .mytoncore import MyTonCore
3938from mytoncore .functions import (
40- Slashing ,
4139 GetMemoryInfo ,
4240 GetSwapInfo ,
4341 GetBinGitHash ,
4745from mytonctrl .migrate import run_migrations
4846from mytonctrl .utils import GetItemFromList , timestamp2utcdatetime , fix_git_config , is_hex , GetColorInt , \
4947 pop_user_from_args , pop_arg_from_args
50-
51- import sys , getopt , os
52-
5348from mytoninstaller .archive_blocks import download_blocks
5449from mytoninstaller .utils import get_ton_storage_port
5550
@@ -89,12 +84,6 @@ def inject_globals(func):
8984 console .AddItem ("rollback" , inject_globals (rollback_to_mtc1 ), local .translate ("rollback_cmd" ))
9085 console .AddItem ("download_archive_blocks" , inject_globals (download_archive_blocks ), local .translate ("download_archive_blocks_cmd" ))
9186
92- #console.AddItem("xrestart", inject_globals(Xrestart), local.translate("xrestart_cmd"))
93- #console.AddItem("xlist", inject_globals(Xlist), local.translate("xlist_cmd"))
94- #console.AddItem("gpk", inject_globals(GetPubKey), local.translate("gpk_cmd"))
95- #console.AddItem("ssoc", inject_globals(SignShardOverlayCert), local.translate("ssoc_cmd"))
96- #console.AddItem("isoc", inject_globals(ImportShardOverlayCert), local.translate("isoc_cmd"))
97-
9887 from modules .backups import BackupModule
9988 module = BackupModule (ton , local )
10089 module .add_console_commands (console )
@@ -180,12 +169,10 @@ def inject_globals(func):
180169 print ("Wallets path " + wallets + " is not a directory" )
181170 sys .exit ()
182171 ton .walletsDir = wallets
183- #end for
184172
185173 local .db .config .logLevel = "debug" if console .debug else "info"
186174 local .db .config .isLocaldbSaving = False
187175 local .run ()
188- #end define
189176
190177
191178def about (local , ton , args ):
@@ -265,7 +252,7 @@ def GetAuthorRepoBranchFromArgs(args):
265252def check_vport (local , ton ):
266253 try :
267254 vconfig = ton .GetValidatorConfig ()
268- except :
255+ except Exception :
269256 local .add_log ("GetValidatorConfig error" , "error" )
270257 return
271258 addr = vconfig .addrs .pop ()
@@ -524,7 +511,7 @@ def check_validator_balance(local, ton):
524511 validator_wallet = ton .GetValidatorWallet ()
525512 validator_account = local .try_function (ton .GetAccount , args = [validator_wallet .addrB64 ])
526513 if validator_account is None :
527- local .add_log (f "Failed to check validator wallet balance" , "warning" )
514+ local .add_log ("Failed to check validator wallet balance" , "warning" )
528515 return
529516 if validator_account .balance < 100 :
530517 print_warning (local , "validator_balance_warning" )
@@ -559,7 +546,8 @@ def check_adnl(local, ton):
559546 config = ton .GetValidatorConfig ()
560547 if config .fullnodeslaves :
561548 return
562- except : ...
549+ except Exception :
550+ pass
563551 from modules .utilities import UtilitiesModule
564552 utils_module = UtilitiesModule (ton , local )
565553 ok , error = utils_module .check_adnl_connection ()
@@ -633,12 +621,12 @@ def PrintStatus(local, ton, args):
633621 disks_load_avg = ton .GetStatistics ("disksLoadAvg" , statistics )
634622 disks_load_percent_avg = ton .GetStatistics ("disksLoadPercentAvg" , statistics )
635623
636- all_status = validator_status .is_working == True and validator_status .out_of_sync < 20
624+ all_status = validator_status .is_working and validator_status .out_of_sync < 20
637625
638626 try :
639627 vconfig = ton .GetValidatorConfig ()
640628 fullnode_adnl = base64 .b64decode (vconfig .fullnode ).hex ().upper ()
641- except :
629+ except Exception :
642630 fullnode_adnl = 'n/a'
643631
644632 if all_status :
@@ -782,11 +770,7 @@ def PrintLocalStatus(local, ton, adnlAddr, validatorIndex, validatorEfficiency,
782770 # Disks status
783771 disksLoad_data = list ()
784772 for key , item in disksLoadAvg .items ():
785- diskLoad1_text = bcolors .green_text (item [0 ]) # TODO: this variables is unused. Why?
786- diskLoad5_text = bcolors .green_text (item [1 ]) # TODO: this variables is unused. Why?
787773 diskLoad15_text = bcolors .green_text (item [2 ])
788- diskLoadPercent1_text = GetColorInt (disksLoadPercentAvg [key ][0 ], 80 , logic = "less" , ending = "%" ) # TODO: this variables is unused. Why?
789- diskLoadPercent5_text = GetColorInt (disksLoadPercentAvg [key ][1 ], 80 , logic = "less" , ending = "%" ) # TODO: this variables is unused. Why?
790774 diskLoadPercent15_text = GetColorInt (disksLoadPercentAvg [key ][2 ], 80 , logic = "less" , ending = "%" )
791775 buff = "{}, {}"
792776 buff = "{}{}:[{}{}{}]{}" .format (bcolors .cyan , key , bcolors .default , buff , bcolors .cyan , bcolors .endc )
@@ -941,8 +925,8 @@ def PrintLocalStatus(local, ton, adnlAddr, validatorIndex, validatorEfficiency,
941925 print ()
942926#end define
943927
944- def GetColorStatus (input ):
945- if input == True :
928+ def GetColorStatus (status : bool ):
929+ if status :
946930 result = bcolors .green_text ("working" )
947931 else :
948932 result = bcolors .red_text ("not working" )
@@ -1030,7 +1014,7 @@ def GetColorTime(datetime, timestamp):
10301014def GetSettings (ton , args ):
10311015 try :
10321016 name = args [0 ]
1033- except :
1017+ except IndexError :
10341018 color_print ("{red}Bad args. Usage:{endc} get <settings-name>" )
10351019 return
10361020 result = ton .GetSettings (name )
@@ -1041,7 +1025,7 @@ def SetSettings(local, ton, args):
10411025 try :
10421026 name = args [0 ]
10431027 value = args [1 ]
1044- except :
1028+ except IndexError :
10451029 color_print ("{red}Bad args. Usage:{endc} set <settings-name> <settings-value>" )
10461030 return
10471031 if name == 'usePool' or name == 'useController' :
@@ -1070,7 +1054,7 @@ def SetSettings(local, ton, args):
10701054def enable_mode (local , ton , args ):
10711055 try :
10721056 name = args [0 ]
1073- except :
1057+ except IndexError :
10741058 color_print ("{red}Bad args. Usage:{endc} enable_mode <mode_name>" )
10751059 return
10761060 ton .enable_mode (name )
@@ -1081,7 +1065,7 @@ def enable_mode(local, ton, args):
10811065def disable_mode (local , ton , args ):
10821066 try :
10831067 name = args [0 ]
1084- except :
1068+ except IndexError :
10851069 color_print ("{red}Bad args. Usage:{endc} disable_mode <mode_name>" )
10861070 return
10871071 ton .disable_mode (name )
@@ -1090,46 +1074,6 @@ def disable_mode(local, ton, args):
10901074#end define
10911075
10921076
1093- def Xrestart (inputArgs ):
1094- if len (inputArgs ) < 2 :
1095- color_print ("{red}Bad args. Usage:{endc} xrestart <timestamp> <args>" )
1096- return
1097- with get_package_resource_path ('mytonctrl' , 'scripts/xrestart.py' ) as xrestart_script_path :
1098- args = ["python3" , xrestart_script_path ] # TODO: Fix path
1099- args += inputArgs
1100- exitCode = run_as_root (args )
1101- if exitCode == 0 :
1102- text = "Xrestart - {green}OK{endc}"
1103- else :
1104- text = "Xrestart - {red}Error{endc}"
1105- color_print (text )
1106- #end define
1107-
1108- def Xlist (args ):
1109- color_print ("Xlist - {green}OK{endc}" )
1110- #end define
1111-
1112- def GetPubKey (ton , args ):
1113- adnlAddr = ton .GetAdnlAddr ()
1114- pubkey = ton .GetPubKey (adnlAddr )
1115- print ("pubkey:" , pubkey )
1116- #end define
1117-
1118- def SignShardOverlayCert (ton , args ):
1119- try :
1120- adnl = args [0 ]
1121- pubkey = args [0 ]
1122- except :
1123- color_print ("{red}Bad args. Usage:{endc} ssoc <pubkey>" )
1124- return
1125- ton .SignShardOverlayCert (adnl , pubkey )
1126- #end define
1127-
1128- def ImportShardOverlayCert (ton , args ):
1129- ton .ImportShardOverlayCert ()
1130- #end define
1131-
1132-
11331077def download_archive_blocks (local , args : list ):
11341078 if len (args ) < 2 :
11351079 color_print ("{red}Bad args. Usage:{endc} download_archive_blocks [ton_storage_api_port] <download_path> <from_block_seqno> [to_block_seqno] [--only-master]" )
@@ -1145,22 +1089,22 @@ def download_archive_blocks(local, args: list):
11451089 to_block = args [2 ] if len (args ) >= 3 else None
11461090 try :
11471091 from_block , to_block = int (from_block ), int (to_block ) if to_block else None
1148- except :
1092+ except ValueError :
11491093 color_print ("{red}Bad args. from_block and to_block must be integers.{endc}" )
11501094 return
11511095
11521096 if api_port is None :
11531097 api_port = get_ton_storage_port (local )
11541098 if api_port is None :
1155- raise Exception (f 'Failed to get Ton Storage API port and port was not provided' )
1099+ raise Exception ('Failed to get Ton Storage API port and port was not provided' )
11561100
11571101 # check ton storage is alive
11581102 local_ts_url = f"http://127.0.0.1:{ api_port } "
11591103
11601104 try :
11611105 requests .get (local_ts_url + '/api/v1/list' , timeout = 3 )
1162- except :
1163- color_print (f"{{red}}Error: cannot connect to ton-storage at 127.0.0.1:{ api_port } . "
1106+ except Exception as e :
1107+ color_print (f"{{red}}Error: cannot connect to ton-storage at 127.0.0.1:{ api_port } : { type ( e ) } : { e } . "
11641108 f"Make sure `ton_storage` daemon is running or install it via `installer enable TS`.{{endc}}" )
11651109 return
11661110
0 commit comments