def normalize_ids_after_copy(node, id_prefix='e', ids=[]): request = node.REQUEST copy_of_prefix = 'copy_of_' for childNode in node.getChildNodes(): # validate id id = childNode.getId() new_id = None if '*' in ids or id in ids or id.startswith(copy_of_prefix): # reset ref_by childNode.ref_by = [] # init object-state if not '*' in ids: lang = request.get('lang') for langId in node.getLangIds(): request.set('lang', langId) childNode.setObjStateNew(request, reset=0) childNode.onChangeObj(request) request.set('lang', lang) # new id new_id = node.getNewId(id_prefix) else: # new id new_id = node.getNewId(standard.id_prefix(id)) # reset id if new_id is not None and new_id != id: standard.writeBlock( node, '[CopySupport._normalize_ids_after_copy]: rename %s(%s) to %s' % (childNode.absolute_url(), childNode.meta_id, new_id)) node.manage_renameObject(id=id, new_id=new_id) # traverse tree normalize_ids_after_copy(childNode, id_prefix, ids=['*'])
def clearData(self): if self.SQLStorage and not self.noStorage: try: # Using a with statement ensures that the connection is always released # back into the pool at the end of statement (even if an error occurs) with self.engine.connect() as conn: res = conn.execute(self.sqldb.delete()) except Exception as e: raise e finally: conn.close() return True else: self._data.clear() zodb = getConfiguration().dbtab.getDatabase('/', is_root=1)._storage if not zodb.isReadOnly() and not self.noStorage: lang = self.this.REQUEST.get('lang', self.this.getPrimaryLanguage()) self.this.REQUEST.set('lang', self.this.getPrimaryLanguage()) self.this.setObjStateModified(self.this.REQUEST) self.this.attr('_data', self._data) self.this.onChangeObj(self.this.REQUEST) self.this.commitObj(self.this.REQUEST,forced=True) self.this.REQUEST.set('lang', lang) return True else: _globals.writeBlock(self.thisMaster, "[ZMSFormulator.clearData] zodb.isReadOnly") return False
def normalize_ids_after_move(node, id_prefix='e', ids=[]): request = node.REQUEST copy_of_prefix = 'copy_of_' for childNode in node.getChildNodes(): # validate id id = childNode.getId() new_id = None if '*' in ids or id in ids or id.startswith(copy_of_prefix): # init object-state if not '*' in ids: lang = request.get('lang') for langId in node.getLangIds(): request.set('lang', langId) childNode.setObjStateModified(request) childNode.onChangeObj(request) request.set('lang', lang) # new id if id.startswith(copy_of_prefix): new_id = id[len(id.startswith(copy_of_prefix)):] elif standard.id_prefix(id) != id_prefix: new_id = node.getNewId(id_prefix) # reset id if new_id is not None and new_id != id: standard.writeBlock( node, '[CopySupport._normalize_ids_after_move]: rename %s(%s) to %s' % (childNode.absolute_url(), childNode.meta_id, new_id)) node.manage_renameObject(id=id, new_id=new_id)
def provideRepositoryActivities(self, r, ids=None): standard.writeBlock(self, "[provideRepositoryActivities]: ids=%s"%str(ids)) r['workflow']['Activities'] = [] for id in self.getActivityIds(): d = self.getActivity(id) d['id'] = id r['workflow']['Activities'].append(d)
def moveObjsToTrashcan(self, ids, REQUEST): if self.meta_id == 'ZMSTrashcan': return trashcan = self.getTrashcan() # Set deletion-date. ids_copy = [] for id in ids: try: context = getattr(self, id) context.del_uid = str(REQUEST.get('AUTHENTICATED_USER', None)) context.del_dt = standard.getDateTime(time.time()) ids_copy.append(id) except: standard.writeBlock( self, "[moveObjsToTrashcan]: Attribute Error %s" % (id)) # Use only successfully tried ids ids = ids_copy # Move (Cut & Paste). children = [getattr(self, x) for x in ids] [ standard.triggerEvent(child, 'beforeDeleteObjsEvt') for child in children ] cb_copy_data = _cb_decode(self.manage_cutObjects(ids)) trashcan.manage_pasteObjects(cb_copy_data=_cb_encode(cb_copy_data)) trashcan.normalizeSortIds() trashcan.run_garbage_collection(forced=1) # Sort-IDs. self.normalizeSortIds() [ standard.triggerEvent(child, 'afterDeleteObjsEvt') for child in children ]
def provideRepositoryTransitions(self, r, ids=None): standard.writeBlock( self, "[provideRepositoryTransitions]: ids=%s" % str(ids)) r['workflow']['Transitions'] = [] for id in self.getTransitionIds(): d = self.getTransition(id) d['id'] = id r['workflow']['Transitions'].append(d)
def updateRepositoryActivities(self, r): id = r['id'] standard.writeBlock(self, "[updateRepositoryActivities]: id=%s"%id) # Clear. self.activities = [] # Set. for attr in r.get('Activities', []): self.setActivity(attr['id'], attr['id'], attr['name'], attr.get('icon_clazz'), attr.get('icon')) return id
def importFile(self, file, REQUEST, handler): # Get filename. if isinstance(file, ZPublisher.HTTPRequest.FileUpload): filename = file.filename else: filename = file.name standard.writeBlock(self, '[importFile]: filename=' + filename) # Create temporary folder. folder = tempfile.mktemp() os.mkdir(folder) # Save to temporary file. filename = _fileutil.getOSPath( '%s/%s' % (folder, _fileutil.extractFilename(filename))) _fileutil.exportObj(file, filename) # Import ZEXP-file. if _fileutil.extractFileExt(filename) == 'zexp': ob = self._importObjectFromFile(filename, verify=0) # Remove temporary files. _fileutil.remove(folder, deep=1) # Refresh zcatalog_index standard.triggerEvent(self, '*.onImportObjEvt') return ob # Find XML-file. if _fileutil.extractFileExt(filename) == 'zip': _fileutil.extractZipArchive(filename) filename = None for deep in [0, 1]: for ext in ['xml', 'htm', 'html']: if filename is None: filename = _fileutil.findExtension(ext, folder, deep) break if filename is None: raise zExceptions.InternalError('XML-File not found!') # Import Filter. if REQUEST.get('filter', '') in self.getFilterManager().getFilterIds(): filename = _filtermanager.importFilter(self, filename, REQUEST.get('filter', ''), REQUEST) # Import XML-file. standard.writeBlock(self, '[importFile]: filename=' + filename) f = standard.pyopen(filename, 'r', encoding='utf-8') ob = handler(self, f) f.close() # Remove temporary files. _fileutil.remove(folder, deep=1) # Return imported object. return ob
def updateRepositoryMetas(self, r): id = r['id'] if id == '__metas__': standard.writeBlock(self, "[updateRepositoryMetas]: id=%s" % id) self.metas = [] for attr in r.get('Metas', []): self.metas.extend([attr['id'], attr]) # Make persistent. self.metas = copy.deepcopy(self.metas) return id
def init_domains(doc,domains): domain = doc.getConfProperty('ASP.ip_or_domain','') if domain != '': domain = '^http(\\w)?://%s'%domain path = '/'.join(doc.getPhysicalPath()) if domain in domains: log.append('ERROR %s'%standard.writeBlock(doc,'[ZMSIndex] ### init_domains DUPLICATE %s=%s'%(domain,path))) else: domains[domain] = path log.append('INFO %s'%standard.writeBlock(doc,'[ZMSIndex] init_domains %s=%s'%(domain,path))) for portalClient in doc.getPortalClients(): init_domains(portalClient,domains)
def updateRepositoryTransitions(self, r): id = r['id'] standard.writeBlock(self, "[updateRepositoryTransitions]: id=%s" % id) # Clear. self.transitions = [] # Set. for attr in r.get('Transitions', []): self.setTransition(attr['id'], attr['id'], attr['name'], attr.get('type'), attr.get('icon_clazz', ''), attr.get('from', []), attr.get('to', ''), attr.get('performer', ''), attr.get('data', '')) return id
def processFile(self, processId, filename, trans=None): standard.writeBlock( self, '[processFile]: processId=%s'%processId) folder = _fileutil.getFilePath(filename) processOb = self.getFilterManager().getProcess(processId) command = processOb.get('command') # Save transformation to file. if trans: command = command.replace( '{trans}', getTransFilename(self, folder, trans)) # Execute command. filename = processCommand(self, filename, command) # Return filename. return filename
def handleInline(node,v): p = '<dtml-var "getLinkUrl\(\'(.*?)\'(,REQUEST)?\)">' r = re.compile(p) for f in r.findall(v): data_id = f[0] old = '<dtml-var "getLinkUrl(\'%s\'%s)">'%(data_id,f[1]) ref = node.getLinkObj(data_id) if ref: new = ref.absolute_url() log.append('INFO %s'%standard.writeBlock(node,'[ZMSIndex] handleInline %s->%s'%(old,new))) v = v.replace(old,new) p = '<a(.*?)>(.*?)<\\/a>' r = re.compile(p) for f in r.findall(v): data_data = '' brain = None d = dict(re.findall('\\s(.*?)="(.*?)"',f[0])) if brain is None and 'data-id' in d: data_id = d['data-id'] log.append('INFO %s'%standard.writeBlock(node,'[ZMSIndex] handleInline data_id=%s'%data_id)) brain = find_brain(data_id) if data_id.find(';') > 0: data_data = data_id[data_id.find(';'):-1] if brain is None and 'href' in d: href = d['href'] href = re.sub('http://localhost:(\\d)*','',href) for domain in domains: path = domains[domain] href = re.sub(domain,path,href) log.append('INFO %s'%standard.writeBlock(node,'[ZMSIndex] handleInline href=%s'%href)) if href.startswith('.') or href.startswith('/'): nf = re.compile('(.*?)\\?op=not_found&url={\\$(.*?)}').findall(href) if nf: url = nf[0][1] else: url = href brain = find_node(node,url) old_data_id = d.get('data_id') old_url = d.get('href') data_id = None if brain is not None: data_id = '{$%s%s}'%(brain['get_uid'],data_data) d['data-id'] = data_id old = (p.replace('\\','').replace('(.*?)','%s'))%tuple(f) title = f[1] new = '<a %s>%s</a>'%(' '.join(['%s="%s"'%(x,d[x]) for x in d]),title) if old != new: ref = getLinkObj('{$%s}'%brain['get_uid']) ref.registerRefObj(node) log.append('INFO %s'%standard.writeBlock(node,'[ZMSIndex] handleInline %s->%s'%(old,new))) v = v.replace(old,new) return v
def provideRepository(self, r, ids=None): standard.writeBlock(self, "[provideRepository]: ids=%s" % str(ids)) r = {} id = 'workflow' d = { 'id': id, 'revision': self.getRevision(), '__filename__': ['__init__.py'] } r[id] = d self.provideRepositoryActivities(r, ids) self.provideRepositoryTransitions(r, ids) return r
def traverse(path, p): for filename in os.listdir(path): filepath = os.path.join(path, filename) if os.path.isdir(filepath): traverse(filepath, p) elif os.path.isfile(filepath): if filename not in p['filenames']: standard.writeBlock( self, "[manage_packMediaDb]: filename %s" % str(filename)) shutil.move(filepath, p['tempfolder'] + os.sep + filename) p['c'] += 1 p['t'] += 1
def parseXmlString(self, file): standard.writeBlock(self, '[parseXmlString]') message = '' REQUEST = self.REQUEST lang = REQUEST.get('lang', self.getPrimaryLanguage()) v = standard.parseXmlString(file) metaObj = self.getMetaobj(self.meta_id) res_id = metaObj['attrs'][0]['id'] res_abs = self.getObjProperty(res_id, REQUEST) res_abs.extend(v) self.setObjStateModified(REQUEST) self.setObjProperty(res_id, res_abs, lang) self.onChangeObj(REQUEST) return message
def updateRepository(self, r): id = r['id'] if not id.startswith('__') and not id.endswith('__'): standard.writeBlock(self, "[updateRepository]: id=%s" % id) oldId = id newId = id if r.get('meta_type') == 'filter': newName = r['name'] newFormat = r['format'] newContentType = r['content_type'] newDescription = r.get('description', '') newRoles = r.get('roles', []) newMetaTypes = r.get('meta_types', []) self.setFilter(oldId, newId, newAcquired=0, newName=newName, newFormat=newFormat, newContentType=newContentType, newDescription=newDescription, newRoles=newRoles, newMetaTypes=newMetaTypes) index = 0 for process in r.get('Processes', []): newProcessId = process.get('id') newProcessFile = None if newProcessId.find('/') >= 0: data = process.get('data') filename = process.get('id') filename = filename[filename.find('/') + 1:] filename = filename[filename.find('.') + 1:] newProcessId = newProcessId[:newProcessId.find('/')] newProcessFile = standard.FileFromData( self, data, filename) self.setFilterProcess(newId, index, newProcessId, newProcessFile) index += 1 elif r.get('meta_type') == 'process': newName = r['name'] newType = r['type'] newCommand = r.get('command', None) for command in r.get('Command', []): newCommand = command['data'] break self.setProcess(oldId, newId, newName=newName, newType=newType, newCommand=newCommand) return id
def processCommand(self, filename, command): standard.writeBlock( self, '[processCommand]: infilename=%s'%filename) infilename = _fileutil.getOSPath( filename) outfilename = _fileutil.getOSPath( filename) mCurDir = '{cur_dir}' mIn = '{in}' mOut = '{out}' i = command.find(mOut[:-1]) if i >= 0: j = command.find('}', i) mExt = command[i+len(mOut[:-1]):j] mOut = command[i:j+1] if len(mExt) > 0: outfilename = outfilename[:outfilename.rfind('.')] + mExt else: outfilename += '.tmp' tmpoutfilename = outfilename + '~' instance_home = standard.getINSTANCE_HOME() package_home = standard.getPACKAGE_HOME() package_home = os.path.normpath(package_home) command = command.replace( '{package_home}', package_home) command = command.replace( '{instance_home}', instance_home) command = command.replace( mCurDir, _fileutil.getFilePath(infilename)) command = command.replace( mIn, infilename) command = command.replace( mOut, tmpoutfilename) # Change directory (deprecated!). if self.getConfProperty('ZMS.filtermanager.processCommand.chdir', 0): path = _fileutil.getFilePath(filename) standard.writeBlock( self, '[processCommand]: path=%s'%path) os.chdir(path) # Execute command. standard.writeBlock( self, '[processCommand]: command=%s'%command) os.system(command) # Check if output file exists. try: os.stat( _fileutil.getOSPath( tmpoutfilename)) standard.writeBlock( self, '[processCommand]: rename %s to %s'%( tmpoutfilename, outfilename)) try: os.remove( outfilename) except OSError: pass os.rename( tmpoutfilename, outfilename) except OSError: outfilename = infilename # Remove input file if it is the result of a transformation of output file. if outfilename != infilename: os.remove( infilename) # Return filename. standard.writeBlock( self, '[processCommand]: outfilename=%s'%( outfilename)) return outfilename
def visit(node): l = [] l.append(1) if node.meta_id == 'ZMS': # Clear catalog for i in catalog({'path':'/'.join(node.getPhysicalPath())}): path = i['getPath'] log.append('INFO %s'%standard.writeBlock(self,'[ZMSIndex] uncatalog_object %s'%path)) catalog.uncatalog_object(path) log.append('INFO %s'%standard.writeBlock(self,'[ZMSIndex] catalog_object %s %s'%(node.getPath(),str(node.get_uid())))) self.catalog_object(catalog,node,regenerate_duplicates) for childNode in node.getChildNodes(): l.extend(visit(childNode)) return l
def recurse_importContent(self, folder): # Cleanup. for key in ['oRootTag', 'oCurrNode', 'oParent', 'dTagStack', 'dValueStack']: try: delattr(self, key) except: pass # Upload ressources. langs = self.getLangIds() prim_lang = self.getPrimaryLanguage() obj_attrs = self.getObjAttrs() for key in obj_attrs: obj_attr = self.getObjAttr(key) datatype = obj_attr['datatype_key'] if datatype in _globals.DT_BLOBS: for lang in langs: try: if obj_attr['multilang'] or lang==prim_lang: req = {'lang':lang,'preview':'preview'} obj_vers = self.getObjVersion(req) blob = self._getObjAttrValue(obj_attr, obj_vers, lang) if blob is not None: filename = _fileutil.getOSPath('%s/%s'%(folder, blob.filename)) standard.writeBlock( self, '[recurse_importContent]: filename=%s'%filename) # Backup properties (otherwise manage_upload sets it). bk = {} for __xml_attr__ in blob.__xml_attrs__: bk[__xml_attr__] = getattr(blob, __xml_attr__, '') # Read file to ZODB. f = open( filename, 'rb') try: blob = _blobfields.createBlobField( self, datatype, file={'data':f,'filename':filename}) finally: f.close() # Restore properties. for __xml_attr__ in blob.__xml_attrs__: if bk.get(__xml_attr__, '') not in ['', 'text/x-unknown-content-type']: setattr(blob, __xml_attr__, bk[__xml_attr__]) blob.getFilename() # Normalize filename self.setObjProperty(key, blob, lang) except: standard.writeError(self, "[recurse_importContent]") # Commit object. self.onChangeObj( self.REQUEST, forced=1) transaction.commit() # Process children. for ob in self.getChildNodes(): recurse_importContent(ob, folder)
def provideRepositoryMetas(self, r, ids=None): standard.writeBlock(self, "[provideRepositoryMetas]: ids=%s" % str(ids)) valid_ids = ['__metas__'] if ids is None: ids = valid_ids for id in [x for x in ids if x in valid_ids]: metas = copy.deepcopy(self.metas) metas = [metas[x * 2 + 1] for x in range(len(metas) // 2)] [ self.operator_delitem(x, 'acquired') for x in metas if 'acquired' in x ] d = {'id': id, '__filename__': ['__metas__.py'], 'Metas': metas} r[id] = d
def find_node(base, path): ref = base if path.find('?')>0: if path.find('#')>path.find('?'): path = path[:path.find('?')]+path[path.find('#'):] else: path = path[:path.find('?')] ids = [] for id in path.split('/'): ids.extend(id.split('#')) ids = [x for x in ids if x not in ['','.','..'] and not (x.startswith('index_') and x.endswith('.html'))] log.append('INFO %s'%standard.writeBlock(self,'[ZMSIndex] find_node ids=%s'%str(ids))) if len(ids)==0 or len([x for x in ids if x.startswith('manage')]) > 0: return None # find id in catalog brain = find_brain('/'.join(ids)) if brain is not None: return brain # find declarative id while ref is not None: o = find_decl_id(ref,ids[0]) if o is not None: for id in ids[1:]: o = find_decl_id(o,id) if o is None: return None return find_brain(o.get_uid()) ref = ref.getParentNode() return ref
def processMethod(self, processId, filename, trans, REQUEST): standard.writeBlock( self, '[processMethod]: processId=%s'%processId) infilename = filename outfilename = filename REQUEST.set( 'ZMS_FILTER_IN', infilename) REQUEST.set( 'ZMS_FILTER_OUT', outfilename) REQUEST.set( 'ZMS_FILTER_TRANS', trans) REQUEST.set( 'ZMS_FILTER_CUR_DIR', _fileutil.getFilePath(infilename)) try: process = self.getFilterManager().getProcess(processId) ob = process['ob'] value = zopeutil.callObject( ob, self) except: value = standard.writeError( self, '[processMethod]: processId=%s'%processId) outfilename = REQUEST.get( 'ZMS_FILTER_OUT') # Return filename. return outfilename
def execProcessFilter(self, ob_process, folder, filename, REQUEST): processId = ob_process.get( 'id') standard.writeBlock(self,"[execProcessFilter]: processId=%s"%(processId)) processOb = self.getFilterManager().getProcess(processId) if processOb is not None: processType = processOb.get( 'type', 'process') standard.writeBlock(self,"[execProcessFilter]: processId=%s, processType=%s"%(processId,processType)) trans = ob_process.get('file') # Save transformation to file. if trans: _fileutil.exportObj( trans, getTransFilename(self, folder, trans)) if processType in [ 'DTML Method', 'External Method', 'Script (Python)']: filename = processMethod(self, processId, filename, trans, REQUEST) else: filename = processFile(self, processId, filename, trans) # Return filename. return filename
def manage_structureMediaDb(self, structure, REQUEST=None, RESPONSE=None): """ manage_structureMediaDb """ message = '' mediadb = self.getMediaDb() mediadb.structure = structure # Temp location. path = mediadb.getLocation() location = mediadb.location mediadb.location = location + "_tmp" temp = mediadb.getLocation() # Traverse existing structure. def traverse(path, p): standard.writeBlock(self, "[manage_structureMediaDb]: traverse %s" % path) for filename in os.listdir(path): filepath = os.path.join(path, filename) if os.path.isdir(filepath): traverse(filepath, p) elif os.path.isfile(filepath): targetpath = mediadb.targetFile(filepath) standard.writeBlock( self, "[manage_structureMediaDb]: %s -> %s" % (filepath, targetpath)) targetdir = os.sep.join(targetpath.split(os.sep)[:-1]) if not os.path.exists(targetdir): standard.writeBlock( self, "[manage_structureMediaDb]: makedirs %s" % targetdir) os.makedirs(targetdir) shutil.move(filepath, targetpath) p['t'] += 1 standard.writeBlock(self, "[manage_structureMediaDb]: makedirs %s" % temp) os.makedirs(temp) p = {'t': 0} traverse(path, p) standard.writeBlock(self, "[manage_structureMediaDb]: remove %s" % path) shutil.rmtree(path) standard.writeBlock( self, "[manage_structureMediaDb]: rename %s -> %s" % (temp, path)) os.rename(temp, path) # Restore location. mediadb.location = location # Return with message. message = "Restructured Media-Folder %s: %i files proecessed." % ( str(structure), p['t']) standard.writeBlock(self, "[manage_structureMediaDb]: " + message) return message
def manage_pasteObjs(self, REQUEST, RESPONSE=None): """ CopySupport.manage_pasteObjs """ id_prefix = REQUEST.get('id_prefix', 'e') standard.writeBlock(self, "[CopySupport.manage_pasteObjs]") t0 = time.time() # Analyze request cb_copy_data = self._get_cb_copy_data(cb_copy_data=None, REQUEST=REQUEST) op = cb_copy_data[0] cp = (op, cb_copy_data[1]) cp = _cb_encode(cp) ids = [self._get_id(x.getId()) for x in self._get_obs(cp)] oblist = self._get_obs(cp) # Paste objects. action = ['Copy', 'Move'][op == OP_MOVE] standard.triggerEvent(self, 'before%sObjsEvt' % action) self.manage_pasteObjects(cb_copy_data=None, REQUEST=REQUEST) standard.triggerEvent(self, 'after%sObjsEvt' % action) # Sort order (I). self._set_sort_ids(ids=ids, op=op, REQUEST=REQUEST) # Move objects. if op == OP_MOVE: normalize_ids_after_move(self, id_prefix=id_prefix, ids=ids) # Copy objects. else: normalize_ids_after_copy(self, id_prefix=id_prefix, ids=ids) # Sort order (II). self.normalizeSortIds() # Return with message. if RESPONSE is not None: message = standard.pybytes(self.getZMILangStr('MSG_PASTED')) message += ' (in ' + str(int( (time.time() - t0) * 100.0) / 100.0) + ' secs.)' RESPONSE.redirect('manage_main?lang=%s&manage_tabs_message=%s' % (REQUEST['lang'], standard.url_quote(message)))
def handleUrl(node,v): standard.writeLog(node,'[ZMSIndex] handleUrl %s'%v) if v.startswith('{$') and v.endswith('}'): old = v if not (v.startswith('{$__') and v.endswith('__}')) \ and not (v.startswith('{$') and v.find('id:')>0 and v.endswith('}')): data_data = '' brain = find_brain(v) if brain is not None: if v.find(';') > 0: data_data = v[v.find(';'):-1] data_id = '{$%s%s}'%(brain['get_uid'],data_data) new = data_id if old != new: standard.writeBlock(node,'[ZMSIndex] handleUrl %s->%s'%(old,new)) v = new ref = getLinkObj('{$%s}'%brain['get_uid']) ref.registerRefObj(node) else: log.append('ERROR %s'%standard.writeBlock(node,'[ZMSIndex] handleUrl ### MISSING LINKTARGET %s'%(v))) v = '{$__%s__}'%v[2:-1] return v
def exportFilter(self, id, REQUEST): # Set local variables. ob_filter = self.getFilterManager().getFilter(id) tempfolder, outfilename = self.initExportFilter( id, REQUEST) # Process filter. outfilename = processFilter(self, ob_filter, tempfolder, outfilename, REQUEST) # Return values. content_type = ob_filter.get('content_type', 'content/unknown') filename = 'exportFilter.%s'%content_type[content_type.find('/')+1:] # Zip File. if content_type == 'application/zip': data = _fileutil.buildZipArchive( outfilename, get_data=True) # Read File. else: standard.writeBlock( self, '[exportFilter]: Read %s'%outfilename) f = open(outfilename, 'rb') data = f.read() f.close() # Remove temporary folder. if not self.getConfProperty('ZMS.debug', 0): _fileutil.remove( tempfolder, deep=1) # Return. return filename, data, content_type
def manage_reindex(self, regenerate_duplicates=False): """ ZMSIndex.manage_reindex """ request = self.REQUEST response = request.RESPONSE log = [] zmsroot = self.getRootElement() home = zmsroot.getHome() catalog = getattr(home,self.catalog_id,None) regenerate_duplicates = regenerate_duplicates or catalog is None # Visit tree def visit(node): l = [] l.append(1) if node.meta_id == 'ZMS': # Clear catalog for i in catalog({'path':'/'.join(node.getPhysicalPath())}): path = i['getPath'] log.append('INFO %s'%standard.writeBlock(self,'[ZMSIndex] uncatalog_object %s'%path)) catalog.uncatalog_object(path) log.append('INFO %s'%standard.writeBlock(self,'[ZMSIndex] catalog_object %s %s'%(node.getPath(),str(node.get_uid())))) self.catalog_object(catalog,node,regenerate_duplicates) for childNode in node.getChildNodes(): l.extend(visit(childNode)) return l urls = [x for x in request['url'].split(',') if x] for url in urls: catalog = self.get_catalog() log.append('INFO %s'%standard.writeBlock(self,'[ZMSIndex] ### reindex for %s'%url)) t0 = time.time() base = self.getLinkObj(url) if base is not None: count = visit(base.getDocumentElement()) log.append('INFO %s'%standard.writeBlock(self,'[ZMSIndex] reindex for %s done: %i in %.2fsecs.'%(url,len(count),time.time()-t0))) return self.get_log(log,request)
def manage_packMediaDb(self, REQUEST=None, RESPONSE=None): """ manage_packMediaDb """ message = '' mediadb = self.getMediaDb() path = mediadb.getLocation() # Get filenames. filenames = mediadb.valid_filenames() standard.writeLog(self, "[manage_packMediaDb]: filenames %s" % str(filenames)) tempfolder = tempfile.mktemp() os.makedirs(tempfolder) standard.writeLog(self, "[manage_packMediaDb]: tempfolder %s" % tempfolder) # Traverse existing structure. def traverse(path, p): for filename in os.listdir(path): filepath = os.path.join(path, filename) if os.path.isdir(filepath): traverse(filepath, p) elif os.path.isfile(filepath): if filename not in p['filenames']: standard.writeBlock( self, "[manage_packMediaDb]: filename %s" % str(filename)) shutil.move(filepath, p['tempfolder'] + os.sep + filename) p['c'] += 1 p['t'] += 1 p = {'t': 0, 'c': 0, 'filenames': filenames, 'tempfolder': tempfolder} traverse(path, p) # Return with message. message = "%i files (total %i) moved to %s." % (p['c'], p['t'], p['tempfolder']) standard.writeBlock(self, "[manage_packMediaDb]: " + message) return message