Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
dvershinin committed Sep 24, 2023
1 parent 422480e commit 8ac55df
Show file tree
Hide file tree
Showing 10 changed files with 74 additions and 32 deletions.
1 change: 1 addition & 0 deletions lastversion/BitBucketRepoSession.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def __init__(self, repo, hostname):
self.set_repo(repo)

def get_latest(self, pre_ok=False, major=None):
"""Get the latest release."""
response = self.get("https://api.bitbucket.org/2.0/repositories/{}/downloads".format(
self.repo))
data = response.json()
Expand Down
1 change: 1 addition & 0 deletions lastversion/FeedRepoSession.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ def __init__(self, repo, hostname):
self.feed_url = feeds[0]

def get_latest(self, pre_ok=False, major=None):
"""Get the latest release."""
ret = None
# to leverage cachecontrol, we fetch the feed using requests as usual,
# then feed the feed to feedparser as a raw string
Expand Down
1 change: 0 additions & 1 deletion lastversion/GitHubRepoSession.py
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,6 @@ def set_matching_formal_release(self, ret, formal_release, version, pre_ok,
if not found_asset:
log.info('Desired asset not found in the release.')
return ret
# formal_release['tag_name'] = tag_name
formal_release['tag_date'] = parser.parse(formal_release['published_at'])
formal_release['version'] = version
formal_release['type'] = data_type
Expand Down
1 change: 1 addition & 0 deletions lastversion/GitLabRepoSession.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def get_formal_release_for_tag(self, tag):
return self.formal_releases_by_tag.get(tag)

def get_latest(self, pre_ok=False, major=None):
"""Get the latest release."""
ret = None

# gitlab returns tags by updated in desc order, this is just what we want :)
Expand Down
1 change: 0 additions & 1 deletion lastversion/GiteaRepoSession.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,6 @@ def set_matching_formal_release(self, ret, formal_release, version, pre_ok,
if not found_asset:
log.info('Desired asset not found in the release.')
return ret
# formal_release['tag_name'] = tag_name
formal_release['tag_date'] = parser.parse(formal_release['published_at'])
formal_release['version'] = version
formal_release['type'] = data_type
Expand Down
1 change: 1 addition & 0 deletions lastversion/HelmChartRepoSession.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def __init__(self, repo, hostname=None):
self.url = repo

def get_latest(self, pre_ok=False, major=None):
"""Get the latest release."""
# https://github.com/bitnami/charts/blob/master/bitnami/aspnet-core/Chart.yaml
# https://raw.githubusercontent.com/bitnami/charts/master/bitnami/aspnet-core/Chart.yaml
url = self.url
Expand Down
1 change: 1 addition & 0 deletions lastversion/LocalVersionSession.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def __init__(self, repo, hostname):
self.hostname = hostname

def get_latest(self, pre_ok=False, major=None):
"""Get the latest release."""
if pre_ok:
log.info('--pre is not supported for local version sources')
if not major:
Expand Down
4 changes: 1 addition & 3 deletions lastversion/ProjectHolder.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,10 +254,8 @@ def sanitize_version(self, version_s, pre_ok=False, major=None):
for s in matches:
version_s = s[0]
log.info("Sanitized tag name value to %s.", version_s)
# 1.10.x is a dev release without a clear version, so even pre ok will not get it
#if not version_s.endswith('.x'):
# now we may have gotten a non-version like 2.x, so let's try to parse it
try:
# we know regex is a valid version format, so no need to try catch
res = Version(version_s)
except InvalidVersion:
log.info("Failed to parse %s as Version.", version_s)
Expand Down
1 change: 1 addition & 0 deletions lastversion/SourceForgeRepoSession.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def get_normalized_url(download_url):
return None

def get_latest(self, pre_ok=False, major=None):
"""Get the latest release."""
ret = None
# to leverage cachecontrol, we fetch the feed using requests as usual
# then feed the feed to feedparser as a raw string
Expand Down
94 changes: 67 additions & 27 deletions lastversion/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,53 @@ class BadProjectError(Exception):
'mips64', 'ppc64', 'mips64le', 'ppc64le', 'aarch64', 'armhf', 'armv7hl']


def is_file_ext_not_compatible_with_os(file_ext):
"""
Check if the file extension is not compatible with the OS
Returns:
"""
for os_name, ext in os_extensions.items():
if os.name != os_name and file_ext == ext:
return True
return False


def is_asset_name_compatible_with_platform(asset_name):
"""Check if an asset's name contains words that indicate it's meant for another platform"""
for pf, pf_words in platform_markers.items():
if not sys.platform.startswith(pf):
for pf_word in pf_words:
r = re.compile(r'\b{}(\d+)?\b'.format(pf_word), flags=re.IGNORECASE)
matches = r.search(asset_name)
if matches:
return True
return False


def is_not_compatible_to_distro(asset_ext):
"""Check if the file extension is not compatible with the current Linux distro"""
# Weeding out non-matching Linux distros
if asset_ext != 'AppImage':
for ext, ext_distros in extension_distros.items():
if asset_ext == ext and distro.id() not in ext_distros:
return True

return False


def not_amd64_asset(asset_name):
"""Check if an asset's name contains words that indicate it's not meant for 64-bit OS"""
for non_amd64_word in non_amd64_markers:
r = re.compile(r'\b{}\b'.format(non_amd64_word), flags=re.IGNORECASE)
if r.search(asset_name):
return True
r = re.compile(r'\barm\d+\b', flags=re.IGNORECASE)
if r.search(asset_name):
return True
return False


def asset_does_not_belong_to_machine(asset_name):
"""
Check if asset's name contains words that indicate it's not meant for this machine
Expand All @@ -65,34 +112,27 @@ def asset_does_not_belong_to_machine(asset_name):
# replace underscore with dash so that our shiny word boundary regexes won't break
asset_name = asset_name.replace('_', '-')
asset_ext = os.path.splitext(asset_name)[1].lstrip('.')
# bail if asset's extension "belongs" to other OS (simple)
if asset_ext:
for os_name, ext in os_extensions.items():
if os.name != os_name and asset_ext == ext:
return True
for pf, pf_words in platform_markers.items():
if not sys.platform.startswith(pf):
for pf_word in pf_words:
r = re.compile(r'\b{}(\d+)?\b'.format(pf_word), flags=re.IGNORECASE)
matches = r.search(asset_name)
if matches:
return True
if sys.platform.startswith('linux'):
# Weeding out non-matching Linux distros
if asset_ext != 'AppImage':
for ext, ext_distros in extension_distros.items():
if asset_name.endswith("." + ext) and distro.id() not in ext_distros:
return True

if not asset_ext:
# We don't know. Maybe compatible, maybe not. Let's not filter it out.
return False

# Bail if asset's extension "belongs" to other OS (simple)
if is_file_ext_not_compatible_with_os(asset_ext):
return True

if is_asset_name_compatible_with_platform(asset_name):
return True

# Bail if asset's extension "belongs" to other linux distros (complex)
if sys.platform.startswith('linux') and is_not_compatible_to_distro(asset_ext):
return True

# weed out non-64 bit stuff from x86_64 bit OS
# caution: may be false positive with 32-bit Python on 64-bit OS
if platform.machine() in ['x86_64', 'AMD64']:
for non_amd64_word in non_amd64_markers:
r = re.compile(r'\b{}\b'.format(non_amd64_word), flags=re.IGNORECASE)
if r.search(asset_name):
return True
r = re.compile(r'\barm\d+\b', flags=re.IGNORECASE)
if r.search(asset_name):
return True
if platform.machine() in ['x86_64', 'AMD64'] is not_amd64_asset(asset_name):
return True

return False


Expand Down Expand Up @@ -136,7 +176,7 @@ def extract_appimage_desktop_file(appimage_path):

# Search the temporary directory for the .desktop file
desktop_file = None
for root, dirs, files in os.walk(temp_dir):
for root, _, files in os.walk(temp_dir):
for file in files:
if file.endswith(".desktop"):
desktop_file = os.path.join(root, file)
Expand Down

0 comments on commit 8ac55df

Please sign in to comment.