Changeset 1357 in products


Ignore:
Timestamp:
Nov 1, 2009 11:07:11 AM (14 years ago)
Author:
mylan
Message:

#108: Refactored theme vars storage, some cleanup

Location:
quintagroup.themetemplate/trunk
Files:
1 added
1 deleted
6 edited

Legend:

Unmodified
Added
Removed
  • quintagroup.themetemplate/trunk/docs/HISTORY.txt

    r1022 r1357  
    22========= 
    33 
    4 0.12 (unreleased) 
     40.14 (unreleased) 
    55----------------- 
    66 
    7 - Nothing changed yet. 
     7- Refactoring theme vars storage-now storing in separate 
     8  theme_vars.cfg file, without distutils writers [mylan] 
     9- Cleanup code [mylan] 
    810 
    911 
  • quintagroup.themetemplate/trunk/quintagroup/themetemplate/__init__.py

    r1005 r1357  
    11# 
    2 import os,types 
    3 from StringIO import StringIO 
    4 from ConfigParser import SafeConfigParser 
     2import os 
     3from paste.script import pluginlib 
    54 
    65from quintagroup.themetemplate.qplone3_theme import qPlone3Theme 
    76 
    8 def write_map(cmd, basename, filename, force=False): 
    9     argname = os.path.splitext(basename)[0] 
    10     value = getattr(cmd.distribution, argname, None) 
     7def getEggInfo(output_dir): 
     8    """ Return path to egg info directory, raise error if not found. 
     9    """ 
     10    egg_info = pluginlib.find_egg_info_dir(output_dir) 
     11    assert egg_info is not None, "egg_info directory must present for the package" 
    1112 
    12     if value: 
    13         config = SafeConfigParser() 
    14         config.add_section('qplone3_theme') 
    15         for name, val in value.items(): 
    16             val = val and str(val) or '' 
    17             config.set('qplone3_theme', name, val) 
    18  
    19         strvalue = StringIO() 
    20         config.write(strvalue) 
    21         value = strvalue.getvalue() 
    22  
    23     cmd.write_or_delete_file(argname, filename, value, force) 
     13    return egg_info 
    2414 
    2515 
    26 def assert_dict(dist, attr, value): 
    27     """Verify that value is a dict or None""" 
    28     try: 
    29         assert type(value) == types.DictType 
    30     except (TypeError,ValueError,AttributeError,AssertionError): 
    31         raise DistutilsSetupError( 
    32             "%r must be a dict (got %r)" % (attr,value) 
    33         ) 
     16def getThemeVarsFP(egg_info): 
     17    """ Return file system path to theme vars configurations 
     18    """ 
     19    return os.path.join(egg_info, '..', 'theme_vars.cfg') 
  • quintagroup.themetemplate/trunk/quintagroup/themetemplate/localcommands/__init__.py

    r1005 r1357  
    44import os 
    55from ConfigParser import SafeConfigParser 
    6 from paste.script import pluginlib 
    76 
    87from zopeskel.base import var 
    98from zopeskel.localcommands import ZopeSkelLocalTemplate 
     9 
     10from quintagroup.themetemplate import getEggInfo 
     11from quintagroup.themetemplate import getThemeVarsFP 
    1012 
    1113class QThemeSubTemplate(ZopeSkelLocalTemplate): 
     
    5860 
    5961        res = {} 
    60         egg_info = pluginlib.find_egg_info_dir(output_dir) 
    61         theme_vars_fp = os.path.join(egg_info, 'theme_vars.txt') 
     62        egg_info = getEggInfo(output_dir) 
     63        theme_vars_fp = getThemeVarsFP(egg_info) 
    6264 
    63         if egg_info and os.path.exists(theme_vars_fp): 
     65        if os.path.exists(theme_vars_fp): 
    6466            config = SafeConfigParser() 
    6567            config.read(theme_vars_fp) 
     
    7779    def add_template_vars(self, output_dir, vars): 
    7880 
    79         egg_info = pluginlib.find_egg_info_dir(output_dir) 
    80         theme_vars_fp = os.path.join(egg_info, 'theme_vars.txt') 
     81        egg_info = getEggInfo(output_dir) 
     82        theme_vars_fp = getThemeVarsFP(egg_info) 
    8183 
    82         if egg_info and os.path.exists(theme_vars_fp): 
     84        if os.path.exists(theme_vars_fp): 
    8385            config = SafeConfigParser() 
    8486            config.read(theme_vars_fp) 
  • quintagroup.themetemplate/trunk/quintagroup/themetemplate/localcommands/subtemplates.py

    r1005 r1357  
    88from zopeskel.base import var 
    99from zopeskel.localcommands import ZopeSkelLocalTemplate 
     10 
     11from quintagroup.themetemplate import getEggInfo 
     12from quintagroup.themetemplate import getThemeVarsFP 
    1013from quintagroup.themetemplate.localcommands import QThemeSubTemplate 
    1114 
     
    156159    def add_order_tag(self, output_dir, vars, pmarker): 
    157160        need_update = True 
    158         egg_info = pluginlib.find_egg_info_dir(output_dir) 
    159         theme_vars_fp = os.path.join(egg_info, 'theme_vars.txt') 
    160  
    161         if egg_info and os.path.exists(theme_vars_fp): 
     161        egg_info = getEggInfo(output_dir) 
     162        theme_vars_fp = getThemeVarsFP(egg_info) 
     163 
     164        if os.path.exists(theme_vars_fp): 
    162165            config = SafeConfigParser() 
    163166            config.read(theme_vars_fp) 
     
    215218    def add_hidden_tag(self, output_dir, vars, pmarker): 
    216219        add_hidden = True 
    217         egg_info = pluginlib.find_egg_info_dir(output_dir) 
    218         theme_vars_fp = os.path.join(egg_info, 'theme_vars.txt') 
    219  
    220         if egg_info and os.path.exists(theme_vars_fp): 
     220        egg_info = getEggInfo(output_dir) 
     221        theme_vars_fp = getThemeVarsFP(egg_info) 
     222 
     223        if os.path.exists(theme_vars_fp): 
    221224            config = SafeConfigParser() 
    222225            config.read(theme_vars_fp) 
  • quintagroup.themetemplate/trunk/quintagroup/themetemplate/templates/qplone3_theme/setup.py_tmpl

    r1005 r1357  
    4545      entry_points=""" 
    4646      # -*- entry_points -*- # 
    47  
    48       [distutils.setup_keywords] 
    49       paster_plugins = setuptools.dist:assert_string_list 
    50       theme_vars = distwriters:assert_dict 
    51  
    52       [egg_info.writers] 
    53       paster_plugins.txt = setuptools.command.egg_info:write_arg 
    54       theme_vars.txt = distwriters:write_map 
    55  
    5647      """, 
    5748      paster_plugins = ["ZopeSkel",], 
    5849      setup_requires = ["setuptools",], 
    59       theme_vars = {'skinname': '$skinname', 
    60           'skinbase'          : '$skinbase', 
    61           'namespace_package' : '$namespace_package', 
    62           'namespace_package2': '$namespace_package2', 
    63           'package'           : '$package', 
    64           'used_subtemplates' : '', 
    65       }, 
    6650      ) 
  • quintagroup.themetemplate/trunk/setup.py

    r1022 r1357  
    22import os 
    33 
    4 version = '0.12 dev' 
     4version = '0.14' 
    55 
    66tests_require=['zope.testing'] 
     
    4848          import_zexps = quintagroup.themetemplate.localcommands.subtemplates:ImportSubTemplate 
    4949 
    50           [distutils.setup_keywords] 
    51           theme_vars = quintagroup.themetemplate:assert_dict 
    52  
    53           [egg_info.writers] 
    54           theme_vars.txt = quintagroup.themetemplate:write_map 
    55  
    5650      # -*- Entry points: -*- 
    5751      """, 
Note: See TracChangeset for help on using the changeset viewer.