Skip to content

tweaks to improve the script #1566

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 1 commit into from
Jun 1, 2025
Merged
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
74 changes: 32 additions & 42 deletions updateSWT.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import re
import argparse
import atexit
import tempfile

####################################################################
# Prerequisites:
Expand All @@ -17,7 +18,7 @@
# - Python requests installed locally. Run 'pip3 install requests'
#
# Side-effects:
# - Zip content extracted in ~/Downloads directory
# - Zip content extracted in temporary directory
# - SWT jar files installed in <git clone root>/local-proj-repo subdirectories
#
# Follow-on manual steps:
Expand All @@ -35,16 +36,14 @@
####################################################################

LOCAL_REPO_DIR = "./local-proj-repo"
LOCAL_REPO_SAVE_DIR = "../local-proj-repo-save"
TEMP_DIR = None

def is_exe(fpath):
return os.path.isfile(fpath) and os.access(fpath, os.X_OK)

def cleanupBeforeExit():
if os.path.isdir(LOCAL_REPO_SAVE_DIR):
# restore local SWT repo before exiting
shutil.move(LOCAL_REPO_SAVE_DIR + "/", LOCAL_REPO_DIR)
shutil.rmtree(LOCAL_REPO_SAVE_DIR)
if TEMP_DIR and os.path.exists(TEMP_DIR):
shutil.rmtree(TEMP_DIR)

def exitWithError(errorStr):
print(errorStr)
Expand All @@ -66,28 +65,22 @@

def downloadAndExtractZip(url):
zipfileName = url.split('=',1)[1]

home = expanduser("~")
unzippedDirName = home + "/Downloads/" + zipfileName.removesuffix('.zip') + "/"
# print(unzippedDirName)
unzippedDirName = os.path.join(TEMP_DIR, zipfileName.removesuffix('.zip'))

page = requests.get(url)
soup = BeautifulSoup(page.content, "html.parser")
zipURL = soup.find("meta").find_next("a")['href']
# print(zipURL)

page = requests.get(zipURL)
soup = BeautifulSoup(page.content, "html.parser")
divWithZip = soup.find("div", {"class":"mirror-well"})
zipURL = divWithZip.find_next("a")['href']
zipURL = "https://www.eclipse.org/downloads/" + zipURL
# print(zipURL)

# navigate the redirect to the actual mirror
page = requests.get(zipURL)
soup = BeautifulSoup(page.content, "html.parser")
zipURL = soup.find('meta', attrs={'http-equiv': 'Refresh'})['content'].split(';')[1].split('=')[1]
# print(zipURL)

# delete existing content
if os.path.exists(unzippedDirName) and os.path.isdir(unzippedDirName):
Expand All @@ -97,7 +90,7 @@
z.extractall(unzippedDirName)
subprocess.run(["zip",
"-d",
unzippedDirName + "swt.jar",
unzippedDirName + "/swt.jar",
"META-INF/ECLIPSE_.SF",
"META-INF/ECLIPSE_.DSA",
"META-INF/ECLIPSE_.RSA"])
Expand All @@ -107,46 +100,47 @@
######## end of downloadAndExtractZip ##########

def installInLocalMavenRepo(unzippedSWTDir, mvnArtifactId, gitCloneRootDir):
# command to execute
swtVersion = unzippedSWTDir.split('-')[1]
# print(swtVersion)

if shutil.which("mvn") == None :
exitWithError("did not find mvn command in the execute path")


mavenCommand = "mvn install:install-file " \
+ "-Dfile=" + unzippedSWTDir + "swt.jar " \
+ "-Dfile=" + unzippedSWTDir + "/swt.jar " \
+ "-DgroupId=local.swt " \
+ "-DartifactId=" + mvnArtifactId + " " \
+ "-Dversion=" + swtVersion + " " \
+ "-Dpackaging=jar " \
+ "-Dmaven.repo.local=" + gitCloneRootDir + "/local-proj-repo"
# print(mavenCommand)
subprocess.run(mavenCommand, shell=True)

######## end of installInLocalMavenRepo ##########

def getLocalSWTVersion(mvnArtifactId):
localSWTVersion = ""
artifactPath = os.path.join(LOCAL_REPO_DIR, "local/swt", mvnArtifactId)
if os.path.isdir(artifactPath):
# Look for version directories (they should be numeric)
subdirs = [d for d in os.listdir(artifactPath)
if os.path.isdir(os.path.join(artifactPath, d))]
if subdirs:
localSWTVersion = subdirs[0] # Take the first version directory
print(f"Found local version for {mvnArtifactId}: {localSWTVersion}")
return localSWTVersion

def updateSWT(mvnArtifactId, downloadPageLabel, gitCloneRootDir, version, forceUpdate):
URL = "https://download.eclipse.org/eclipse/downloads/"
page = requests.get(URL)

soup = BeautifulSoup(page.content, "html.parser")
linkToVersionDownload = ""

Check warning

Code scanning / Pylint (reported by Codacy)

Variable name "localSWTVersion" doesn't conform to snake_case naming style Warning

Variable name "localSWTVersion" doesn't conform to snake_case naming style
localSWTVersion = ""

if os.path.isdir(LOCAL_REPO_SAVE_DIR + "/local/swt/" + mvnArtifactId):
# Look for version directories (they should be numeric)
subdirs = [d for d in os.listdir(LOCAL_REPO_SAVE_DIR + "/local/swt/" + mvnArtifactId + "/")
if os.path.isdir(LOCAL_REPO_SAVE_DIR + "/local/swt/" + mvnArtifactId + "/" + d)]
if subdirs:
localSWTVersion = subdirs[0] # Take the first version directory
print(f"Found local version for {mvnArtifactId}: {localSWTVersion}")
localSWTVersion = getLocalSWTVersion(mvnArtifactId)

if version == "" :
anchorElement = soup.find(id="Latest_Release").find_next("a")
linkToVersionDownload = anchorElement['href']
version = anchorElement.text

Check warning

Code scanning / Pylintpython3 (reported by Codacy)

Variable name "localSWTVersion" doesn't conform to snake_case naming style Warning

Variable name "localSWTVersion" doesn't conform to snake_case naming style

Check warning

Code scanning / Pylint (reported by Codacy)

Variable name "localSWTVersion" doesn't conform to snake_case naming style Warning

Variable name "localSWTVersion" doesn't conform to snake_case naming style
print(f"Found download version: {version}")
else:
for link in soup.findAll('a', href=True):
Expand All @@ -155,17 +149,12 @@
break

print(f"Comparing versions - Local: '{localSWTVersion}', Download: '{version}'")
if forceUpdate == False \
and version.strip() == localSWTVersion.strip() \
and os.path.isdir(LOCAL_REPO_SAVE_DIR + "/local/swt/" + mvnArtifactId) :
if not forceUpdate and version.strip() == localSWTVersion.strip():
print(f"Skipping download for {mvnArtifactId} - version {version} already installed")
# Move the directory back to LOCAL_REPO_DIR since we're skipping the download
shutil.move(LOCAL_REPO_SAVE_DIR + "/local/swt/" + mvnArtifactId + "/", LOCAL_REPO_DIR + "/local/swt/" + mvnArtifactId)
return

if linkToVersionDownload == "" :
exitWithError("version " + version + " not found for download")


downloadsPage = URL + linkToVersionDownload
page = requests.get(downloadsPage)
Expand All @@ -190,19 +179,18 @@
version = arguments.version
rootdir = arguments.cloneroot
forceUpdate = arguments.force
localSWTVersion = ""

# Save the local SWT repo before proceeding to update
if os.path.isdir(LOCAL_REPO_DIR):
shutil.move(LOCAL_REPO_DIR + "/", LOCAL_REPO_SAVE_DIR)
# Create temporary directory for downloads
TEMP_DIR = tempfile.mkdtemp()
print(f"Created temporary directory: {TEMP_DIR}")

# Windows x86
updateSWT("swtwin32_x86_64", "Windows (x86 64-bit)", rootdir, version, forceUpdate)

# Windows ARM
updateSWT("swtwin32_aarch64", "Windows (ARM 64-bit)", rootdir, version, forceUpdate)

# Mac x86

Check warning

Code scanning / Pylintpython3 (reported by Codacy)

Variable name "localSWTVersion" doesn't conform to snake_case naming style Warning

Variable name "localSWTVersion" doesn't conform to snake_case naming style
updateSWT("swtmac_x86_64", "Mac OSX (x86 64-bit)", rootdir, version, forceUpdate)

# Mac ARM
Expand All @@ -214,9 +202,11 @@
# Linux ARM
updateSWT("swtlinux_aarch64", "Linux (ARM 64-bit)", rootdir, version, forceUpdate)

if os.path.isdir(LOCAL_REPO_SAVE_DIR):
shutil.rmtree(LOCAL_REPO_SAVE_DIR)
# Clean up temporary directory
if os.path.exists(TEMP_DIR):
shutil.rmtree(TEMP_DIR)

# Clean up any non-local directories in the local repo
for subdir in os.listdir(LOCAL_REPO_DIR):
if subdir != "local" :
shutil.rmtree(LOCAL_REPO_DIR + "/" + subdir)
if subdir != "local":
shutil.rmtree(os.path.join(LOCAL_REPO_DIR, subdir))
Loading