def process(self, block, context): # filename or content element if 'filename' in block: filename = context.processTextCmds(block['filename']).strip() data = cmn_utils_fs.deserialize(os.path.join(block['_path'], filename)) elif 'content' in block: data = block['content'] else: return [] if 'select' in block: selectCmd = context.processTextCmds(block['select']).strip() data = cmn_utils_di.selectSubset(data, selectCmd) # alias element alias = block['alias'] # level element, default 1 setGlobal = self.getElemValue(block, 'global', False) if alias in context.resources: context.resources[alias].update(data) else: context.resources[alias] = data if setGlobal: context.docInfo.update(data) # return empty list return []
def __init__(self, aSourcePath, aOutputPath, extPluginFolders=[], dumpContent=False): self.chrono = timer() self.dumpContentFlag = dumpContent self.pluginMng = PluginManager() self.pluginMng.addPluginFolder( os.path.join(os.path.dirname(__file__), '../plugins/')) for extPluginFolder in extPluginFolders: self.pluginMng.addPluginFolder(extPluginFolder) self.pluginMng.loadPlugins() # Load general prefs docInfos = cmn_utils_fs.deserialize( os.path.join(aSourcePath, "doc_info.yaml")) self.context = NWProcContext(docInfos, aSourcePath, aOutputPath, self.prepareBlocks, self.processBlocks) self.context.addResource( 'noWordInfo', {'name': meta.__name__, 'version': meta.__version__}) self.context.addResource( 'buildInfo', { 'timestamp': datetime.datetime.now().isoformat(), 'builder': getpass.getuser()}) self.overrideValues( 'styles', self.context.styleSheet, self.context.docInfo) self.doc = NWDocument(self.context.docInfo, self.context.styleSheet) self.context.doc = self.doc enabledDecorations = self.context.docInfo["decorations"] if "decorations" in self.context.docInfo else [] additionalDecorations = self.context.docInfo["additionalDecorations"] if "additionalDecorations" in self.context.docInfo else [] availableDecorations = list(set(enabledDecorations).union(set(additionalDecorations))) for deco in availableDecorations: if hasattr(NoWordDecoration, deco): self.doc.addDecoration(getattr(NoWordDecoration, deco), deco in enabledDecorations) # Load transformations from DefaultTransformation availableTransformations = NoWordTransformation.availableTransformations() for transfo in availableTransformations: if hasattr(NoWordTransformation, transfo): self.doc.addTransformation(getattr(NoWordTransformation, transfo), transfo)
def __init__(self, aSourcePath, aOutputPath, extPluginFolders=[], dumpContent=False): self.dumpContentFlag = dumpContent self.pluginMng = PluginManager() self.pluginMng.addPluginFolder( os.path.join(os.path.dirname(__file__), '../plugins/')) for extPluginFolder in extPluginFolders: self.pluginMng.addPluginFolder(extPluginFolder) self.pluginMng.loadPlugins() # Load general prefs docInfos = cmn_utils_fs.deserialize( os.path.join(aSourcePath, "doc_info.yaml")) self.context = NWProcContext(docInfos, aSourcePath, aOutputPath, self.prepareBlocks, self.processBlocks) self.context.addResource('noWordInfo', { 'name': meta.__name__, 'version': meta.__version__ }) self.context.addResource( 'buildInfo', { 'timestamp': datetime.datetime.now().isoformat(), 'builder': getpass.getuser() }) self.overrideValues('styles', self.context.styleSheet, self.context.docInfo) self.doc = NWDocument(self.context.docInfo, self.context.styleSheet) self.context.doc = self.doc if 'decorations' in self.context.docInfo: decorations = self.context.docInfo['decorations'] for decoration in decorations: if hasattr(NoWordDecoration, decoration): self.addDecoration(getattr(NoWordDecoration, decoration))
def process(self, block, context): # filename element filename = block['filename'] # alias element alias = block['alias'] # level element, default 1 setGlobal = self.getElemValue(block, 'global', False) data = cmn_utils_fs.deserialize(os.path.join(block['_path'], filename)) if alias in context.resources: context.resources[alias].update(data) else: context.resources[alias] = data if setGlobal: context.docInfo.update(data) # return empty list return []
def process(self, block, context): file_types = ('*.yaml','*.json','*.plist','*.xml'); # filename or content element if 'filename' in block: filename = context.processTextCmds(block['filename']).strip() data = cmn_utils_fs.deserialize(os.path.join(block['_path'], filename)) elif 'folder' in block: folder = os.path.join( block['_path'], block['folder']) recursive = self.getElemValue(block, 'recursive', False) files = [] for type in file_types: files.extend(glob.glob(os.path.join(folder, type),recursive=recursive)) data=[] for file in files: data.append( cmn_utils_fs.deserialize(file)) elif 'content' in block: data = block['content'] else: return [] if 'sort' in block: sortKey=block['sort'] if isinstance(sortKey,str): data = sorted(data, key=lambda k: k[sortKey]) elif type(sortKey) == list: if len(sortKey)==1: data = sorted(data, key=lambda k: k[sortKey[0]]) if len(sortKey)==2: data = sorted(data, key=lambda k: (k[sortKey[0]], k[sortKey[1]])) if len(sortKey)==3: data = sorted(data, key=lambda k: (k[sortKey[0]], k[sortKey[1]], k[sortKey[3]])) else: print('Sort with more than 3 fields not supported') if 'select' in block: selectCmd = context.processTextCmds(block['select']).strip() data = cmn_utils_di.selectSubset(data, selectCmd) # autonumbering autonumber = self.getElemValue(block, 'autonumber', False) if autonumber: for x, entry in enumerate(data): data[x]['number']=str(x+1) # alias element alias = block['alias'] # level element, default 1 setGlobal = self.getElemValue(block, 'global', False) if alias in context.resources: context.resources[alias].update(data) else: context.resources[alias] = data if setGlobal: context.docInfo.update(data) # return empty list return []