|
30 | 30 | get_timestamp, |
31 | 31 | timestamp2datetime, |
32 | 32 | dec2hex, |
33 | | - Dict |
| 33 | + Dict, int2ip |
34 | 34 | ) |
35 | 35 |
|
36 | 36 |
|
@@ -115,6 +115,7 @@ def CheckConfigFile(self, fift, liteClient): |
115 | 115 | self.local.add_log("Restoring the configuration file", "info") |
116 | 116 | args = ["cp", backup_path, mconfig_path] |
117 | 117 | subprocess.run(args) |
| 118 | + self.dbFile = mconfig_path |
118 | 119 | self.Refresh() |
119 | 120 | elif os.path.isfile(backup_path) == False: |
120 | 121 | self.local.add_log("Create backup config file", "info") |
@@ -1454,21 +1455,47 @@ def ElectionEntry(self, args=None): |
1454 | 1455 | self.local.add_log("ElectionEntry completed. Start work time: " + str(startWorkTime)) |
1455 | 1456 |
|
1456 | 1457 | self.clear_tmp() |
| 1458 | + self.make_backup(startWorkTime) |
1457 | 1459 |
|
1458 | 1460 | #end define |
1459 | 1461 |
|
1460 | | - def clear_tmp(self): |
| 1462 | + def clear_dir(self, dir_name): |
1461 | 1463 | start = time.time() |
1462 | 1464 | count = 0 |
1463 | 1465 | week_ago = 60 * 60 * 24 * 7 |
1464 | | - dir = self.tempDir |
1465 | | - for f in os.listdir(dir): |
1466 | | - ts = os.path.getmtime(os.path.join(dir, f)) |
| 1466 | + for f in os.listdir(dir_name): |
| 1467 | + ts = os.path.getmtime(os.path.join(dir_name, f)) |
1467 | 1468 | if ts < time.time() - week_ago: |
1468 | 1469 | count += 1 |
1469 | | - os.remove(os.path.join(dir, f)) |
| 1470 | + if os.path.isfile(os.path.join(dir_name, f)): |
| 1471 | + os.remove(os.path.join(dir_name, f)) |
| 1472 | + self.local.add_log(f"Removed {count} old files from {dir_name} directory for {int(time.time() - start)} seconds", "info") |
| 1473 | + |
| 1474 | + def clear_tmp(self): |
| 1475 | + self.clear_dir(self.tempDir) |
1470 | 1476 |
|
1471 | | - self.local.add_log(f"Removed {count} old files from tmp dir for {int(time.time() - start)} seconds", "info") |
| 1477 | + def make_backup(self, election_id: str): |
| 1478 | + if not self.local.db.get("auto_backup"): |
| 1479 | + return |
| 1480 | + from modules.backups import BackupModule |
| 1481 | + module = BackupModule(self, self.local) |
| 1482 | + args = [] |
| 1483 | + name = f"/mytonctrl_backup_elid{election_id}.zip" |
| 1484 | + backups_dir = self.tempDir + "/auto_backups" |
| 1485 | + if self.local.db.get("auto_backup_path"): |
| 1486 | + backups_dir = self.local.db.get("auto_backup_path") |
| 1487 | + os.makedirs(backups_dir, exist_ok=True) |
| 1488 | + args.append(backups_dir + name) |
| 1489 | + self.clear_dir(backups_dir) |
| 1490 | + exit_code = module.create_backup(args) |
| 1491 | + if exit_code != 0: |
| 1492 | + self.local.add_log(f"Backup failed with exit code {exit_code}", "error") |
| 1493 | + # try one more time |
| 1494 | + exit_code = module.create_backup(args) |
| 1495 | + if exit_code != 0: |
| 1496 | + self.local.add_log(f"Backup failed with exit code {exit_code}", "error") |
| 1497 | + if exit_code == 0: |
| 1498 | + self.local.add_log(f"Backup created successfully", "info") |
1472 | 1499 |
|
1473 | 1500 | def GetValidatorKeyByTime(self, startWorkTime, endWorkTime): |
1474 | 1501 | self.local.add_log("start GetValidatorKeyByTime function", "debug") |
@@ -2490,6 +2517,8 @@ def GetValidatorsList(self, past=False, fast=False, start=None, end=None): |
2490 | 2517 | validator["efficiency"] = round(validator["wr"] * 100, 2) |
2491 | 2518 | if saveElectionEntries and adnlAddr in saveElectionEntries: |
2492 | 2519 | validator["walletAddr"] = saveElectionEntries[adnlAddr]["walletAddr"] |
| 2520 | + validator["stake"] = saveElectionEntries[adnlAddr].get("stake") |
| 2521 | + validator["stake"] = int(validator["stake"]) if validator["stake"] else None |
2493 | 2522 | #end for |
2494 | 2523 |
|
2495 | 2524 | # Set buffer |
@@ -3791,6 +3820,13 @@ def GetNetworkName(self): |
3791 | 3820 | return "unknown" |
3792 | 3821 | #end define |
3793 | 3822 |
|
| 3823 | + def get_validator_engine_ip(self): |
| 3824 | + try: |
| 3825 | + config = self.GetValidatorConfig() |
| 3826 | + return int2ip(config['addrs'][0]['ip']) |
| 3827 | + except: |
| 3828 | + return None |
| 3829 | + |
3794 | 3830 | def GetFunctionBuffer(self, name, timeout=10): |
3795 | 3831 | timestamp = get_timestamp() |
3796 | 3832 | buff = self.local.buffer.get(name) |
|
0 commit comments