Changeset 4688

Show
Ignore:
Timestamp:
06/08/08 10:05:27 (6 months ago)
Author:
deets
Message:

added version handling stuff, tests and docuementation

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • projects/tgMochiKit/trunk/README.txt

    r4684 r4688  
    121121    This setting selects the version of the MochiKit library that the 
    122122    ``turbogears.mochikit`` widget will use. tgMochiKit currently ships 
    123     with version 1.3.1 and a snapshot of the 1.4 development version. 
     123    with version 1.3.1 and several snapshots of the 1.4 development version. 
    124124 
    125125``tg_mochikit.packed -- False`` 
     
    132132    ``MochiKit.js`` file. 
    133133 
     134``tg_mochikit.draganddrop -- False`` 
     135    Selects whether the ``turbogears.mochikit`` widget should include the 
     136    ``DragAndDrop.js`` file. 
     137 
     138Version selection 
     139----------------- 
     140 
     141The selection of a proper version of MochiKit is a bit more elaborated due to  
     142the fact that MockiKit hasn't had a proper 1.4 release for a few years now. 
     143 
     144tgMochiKit ships with various versions of MochKit. 
     145 
     146 - the stable 1.3.1 version, as used by the TurboGears 1.0.x series. 
     147 - various snapshots of the 1.4 version from the subversion. 
     148 - the ``trunk``, also a subversion snapshot, which reflects the 
     149   version inside trunk at the time of the tgMochiKit release you are using. 
     150 
     151You can get the shipped versions by doing ::: 
     152 
     153  >>> import tgmochikit 
     154  >>> print tgmochikit.get_shipped_versions() 
     155 
     156 
     157Now when using tgMochiKit, the problem of which version to chose arises.  
     158 
     159If you want 1.3.1, just configure that as version to chose. 
     160 
     161If you want a specific version that is shipped, configure that. This is the 
     162safe course of action for you application, because by this you ensure that 
     163even if you install newer versions of tgMochiKit (which might happen due 
     164to TurboGears upgrades), you will end up with code you verified that it works. 
     165 
     166If you feel confident that using the latest of MochiKit is ok for you, configure 
     167``tg_mochikit.version`` to be ``1.4``. This will always pick the newest from the  
     168pack. 
     169 
     170The ``trunk``-version is something special. In the shipped tgMochiKit it will always 
     171be equal to the latest 1.4 version. 
     172 
     173However, if you want the latest from trunk, you can simply  
     174 
     175 - check out tgMochiKit. This will fetch the latest from trunk into the distribution 
     176 - create your own tgMochiKit.egg, and use that for your application. 
     177 
     178The version actually used by tgMochiKit based on your configuration is by the way 
     179logged on the logger ``tgmochikit`` with level ``INFO`` with the text:: 
     180 
     181  Version chosen: <version> 
    134182 
    135183Installation 
  • projects/tgMochiKit/trunk/tgmochikit/base.py

    r4683 r4688  
     1import pkg_resources 
     2 
     3import os 
    14import glob 
    2 import os 
     5import logging 
    36 
    4 import pkg_resources 
     7logger = logging.getLogger(".".join(__name__.split(".")[:-1])) 
    58 
    69VERSION = '1.3.1' 
     
    1316DRAGANDDROP = False 
    1417 
    15 def init(register_static_directory, version=None, packed=None, xhtml=None, draganddrop=None): 
     18def init(register_static_directory, config={}, version=None, packed=None, xhtml=None, draganddrop=None): 
    1619    """Initializes the MochiKit resources. 
    1720 
     
    3235        if draganddrop is not None: 
    3336            DRAGANDDROP = draganddrop 
    34         import turbogears.config 
    3537        INITIALIZED = True 
    36         PACKED = turbogears.config.get('tg_mochikit.packed', PACKED) 
    37         VERSION = turbogears.config.get('tg_mochikit.version', VERSION) 
    38         XHTML = turbogears.config.get('tg_mochikit.xhtml', XHTML) 
    39         DRAGANDDROP = turbogears.config.get('tg_mochikit.draganddrop', DRAGANDDROP) 
     38        PACKED = config.get('tg_mochikit.packed', PACKED) 
     39        VERSION = config.get('tg_mochikit.version', VERSION) 
     40        XHTML = config.get('tg_mochikit.xhtml', XHTML) 
     41        DRAGANDDROP = config.get('tg_mochikit.draganddrop', DRAGANDDROP) 
    4042 
    41         js_dir = pkg_resources.resource_filename("tgmochikit", 
    42             "static/javascript/%s" % VERSION) 
    43  
     43        is_131 = '1.3.1' in VERSION 
     44        js_base_dir = pkg_resources.resource_filename("tgmochikit", 
     45            "static/javascript/") 
     46        # we check for all the versions in the js_base_dir and fetch the 
     47        # one that matches best. If several candidates exist, the best is the latest. 
     48        candidates = glob.glob(os.path.join(js_base_dir, "%s*" % VERSION)) 
     49        candidates.sort() 
     50        js_dir = candidates[-1] 
     51        logger.info("MochiKit version chosen: %s", os.path.basename(js_dir)) 
    4452        path = os.path.join(js_dir, "unpacked", "*.js") 
    4553        for name in glob.glob(path): 
     
    5765                    res.append("unpacked/%s" % submodule) 
    5866            PATHS = res 
    59         if DRAGANDDROP
     67        if DRAGANDDROP and not is_131
    6068            PATHS.append("unpacked/DragAndDrop.js") 
    6169 
    6270def get_paths(): 
    6371    return PATHS 
     72 
     73 
     74def get_shipped_versions(): 
     75    js_base_dir = pkg_resources.resource_filename("tgmochikit", 
     76                                                  "static/javascript/") 
     77    return [os.path.basename(p) for p in glob.glob(os.path.join(js_base_dir, "*"))] 
     78     
  • projects/tgMochiKit/trunk/tgmochikit/__init__.py

    r4604 r4688  
    1 from tgmochikit.base import init, get_paths 
     1from tgmochikit.base import init, get_paths, get_shipped_versions 
    22 
    33__all__ = [ 
    44    "init", 
    5     "get_paths" 
     5    "get_paths", 
     6    "get_shipped_versions", 
    67]