From 44531bd09786407c1198618a7a7dd8495975238e Mon Sep 17 00:00:00 2001 From: Arnaud Alies Date: Mon, 9 Dec 2019 22:21:02 +0100 Subject: [PATCH] REVERT CHANGES --- examples/test_gitlab_gui bitbucket.py | 24 ------ iquail/solution/__init__.py | 1 - iquail/solution/solution_bitbucket.py | 102 -------------------------- iquail/solution/solution_gitlab.py | 22 ++++-- tests/test_misc.py | 9 +-- 5 files changed, 20 insertions(+), 138 deletions(-) delete mode 100644 examples/test_gitlab_gui bitbucket.py delete mode 100644 iquail/solution/solution_bitbucket.py diff --git a/examples/test_gitlab_gui bitbucket.py b/examples/test_gitlab_gui bitbucket.py deleted file mode 100644 index 7e86353..0000000 --- a/examples/test_gitlab_gui bitbucket.py +++ /dev/null @@ -1,24 +0,0 @@ -#!/usr/bin/python3 - -import iquail - -if not iquail.helper.OS_WINDOWS: - raise AssertionError("This test solution is windows only") - -iquail.run( - solution=iquail.SolutionBitBucket( - "cmder_mini.zip", "https://bitbucket.org/artous/cmder/downloads/"), - installer=iquail.Installer( - publisher='cmderdev', - name='Cmder', - icon='Cmder.exe', - binary='Cmder.exe', - console=False, - launch_with_quail=True - ), - builder=iquail.builder.Builder( - iquail.builder.CmdIcon('icon.ico'), - iquail.builder.CmdNoconsole() - ), - controller=iquail.ControllerTkinter(eula="This is a test") -) diff --git a/iquail/solution/__init__.py b/iquail/solution/__init__.py index a2b0c73..c8ecbea 100644 --- a/iquail/solution/__init__.py +++ b/iquail/solution/__init__.py @@ -3,4 +3,3 @@ from .solution_zip import SolutionZip from .solution_packed import SolutionPacked from .solution_gitlab import SolutionGitLab -from .solution_bitbucket import SolutionBitBucket diff --git a/iquail/solution/solution_bitbucket.py b/iquail/solution/solution_bitbucket.py deleted file mode 100644 index 27e994b..0000000 --- a/iquail/solution/solution_bitbucket.py +++ /dev/null @@ -1,102 +0,0 @@ -import os -import json -import re -import os -import shutil -import ssl -import tempfile -import urllib.request -from pprint import pprint - -from ..errors import * -from ..helper import cache_result -from .solution_base import SolutionBase -from .solution_zip import SolutionZip - -ssl._create_default_https_context = ssl._create_unverified_context - - -class SolutionBitBucket(SolutionBase): - """ BitBucket solution - Find zip solutions on bitbucket - """ - - def __init__(self, zip_name, repo_url): - super().__init__() - self._solution_zip = None - self._repo_url = repo_url - self._zip_name = zip_name - - @cache_result - def _parse_bitbucket_url(self): - """Parse bitbucket url, returns tuple: - (repo_owner, repo_name) - """ - re1 = '.*?' # Non-greedy match on filler - re2 = '(?:[a-z][a-z0-9_]*)' # Uninteresting: var - re3 = '.*?' # Non-greedy match on filler - re4 = '(?:[a-z][a-z0-9_]*)' # Uninteresting: var - re5 = '.*?' # Non-greedy match on filler - re6 = '(?:[a-z][a-z0-9_]*)' # Uninteresting: var - re7 = '.*?' # Non-greedy match on filler - re8 = '((?:[a-z][a-z0-9_]*))' # Variable Name 1 - re9 = '.*?' # Non-greedy match on filler - re10 = '((?:[a-z][a-z0-9_]*))' # Variable Name 2 - - rg = re.compile(re1+re2+re3+re4+re5+re6+re7+re8 + - re9+re10, re.IGNORECASE | re.DOTALL) - m = rg.search(self._repo_url) - owner = m.group(1) - repo_name = m.group(2) - return (owner, repo_name) - - def _get_zip_url(self): - return "%s/downloads/%s" % (self._repo_url, self._zip_name) - - def get_version_string(self): - owner, repo_name = self._parse_bitbucket_url() - try: - response = urllib.request.urlopen("https://api.bitbucket.org/2.0/repositories/%s/%s/downloads/" % (owner, repo_name)) - data = response.read() - encoding = response.info().get_content_charset("utf-8") - downloads = json.loads(data.decode(encoding)) - except Exception as e: - raise SolutionUnreachableError("SolutionBitBucket get release") from e - if not downloads: - raise SolutionUnreachableError("No releases") - for download in downloads['values']: - if download['name'] is self._zip_name: - return download['created_on'] - raise SolutionUnreachableError("Can not find release file on remote source") - - def local(self): - return False - - def open(self): - zip_url = self._get_zip_url() - self._update_progress(percent=0, - status="downloading", - log="Downloading file:\n" + zip_url + "\n") - - def hook(count, block_size, total_size): - self._update_progress(percent=count / (total_size / block_size) * 100, - status="downloading") - try: - (zip_file, headers) = urllib.request.urlretrieve(zip_url, - reporthook=hook) - except Exception as e: - raise SolutionUnreachableError( - "Solution bitbucket retrieve error") from e - self._solution_zip = SolutionZip(zip_file) - self._solution_zip.set_progress_hook(self._progress_hook) - return self._solution_zip.open() - - def close(self): - if self._solution_zip: - self._solution_zip.close() - - def walk(self): - return self._solution_zip.walk() - - def retrieve_file(self, relative_path): - return self._solution_zip.retrieve_file(relative_path) diff --git a/iquail/solution/solution_gitlab.py b/iquail/solution/solution_gitlab.py index 3a9b9ab..176c496 100644 --- a/iquail/solution/solution_gitlab.py +++ b/iquail/solution/solution_gitlab.py @@ -34,15 +34,15 @@ def _parse_gitlab_url(self): (repo_owner, repo_name) """ re1 = '.*?' # Non-greedy match on filler - re2 = '(?:[a-z][a-z0-9_]*)' # Uninteresting: var + re2 = '(?:[a-z][a-z]+)' # Uninteresting: word re3 = '.*?' # Non-greedy match on filler - re4 = '(?:[a-z][a-z0-9_]*)' # Uninteresting: var + re4 = '(?:[a-z][a-z]+)' # Uninteresting: word re5 = '.*?' # Non-greedy match on filler - re6 = '(?:[a-z][a-z0-9_]*)' # Uninteresting: var + re6 = '(?:[a-z][a-z]+)' # Uninteresting: word re7 = '.*?' # Non-greedy match on filler - re8 = '((?:[a-z][a-z0-9_]*))' # Variable Name 1 + re8 = '((?:[a-z][a-z]+))' # Word 1 re9 = '.*?' # Non-greedy match on filler - re10 = '((?:[a-z][a-z0-9_]*))' # Variable Name 2 + re10 = '((?:[a-z][a-z0-9_]*))' # Variable Name 1 rg = re.compile(re1+re2+re3+re4+re5+re6+re7+re8 + re9+re10, re.IGNORECASE | re.DOTALL) @@ -61,7 +61,7 @@ def _get_zip_url(self, release): m = rg.search(release['description']) file_path = m.group(1) owner, repo_name = self._parse_gitlab_url() - return "https://gitlab.com/%s/%s/%s" % (owner, repo_name, file_path) + return "https://gitlab.com/" + owner + '/' + repo_name + '/' + file_path @cache_result def _get_releases(self): @@ -114,3 +114,13 @@ def walk(self): def retrieve_file(self, relative_path): return self._solution_zip.retrieve_file(relative_path) + + +p = SolutionGitLab( + "cmder_mini.zip", "https://gitlab.com/Artous/quail_cmder_test", 14938606) +url = p._get_release_url() +print("release url : " + url) + +url = p._get_zip_url(p._get_last_release()) +print("zip url : " + url) + diff --git a/tests/test_misc.py b/tests/test_misc.py index 4832b36..fc45341 100644 --- a/tests/test_misc.py +++ b/tests/test_misc.py @@ -50,10 +50,9 @@ def test_rerun_as_admin(self): ctypes.windll.shell32.ShellExecuteW = MagicMock() mock = ctypes.windll.shell32.ShellExecuteW return # TODO test disabled - sys.argv = [os.path.abspath('./test.py')] + sys.argv = ['./test.py'] misc.rerun_as_admin(False) - mock.assert_called_with('sudo', ['sudo', os.path.abspath('./test.py')]) - sys.argv = [os.path.abspath('./bin')] - misc.rerun_as_admin(True, './bin') - mock.assert_called_with('pkexec', ['pkexec', './dir/bin', '--iquail_install_polkit']) + mock.assert_called_with('sudo', ['sudo', './test.py']) + misc.rerun_as_admin(True, '/dir/', '/bin') + mock.assert_called_with('pkexec', ['pkexec', '/bin', '--iquail_path', '/dir/'])