mirror of
https://gitlab.com/dslackw/slpkg.git
synced 2024-12-27 09:58:10 +01:00
Updated for the view mode
This commit is contained in:
parent
4256c2733f
commit
9a3ac15270
3 changed files with 51 additions and 19 deletions
|
@ -1,13 +1,12 @@
|
|||
#!/usr/bin/python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import time
|
||||
from progress.spinner import PixelSpinner
|
||||
import subprocess
|
||||
import multiprocessing
|
||||
from pathlib import Path
|
||||
from typing import Union
|
||||
|
||||
from slpkg.progress_bar import ProgressBar
|
||||
from slpkg.configs import Configs
|
||||
|
||||
|
||||
|
@ -19,6 +18,7 @@ class Downloader:
|
|||
self.url = url
|
||||
self.filename = url.split('/')[-1]
|
||||
self.configs = Configs
|
||||
self.progress = ProgressBar()
|
||||
self.stderr = None
|
||||
self.stdout = None
|
||||
|
||||
|
@ -26,14 +26,6 @@ class Downloader:
|
|||
""" Wget downloader. """
|
||||
subprocess.call(f'wget {self.configs.wget_options} --directory-prefix={self.path} {self.url}',
|
||||
shell=True, stderr=self.stderr, stdout=self.stdout)
|
||||
time.sleep(0.5)
|
||||
|
||||
def progress(self):
|
||||
""" Creating progress bar. """
|
||||
spinner = PixelSpinner(f'Downloading {self.filename}... ')
|
||||
while True:
|
||||
time.sleep(0.1)
|
||||
spinner.next()
|
||||
|
||||
def download(self):
|
||||
""" Start download process. """
|
||||
|
@ -43,7 +35,7 @@ class Downloader:
|
|||
|
||||
# Starting multiprocessing
|
||||
p1 = multiprocessing.Process(target=self.wget)
|
||||
p2 = multiprocessing.Process(target=self.progress)
|
||||
p2 = multiprocessing.Process(target=self.progress.bar, args=('[ Downloading ]', self.filename))
|
||||
|
||||
p1.start()
|
||||
p2.start()
|
||||
|
|
31
slpkg/progress_bar.py
Normal file
31
slpkg/progress_bar.py
Normal file
|
@ -0,0 +1,31 @@
|
|||
#!/usr/bin/python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import codecs
|
||||
import time
|
||||
from progress.spinner import PixelSpinner
|
||||
|
||||
|
||||
class ProgressBar:
|
||||
|
||||
def __init__(self):
|
||||
self.vl = '│' # vertical_line
|
||||
self.hl = '─' # horizontal_line
|
||||
self.hv = '┼' # horizontal_vertical
|
||||
self.urc = '┐' # upper_right_corner
|
||||
self.llc = '└' # lower_left_corner
|
||||
self.lrc = ' ┘' # lower_right_corner
|
||||
self.ulc = '┌' # upper_left_corner
|
||||
self.hau = '┴' # horizontal_and_up
|
||||
self.had = '┬' # horizontal_and_down
|
||||
self.var = '├' # vertical_and_right
|
||||
self.val = '┤' # vertical_and_left
|
||||
|
||||
@staticmethod
|
||||
def bar(message, filename):
|
||||
""" Creating progress bar. """
|
||||
spinner = PixelSpinner(f'{message} {filename}... ')
|
||||
# print('\033[F', end='', flush=True)
|
||||
while True:
|
||||
time.sleep(0.1)
|
||||
spinner.next()
|
|
@ -2,6 +2,7 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import os
|
||||
import shutil
|
||||
from typing import Any
|
||||
|
||||
from slpkg.configs import Configs
|
||||
|
@ -25,10 +26,17 @@ class ViewMessage:
|
|||
self.black = Blacklist()
|
||||
self.dialog = DialogBox()
|
||||
self.installed_packages = []
|
||||
self.columns, self.rows = shutil.get_terminal_size()
|
||||
|
||||
def title_box(self, message):
|
||||
""" Drawing box title message. """
|
||||
print('┌' + '─' * (self.columns - 2) + '┐')
|
||||
print(f'│ {message}' + ' ' * (self.columns - len(message) - 3) + '│')
|
||||
print('└' + '─' * (self.columns - 2) + '┘')
|
||||
|
||||
def build_packages(self, slackbuilds: list, dependencies: list):
|
||||
""" View packages for build only. """
|
||||
print('The following packages will be build:\n')
|
||||
self.title_box('The following packages will be build:')
|
||||
|
||||
for sbo in slackbuilds:
|
||||
version = SBoQueries(sbo).version()
|
||||
|
@ -44,7 +52,7 @@ class ViewMessage:
|
|||
|
||||
def install_packages(self, slackbuilds: list, dependencies: list):
|
||||
""" View packages for install. """
|
||||
print('The following packages will be installed or upgraded:\n')
|
||||
self.title_box('The following packages will be installed or upgraded:')
|
||||
|
||||
for sbo in slackbuilds:
|
||||
version = SBoQueries(sbo).version()
|
||||
|
@ -60,7 +68,7 @@ class ViewMessage:
|
|||
|
||||
def download_packages(self, slackbuilds: list):
|
||||
""" View downloaded packages. """
|
||||
print('The following packages will be downloaded:\n')
|
||||
self.title_box('The following packages will be downloaded:')
|
||||
|
||||
for sbo in slackbuilds:
|
||||
version = SBoQueries(sbo).version()
|
||||
|
@ -86,7 +94,7 @@ class ViewMessage:
|
|||
if deps and '--resolve-off' not in self.flags:
|
||||
dependencies = self.choose_dependencies_for_remove(dependencies)
|
||||
|
||||
print('The following packages will be removed:\n')
|
||||
self.title_box('The following packages will be removed:')
|
||||
|
||||
for pkg in slackbuilds:
|
||||
self._view_removed(pkg)
|
||||
|
@ -102,7 +110,7 @@ class ViewMessage:
|
|||
return self.installed_packages, dependencies
|
||||
|
||||
def choose_dependencies_for_remove(self, dependencies: list) -> list:
|
||||
""" Choose packages for remove. """
|
||||
""" Choose packages for remove using the dialog box. """
|
||||
height = 10
|
||||
width = 70
|
||||
list_height = 0
|
||||
|
@ -191,16 +199,17 @@ class ViewMessage:
|
|||
else:
|
||||
installed += 1
|
||||
|
||||
print('─' * self.columns)
|
||||
if option == 'install':
|
||||
print(f'\n{color["grey"]}Total {installed} packages will be '
|
||||
print(f'{color["grey"]}Total {installed} packages will be '
|
||||
f'installed and {upgraded} will be upgraded.{color["endc"]}')
|
||||
|
||||
elif option == 'build':
|
||||
print(f'\n{color["grey"]}Total {installed + upgraded} packages '
|
||||
print(f'{color["grey"]}Total {installed + upgraded} packages '
|
||||
f'will be build.{color["endc"]}')
|
||||
|
||||
elif option == 'remove':
|
||||
print(f'\n{color["grey"]}Total {installed + upgraded} packages '
|
||||
print(f'{color["grey"]}Total {installed + upgraded} packages '
|
||||
f'will be removed.{color["endc"]}')
|
||||
|
||||
def logs_packages(self, dependencies: list):
|
||||
|
|
Loading…
Reference in a new issue