Skip to content
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

add --update option #693

Merged
merged 5 commits into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
13 changes: 12 additions & 1 deletion umake/frameworks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import pkgutil
import sys
import subprocess
import re
from umake.network.requirements_handler import RequirementsHandler
from umake.settings import DEFAULT_INSTALL_TOOLS_PATH, UMAKE_FRAMEWORKS_ENVIRON_VARIABLE, DEFAULT_BINARY_LINK_PATH
from umake.tools import ConfigHandler, NoneDict, classproperty, get_current_arch, get_current_distro_version,\
Expand Down Expand Up @@ -140,7 +141,7 @@ class BaseFramework(metaclass=abc.ABCMeta):
def __init__(self, name, description, category, force_loading=False, logo_path=None, is_category_default=False,
install_path_dir=None, only_on_archs=None, only_ubuntu=False, only_ubuntu_version=None,
packages_requirements=None, only_for_removal=False, expect_license=False,
need_root_access=False, json=False, override_install_path=None):
need_root_access=False, json=False, override_install_path=None, version_regex=None):
self.name = name
self.description = description
self.logo_path = None
Expand All @@ -153,6 +154,8 @@ def __init__(self, name, description, category, force_loading=False, logo_path=N
self.packages_requirements.extend(self.category.packages_requirements)
self.only_for_removal = only_for_removal
self.expect_license = expect_license
self.version_regex = version_regex
self.forbidden_to_update = False
Copy link
Contributor Author

@NicolasKeita NicolasKeita Jan 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

    self.forbidden_to_update = False

This was my way of preventing an update on some frameworks like Intellij.
Set by default at False then overridden in the class BaseJetBrains for example.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would have used it the other way around, keeping the default as not updatable, and setting a framework to updatable explicitly. This way we only add information for those that have this functionality.

What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After thinking about it, I 100% agree with you. I have committed these changes 👍

# self.override_install_path = "" if override_install_path is None else override_install_path

# don't detect anything for completion mode (as we need to be quick), so avoid opening apt cache and detect
Expand Down Expand Up @@ -331,6 +334,14 @@ def run_for(self, args):
auto_accept_license=auto_accept_license,
dry_run=dry_run)

def get_latest_version(self):
return (re.search(self.version_regex, self.package_url).group(1).replace('_', '.')
if self.package_url and self.version_regex else None)

@staticmethod
def get_current_user_version(install_path):
return None

Copy link
Contributor Author

@NicolasKeita NicolasKeita Jan 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding two default methods for each framework.
get_latest_version() is getting the version from parsing the download_url.
get_current_user_version() is overridden in each of the framework. It is checking the installed files (like VERSION.txt for example) to fetch the version.


class MainCategory(BaseCategory):

Expand Down
15 changes: 6 additions & 9 deletions umake/frameworks/android.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ def __init__(self, **kwargs):
checksum_type=ChecksumType.sha256,
dir_to_decompress_in_tarball="android-studio",
desktop_filename="android-studio.desktop",
required_files_path=[os.path.join("bin", "studio.sh")], **kwargs)
required_files_path=[os.path.join("bin", "studio.sh")],
version_regex='(\d+\.\d+)',
**kwargs)

def parse_license(self, line, license_txt, in_license):
"""Parse Android Studio download page for license"""
Expand All @@ -108,20 +110,15 @@ def post_install(self):
categories="Development;IDE;",
extra="StartupWMClass=jetbrains-studio"))

def parse_latest_version_from_package_url(self):
return (re.search(r'(\d+\.\d+)', self.package_url).group(1)
if self.package_url else 'Missing information')

@staticmethod
def get_current_user_version(install_path):
try:
with open(os.path.join(install_path, 'product-info.json'), 'r') as file:
data = json.load(file)
version_not_formatted = data.get('dataDirectoryName', 'Missing information')
match = re.search(r'\d+\.\d+', version_not_formatted)
return match.group() if match else 'Missing information'
version_not_formatted = data.get('dataDirectoryName')
return re.search(r'\d+\.\d+', version_not_formatted).group() if version_not_formatted else None
except FileNotFoundError:
return 'Missing information'
return


class AndroidSDK(umake.frameworks.baseinstaller.BaseInstaller):
Expand Down
7 changes: 0 additions & 7 deletions umake/frameworks/crystal.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,3 @@ def post_install(self):
"""Add Crystal necessary env variables"""
add_env_to_user(self.name, {"PATH": {"value": os.path.join(self.install_path, "bin")}})
UI.delayed_display(DisplayMessage(self.RELOGIN_REQUIRE_MSG.format(self.name)))

def parse_latest_version_from_package_url(self):
return 'Missing information'

@staticmethod
def get_current_user_version(install_path):
return 'Missing information'
12 changes: 5 additions & 7 deletions umake/frameworks/dart.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ def __init__(self, **kwargs):
"stable/release/latest/VERSION",
dir_to_decompress_in_tarball="dart-sdk",
required_files_path=[os.path.join("bin", "dart")],
json=True, **kwargs)
json=True,
version_regex='/(\d+\.\d+\.\d+)',
**kwargs)

arch_trans = {
"amd64": "x64",
Expand All @@ -79,17 +81,13 @@ def post_install(self):
add_env_to_user(self.name, {"PATH": {"value": os.path.join(self.install_path, "bin")}})
UI.delayed_display(DisplayMessage(self.RELOGIN_REQUIRE_MSG.format(self.name)))

def parse_latest_version_from_package_url(self):
return (re.search(r'/(\d+\.\d+\.\d+)', self.package_url).group(1)
if self.package_url else 'Missing information')

@staticmethod
def get_current_user_version(install_path):
try:
with open(os.path.join(install_path, 'version'), 'r') as file:
return file.readline().strip() if file else 'Missing information'
return file.readline().strip() if file else None
except FileNotFoundError:
return 'Missing information'
return


class FlutterLang(umake.frameworks.baseinstaller.BaseInstaller):
Expand Down
14 changes: 6 additions & 8 deletions umake/frameworks/devops.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ def __init__(self, **kwargs):
download_page="https://api.github.com/repos/hashicorp/terraform/releases/latest",
dir_to_decompress_in_tarball=".",
required_files_path=["terraform"],
json=True, **kwargs)
json=True,
version_regex='/(\d+\.\d+\.\d+)',
**kwargs)

arch_trans = {
"amd64": "amd64",
Expand All @@ -69,17 +71,13 @@ def post_install(self):
add_env_to_user(self.name, {"PATH": {"value": os.path.join(self.install_path)}})
UI.delayed_display(DisplayMessage(self.RELOGIN_REQUIRE_MSG.format(self.name)))

def parse_latest_version_from_package_url(self):
return (re.search(r'/(\d+\.\d+\.\d+)', self.package_url).group(1)
if self.package_url else 'Missing information')

@staticmethod
def get_current_user_version(install_path):
file = os.path.join(install_path, 'terraform')
command = f"{file} --version"
try:
result = subprocess.check_output(command, shell=True, text=True)
match = re.search(r'Terraform\s+v(\d+\.\d+\.\d+)', result)
return match.group(1) if match else 'Missing information'
except subprocess.CalledProcessError as e:
return 'Missing information'
return match.group(1) if match else None
except subprocess.CalledProcessError:
return
24 changes: 3 additions & 21 deletions umake/frameworks/electronics.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,6 @@ def post_install(self):
UI.return_main_screen(status_code=1)
UI.delayed_display(DisplayMessage(_("You need to logout and login again for your installation to work")))

def parse_latest_version_from_package_url(self):
return 'Missing information'

@staticmethod
def get_current_user_version(install_path):
return 'Missing information'




class ArduinoLegacy(umake.frameworks.baseinstaller.BaseInstaller):
Expand Down Expand Up @@ -183,13 +175,6 @@ def post_install(self):
UI.return_main_screen(status_code=1)
UI.delayed_display(DisplayMessage(_("You need to logout and login again for your installation to work")))

def parse_latest_version_from_package_url(self):
return 'Missing information'

@staticmethod
def get_current_user_version(install_path):
return 'Missing information'


class Eagle(umake.frameworks.baseinstaller.BaseInstaller):

Expand All @@ -200,6 +185,7 @@ def __init__(self, **kwargs):
desktop_filename="eagle.desktop",
required_files_path=["eagle"],
dir_to_decompress_in_tarball="eagle-*",
version_regex=r'/(\d+(?:_\d+)*)/',
**kwargs)

def parse_download_link(self, line, in_download):
Expand All @@ -220,17 +206,13 @@ def post_install(self):
comment=self.description,
categories="Development;"))

def parse_latest_version_from_package_url(self):
return re.search(r'/(\d+(?:_\d+)*)/', self.package_url).group(1). \
replace('_', '.') if self.package_url else 'Missing information'

@staticmethod
def get_current_user_version(install_path):
try:
with open(os.path.join(install_path, 'bin', 'eagle.def'), 'r') as file:
return re.search(r'(\d+(\.\d+)+)', next(file)).group(1) if file else 'Missing information'
return re.search(r'(\d+(\.\d+)+)', next(file)).group(1) if file else None
except FileNotFoundError:
return 'Missing information'
return


class Fritzing(umake.frameworks.baseinstaller.BaseInstaller):
Expand Down
42 changes: 11 additions & 31 deletions umake/frameworks/games.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,12 @@ def parse_download_link(self, line, in_download):
"""Parse Blender download links"""
url = None
if 'linux-x64.tar.xz' in line:
p = re.search(r'href=\"https:\/\/www\.blender\.org\/download(.*linux-x64\.tar\.xz).?"', line)
url = "https://mirrors.dotsrc.org/blender/" + p.group(1)
print(url)
p = re.search(r'href=\"(https:\/\/www\.blender\.org\/.*linux-x64\.tar\.xz).?"', line)
with suppress(AttributeError):
url = p.group(1)
filename = 'release' + re.search('blender-(.*)-linux', url).group(1).replace('.', '') + '.md5'
self.checksum_url = os.path.join(os.path.dirname(url),
filename).replace('download', 'release').replace('www', 'download')
return ((url, None), in_download)

def post_install(self):
Expand All @@ -76,13 +79,6 @@ def post_install(self):
comment=self.description,
categories="Development;IDE;Graphics"))

def parse_latest_version_from_package_url(self):
return 'Missing information'

@staticmethod
def get_current_user_version(install_path):
return 'Missing information'


class Unity3D(umake.frameworks.baseinstaller.BaseInstaller):

Expand Down Expand Up @@ -137,13 +133,6 @@ def save_icon(self, download_result):
shutil.copy(icon, os.path.join(self.install_path, self.icon_name))
logger.debug("Copied icon: {}".format(self.icon_url))

def parse_latest_version_from_package_url(self):
return 'Missing information'

@staticmethod
def get_current_user_version(install_path):
return 'Missing information'


class Superpowers(umake.frameworks.baseinstaller.BaseInstaller):

Expand All @@ -154,7 +143,9 @@ def __init__(self, **kwargs):
dir_to_decompress_in_tarball='superpowers*',
desktop_filename="superpowers.desktop",
required_files_path=["Superpowers"],
json=True, **kwargs)
json=True,
version_regex='/v(\d+\.\d+\.\d+)',
**kwargs)

arch_trans = {
"amd64": "x64",
Expand All @@ -179,17 +170,13 @@ def post_install(self):
comment=self.description,
categories="Development;IDE;"))

def parse_latest_version_from_package_url(self):
return (re.search(r'/v(\d+\.\d+\.\d+)', self.package_url).group(1)
if self.package_url else 'Missing information')

@staticmethod
def get_current_user_version(install_path):
try:
with open(os.path.join(install_path, 'version'), 'r') as file:
return file.readline().strip() if file else 'Missing information'
return file.readline().strip() if file else None
except FileNotFoundError:
return 'Missing information'
return


class GDevelop(umake.frameworks.baseinstaller.BaseInstaller):
Expand Down Expand Up @@ -252,10 +239,3 @@ def save_icon(self, download_result):
icon = download_result.pop(self.icon_url).fd.name
shutil.copy(icon, os.path.join(self.install_path, self.icon_filename))
logger.debug("Copied icon: {}".format(self.icon_url))

def parse_latest_version_from_package_url(self):
return 'Missing information'

@staticmethod
def get_current_user_version(install_path):
return 'Missing information'
9 changes: 3 additions & 6 deletions umake/frameworks/go.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def __init__(self, **kwargs):
checksum_type=ChecksumType.sha256,
dir_to_decompress_in_tarball="go",
required_files_path=[os.path.join("bin", "go")],
version_regex=r'go(\d+(\.\d+)+)',
**kwargs)

arch_trans = {
Expand Down Expand Up @@ -94,14 +95,10 @@ def post_install(self):
"GOROOT": {"value": self.install_path, "keep": False}})
UI.delayed_display(DisplayMessage(self.RELOGIN_REQUIRE_MSG.format(self.name)))

def parse_latest_version_from_package_url(self):
return (re.search(r'go(\d+(\.\d+)+)', self.package_url).group(1)
if self.package_url else 'Missing information')

@staticmethod
def get_current_user_version(install_path):
try:
with open(os.path.join(install_path, 'VERSION'), 'r') as file:
return re.search(r'go(\d+(\.\d+)+)', next(file)).group(1) if file else 'Missing information'
return re.search(r'go(\d+(\.\d+)+)', next(file)).group(1) if file else None
except FileNotFoundError:
return 'Missing information'
return
Loading