Changeset d8e9cb2325469b3c2eb53e85bca47650b14a8822


Ignore:
Timestamp:
11/22/10 14:43:16 (18 months ago)
Author:
Luper Rouch <luper.rouch@…>
Children:
a9600c54b979c31276a8cb1ebde6f86a1fad96b1, cf7994aa7727099d65825b7d6e36b7077d59ad18
Parents:
bad98400ae7869c9fbc79bec7e188fd66356b64c
git-committer:
Luper Rouch <luper.rouch@…> (11/22/10 14:43:16)
Message:

pyflu.update:

  • qt update dialog mixin class supports non-fixed progress bar and label widgets names
  • sending signals.not_updated when appropriate so listeners can react appropriately (e.g. show main window)
  • passing on HTTP errors when checking the update URL
Location:
pyflu/pyflu/update
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • pyflu/pyflu/update/qt.py

    rbad9840 rd8e9cb2  
    55import re 
    66import louie 
     7import urllib2 
    78from PyQt4.QtGui import * 
    89from PyQt4.QtCore import *     
     
    1213from pyflu.update.remote import find_patches_groups 
    1314from pyflu.update.version import Version 
     15from pyflu.qt.util import get_or_create_app 
    1416 
    1517 
     
    3941    patch_dl_dir = None 
    4042    patch_target_dir = None 
     43    progress_bar_name = "progress_bar" 
     44    operation_label_name = "operation_label" 
    4145 
    4246    def start_update(self, confirm=True): 
     
    4549 
    4650        If *confirm* is True, a confirmation dialog is shown before starting 
    47         the update. 
    48         """ 
     51        the update. The :class:`~pyflu.update.signals.not_updated` signal is 
     52        sent if no update was performed (either because there was no update 
     53        available or the user refused to apply it). 
     54        """ 
     55        # Check for updates 
    4956        self.patches_paths = [] 
    50         QDialog.show(self) 
    51         # Check for updates if we are running a frozen executable 
    5257        self.start_long_operation( 
    5358                self.trUtf8("Searching for updates..."), 1) 
     
    6873                self._download_next() 
    6974                return 
    70             else: 
    71                 self._exit(0) 
    72                 return 
     75        louie.send(signals.not_updated, self) 
    7376 
    7477    def start_long_operation(self, text, length): 
    75         self.operation_label.setText(text) 
    76         self.progress_bar.setValue(0) 
    77         self.progress_bar.setRange(0, length) 
     78        pb = getattr(self, self.progress_bar_name) 
     79        ol = getattr(self, self.operation_label_name) 
     80        ol.setText(text) 
     81        pb.setValue(0) 
     82        pb.setRange(0, length) 
     83        app = get_or_create_app() 
     84        app.processEvents() 
    7885 
    7986    def update_long_operation(self, index): 
    80         self.progress_bar.setValue(index) 
     87        pb = getattr(self, self.progress_bar_name) 
     88        pb.setValue(index) 
     89        app = get_or_create_app() 
     90        app.processEvents() 
    8191 
    8292    def _download_next(self): 
     93        pb = getattr(self, self.progress_bar_name) 
     94        ol = getattr(self, self.operation_label_name) 
    8395        # Open download file object 
    8496        self.download_url = self.download_queue.pop(0)         
    8597        fname = basename(self.download_url) 
    8698        self.save_path = join(self.patch_dl_dir, fname) 
    87         self.operation_label.setText(self.trUtf8("Downloading '%1'") 
    88                 .arg(fname)) 
    89         self.progress_bar.setValue(0) 
     99        ol.setText(self.trUtf8("Downloading '%1'").arg(fname)) 
     100        pb.setValue(0) 
    90101        self.file = QFile(self.save_path) 
    91102        self.file.open(QFile.ReadWrite) 
     
    99110 
    100111    def _update_download_progress(self, received, total): 
    101         self.progress_bar.setRange(0, total) 
    102         self.progress_bar.setValue(received) 
     112        pb = getattr(self, self.progress_bar_name) 
     113        pb.setRange(0, total) 
     114        pb.setValue(received) 
    103115 
    104116    def _flush_download(self): 
     
    191203        latest version. 
    192204        """ 
    193         groups = find_patches_groups(self.update_url, 
    194                 re.compile(self.patch_files_pattern)) 
    195         # Find patches chain entry point 
    196         current_version = Version(self.current_version) 
    197         group = groups.get(current_version, []) 
    198         return [x[2] for x in group] 
     205        try: 
     206            groups = find_patches_groups(self.update_url, 
     207                    re.compile(self.patch_files_pattern)) 
     208        except urllib2.HTTPError, err: 
     209            pb = getattr(self, self.progress_bar_name) 
     210            ol = getattr(self, self.operation_label_name) 
     211            pb.setValue(0) 
     212            ol.setText(self.trUtf8("Error opening update url: %1") 
     213                    .arg(unicode(err)))                 
     214        else: 
     215            # Find patches chain entry point 
     216            current_version = Version(self.current_version) 
     217            group = groups.get(current_version, []) 
     218            return [x[2] for x in group] 
    199219 
    200220 
    201221__all__ = ["StartupDialog"] 
    202  
    203  
  • pyflu/pyflu/update/signals.py

    r77bf72f rd8e9cb2  
    99    It receives a single argument, containing the path of the patched files. 
    1010    """ 
     11 
     12 
     13class not_updated(Signal): 
     14    """ 
     15    Sent by :meth:`~pyflu.update.qt.UpdateDialogMixin.start_update` when no 
     16    update was performed. 
     17    """ 
Note: See TracChangeset for help on using the changeset viewer.