adjust to fe2 stream wrapper

This commit is contained in:
KatKatKateryna
2023-11-10 12:54:54 +00:00
parent 90285387f9
commit b73753d15c
2 changed files with 19 additions and 43 deletions
+7 -6
View File
@@ -1,4 +1,5 @@
from textwrap import wrap
import requests
def splitTextIntoLines(text: str = "", number: int = 40) -> str:
@@ -56,18 +57,18 @@ def constructCommitURL(
def constructCommitURLfromServerCommit(serverURL: str, stream_id: str) -> str:
import requests
r = requests.get(serverURL)
# check for frontend2
# only check the url string
try:
header = r.headers["x-speckle-frontend-2"]
# url = streamUrl.replace("streams", "projects") + "/models/" + branch_id + "@" + commit_id
url = (
serverURL + "/projects/" + stream_id
) # replace with 'projects' after it's implemented in Specklepy
except:
serverURL
+ "/projects/"
+ stream_id # + "/models/" + branch_id + "@" + commit_id
)
except KeyError:
url = serverURL + "/streams/" + stream_id
return url
+12 -37
View File
@@ -117,61 +117,33 @@ class AddStreamModalDialog(QtWidgets.QWidget, FORM_CLASS):
streams = []
branch = None
commit = None
# print("_____ onSearchClicked___")
if "http" in query and len(query.split("/")) >= 3: # URL
sw = StreamWrapper(query)
sw = StreamWrapper(
query,
)
stream = sw.get_client().stream.get(
id=sw.stream_id, branch_limit=100, commit_limit=100
)
if isinstance(stream, Stream):
streams = [stream]
if "/branches/" in query:
# print("branches")
branch_name = (
query.split("/branches/")[
len(query.split("/branches/")) - 1
]
.split("/")[0]
.split("?")[0]
.split("&")[0]
.split("@")[0]
)
# print(branch_name)
# print(stream)
# print(len(stream.branches.items))
if sw.type == "branch":
branch_name = sw.branch_name
for br in stream.branches.items:
name = urllib.parse.quote(br.name)
# print(name)
if name == branch_name:
branch = br
break
elif "/commits/" in query:
# print("commits")
commit_id = (
query.split("/commits/")[len(query.split("/commits/")) - 1]
.split("/")[0]
.split("?")[0]
.split("&")[0]
.split("@")[0]
)
if sw.type == "commit":
commit_id = sw.commit_id
for br in stream.branches.items:
for com in br.commits.items:
if com.id == commit_id:
branch = br
commit = com
# print(branch)
# print(commit)
break
elif isinstance(stream, Exception):
print(stream)
# if "/commits/" in query:
# branch_id = query.split("/commits/")[len(query.split("/commits/"))-1].split("/")[0].split("?")[0].split("&")[0].split("@")[0]
# for com in stream.
# if br.id == branch_id:
# branch = br
# break
try:
metrics.track(
"Connector Action",
@@ -260,14 +232,15 @@ class AddStreamModalDialog(QtWidgets.QWidget, FORM_CLASS):
else:
try:
index = self.search_results_list.currentIndex().row()
stream = self.stream_results[index]
# stream = self.stream_results[index]
item = self.search_results_list.item(index)
url = constructCommitURLfromServerCommit(
item.text().split(" | ")[1],
item.text().split(", ")[1].split(" | ")[0],
)
# url = item.text().split(" | ")[1] + "/streams/" + item.text().split(", ")[1].split(" | ")[0]
print(url)
sw = StreamWrapper(url)
print(sw)
try:
metrics.track(
@@ -294,9 +267,11 @@ class AddStreamModalDialog(QtWidgets.QWidget, FORM_CLASS):
level=1,
func=inspect.stack()[0][3],
)
print(e)
return
except Exception as e:
logToUser(e, level=2, func=inspect.stack()[0][3])
print(e)
return
def onCancelClicked(self):