Best Python code snippet using localstack_python
wariety_app_updater.py
Source:wariety_app_updater.py  
1#!/usr/bin/env python2# -*- coding: UTF-8 -*-3# Wariety - A wallpaper manager for MS Windows operating system.4# Copyright (C) 2021  Roland Rickborn <wariety@gmx.net>5#6# This program is free software: you can redistribute it and/or modify7# it under the terms of the GNU General Public License as published by8# the Free Software Foundation, version 3 of the License.9#10# This program is distributed in the hope that it will be useful,11# but WITHOUT ANY WARRANTY; without even the implied warranty of12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the13# GNU General Public License for more details.14#15# You should have received a copy of the GNU General Public License16# along with this program.  If not, see https://www.gnu.org/licenses/.17import logging18import re19import sys20import threading21import requests22from pubsub import pub23logger = logging.getLogger(__name__)24def get_remote_version():25    """26    :return:27    """28    logger.debug('get_remote_version()')29    # Static URL to Wariety main at Github30    url = 'https://github.com/gitRigge/Wariety/blob/master/wariety/wariety.py'31    ret_val = '0.0.0'32    version_search = '(__version__).*([0-9]\.[0-9]\.[0-9])'33    status_search1 = '(__status__).*'34    status_search2 = '"([^&]*)"'35    response = requests.get(url)36    result1 = re.search(version_search, response.text)37    result2 = re.search(status_search1, response.text)38    if result1:39        ret_val = result1.group(2)40    else:41        ret_val = '0.0.0'42    _status = ''43    if result2:44        result3 = re.search(status_search2, result2.group(0))45        if result3:46            _status = result3.group(1)47        else:48            _status = 'Test'  # TODO Replace with "ENUM"49    else:50        _status = 'Test'  # TODO Replace with "ENUM"51    if _status != 'Release':  # TODO Replace with "ENUM"52        ret_val = '0.0.0'53    return ret_val54def is_update_available(local_version_str, remote_version_str):55    """56    Compares the local version given by 'local_version_str' with57    the remote version given by 'remote_version_str'. Returns True58    if the remote version is higher than the local version. Otherwise,59    returns False.60    :param local_version_str:61    :param remote_version_str:62    :return ret_val:63    """64    logger.debug('is_update_available({}, {})'.format(local_version_str, remote_version_str))65    ret_val = False66    local_version = 067    try:68        local_version = int(local_version_str.replace('.', ''))69        logger.debug('is_update_available() - local version = {}'.format(local_version))70    except:71        local_version = 072    remote_version = 073    try:74        remote_version = int(remote_version_str.replace('.', ''))75        logger.debug('is_update_available() - remote version = {}'.format(remote_version))76    except:77        remote_version = 078    if remote_version > local_version:79        ret_val = True80    else:81        ret_val = False82    return ret_val83def push_app_update(self):84    """85    Sends 'show app update' message86    :return:87    """88    logger.debug('push_app_update()')89    pub.sendMessage("show app update", event='')90def push_version_str(self, msg, update_available):91    """92    Sends 'show version str' message93    :return:94    """95    logger.debug('push_version_str()')96    pub.sendMessage("show version str", event='', msg=msg, update_available=update_available)97class WarietyAppUpdaterThread(threading.Thread):98    """docstring for WarietyAppUpdaterThread"""99    def __init__(self, show_balloon=False, show_version_str=False):100        """Init Worker Thread Class."""101        logger.debug('Starting app updater thread')102        logger.debug('__init__()')103        self.my_version = ''104        self.show_balloon = show_balloon105        self.show_version_str = show_version_str106        threading.Thread.__init__(self)107        if getattr(sys, 'frozen', False):108            import wariety.wariety109            self.my_version = wariety.wariety.__version__110        else:111            from wariety import __version__112            self.my_version = __version__113        self.start()114    def run(self):115        """Run Worker Thread."""116        logger.debug('run()')117        remote_version = get_remote_version()118        is_updateable = is_update_available(self.my_version, remote_version)119        if is_updateable:120            if self.show_balloon:121                push_app_update(self)122            if self.show_version_str:123                push_version_str(self, remote_version, is_updateable)124        else:125            remote_version = self.my_version126            if self.show_version_str:...check.py
Source:check.py  
...40    @property41    def v_latest(self):42        raise NotImplementedError()43    @property44    def is_updateable(self):45        if self.v_current is None or self.v_latest is None:46            return False47        48        return version.parse(self.v_latest) > version.parse(self.v_current)49    50    @property51    def update_dir(self):52        53        install_dir = dirs.INSTALL_DIR54        v_latest    = self.v_latest55        update_dir = install_dir / f'{install_dir.name}_{v_latest}'56        return update_dir57class RemoteUpdateContext(UpdateContext):58    def __init__(self, data):59        super().__init__()60        self.data = data61    @property62    def v_latest(self):63        return self.data['tag_name']64    @property65    def asset_url(self):66        67        assets     = self.data['assets']68        zip_assets = [a for a in assets if a['content_type'] == ZIP_FILE_TYPE]69        if len(zip_assets) == 0:70            return None71        zip_url = zip_assets[0]['url']72        return zip_url73    74    def download(self):75        try:76            url     = self.asset_url77            headers = {78                'Accept': 'application/octet-stream'79            }80        81            utils.log('Downloading zip file:', url)82            r = requests.get(url, headers=headers)83            r.raise_for_status()84            zip_data = BytesIO()85            zip_data.write(r.content)86            return zip_data87        except:88            raise Exception('Unable to download the zip file.  Contact your local tech support.')89    90class LocalUpdateContext(UpdateContext):91    def __init__(self, is_updateable):92        super().__init__()93        self.conf = UPDATE_CONF.local94        95        self.file = self.conf.file.resolve()96        self._is_updateable = is_updateable97        self._time          = time.time()98    def download(self):99        zip_file = Path(self.file)100        zip_data = BytesIO()101        zip_data.write(zip_file.read_bytes())102        return zip_data103    104    @property105    def v_latest(self):106        return self.conf.version.resolve()107    @property108    def update_dir(self):109        dir = super().update_dir110        111        return dir.parent / f'{dir.name}_{self._time}'112    @property113    def is_updateable(self):...extras.py
Source:extras.py  
...11    folio: Optional[int] = None12    description: Optional[str] = None13    balance_id: Optional[UUID] = None14    @property15    def is_updateable(self) -> bool:16        if self.balance_id:17            return False18        return True19class EntryMixin(BaseMixin):20    """Basic entry mixin"""21    22    amount: int23    issuer: str    24    date_received: Arrow25    transaction_type: TransactionType = TransactionType.CASH26    folio: Optional[int] = None27    description: Optional[str] = None    28    balance_id: Optional[UUID] = None29    @property30    def is_updateable(self) -> bool:31        if self.balance_id:32            return False...Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
