Skip to content

Finish Implement winget sources #1352

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 63 additions & 36 deletions wingetui/PackageManagers/winget.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,8 @@ def getPackagesForQuery(self, query: str) -> list[Package]:
versionPosition = len(line.split("Version")[0])
sourcePosition = len(line.split("Source")[0])
if len(line) == sourcePosition:
print(len(line), sourcePosition)
noSourcesAvailable = True
print("🟡 Winget reported no sources")
print("🟡 Winget reported no sources on getPackagesForQuery")

elif "---" in line:
pass
Expand All @@ -108,40 +107,44 @@ def getPackagesForQuery(self, query: str) -> list[Package]:
iOffset = 0
id = idVersionSubstr.split(" ")[iOffset]
ver = idVersionSubstr.split(" ")[iOffset+1]
source = idVersionSubstr.split(" ")[iOffset+2]
if not noSourcesAvailable:
source = "Winget: "+idVersionSubstr.split(" ")[iOffset+2]
if len(id) == 1:
iOffset + 1
id = idVersionSubstr.split(" ")[iOffset]
ver = idVersionSubstr.split(" ")[iOffset+1]
source = idVersionSubstr.split(" ")[iOffset+2]
if not noSourcesAvailable:
source = "Winget: "+idVersionSubstr.split(" ")[iOffset+2]
if ver.strip() in ("<", "-"):
iOffset += 1
ver = idVersionSubstr.split(" ")[iOffset+1]
source = idVersionSubstr.split(" ")[iOffset+2]

if source.strip() == "":
if not noSourcesAvailable:
source = "Winget: "+idVersionSubstr.split(" ")[iOffset+2]

if noSourcesAvailable:
source = "Winget"
elif source.strip() == "":
if len(globals.wingetSources.keys()>=0):
source = globals.wingetSources.keys()[0]
source = "Winget: "+list(globals.wingetSources.keys())[0]
else:
source = _("Unknown")
elif noSourcesAvailable:
source = list(globals.wingetSources.keys())[0]

source = "Winget"

if not " " in name:
if not name in self.BLACKLISTED_PACKAGE_NAMES and not id in self.BLACKLISTED_PACKAGE_IDS and not version in self.BLACKLISTED_PACKAGE_VERSIONS:
packages.append(Package(name, id, ver, f"Winget: {source}", Winget))
packages.append(Package(name, id, ver, source, Winget))
else:
if not name in self.BLACKLISTED_PACKAGE_NAMES and not id in self.BLACKLISTED_PACKAGE_IDS and not version in self.BLACKLISTED_PACKAGE_VERSIONS:
name = name.replace(" ", "#").replace("# ", "#").replace(" #", "#")
while "##" in name:
name = name.replace("##", "#")
print(f"🟡 package {name} failed parsing, going for method 2...")
packages.append(Package(name, id, ver, f"Winget: {source}", Winget))
packages.append(Package(name, id, ver, source, Winget))
except Exception as e:
report(e)
packages.append(Package(line[0:idPosition].strip(), line[idPosition:versionPosition].strip(), line[versionPosition:sourcePosition].strip(), f"Winget: {line[sourcePosition:].strip()}", Winget))
if type(e) != IndexError:
report(e)
print(f"🟢 {self.NAME} search for updates finished with {len(packages)} result(s) (msstore)")
print(f"🟢 {self.NAME} search for updates finished with {len(packages)} result(s)")
globals.PackageManagerOutput += rawOutput
return packages

Expand All @@ -162,6 +165,7 @@ def getAvailableUpdates(self) -> list[UpgradablePackage]:
versionPosition: int = 0
newVerPosition: int = 0
rawoutput = "\n\n---------"+self.NAME
noSourcesAvailable = False
while p.poll() is None:
line: str = str(p.stdout.readline().strip(), "utf-8", errors="ignore")
rawoutput += "\n"+line
Expand All @@ -174,6 +178,10 @@ def getAvailableUpdates(self) -> list[UpgradablePackage]:
idPosition = len(line.split("Id")[0])
versionPosition = len(line.split("Version")[0])
newVerPosition = len(line.split("Available")[0])
sourcePosition = len(line.split("Source")[0])
if len(line) == sourcePosition:
noSourcesAvailable = True
print("🟡 Winget reported no sources on getAvailableUpdates")
else:
pass
elif "---" in line:
Expand All @@ -191,32 +199,44 @@ def getAvailableUpdates(self) -> list[UpgradablePackage]:
id = verElement.split(" ")[iOffset+0]
ver = verElement.split(" ")[iOffset+1]
newver = verElement.split(" ")[iOffset+2]
if not noSourcesAvailable:
source = "Winget: "+verElement.split(" ")[iOffset+3]
if len(id)==1:
iOffset + 1
id = verElement.split(" ")[iOffset+0]
newver = verElement.split(" ")[iOffset+2]
ver = verElement.split(" ")[iOffset+1]
newver = verElement.split(" ")[iOffset+2]
if not noSourcesAvailable:
source = "Winget: "+verElement.split(" ")[iOffset+3]
if ver.strip() in ("<", ">", "-"):
iOffset += 1
ver = verElement.split(" ")[iOffset+1]
newver = verElement.split(" ")[iOffset+2]
if not noSourcesAvailable:
source = "Winget: "+verElement.split(" ")[iOffset+3]
name = element[0:idPosition].strip()
StoreName = "Winget"
if "winget" in line:
StoreName = "Winget: winget"
elif "msstore" in line:
StoreName = "Winget: msstore"

if noSourcesAvailable:
source = "Winget"
elif source.strip() == "":
if len(list(globals.wingetSources.keys())>=0):
print("🟠 No source found on Winget.getAvailableUpdates()!")
source = "Winget: "+list(globals.wingetSources.keys())[0]
else:
source = "Winget"

if not " " in name:
if not name in self.BLACKLISTED_PACKAGE_NAMES and not id in self.BLACKLISTED_PACKAGE_IDS and not version in self.BLACKLISTED_PACKAGE_VERSIONS:
packages.append(UpgradablePackage(name, id, ver, newver, StoreName, Winget))
packages.append(UpgradablePackage(name, id, ver, newver, source, Winget))
else:
name = name.replace(" ", "#").replace("# ", "#").replace(" #", "#")
while "##" in name:
name = name.replace("##", "#")
if not name in self.BLACKLISTED_PACKAGE_NAMES and not id in self.BLACKLISTED_PACKAGE_IDS and not version in self.BLACKLISTED_PACKAGE_VERSIONS:
packages.append(UpgradablePackage(name.split("#")[0], name.split("#")[-1]+id, ver, newver, StoreName, Winget))
packages.append(UpgradablePackage(name.split("#")[0], name.split("#")[-1]+id, ver, newver, source, Winget))
except Exception as e:
packages.append(UpgradablePackage(element[0:idPosition].strip(), element[idPosition:versionPosition].strip(), element[versionPosition:newVerPosition].split(" ")[0].strip(), element[newVerPosition:].split(" ")[0].strip(), StoreName, Winget))
report(e)
packages.append(UpgradablePackage(element[0:idPosition].strip(), element[idPosition:versionPosition].strip(), element[versionPosition:newVerPosition].split(" ")[0].strip(), element[newVerPosition:sourcePosition].split(" ")[0].strip(), "Winget: "+element[sourcePosition:].split(" ")[0].strip(), Winget))
if type(e) != IndexError:
report(e)
print(f"🟢 {self.NAME} search for updates finished with {len(packages)} result(s)")
Expand Down Expand Up @@ -297,14 +317,15 @@ def getSource(id: str) -> str:
hasShownId = True
idPosition = len(line.split("Id")[0])
versionPosition = len(line.split("Version")[0])
sourcePosition = len(line.split("Source")[0])
else:
pass
elif "---" in line:
pass
else:
element = line.replace("2010 x", "2010 x").replace("Microsoft.VCRedist.2010", " Microsoft.VCRedist.2010") # Fix an issue with MSVC++ 2010, where it shows with a double space (see https://github.com/marticliment/WingetUI#450)
packageLine = line.replace("2010 x", "2010 x").replace("Microsoft.VCRedist.2010", " Microsoft.VCRedist.2010") # Fix an issue with MSVC++ 2010, where it shows with a double space (see https://github.com/marticliment/WingetUI#450)
try:
verElement = element[idPosition:].strip()
verElement = packageLine[idPosition:].strip()
verElement.replace("\t", " ")
untrimmedVerelement = verElement
while " " in verElement:
Expand All @@ -319,28 +340,34 @@ def getSource(id: str) -> str:
if len(id) == 1:
iOffset + 1
id = verElement.split(" ")[iOffset+0]
ver = verElement.split(" ")[iOffset+1]
ver = verElement.split(" ")[iOffset+1]
if ver.strip() in ("<", "-", ">"):
iOffset += 1
ver = verElement.split(" ")[iOffset+1]
name = element[0:idPosition].strip()
StoreName = "Winget"
if "winget" in line:
StoreName = "Winget: winget"
elif "msstore" in line:
StoreName = "Winget: msstore"
name = packageLine[0:idPosition].strip()

if name.strip() == "":
continue
else:
print('"'+name+'"')

if packageLine.strip().split(" ")[-1] in globals.wingetSources.keys():
source = "Winget: "+packageLine.split( )[-1]
else:
source = getSource(id)

if not " " in name:
if not name in self.BLACKLISTED_PACKAGE_NAMES and not id.strip() in self.BLACKLISTED_PACKAGE_IDS and not version in self.BLACKLISTED_PACKAGE_VERSIONS:
packages.append(Package(name, id.strip(), ver, getSource(id), Winget))
packages.append(Package(name, id.strip(), ver, source, Winget))
else:
if not name in self.BLACKLISTED_PACKAGE_NAMES and not id.strip() in self.BLACKLISTED_PACKAGE_IDS and not version in self.BLACKLISTED_PACKAGE_VERSIONS:
print(f"🟡 package {name} failed parsing, going for method 2...")
name = name.replace(" ", "#").replace("# ", "#").replace(" #", "#")
while "##" in name:
name = name.replace("##", "#")
packages.append(Package(name.split("#")[0], (name.split("#")[-1]+id).strip(), ver, getSource(id), Winget))
packages.append(Package(name.split("#")[0], (name.split("#")[-1]+id).strip(), ver, source, Winget))
except Exception as e:
packages.append(Package(element[0:idPosition].strip(), element[idPosition:versionPosition].strip(), element[versionPosition:].strip(), getSource(id), Winget))
packages.append(Package(packageLine[0:idPosition].strip(), packageLine[idPosition:versionPosition].strip(), packageLine[versionPosition:sourcePosition].strip(), "Winget: "+packageLine[sourcePosition:].strip(), Winget))
if type(e) != IndexError:
report(e)
print(f"🟢 {self.NAME} search for installed packages finished with {len(packages)} result(s)")
Expand Down
2 changes: 2 additions & 0 deletions wingetui/storeEngine.py
Original file line number Diff line number Diff line change
Expand Up @@ -982,6 +982,8 @@ def __init__(self):
self.rightFast.finished.connect(lambda: (self.leftSlow.start(), self.changeBarOrientation.emit()))

self.leftSlow.start()

self.loadSources()

self.registeredThemeEvent = False
self.ApplyIcons()
Expand Down