mirror of
https://gitlab.com/dslackw/slpkg.git
synced 2025-01-19 10:27:07 +01:00
Merge multiprocess
This commit is contained in:
parent
1e3d1f242d
commit
b66ca72fed
2 changed files with 8 additions and 30 deletions
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
import os
|
import os
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from multiprocessing import Process
|
from multiprocessing import Process, Queue
|
||||||
from urllib3.exceptions import HTTPError
|
from urllib3.exceptions import HTTPError
|
||||||
from urllib3 import PoolManager, ProxyManager, make_headers
|
from urllib3 import PoolManager, ProxyManager, make_headers
|
||||||
|
|
||||||
|
@ -36,14 +36,14 @@ class CheckUpdates(Configs):
|
||||||
self.option_for_repository: bool = self.utils.is_option(
|
self.option_for_repository: bool = self.utils.is_option(
|
||||||
('-o', '--repository='), flags)
|
('-o', '--repository='), flags)
|
||||||
|
|
||||||
def check_the_repositories(self) -> dict:
|
def check_the_repositories(self, queue) -> None:
|
||||||
if self.option_for_repository:
|
if self.option_for_repository:
|
||||||
self.repositories(self.repository)
|
self.repositories(self.repository)
|
||||||
else:
|
else:
|
||||||
self.check_updates_for_repositories()
|
self.check_updates_for_repositories()
|
||||||
|
|
||||||
self.view_messages(self.compare)
|
self.view_messages(self.compare)
|
||||||
return self.compare
|
queue.put(self.compare)
|
||||||
|
|
||||||
def check_updates_for_repositories(self) -> None:
|
def check_updates_for_repositories(self) -> None:
|
||||||
for repo, enable in self.repos.repositories.items():
|
for repo, enable in self.repos.repositories.items():
|
||||||
|
@ -125,11 +125,12 @@ class CheckUpdates(Configs):
|
||||||
else:
|
else:
|
||||||
print(f'\n\n{self.endc}{self.yellow}No updated packages since the last check.{self.endc}')
|
print(f'\n\n{self.endc}{self.yellow}No updated packages since the last check.{self.endc}')
|
||||||
|
|
||||||
def updates(self) -> None:
|
def updates(self) -> dict:
|
||||||
|
queue = Queue()
|
||||||
message: str = 'Checking for news, please wait...'
|
message: str = 'Checking for news, please wait...'
|
||||||
|
|
||||||
# Starting multiprocessing
|
# Starting multiprocessing
|
||||||
process_1 = Process(target=self.check_the_repositories)
|
process_1 = Process(target=self.check_the_repositories, args=(queue,))
|
||||||
process_2 = Process(target=self.progress.progress_bar, args=(message,))
|
process_2 = Process(target=self.progress.progress_bar, args=(message,))
|
||||||
|
|
||||||
process_1.start()
|
process_1.start()
|
||||||
|
@ -144,3 +145,4 @@ class CheckUpdates(Configs):
|
||||||
|
|
||||||
# Restore the terminal cursor
|
# Restore the terminal cursor
|
||||||
print('\x1b[?25h', self.endc)
|
print('\x1b[?25h', self.endc)
|
||||||
|
return queue.get()
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from multiprocessing import Process, Queue
|
|
||||||
|
|
||||||
from slpkg.configs import Configs
|
from slpkg.configs import Configs
|
||||||
from slpkg.views.views import View
|
from slpkg.views.views import View
|
||||||
|
@ -606,29 +605,6 @@ class UpdateRepositories(Configs):
|
||||||
|
|
||||||
self.data.install_sbo_data()
|
self.data.install_sbo_data()
|
||||||
|
|
||||||
def check_for_updates(self, queue) -> dict:
|
|
||||||
compare: dict = self.check_updates.check_the_repositories()
|
|
||||||
return queue.put(compare)
|
|
||||||
|
|
||||||
def repositories(self) -> None:
|
def repositories(self) -> None:
|
||||||
queue = Queue()
|
self.repos_for_update: dict = self.check_updates.updates()
|
||||||
message: str = 'Checking for news, please wait...'
|
|
||||||
|
|
||||||
# Starting multiprocessing
|
|
||||||
process_1 = Process(target=self.check_for_updates, args=(queue,))
|
|
||||||
process_2 = Process(target=self.progress.progress_bar, args=(message,))
|
|
||||||
|
|
||||||
process_1.start()
|
|
||||||
process_2.start()
|
|
||||||
|
|
||||||
# Wait until process 1 finish
|
|
||||||
process_1.join()
|
|
||||||
|
|
||||||
# Terminate process 2 if process 1 finished
|
|
||||||
if not process_1.is_alive():
|
|
||||||
process_2.terminate()
|
|
||||||
|
|
||||||
# Restore the terminal cursor
|
|
||||||
print('\x1b[?25h', self.endc, end='')
|
|
||||||
self.repos_for_update: dict = queue.get()
|
|
||||||
self.update_the_repositories()
|
self.update_the_repositories()
|
||||||
|
|
Loading…
Reference in a new issue