Changeset 77bf72ffc703e0c38bd368f20c9eb99ac02ff316


Ignore:
Timestamp:
11/18/10 17:27:03 (18 months ago)
Author:
Luper Rouch <luper.rouch@…>
Children:
36ddc5be7316607eb8f7801ba2f59b4dd331d05c
Parents:
6e701d84a43b80d129ed34ee062f6f6abe14a7b7
git-committer:
Luper Rouch <luper.rouch@…> (11/18/10 17:27:03)
Message:

pyflu: new mixin class to create update dialogs in Qt

Location:
pyflu
Files:
19 added
6 edited

Legend:

Unmodified
Added
Removed
  • pyflu/pyflu/__init__.py

    rd784e4c r77bf72f  
    55 
    66def version(): 
    7     return "0.6.7" 
     7    return "0.7" 
    88 
  • pyflu/pyflu/tests/test_update/__init__.py

    rfd03e3e r77bf72f  
    11import os 
     2from nose.tools import assert_true 
    23from os.path import dirname, join, isdir, isfile 
    34from pyflu.update import patch, diff, sub_path, control_sum, \ 
    45        InvalidOriginalFile, InvalidResultingFile, IncompatiblePatchFormat, \ 
    56        archive_path 
     7from pyflu.update.version import Version 
    68import shutil 
    79 
     
    1820 
    1921 
    20 def one_way_compare(d1, d2, visited): 
     22def one_way_compare(d1, d2, visited=None): 
     23    """ 
     24    Compare directory *d2* against *d1* for removal and changes. 
     25 
     26    Raise an error if a file present in *d1* is not found or is different from 
     27    the one found in *d2*, but ignores files present in *d2* and not in *d1*. 
     28    """ 
     29    if visited is None: 
     30        visited = {} 
    2131    for base, dirs, files in os.walk(d1): 
    2232        sub_dir = sub_path(base, d1) 
     
    91101 
    92102 
    93 def teardown(): 
     103def test_version(): 
     104    version_groups = [[ 
     105        "1.0", 
     106        "1.0a", 
     107        "1.0beta", 
     108        "1.0pre", 
     109        "1.0pre2", 
     110        "1.1", 
     111        "1.1.2", 
     112        "1.1.2_3", 
     113        "1.1.2_10", 
     114    ], 
     115    [ 
     116        "r1-flap" 
     117        "r1234" 
     118        "r12345-final" 
     119    ]] 
     120    for group in version_groups: 
     121        prev = None 
     122        for version in group: 
     123            obj = Version(version) 
     124            if prev is not None: 
     125                assert_true(obj > prev) 
     126            prev = obj 
     127 
     128 
     129def setup(): 
    94130    if isdir(tmp_dir): 
    95131        shutil.rmtree(tmp_dir) 
  • pyflu/pyflu/update/__init__.py

    r231ef65 r77bf72f  
    22import os 
    33import hashlib 
    4 from os.path import join, commonprefix, isfile, isdir, dirname 
     4from os.path import join, commonprefix, isfile, isdir, dirname, basename 
    55from pyflu.path import sub_path 
    66import bsdiff 
     
    343343 
    344344 
    345 if __name__ == "__main__": 
    346     if len(sys.argv) != 5: 
    347         usage() 
     345def makepatch(): 
     346    """ 
     347    Entry points for the create patch command line script. 
     348    """ 
     349    try: 
     350        olddir, newdir, patchfile = sys.argv[1:] 
     351    except: 
     352        print >>sys.stderr, ("usage: %s olddir newdir patchfile"  
     353                % basename(sys.argv[0])) 
    348354        sys.exit(1) 
    349     if sys.argv[1] == "diff": 
    350         diff(*sys.argv[2:]) 
    351     elif sys.argv[1] == "patch": 
    352         patch(*sys.argv[2:]) 
    353     else: 
    354         usage() 
    355         sys.exit(1) 
     355    diff(patchfile, olddir, newdir) 
     356    sys.exit(0) 
  • pyflu/pyflu/update/remote.py

    rf0cace8 r77bf72f  
    33from lxml import etree 
    44from os.path import join, basename 
     5from urlparse import urljoin 
    56from pyflu.update.version import Version 
    6 from urlparse import urljoin 
     7from pyflu.odict import odict 
    78 
    89 
    9 def patches_chain(url, updates_pattern): 
     10def find_patches_groups(url, updates_pattern): 
    1011    """ 
    11     Retrieves the list of _consecutive_ patches on an HTML page. 
     12    Retrieves groups of _consecutive_ patches in an HTML page. 
    1213     
    13     The links are parsed from the HTML page found at ``url``. Links not 
    14     matching the regular expression ``updates_pattern`` are filtered. 
    15     ``updates_pattern`` must define two groups named 'from' and 'to', isolating 
    16     the versions numbers of the update. 
     14    The links are parsed from the HTML page found at *url*. Links not 
     15    matching the regular expression *updates_pattern* are filtered. 
     16    *updates_pattern* must define two groups named 'from' and 'to', isolating 
     17    the version numbers of the update. 
    1718 
    18     Returns a list of tuples containing 'from' and 'to' versions and the update 
    19     file URL. 
    20  
    21     A ValueError is raised if the chain of versions is not continuous.  
     19    Returns an :class:`~pyflu.odict.odict` object, containing lists of update 
     20    chains (updates that can be applied successively to update from a version 
     21    to another), indexed by the first :class:`~pyflu.update.version.Version`  
     22    object of the chain. 
    2223    """ 
    23     # Make sure the url has a trailing slash 
    24     if not url.endswith("/"): 
    25         url += "/" 
    26     # Get links 
     24    # Get links from the HTML update page 
    2725    parser = etree.HTMLParser() 
    2826    doc = etree.parse(urllib2.urlopen(url), parser) 
     
    3836                Version(match.group("to")),  
    3937                href)) 
    40     # Verify updates chain continuity 
     38    # Create version groups 
    4139    updates.sort(key=lambda x: x[0]) 
    4240    last_version = None 
    43     missing_updates = [] 
     41    groups = odict() 
     42    current_group = [] 
    4443    for from_version, to_version, url in updates: 
    4544        if last_version is not None: 
    4645            if from_version != last_version: 
    47                 missing_updates.append((last_version, from_version)) 
     46                groups[current_group[0][0]] = current_group 
     47                current_group = [] 
    4848        last_version = to_version 
    49     if missing_updates: 
    50         raise ValueError("missing udpates:\n%s" %  
    51                 "\n".join(["%s => %s" % (f, t) for f, t in missing_updates])) 
    52     return updates 
     49        current_group.append((from_version, to_version, url)) 
     50    if current_group: 
     51        groups[current_group[0][0]] = current_group 
     52    return groups 
  • pyflu/pyflu/update/version.py

    r8e8dabb r77bf72f  
    1616         1.1 
    1717         1.1.2 
     18         1.1.2_3 
     19         1.1.2_10 
    1820     * snapshot versions, composed by a revision number and an optional branch 
    1921       specifier. The branch specifier is ignored in comparisons: 
     
    3436        if match: 
    3537            self.is_release = True 
    36             self.release_numbers = [int(n) for n in  
    37                     match.group("release").split(".")] 
     38            self.release_numbers = tuple(int(n) for n in  
     39                    match.group("release").split(".")) 
    3840            self.release_suffix = match.group("suffix") 
     41            if "_" in self.release_suffix: 
     42                pre, rev = self.release_suffix.rsplit("_", 1) 
     43                rev = int(rev) 
     44            else: 
     45                pre = self.release_suffix 
     46                rev = 0 
     47            self.release_suffix = (pre, rev) 
    3948        else: 
    4049            match = self.snapshot_pattern.match(version_string) 
     
    7584    def __str__(self): 
    7685        return self.version_string 
     86 
     87    def __hash__(self): 
     88        if self.is_release: 
     89            return hash((self.release_numbers, self.release_suffix)) 
     90        return hash(self.snapshot_revision) 
  • pyflu/setup.py

    r3532e9f r77bf72f  
    3131 
    3232    packages = find_packages(), 
     33 
     34    entry_points = { 
     35        "console_scripts": ["pyflu-makepatch = pyflu.update:makepatch"], 
     36    }, 
    3337) 
Note: See TracChangeset for help on using the changeset viewer.