Skip to content

Commit

Permalink
replaced multiprocessing with threading
Browse files Browse the repository at this point in the history
  • Loading branch information
int-72h committed May 31, 2022
1 parent 1f1476c commit c6a044b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 18 deletions.
26 changes: 14 additions & 12 deletions gui.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
from concurrent.futures import ThreadPoolExecutor,as_completed
import os
import urllib.request
from urllib.error import HTTPError
import tempfile
from steam import *
from pathlib import Path, PosixPath, WindowsPath
from pathos.multiprocessing import ProcessPool as Pool
from multiprocessing import shared_memory
from sys import exit
from tvn import *
from shutil import move
Expand Down Expand Up @@ -102,8 +101,8 @@ def retranslateUi(self, MainWindow):
self.label_3.setText(_translate("MainWindow", "Installed Revision: None"))

def clickBrowse(self):
gamepath = QFileDialog.getOpenFileName(MainWindow, "Game path", "", "Game Info (*.txt)")
self.lineEdit.setText(gamepath[0].removesuffix("gameinfo.txt"))
gamepath = QFileDialog.getExistingDirectory(MainWindow, "Game path", "")
# self.lineEdit.setText(gamepath[0].removesuffix("gameinfo.txt"))
revision = get_installed_revision(Path(self.lineEdit.text()))
if revision >= 0:
self.label_3.setText("Installed Revision: " + str(revision))
Expand All @@ -114,8 +113,12 @@ def clickUpdate(self):
self.browse.setDisabled(True)
self.pushButton.setDisabled(True)
self.pushButton_2.setDisabled(True)

game_path = Path(self.lineEdit.text())
if 'open_fortress' not in str(game_path):
try:
Path.mkdir(game_path / Path('open_fortress'))
except FileExistsError:
pass
installed_revision = get_installed_revision(game_path)
try:
latest_revision = fetch_latest_revision(self.lineEdit_2.text())
Expand All @@ -125,6 +128,7 @@ def clickUpdate(self):
errorMsg.setText("Invalid URL!")
errorMsg.exec_()
exit(1)
print(latest_revision)
revisions = fetch_revisions(self.lineEdit_2.text(), installed_revision, latest_revision)
changes = replay_changes(revisions)

Expand Down Expand Up @@ -174,20 +178,18 @@ def work(arr):
file.write(resp.content)
file.close()


def pbar_sg(iter, self, app, num_cpus=12):
def pbar_sg(iter, self, app, num_cpus=40):
length = len(iter)
pool = Pool(num_cpus)
z = 0
map_func = getattr(pool, 'uimap')
for item, it in zip(map_func(work, iter), iter):
executor = ThreadPoolExecutor(num_cpus)
futures = {executor.submit(work, x): x for x in iter}
for future in as_completed(futures):
it = futures[future]
z = z + 1
self.label_4.setText(it[0])
self.progressBar.setValue(z)
self.progressBar.setMaximum(length)
app.processEvents()
yield item
pool.clear()


def get_revision(url: str, revision: int) -> list[Change]:
Expand Down
4 changes: 3 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ tvn~=0.0.1
setuptools~=60.2.0
vdf~=3.4c
pathos~=0.2.9
PyQt5~=5.15.6
PyQt5~=5.15.6
httpx~=0.23.0
future~=0.18.2
13 changes: 8 additions & 5 deletions steam.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,23 @@ def getpath():

if buttonPressed == QMessageBox.Ok:
rmtree(target_path)
Path.mkdir(target_path)
else:
exit()
else:
print('already exists, carrying on')
elif target_path.parents[0].exists():
print('Generating open fortress folder...')
Path.mkdir(target_path)
print('carrying on...')
elif target_path.parents[1].exists():
print('Generating sourcemods folder...')
Path.mkdir(target_path.parents[0])
Path.mkdir(target_path)

else:
print("Ok something's wrong, put in your path manually")
exitMsg = QMessageBox()
exitMsg.setWindowTitle("OFToast")
exitMsg.setText(
"We can't find your steam install. Use the browse button to navigate to the sourcemods folder.")
exitMsg.setStandardButtons(QMessageBox.Ok)
buttonPressed = exitMsg.exec_()
return -1
return target_path

Expand Down

0 comments on commit c6a044b

Please sign in to comment.