Skip to content

Commit

Permalink
Merge pull request #113 from hamishcampbell/move-clone-progressbar
Browse files Browse the repository at this point in the history
Move progress bar widget out of kartapi and into dockwidget
  • Loading branch information
hamishcampbell authored Aug 14, 2024
2 parents e10bd47 + 781e4ba commit b0fa22c
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 34 deletions.
43 changes: 35 additions & 8 deletions kart/gui/dockwidget.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import os
import re
import math
import tempfile
from functools import partial

from qgis.PyQt import uic
from qgis.PyQt.QtCore import Qt, QMimeData, QByteArray, QDataStream, QIODevice
Expand Down Expand Up @@ -50,6 +53,7 @@
setSetting,
LASTREPO,
waitcursor,
progressBar,
)

pluginPath = os.path.split(os.path.dirname(__file__))[0]
Expand Down Expand Up @@ -227,18 +231,41 @@ def createRepo(self):

@executeskart
def cloneRepo(self):
def _processProgressLine(bar, line):
if "Writing dataset" in line:
datasetname = line.split(":")[-1].strip()
bar.setText(f"Checking out layer '{datasetname}'")
elif line.startswith("Receiving objects: ") or line.startswith(
"Writing objects: "
):
tokens = line.split(": ")
bar.setText(tokens[0])
bar.setValue(
math.floor(float(tokens[1][1 : tokens[1].find("%")].strip()))
)
else:
msg = line.split(" - ")[-1]
if "%" in msg:
matches = re.findall(r"(\d+(\.\d+)?)", msg)
if matches:
value = math.floor(float(matches[0][0]))
bar.setValue(value)

dialog = CloneDialog()
dialog.show()
ret = dialog.exec_()
if ret == dialog.Accepted:
repo = Repository.clone(
dialog.src,
dialog.dst,
dialog.location,
dialog.extent,
dialog.username,
dialog.password,
)
with progressBar("Clone") as bar:
bar.setText("Cloning repository")
repo = Repository.clone(
dialog.src,
dialog.dst,
dialog.location,
dialog.extent,
dialog.username,
dialog.password,
output_handler=partial(_processProgressLine, bar),
)
RepoManager.instance().add_repo(repo)

def addRepoToUI(self, repo: Repository):
Expand Down
31 changes: 5 additions & 26 deletions kart/kartapi.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import json
import locale
import math
import os
import re
import subprocess
import sys
import tempfile

from typing import Optional, List
from functools import partial, wraps
from typing import Optional, List, Callable
from functools import wraps

from urllib.parse import urlparse

Expand All @@ -33,7 +32,7 @@
from kart.gui.userconfigdialog import UserConfigDialog
from kart.gui.installationwarningdialog import InstallationWarningDialog

from kart.utils import progressBar, setting, setSetting, KARTPATH, HELPERMODE
from kart.utils import setting, setSetting, KARTPATH, HELPERMODE
from kart import logging


Expand Down Expand Up @@ -258,23 +257,6 @@ def executeKart(commands, path=None, jsonoutput=False, feedback=None):
QApplication.restoreOverrideCursor()


def _processProgressLine(bar, line):
if "Writing dataset" in line:
datasetname = line.split(":")[-1].strip()
bar.setText(f"Checking out layer '{datasetname}'")
elif line.startswith("Receiving objects: ") or line.startswith("Writing objects: "):
tokens = line.split(": ")
bar.setText(tokens[0])
bar.setValue(math.floor(float(tokens[1][1 : tokens[1].find("%")].strip())))
else:
msg = line.split(" - ")[-1]
if "%" in msg:
matches = re.findall(r"(\d+(\.\d+)?)", msg)
if matches:
value = math.floor(float(matches[0][0]))
bar.setValue(value)


class Repository:
def __init__(self, path):
self.path = path
Expand Down Expand Up @@ -342,18 +324,15 @@ def clone(
extent: Optional[QgsReferencedRectangle] = None,
username: Optional[str] = None,
password: Optional[str] = None,
output_handler: Callable[[str], None] = None,
) -> "Repository":
"""
Performs a (blocking, main thread only) clone operation
"""
commands = Repository.generate_clone_arguments(
src, dst, location, extent, username, password
)

with progressBar("Clone") as bar:
bar.setText("Cloning repository")
executeKart(commands, feedback=partial(_processProgressLine, bar))

executeKart(commands, feedback=output_handler)
return Repository(dst)

def title(self):
Expand Down

0 comments on commit b0fa22c

Please sign in to comment.