From 231d79d8eebd7da9abc4bfda713ad466fc62bf68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A5=D0=B8=D1=80=D0=B5=D1=86=D0=BA=D0=B8=D0=B9=20=D0=9C?= =?UTF-8?q?=D0=B8=D1=85=D0=B0=D0=B8=D0=BB?= Date: Mon, 21 Dec 2015 17:04:32 +0300 Subject: [PATCH] =?UTF-8?q?=D0=98=D1=81=D0=BA=D0=BB=D1=8E=D1=87=D1=91?= =?UTF-8?q?=D0=BD=20downgrade=20=D1=80=D0=B5=D0=BF=D0=BE=D0=B7=D0=B8=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D0=B8=D0=B5=D0=B2=20=D0=BF=D0=BE=20timestamp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pym/update/update.py | 14 ++++++-- pym/update/variables/update.py | 59 ++++++++++++++++++++++++---------- 2 files changed, 53 insertions(+), 20 deletions(-) diff --git a/pym/update/update.py b/pym/update/update.py index 9dbcf48..d023b58 100644 --- a/pym/update/update.py +++ b/pym/update/update.py @@ -1169,11 +1169,19 @@ class Update(MethodsInterface): hosts = self.clVars.Get("update.cl_update_binhost_host") if not hosts: self.clVars.Delete('cl_update_binhost', location="system") - raise UpdateError("Binhost is unavailable") + raise UpdateError(_("Update server is unavailable")) if write_binhost: if hosts[0] != self.clVars.Get('update.cl_update_binhost'): self.refresh_binhost = True self.clVars.Write('cl_update_binhost', hosts[0], location="system") + new_ts = self.clVars.Get("update.cl_update_binhost_timestamp") + if new_ts: + new_ts = new_ts[0] + old_ts = self.clVars.Get("update.cl_update_last_timestamp") + if new_ts.isdigit() and (not old_ts.isdigit() or + int(new_ts) > int(old_ts)): + ini = SystemIni(self.clVars) + ini.setVar('update', {'last_update': new_ts}) return True def message_binhost_changed(self): @@ -1201,9 +1209,9 @@ class Update(MethodsInterface): changes = True self.clVars.Set(varname, new_value, force=True) if not changes: - raise UpdateError("Binhost is unavailable") + raise UpdateError(_("Update server is unavailable")) except DataVarsError: - raise UpdateError("Binhost is unavailable") + raise UpdateError(_("Update server is unavailable")) return True def drop_binhosts(self, dv): diff --git a/pym/update/variables/update.py b/pym/update/variables/update.py index 049c431..4c90fb1 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 +from calculate.lib.cl_template import SystemIni from calculate.lib.datavars import (Variable, VariableError, ReadonlyVariable, ReadonlyTableVariable, TableVariable, FieldValue, @@ -277,6 +278,7 @@ class VariableClUpdateBinhostData(ReadonlyTableVariable): """ source = ["cl_update_binhost_host", "cl_update_binhost_revisions", + "cl_update_binhost_timestamp", "cl_update_binhost_time"] def check_binhost(self, binhost): @@ -317,11 +319,13 @@ class VariableClUpdateBinhostData(ReadonlyTableVariable): timeout = self.GetInteger('cl_update_binhost_timeout') timestamp_file = path.join(binhost, self.Get('cl_update_binhost_timestamp_path')) + last_ts = self.Get('cl_update_last_timestamp') try: t = time.time() data = urllib2.urlopen(timestamp_file, timeout=timeout).read().strip() - if data.isdigit(): + if (data.isdigit() and last_ts.isdigit() and + int(data) >= int(last_ts)): return (data, int((time.time() - t) * 1000), t - int(data) < 5 * DAY) except urllib2.URLError as e: @@ -351,7 +355,7 @@ class VariableClUpdateBinhostData(ReadonlyTableVariable): if ts and cur_t - int(ts) < 5 * DAY: data = self.check_binhost(binhost) if data: - return [[binhost, data, str(t)]] + return [[binhost, data, ts, str(t)]] for host, ts, t, good in sorted( generate_by_timestamp(), # критерий сортировки между серверами @@ -359,22 +363,22 @@ class VariableClUpdateBinhostData(ReadonlyTableVariable): # неактульные по timestamp # актуальность - 5 дней reverse=True, - key=lambda x: (# приоритетны актуальные (не более 5 дней) - x[3], - # приоритет для неактуальных - # самое свежее - 0 if x[3] else int(x[1]), - # приоритет для неактуальных - # самое быстрое - 0 if x[3] else -int(x[2]), - # приоритет для актуальных - # самое быстрое - -int(x[2]) if x[3] else 0, - # самое свежее - int(x[1]) if x[3] else 0)): + key=lambda x: ( # приоритетны актуальные (не более 5 дней) + x[3], + # приоритет для неактуальных + # самое свежее + 0 if x[3] else int(x[1]), + # приоритет для неактуальных + # самое быстрое + 0 if x[3] else -int(x[2]), + # приоритет для актуальных + # самое быстрое + -int(x[2]) if x[3] else 0, + # самое свежее + int(x[1]) if x[3] else 0)): data = self.check_binhost(host) if data: - return [[host, data, str(t)]] + return [[host, data, ts, str(t)]] return [[]] @@ -410,7 +414,7 @@ class VariableClUpdateBinhostRevisions(FieldValue, ReadonlyVariable): column = 1 -class VariableClUpdateBinhostTime(FieldValue, ReadonlyVariable): +class VariableClUpdateBinhostTimestamp(FieldValue, ReadonlyVariable): """ Список имен прочих репозиториев """ @@ -419,6 +423,25 @@ class VariableClUpdateBinhostTime(FieldValue, ReadonlyVariable): column = 2 +class VariableClUpdateLastTimestamp(ReadonlyVariable): + """ + Текущий timestamp + """ + + def get(self): + ini = SystemIni(self.parent) + return ini.getVar('update', 'last_update') or "0" + + +class VariableClUpdateBinhostTime(FieldValue, ReadonlyVariable): + """ + Список имен прочих репозиториев + """ + type = "list" + source_variable = "cl_update_binhost_data" + column = 3 + + class VariableClUpdateBranchName(Variable): """ Список доступных репозиторием @@ -1306,6 +1329,8 @@ class DataVarsUpdateProfile(SimpleDataVars): VariableClUpdateBinhostRecheckSet(section="update"), VariableClUpdateBinhostRevisions(section="update"), VariableClUpdateBinhostTime(section="update"), + VariableClUpdateBinhostTimestamp(section="update"), + VariableClUpdateLastTimestamp(section="update"), VariableClUpdateBinhostTimeout(section="update"), VariableClUpdateBinhostTimestampPath(section="update"), VariableClUpdateBinhostList(section="update"),