def traverse ( o, data ): children = [ ] for k, v in o.attrs.items ( ): o.attrs [ k ] = sTemplate ( v ).safe_substitute ( data ) for idx, c in enumerate ( o.children ): if isinstance ( c, Tag ): children.append ( traverse ( copy ( c ), data ) ) elif isinstance ( c, basestring ): children.append ( sTemplate ( c ).safe_substitute ( data ) ) o.children = children return o
def traverse(o, data): children = [] for k, v in sorted(o.attrs.items()): o.attrs[k] = sTemplate(v).safe_substitute(data) for c in o.children: if isinstance(c, Tag): children.append(traverse(copy(c), data)) elif isinstance(c, str): children.append(sTemplate(c).safe_substitute(data)) o.children = children return o
def generate(self, progress=None): if progress == None: def p(val): pass progress = p # gather informations gen = self.generators() files = self.files() steps = 2 + len(files) + len(gen) progress(1 * 100 / steps) # mkdir path = os.path.join( "platforms", '-'.join((str(self.base), str(self.configuration)))) if os.path.isdir(path): shutil.rmtree(path) if any(files + gen): os.makedirs(path) progress(2 * 100 / steps) # writing files num = 2 for f in files: if f.type == None: fdir = path ffile = os.path.join(path, f.name) else: fdir = os.path.join(path, f.type) ffile = os.path.join(path, f.type, f.name) if not os.path.isdir(fdir): os.makedirs(fdir) file = open(ffile, "w") file.write( sTemplate(f.data.strip()).safe_substitute({ 'template': self.base, 'configuration': self.configuration })) #file.write(f.data) num += 1 progress(num * 100 / steps) # generating files for f in gen: if f.path == None: fdir = path ffile = os.path.join(path, f.name) else: fdir = os.path.join(path, f.path) ffile = os.path.join(path, f.path, f.name) if not os.path.isdir(fdir): os.makedirs(fdir) file = open(ffile, "w") file.write( f.generate(self.getModel(), self.base, self.configuration)) num += 1 progress(num * 100 / steps)
def generate(self, model, base = "", conf = ""): def gen(base, node): result = {} var = '_'.join((base,str(node.getVar()))).strip('_').strip() result[var] = str(node.getValue().toString()) for i in range(node.childCount()): result.update(gen(var, node.child(i))) return result result = {} result.update(gen('', model.rootItem.child(0))) result.update({'template':base, 'configuration':conf}) return sTemplate(self.data.strip()+'\n').safe_substitute(result)
def generate(self, model, base="", conf=""): def gen(base, node): result = {} var = '_'.join((base, str(node.getVar()))).strip('_').strip() result[var] = str(node.getValue().toString()) for i in range(node.childCount()): result.update(gen(var, node.child(i))) return result result = {} result.update(gen('', model.rootItem.child(0))) result.update({'template': base, 'configuration': conf}) return sTemplate(self.data.strip() + '\n').safe_substitute(result)
def generate(self, progress = None): if progress == None: def p(val): pass progress = p # gather informations gen = self.generators() files = self.files() steps = 2 + len(files) + len(gen) progress(1 * 100 / steps) # mkdir path = os.path.join("platforms", '-'.join((str(self.base), str(self.configuration)))) if os.path.isdir(path): shutil.rmtree(path) if any(files + gen): os.makedirs(path) progress(2 * 100 / steps) # writing files num = 2 for f in files: if f.type == None: fdir = path ffile = os.path.join(path, f.name) else: fdir = os.path.join(path, f.type) ffile = os.path.join(path, f.type, f.name) if not os.path.isdir(fdir): os.makedirs(fdir) file = open(ffile, "w") file.write(sTemplate(f.data.strip()).safe_substitute({'template':self.base, 'configuration':self.configuration})) #file.write(f.data) num += 1 progress(num * 100 / steps) # generating files for f in gen: if f.path == None: fdir = path ffile = os.path.join(path, f.name) else: fdir = os.path.join(path, f.path) ffile = os.path.join(path, f.path, f.name) if not os.path.isdir(fdir): os.makedirs(fdir) file = open(ffile, "w") file.write(f.generate(self.getModel(), self.base, self.configuration)) num += 1 progress(num * 100 / steps)