Исключён downgrade репозиториев по timestamp

master3.4 3.4.5.4
parent 72393cf50f
commit 231d79d8ee

@ -1169,11 +1169,19 @@ class Update(MethodsInterface):
hosts = self.clVars.Get("update.cl_update_binhost_host") hosts = self.clVars.Get("update.cl_update_binhost_host")
if not hosts: if not hosts:
self.clVars.Delete('cl_update_binhost', location="system") self.clVars.Delete('cl_update_binhost', location="system")
raise UpdateError("Binhost is unavailable") raise UpdateError(_("Update server is unavailable"))
if write_binhost: if write_binhost:
if hosts[0] != self.clVars.Get('update.cl_update_binhost'): if hosts[0] != self.clVars.Get('update.cl_update_binhost'):
self.refresh_binhost = True self.refresh_binhost = True
self.clVars.Write('cl_update_binhost', hosts[0], location="system") 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 return True
def message_binhost_changed(self): def message_binhost_changed(self):
@ -1201,9 +1209,9 @@ class Update(MethodsInterface):
changes = True changes = True
self.clVars.Set(varname, new_value, force=True) self.clVars.Set(varname, new_value, force=True)
if not changes: if not changes:
raise UpdateError("Binhost is unavailable") raise UpdateError(_("Update server is unavailable"))
except DataVarsError: except DataVarsError:
raise UpdateError("Binhost is unavailable") raise UpdateError(_("Update server is unavailable"))
return True return True
def drop_binhosts(self, dv): def drop_binhosts(self, dv):

@ -18,6 +18,7 @@ import os
import sys import sys
import re import re
from os import path from os import path
from calculate.lib.cl_template import SystemIni
from calculate.lib.datavars import (Variable, VariableError, from calculate.lib.datavars import (Variable, VariableError,
ReadonlyVariable, ReadonlyTableVariable, ReadonlyVariable, ReadonlyTableVariable,
TableVariable, FieldValue, TableVariable, FieldValue,
@ -277,6 +278,7 @@ class VariableClUpdateBinhostData(ReadonlyTableVariable):
""" """
source = ["cl_update_binhost_host", source = ["cl_update_binhost_host",
"cl_update_binhost_revisions", "cl_update_binhost_revisions",
"cl_update_binhost_timestamp",
"cl_update_binhost_time"] "cl_update_binhost_time"]
def check_binhost(self, binhost): def check_binhost(self, binhost):
@ -317,11 +319,13 @@ class VariableClUpdateBinhostData(ReadonlyTableVariable):
timeout = self.GetInteger('cl_update_binhost_timeout') timeout = self.GetInteger('cl_update_binhost_timeout')
timestamp_file = path.join(binhost, timestamp_file = path.join(binhost,
self.Get('cl_update_binhost_timestamp_path')) self.Get('cl_update_binhost_timestamp_path'))
last_ts = self.Get('cl_update_last_timestamp')
try: try:
t = time.time() t = time.time()
data = urllib2.urlopen(timestamp_file, data = urllib2.urlopen(timestamp_file,
timeout=timeout).read().strip() 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), return (data, int((time.time() - t) * 1000),
t - int(data) < 5 * DAY) t - int(data) < 5 * DAY)
except urllib2.URLError as e: except urllib2.URLError as e:
@ -351,7 +355,7 @@ class VariableClUpdateBinhostData(ReadonlyTableVariable):
if ts and cur_t - int(ts) < 5 * DAY: if ts and cur_t - int(ts) < 5 * DAY:
data = self.check_binhost(binhost) data = self.check_binhost(binhost)
if data: if data:
return [[binhost, data, str(t)]] return [[binhost, data, ts, str(t)]]
for host, ts, t, good in sorted( for host, ts, t, good in sorted(
generate_by_timestamp(), generate_by_timestamp(),
# критерий сортировки между серверами # критерий сортировки между серверами
@ -359,22 +363,22 @@ class VariableClUpdateBinhostData(ReadonlyTableVariable):
# неактульные по timestamp # неактульные по timestamp
# актуальность - 5 дней # актуальность - 5 дней
reverse=True, reverse=True,
key=lambda x: (# приоритетны актуальные (не более 5 дней) key=lambda x: ( # приоритетны актуальные (не более 5 дней)
x[3], x[3],
# приоритет для неактуальных # приоритет для неактуальных
# самое свежее # самое свежее
0 if x[3] else int(x[1]), 0 if x[3] else int(x[1]),
# приоритет для неактуальных # приоритет для неактуальных
# самое быстрое # самое быстрое
0 if x[3] else -int(x[2]), 0 if x[3] else -int(x[2]),
# приоритет для актуальных # приоритет для актуальных
# самое быстрое # самое быстрое
-int(x[2]) if x[3] else 0, -int(x[2]) if x[3] else 0,
# самое свежее # самое свежее
int(x[1]) if x[3] else 0)): int(x[1]) if x[3] else 0)):
data = self.check_binhost(host) data = self.check_binhost(host)
if data: if data:
return [[host, data, str(t)]] return [[host, data, ts, str(t)]]
return [[]] return [[]]
@ -410,7 +414,7 @@ class VariableClUpdateBinhostRevisions(FieldValue, ReadonlyVariable):
column = 1 column = 1
class VariableClUpdateBinhostTime(FieldValue, ReadonlyVariable): class VariableClUpdateBinhostTimestamp(FieldValue, ReadonlyVariable):
""" """
Список имен прочих репозиториев Список имен прочих репозиториев
""" """
@ -419,6 +423,25 @@ class VariableClUpdateBinhostTime(FieldValue, ReadonlyVariable):
column = 2 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): class VariableClUpdateBranchName(Variable):
""" """
Список доступных репозиторием Список доступных репозиторием
@ -1306,6 +1329,8 @@ class DataVarsUpdateProfile(SimpleDataVars):
VariableClUpdateBinhostRecheckSet(section="update"), VariableClUpdateBinhostRecheckSet(section="update"),
VariableClUpdateBinhostRevisions(section="update"), VariableClUpdateBinhostRevisions(section="update"),
VariableClUpdateBinhostTime(section="update"), VariableClUpdateBinhostTime(section="update"),
VariableClUpdateBinhostTimestamp(section="update"),
VariableClUpdateLastTimestamp(section="update"),
VariableClUpdateBinhostTimeout(section="update"), VariableClUpdateBinhostTimeout(section="update"),
VariableClUpdateBinhostTimestampPath(section="update"), VariableClUpdateBinhostTimestampPath(section="update"),
VariableClUpdateBinhostList(section="update"), VariableClUpdateBinhostList(section="update"),

Loading…
Cancel
Save