64 lines
2.5 KiB
Python
Executable file
64 lines
2.5 KiB
Python
Executable file
#!/usr/bin/env python
|
|
# -*- coding: utf-8 -*-
|
|
import tui
|
|
from tuicolors import *
|
|
import os
|
|
import subprocess
|
|
import threading
|
|
import time
|
|
|
|
ROOT_FOLDER = os.path.dirname(os.path.abspath(__file__))
|
|
|
|
def updateprogress(text: str, lb: tui.LoadingBar) -> int:
|
|
if text == None:
|
|
return -1
|
|
|
|
if lb.getMaximum() == -1 and text.startswith("Starting download"):
|
|
filetotal=int(text[19])
|
|
lb.updateLine(1,f"Downloading files ({filetotal})...")
|
|
lb.setMaximum(filetotal+2)
|
|
elif lb.getMaximum() > 0:
|
|
if text.startswith("Downloading file"):
|
|
filenum = int(text[17])
|
|
lb.setValue(filenum)
|
|
if text.startswith("Extracting files..."):
|
|
lb.updateLine(1,"Extracting files...")
|
|
lb.incrementValue()
|
|
if text.startswith("Download complete!"):
|
|
lb.finish()
|
|
|
|
def showprogress():
|
|
# File info
|
|
lastentry = ""
|
|
# Loading bar
|
|
lb = tui.LoadingBar()
|
|
lb.addLine(3)
|
|
lb.updateLine(1,"Preparing download...")
|
|
|
|
while not(lb.hasFinished()):
|
|
newentry = tui.getLastEntry(f"{ROOT_FOLDER}/temp/log.txt")
|
|
|
|
# If we get a new string -> update percentage depending on the entry
|
|
if newentry != lastentry:
|
|
lastentry = newentry
|
|
updateprogress(lastentry,lb)
|
|
|
|
# Printing and waiting
|
|
print(f"\r{lb}", end='', flush=True)
|
|
time.sleep(0.1)
|
|
|
|
# Testing printing capabilities
|
|
colouredText = tui.colourText("Hello", colour=BRIGHT_RED, backgroundcolour=BLUE)
|
|
print(colouredText)
|
|
wow = tui.limitText("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec dapibus, tellus a consectetur elementum, ex ex laoreet ligula, sit amet dignissim metus eros vel ligula. Nulla malesuada risus nec libero gravida mattis. Fusce sit amet pharetra felis, congue cursus tellus. Morbi faucibus nisi at gravida viverra. Praesent a posuere ex. In hac habitasse platea dictumst. Sed sed feugiat leo. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Donec tincidunt porttitor arcu vel cursus. Vestibulum luctus quam vitae gravida viverra. ")
|
|
print(wow)
|
|
wow = tui.limitText("Tu ne parleras pas", 5)
|
|
print(wow)
|
|
|
|
os.makedirs(ROOT_FOLDER + "/temp", exist_ok=True)
|
|
with open(ROOT_FOLDER + "/temp/log.txt", "a") as log_file:
|
|
thread = threading.Thread(target=showprogress)
|
|
thread.start()
|
|
subprocess.run(["bash", "dummy.sh"], stdout=log_file, stderr=log_file)
|
|
thread.join()
|
|
print(tui.colourText("\nSuccessfully downloaded project!", GREEN))
|