import os, sys import re import json import shutil import requests from bs4 import BeautifulSoup from zipfile import ZipFile import urllib3 urllib3.disable_warnings() folders = [ r'D:\\vsc\\vs-codium\\', r'D:\\vsc\\vs-codium-local\\' ] download_folder = r'D:\\Downloads\\' filename = 'vscodium.zip' # Ordner anlegen, falls nicht vorhanden for f in folders: os.makedirs(f, exist_ok=True) # Aktuelle Download-URL ermitteln res = requests.get('https://github.com/VSCodium/vscodium-insiders/tags') soup = BeautifulSoup(res.text, 'html.parser') # with open("updatevscodium.html", "w", encoding="utf-8") as f: # f.write( soup.prettify() ) urls = re.findall(r'/VSCodium/vscodium-insiders/releases/tag/(.*)-insider', soup.prettify()) if not urls: print("Keine neue Version gefunden.") exit() # Aktuelle Download-URL ermitteln print(f"https://github.com/VSCodium/vscodium-insiders/releases/download/{urls[0]}-insider/VSCodium-win32-x64-{urls[0]}-insider.zip") zip_path = os.path.join(download_folder, filename) if os.path.exists(zip_path): print(f"Entferne {zip_path}") os.remove(zip_path) # Datei herunterladen r = requests.get(f"https://github.com/VSCodium/vscodium-insiders/releases/download/{urls[0]}-insider/VSCodium-win32-x64-{urls[0]}-insider.zip", stream=True, verify=False) with open(zip_path, 'wb') as f: for chunk in r.iter_content(chunk_size=8192): f.write(chunk) # Cachedaten löschen cache_dirs = ['Cache', 'GPUCache', 'CachedData', 'CachedData-x64'] delete_count = 0 if os.path.exists(zip_path): si = os.path.getsize(zip_path) if si < 20: print("Zip ist zu klein") sys.exit(1) print(si) for f in folders: print(f"{f} --> ") if os.path.exists(os.path.join(f, 'VSCodium.exe')): os.remove(os.path.join(f, 'VSCodium.exe')) for item in os.listdir(f): path = os.path.join(f, item) if os.path.isdir(path): if item != 'data': shutil.rmtree(path) else: print("Leere", end=' ') for cache in cache_dirs: cache_path = os.path.join(path, 'user-data', cache) print(cache, end=' ') if os.path.exists(cache_path): shutil.rmtree(cache_path, ignore_errors=True) else: os.remove(path) print("--> gelöscht, Userdaten behalten") delete_count += 1 # Entpacken if delete_count == len(folders): for f in folders: print(f"Entpacke neue Version in {f}") with ZipFile(zip_path, 'r') as zip_ref: zip_ref.extractall(f) os.remove(zip_path) print("ZIP Datei von VSCodium gelöscht") else: print("ZIP nicht gelöscht, da nicht alle Ordner verarbeitet wurden") # product.json anpassen for f in folders: prod_json = os.path.join(f, 'resources', 'app', 'product.json') if os.path.exists(prod_json): with open(prod_json, 'r', encoding='utf-8') as pj: data = json.load(pj) data['extensionsGallery'] = { 'serviceUrl': 'https://marketplace.visualstudio.com/_apis/public/gallery', 'itemUrl': 'https://marketplace.visualstudio.com/items' } with open(prod_json, 'w', encoding='utf-8') as pj: json.dump(data, pj, indent=4) input("Fertig. Beliebige Taste drücken...")