5
0
Derivar 0

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

master3.4 3.4.5.4
ascendente 72393cf50f
cometimento 231d79d8ee

@ -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):

@ -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"),

Carregando…
Cancelar
Guardar