From 017fc09c3156198f34d0adac2fd5ce96e28267be Mon Sep 17 00:00:00 2001 From: root Date: Tue, 13 Dec 2022 13:44:44 +0300 Subject: [PATCH] TG-80 TG-50 cl-update: Fix: current binhost now drops after "-m auto" cl-update: Feature: "--one-depth" now have bool3 type --- pym/update/utils/cl_update.py | 3 ++- pym/update/variables/update.py | 44 ++++++++++++++++++++++++++++++++-- 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/pym/update/utils/cl_update.py b/pym/update/utils/cl_update.py index 7042ab1..cd848d8 100644 --- a/pym/update/utils/cl_update.py +++ b/pym/update/utils/cl_update.py @@ -59,7 +59,8 @@ def get_synchronization_tasks(object_name): 'method': Object('check_current_binhost(update.cl_update_binhost)'), 'condition': lambda GetBool, Get: ( not GetBool('update.cl_update_binhost_recheck_set') and - not (Get('update.cl_update_binhost_choice') and Get('update.cl_update_binhost_choice') != 'auto') and + not Get('update.cl_update_binhost_choice') and + Get('update.cl_update_binhost_choice') != 'auto' and Get('update.cl_update_sync_rep') and Get('update.cl_update_binhost') and Get('update.cl_update_use_migration_host') == 'off') diff --git a/pym/update/variables/update.py b/pym/update/variables/update.py index 9106a18..282d669 100644 --- a/pym/update/variables/update.py +++ b/pym/update/variables/update.py @@ -18,6 +18,7 @@ import os import sys import re from os import path +import datetime from calculate.lib.cl_template import SystemIni from calculate.lib.cl_log import log from calculate.lib.datavars import (Variable, VariableError, @@ -1811,8 +1812,10 @@ class VariableClUpdateOnedepthSet(Variable): """ Удлять лишние файлы из репозиториев (например созданные пользователем) """ - type = "bool" - value = "off" + type = "bool3" + value = 'auto' + max_interval = 'cl_update_onedepth_interval' + check_after = 'cl_update_onedepth_interval' opt = ["--one-depth", "-1"] @@ -1820,6 +1823,43 @@ class VariableClUpdateOnedepthSet(Variable): self.label = _("Clear the history of repositories") self.help = _("clear the history of repositories") + def get_oldest_history(self, rep): + try: + with open(f'{rep}/.git/logs/HEAD') as inf: + oldest_timestamp = int(inf.readline().split()[4]) + date = datetime.datetime.fromtimestamp(oldest_timestamp) + return datetime.datetime.now() - date + except OSError: + return 0 + + def set(self, value): + try: + if value == 'auto' or value is None: + rep_path = self.Get('cl_update_rep_path') + for rep in rep_path: + if self.get_oldest_history(rep).days > int(self.Get(self.max_interval)): + self.value = 'on' + return 'on' + self.value = 'off' + return 'off' + except: + return 'off' + self.value = value + return self.value + + def get(self): + if self.value == 'auto' or self.value is None: + return self.set(self.value) + return self.value + + +class VariableClUpdateOnedepthInterval(Variable): + default_value = 0 + + def get(self): + if not self.value: + return self.default_value + return self.value class VariableClUpdateEixRepositories(ReadonlyVariable): """