Changeset 1281
- Timestamp:
- 09/17/08 13:07:50
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
qtheme.template/trunk/qthemetemplate/__init__.py
r1176 r1281 1 1 # 2 import os,types 3 from StringIO import StringIO 4 from ConfigParser import SafeConfigParser 5 2 6 from qthemetemplate.qplone3_theme import qPlone3Theme 7 8 def write_map(cmd, basename, filename, force=False): 9 argname = os.path.splitext(basename)[0] 10 value = getattr(cmd.distribution, argname, None) 11 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) 24 25 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 print 'success assert' 31 except (TypeError,ValueError,AttributeError,AssertionError): 32 raise DistutilsSetupError( 33 "%r must be a dict (got %r)" % (attr,value) 34 ) qtheme.template/trunk/qthemetemplate/localcommands/__init__.py
r1251 r1281 3 3 """ 4 4 import os 5 from ConfigParser import SafeConfigParser 6 from paste.script import pluginlib 7 5 8 from zopeskel.base import var 6 9 from zopeskel.localcommands import ZopeSkelLocalTemplate … … 16 19 # (compotemplate_name, compo marker), for ex.: 17 20 compo_template_markers = [] 21 # list vars names to add in theme_vars egg_info file 22 shared_vars = [] 18 23 19 24 def template_dir(self): … … 26 31 return super(QThemeSubTemplate, self).template_dir() 27 32 33 def pre(self, command, output_dir, vars): 34 """ Get all previous template vars 35 """ 36 for k, v in self.get_template_vars(output_dir, vars).items(): 37 if not k in vars.keys(): 38 vars[k] = v 39 super(QThemeSubTemplate, self).pre(command, output_dir, vars) 40 28 41 def post(self, command, output_dir, vars): 29 42 """ Call write_files function for every subtemplate, … … 31 44 - set compose prop for change subtemplate path calculation 32 45 """ 33 34 46 if self.compo_template_markers: 35 47 for cname, cmarker in self.compo_template_markers: … … 40 52 self._template_dir = original_template_dir 41 53 54 self.add_template_vars(output_dir, vars) 42 55 super(QThemeSubTemplate, self).post(command, output_dir, vars) 43 56 57 def get_template_vars(self, output_dir, vars): 58 59 res = {} 60 egg_info = pluginlib.find_egg_info_dir(output_dir) 61 theme_vars_fp = os.path.join(egg_info, 'theme_vars.txt') 62 63 if egg_info and os.path.exists(theme_vars_fp): 64 config = SafeConfigParser() 65 config.read(theme_vars_fp) 66 67 for section in config.sections(): 68 for option in config.options(section): 69 key = section + '.' + option 70 val = config.get(section, option) 71 if section == 'multiple_templates': 72 val = val.split(',') 73 res[key] = val 74 75 return res 76 77 def add_template_vars(self, output_dir, vars): 78 79 if not self.shared_vars: 80 return 81 82 egg_info = pluginlib.find_egg_info_dir(output_dir) 83 theme_vars_fp = os.path.join(egg_info, 'theme_vars.txt') 84 85 if egg_info and os.path.exists(theme_vars_fp): 86 config = SafeConfigParser() 87 config.read(theme_vars_fp) 88 89 thesection = self.name 90 if config.has_section(thesection): 91 msection = 'multiple_templates' 92 moption = self.name 93 94 if not config.has_section(msection): 95 config.add_section(msection) 96 97 val = [] 98 if config.has_option(msection, moption): 99 val = config.get(msection, moption).split(',') 100 else: 101 val.append(moption) 102 thesection = "%s_%d"%(moption,len(val)) 103 val.append(thesection) 104 105 config.set(msection, moption, ','.join(val)) 106 107 config.add_section(thesection) 108 for k in self.shared_vars: 109 config.set(thesection, k, vars[k]) 110 111 theme_file = file(theme_vars_fp,'w') 112 config.write(theme_file) 113 theme_file.close() qtheme.template/trunk/qthemetemplate/templates/qplone3_theme/setup.py_tmpl
r1245 r1281 48 48 [distutils.setup_keywords] 49 49 paster_plugins = setuptools.dist:assert_string_list 50 theme_vars = qthemetemplate:assert_dict 50 51 51 52 [egg_info.writers] 52 53 paster_plugins.txt = setuptools.command.egg_info:write_arg 54 theme_vars.txt = qthemetemplate:write_map 55 53 56 """, 54 57 paster_plugins = ["ZopeSkel", "PasteScript"], 55 setup_requires = ["setuptools", "ZopeSkel", "PasteScript"], 58 setup_requires = ["setuptools", "ZopeSkel", "PasteScript", "qtheme.template"], 59 theme_vars = {'skinname': '$skinname', 60 'skinbase' : '$skinbase', 61 'namespace_package' : '$namespace_package', 62 'namespace_package2': '$namespace_package2', 63 'package' : '$package', 64 65 }, 56 66 ) qtheme.template/trunk/setup.py
r1259 r1281 33 33 viewlet_hidden = qthemetemplate.localcommands.subtemplates:ViewletHiddenSubTemplate 34 34 35 [distutils.setup_keywords] 36 theme_vars = qthemetemplate:assert_dict 37 38 [egg_info.writers] 39 theme_vars.txt = qthemetemplate:write_map 40 35 41 # -*- Entry points: -*- 36 42 """,
