-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
175 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.direnv |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,35 @@ | ||
{ | ||
description = "A flake for a Python development environment with requests package"; | ||
description = "A devShell example"; | ||
|
||
inputs = { | ||
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; | ||
flake-utils.url = "github:numtide/flake-utils"; | ||
}; | ||
|
||
outputs = | ||
{ self, nixpkgs }: | ||
{ | ||
devShells.default = nixpkgs.lib.mkShell { | ||
packages = with nixpkgs; [ | ||
python310 | ||
(python310Packages.requests) # Add the requests package | ||
]; | ||
}; | ||
}; | ||
nixpkgs, | ||
flake-utils, | ||
... | ||
}: | ||
flake-utils.lib.eachDefaultSystem ( | ||
system: | ||
let | ||
pkgs = import nixpkgs { inherit system; }; | ||
in | ||
with pkgs; | ||
{ | ||
devShells.default = mkShell { | ||
buildInputs = [ | ||
python310 | ||
(python310Packages.requests) | ||
]; | ||
|
||
shellHook = '' | ||
alias ls=eza | ||
alias find=fd | ||
''; | ||
}; | ||
} | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import re | ||
import requests | ||
|
||
base_url = 'https://download.eclipse.org/jdtls/milestones/' | ||
|
||
def get_latest_version(): | ||
milestones_res = requests.get(base_url, allow_redirects=True) | ||
if(milestones_res.status_code != 200): | ||
raise Exception('Failed to get all versions from milestones page') | ||
version_match_regex = r"<a href='(.*?)'> (\d*.\d*.\d*.)</a>" | ||
matches = re.findall(version_match_regex, milestones_res.text) | ||
versions = [match[1] for match in matches] | ||
|
||
sorted_versions = sorted(versions, key=lambda x: list(map(int, x.split('.')))) | ||
return sorted_versions[-1] | ||
version = get_latest_version() | ||
print(version) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import re | ||
import requests | ||
from urllib.parse import urljoin | ||
import urllib.request | ||
import tarfile | ||
import os | ||
import tempfile | ||
from shutil import move, copyfile | ||
|
||
base_url = 'https://download.eclipse.org/jdtls/milestones/' | ||
|
||
def get_latest_version(): | ||
milestones_res = requests.get(base_url, allow_redirects=True) | ||
if(milestones_res.status_code != 200): | ||
raise Exception('Failed to get all versions from milestones page') | ||
version_match_regex = r"<a href='(.*?)'> (\d*.\d*.\d*.)</a>" | ||
matches = re.findall(version_match_regex, milestones_res.text) | ||
versions = [match[1] for match in matches] | ||
|
||
sorted_versions = sorted(versions, key=lambda x: list(map(int, x.split('.')))) | ||
return sorted_versions[-1] | ||
|
||
def get_jdtls_download_url(version): | ||
url = urljoin(base_url, f'{version}/latest.txt') | ||
pkg_name_res = requests.get(url) | ||
file_name = pkg_name_res.text.strip() | ||
return urljoin(base_url, f'{version}/{file_name}') | ||
|
||
def get_equinox_launcher_name(version): | ||
plugins_res = requests.get(f"https://download.eclipse.org/jdtls/milestones/{version}/repository/plugins/") | ||
pattern = r"<a .*?>(org.eclipse.equinox.launcher_.*?.jar)</a>" | ||
matches = re.findall(pattern, plugins_res.text) | ||
|
||
if len(matches) < 1: | ||
raise Exception('Could not find the equinox launcher plugin') | ||
|
||
if len(matches) > 1: | ||
raise Exception('Found more than one equinox launcher plugin') | ||
|
||
return matches[0] | ||
|
||
def download_file(url): | ||
with tempfile.TemporaryDirectory() as tmp: | ||
res = requests.get(url) | ||
file_path = urljoin(tmp, 'jdtls.tar.gz') | ||
with open(file_path, 'wb') as file: | ||
file.write(res.content) | ||
return file_path | ||
|
||
def extract_tar_gz(tar_gz_path, equinox_plugin_path): | ||
with tarfile.open(tar_gz_path, "r:gz") as tar: | ||
with tempfile.TemporaryDirectory() as tmp: | ||
ex_dir = f'{tmp}/jdtls' | ||
tar.extractall(path=ex_dir) | ||
move(f'{ex_dir}/plugins/{equinox_plugin_path}', f'{ex_dir}/plugins/org.eclipse.equinox.launcher.jar') | ||
with tempfile.TemporaryDirectory() as tmpout: | ||
out_path = f'{tmpout}/jdtls.tar.gz' | ||
with tarfile.open(out_path, "w:gz") as tarout: | ||
for file in os.listdir(ex_dir): | ||
tarout.add(f'{ex_dir}/{file}',arcname=file, recursive=True) | ||
copyfile(f'{tmpout}/jdtls.tar.gz', '/home/s1n7ax/Downloads/Test/jdtls.tar.gz') | ||
|
||
|
||
version = get_latest_version() | ||
download_url = get_jdtls_download_url(version) | ||
equinox_plugin_path = get_equinox_launcher_name(version) | ||
downloaded_path = download_file(download_url) | ||
extract_tar_gz(downloaded_path, equinox_plugin_path) |