Fix line endings
This commit is contained in:
parent
ffa0927119
commit
4e7921e85d
@ -1,81 +1,81 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
from concurrent.futures import ThreadPoolExecutor
|
from concurrent.futures import ThreadPoolExecutor
|
||||||
from math import floor
|
from math import floor
|
||||||
|
|
||||||
SIZE_PREFIXES = ('', 'k', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y')
|
SIZE_PREFIXES = ('', 'k', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y')
|
||||||
|
|
||||||
class ActionItem:
|
class ActionItem:
|
||||||
def __init__(self, text, action):
|
def __init__(self, text, action):
|
||||||
self.text = text
|
self.text = text
|
||||||
self.action = action
|
self.action = action
|
||||||
self.units_total = 0
|
self.units_total = 0
|
||||||
self.units_done = 0
|
self.units_done = 0
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
with ThreadPoolExecutor() as executor:
|
with ThreadPoolExecutor() as executor:
|
||||||
future = executor.submit(self.action, self)
|
future = executor.submit(self.action, self)
|
||||||
while not future.done():
|
while not future.done():
|
||||||
time.sleep(0.2)
|
time.sleep(0.2)
|
||||||
self.print_progress()
|
self.print_progress()
|
||||||
# Get the result of the future and let it raise exception, if there was any
|
# Get the result of the future and let it raise exception, if there was any
|
||||||
data = future.result()
|
data = future.result()
|
||||||
self.print_progress('\n')
|
self.print_progress('\n')
|
||||||
|
|
||||||
def print_progress(self, end='\r'):
|
def print_progress(self, end='\r'):
|
||||||
text = self.text
|
text = self.text
|
||||||
if self.units_total:
|
if self.units_total:
|
||||||
text = f'{text} ({self.units_done}/{self.units_total}) [{floor(self.units_done/self.units_total*100)} %]'
|
text = f'{text} ({self.units_done}/{self.units_total}) [{floor(self.units_done/self.units_total*100)} %]'
|
||||||
print(f'\x1b[K{text}', end=end)
|
print(f'\x1b[K{text}', end=end)
|
||||||
|
|
||||||
class ActionQueue:
|
class ActionQueue:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.queue = []
|
self.queue = []
|
||||||
|
|
||||||
def download_image(self, image):
|
def download_image(self, image):
|
||||||
self.queue.append(ActionItem(f'Downloading image {image.name}', image.download))
|
self.queue.append(ActionItem(f'Downloading image {image.name}', image.download))
|
||||||
self.queue.append(ActionItem(f'Unpacking image {image.name}', image.unpack_downloaded))
|
self.queue.append(ActionItem(f'Unpacking image {image.name}', image.unpack_downloaded))
|
||||||
|
|
||||||
def delete_image(self, image):
|
def delete_image(self, image):
|
||||||
self.queue.append(ActionItem(f'Deleting image {image.name}', image.delete))
|
self.queue.append(ActionItem(f'Deleting image {image.name}', image.delete))
|
||||||
|
|
||||||
def install_app(self, app):
|
def install_app(self, app):
|
||||||
self.queue.append(ActionItem(f'Downloading application {app.name}', app.download))
|
self.queue.append(ActionItem(f'Downloading application {app.name}', app.download))
|
||||||
self.queue.append(ActionItem(f'Unpacking application {app.name}', app.unpack_downloaded))
|
self.queue.append(ActionItem(f'Unpacking application {app.name}', app.unpack_downloaded))
|
||||||
self.queue.append(ActionItem(f'Installing application {app.name}', app.install))
|
self.queue.append(ActionItem(f'Installing application {app.name}', app.install))
|
||||||
|
|
||||||
def update_app(self, app):
|
def update_app(self, app):
|
||||||
self.queue.append(ActionItem(f'Downloading application {app.name}', app.download))
|
self.queue.append(ActionItem(f'Downloading application {app.name}', app.download))
|
||||||
self.queue.append(ActionItem(f'Unpacking application {app.name}', app.unpack_downloaded))
|
self.queue.append(ActionItem(f'Unpacking application {app.name}', app.unpack_downloaded))
|
||||||
self.queue.append(ActionItem(f'Updating application {app.name}', app.update))
|
self.queue.append(ActionItem(f'Updating application {app.name}', app.update))
|
||||||
|
|
||||||
def uninstall_app(self, app):
|
def uninstall_app(self, app):
|
||||||
self.queue.append(ActionItem(f'Uninstalling application {app.name}', app.uninstall))
|
self.queue.append(ActionItem(f'Uninstalling application {app.name}', app.uninstall))
|
||||||
|
|
||||||
def start_app(self, app):
|
def start_app(self, app):
|
||||||
self.queue.append(ActionItem(f'Starting application {app.name}', app.start))
|
self.queue.append(ActionItem(f'Starting application {app.name}', app.start))
|
||||||
|
|
||||||
def stop_app(self, app):
|
def stop_app(self, app):
|
||||||
self.queue.append(ActionItem(f'Stopping application {app.name}', app.stop))
|
self.queue.append(ActionItem(f'Stopping application {app.name}', app.stop))
|
||||||
|
|
||||||
def process(self):
|
def process(self):
|
||||||
index = 0
|
index = 0
|
||||||
queue_length = len(self.queue)
|
queue_length = len(self.queue)
|
||||||
for item in self.queue:
|
for item in self.queue:
|
||||||
index += 1
|
index += 1
|
||||||
item.text = f'[{index}/{queue_length}] {item.text}'
|
item.text = f'[{index}/{queue_length}] {item.text}'
|
||||||
item.run()
|
item.run()
|
||||||
|
|
||||||
def readable_size(bytes):
|
def readable_size(bytes):
|
||||||
i = 0
|
i = 0
|
||||||
while bytes > 1024:
|
while bytes > 1024:
|
||||||
i += 1
|
i += 1
|
||||||
bytes /= 1024
|
bytes /= 1024
|
||||||
return f'{bytes:.2f} {SIZE_PREFIXES[i]}B'
|
return f'{bytes:.2f} {SIZE_PREFIXES[i]}B'
|
||||||
|
|
||||||
def print_lock(pid):
|
def print_lock(pid):
|
||||||
with open(os.path.join('/proc', pid, 'cmdline')) as f:
|
with open(os.path.join('/proc', pid, 'cmdline')) as f:
|
||||||
cmdline = f.read().replace('\0', ' ').strip()
|
cmdline = f.read().replace('\0', ' ').strip()
|
||||||
print(f'Waiting for lock currently held by process {pid} - {cmdline}')
|
print(f'Waiting for lock currently held by process {pid} - {cmdline}')
|
||||||
|
Loading…
Reference in New Issue
Block a user