diff --git a/update/update.py b/update/update.py index 8e082fa..50dd30b 100644 --- a/update/update.py +++ b/update/update.py @@ -13,10 +13,13 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +from itertools import ifilter import sys from os import path import os +import time +from calculate.core.server.gen_pid import search_worked_process from calculate.lib.utils.tools import AddonError from calculate.lib.utils.colortext.palette import TextState @@ -99,6 +102,24 @@ class Update: dv.Set('cl_update_outdate_set', 'on', force=True) return True + def checkRun(self, wait_update): + """ + Проверить повторный запуск + """ + dv = self.clVars + if filter(lambda x: os.getpid() != x, + search_worked_process('update', dv)): + if not wait_update: + raise UpdateError(_("Update is already running. " + "Try to run later.")) + else: + self.startTask(_("Waiting for complete another update")) + while any(ifilter(lambda x: os.getpid() != x, + search_worked_process('update', dv))): + time.sleep(0.3) + self.endTask() + return True + def syncRepositories(self, repname, clean_on_error=True): """ Синхронизировать репозитории diff --git a/update/utils/cl_update.py b/update/utils/cl_update.py index 5a89b7b..b16d018 100644 --- a/update/utils/cl_update.py +++ b/update/utils/cl_update.py @@ -202,6 +202,8 @@ class ClUpdateAction(Action): # список задач для дейсвия tasks = [ + {'name': 'check_run', + 'method': 'Update.checkRun(cl_update_wait_another_set)'}, {'name': 'reps_synchronization', 'group': __("Repository synchronization"), 'tasks': [ diff --git a/update/variables/update.py b/update/variables/update.py index a000e45..f8e4851 100644 --- a/update/variables/update.py +++ b/update/variables/update.py @@ -413,3 +413,15 @@ class VariableClUpdateSyncOnlySet(Variable): self.Get('cl_update_metadata_force') != "force" and self.Get('cl_update_eixupdate_force') != "force"): raise VariableError(_("Select at least one sync repository")) + +class VariableClUpdateWaitAnotherSet(Variable): + """ + Ждать завершения другого процесса обновления + """ + type = "bool" + value = "on" + opt = ["--wait-another-update"] + + def init(self): + self.label = _("Wait for complete another update") + self.help = _("wait until the other updates or abort") diff --git a/update/wsdl_update.py b/update/wsdl_update.py index d2febbf..10ec376 100644 --- a/update/wsdl_update.py +++ b/update/wsdl_update.py @@ -70,6 +70,7 @@ class Wsdl(WsdlBase): 'cl_update_pretend_set', 'cl_update_eixupdate_force', 'cl_update_sync_only_set', + 'cl_update_wait_another_set', 'cl_templates_locate', 'cl_verbose_set', 'cl_dispatch_conf'), next_label=_("Update"))]},