Re: [Zope] LocalFS and PathHandler
Ulrich Wisser wrote: Hello, I try to access LocalFS from my own DTML method. (Exactly from my PathHandler method.) I got all directory information in one array like this path_to_handle = ['sub1', 'sub2', 'sub3'] How can a get a directory listining with LocalFS for path "/sub1/sub2/sub3/"? I know I need something like "lfs['sub1']['sub2']['sub3'].fileids". Hmmm... try this as a Python (Script|Method|External Method), don't try and do it in DTML ;-) object = lfs for id in path_to_handle: object = object.get(id) return object.fileids you could probably turn that into a one liner with reduce: return reduce(lamda x,y: x.get(y), [lfs]+path_to_handle).fileids I'd laugh loads if you could do that in DTML: dtml-var "reduce(lamda x,y: x.get(y), path_to_handle, lfs).fileids" Who said you can't write obfuscated python? *grinz* Chris PS: The first method should work, the one may work through sheer fluke, neither have been tested though... PPS: Nice to see someone using PathHandler :-) ___ Zope maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] LocalFS and PathHandler
Hello, At 19:54 22.01.2001 +0100, Dieter Maurer wrote: Ulrich Wisser writes: How can a get a directory listining with LocalFS for path "/sub1/sub2/sub3/"? I know I need something like "lfs['sub1']['sub2']['sub3'].fileids". But what if there are more (or less) elements in path_to_handle? The easiest answer to these types of questions are recursive functions. [...] this is the code I came up with: dtml-call "REQUEST.set('mylfs',lfs)" dtml-in path_to_handle dtml-call "REQUEST.set('mylfs',mylfs[_['sequence-item']])" /dtml-in Now I should have a reference to the object in mylfs. How can I detect if mylfs is a file or a directory? Thanks Ulrich -- Searchengine Know How - Webpromotion - Optimization - Internal Search World Wide Web Publisher, Ulrich Wisser, Odensvag 13, S-14571 Norsborg http://www.publisher.de Tel: +46-8-53460905Fax: +46-8-534 609 06 ___ Zope maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] LocalFS and PathHandler
Ulrich Wisser writes: How can I detect if mylfs is a file or a directory? I fear that is a difficult question. For unknown reasons, the builtin Python function "type" is considered unsafe (and would not help anyway). Thus, you cannot test for types. In PythonScript you have the function "same_type" that can be used to check whether two type are identical. I do not know, how well this function works with acquisition wrappers. There there is "isinstance". As I heard (but did not verify) there should be problems with ExtensionClass and Acquisition, as well. Thus, I would not try to determine, whether it is a directory or file. Instead, I would go for the interface based approach. Ask yourself, what operations you would need for a directory or file, respectively. Check for these operations to differenciate between the two. Dieter ___ Zope maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
[Zope] LocalFS and PathHandler
Hello, I try to access LocalFS from my own DTML method. (Exactly from my PathHandler method.) I got all directory information in one array like this path_to_handle = ['sub1', 'sub2', 'sub3'] How can a get a directory listining with LocalFS for path "/sub1/sub2/sub3/"? I know I need something like "lfs['sub1']['sub2']['sub3'].fileids". But what if there are more (or less) elements in path_to_handle? I hope made my point clear? Thanks Ulli -- Searchengine Know How - Webpromotion - Optimization - Internal Search World Wide Web Publisher, Ulrich Wisser, Odensvag 13, S-14571 Norsborg http://www.publisher.de Tel: +46-8-53460905Fax: +46-8-534 609 06 ___ Zope maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] LocalFS and PathHandler
On Mon, 22 Jan 2001, Ulrich Wisser wrote: I try to access LocalFS from my own DTML method. (Exactly from my PathHandler method.) I got all directory information in one array like this path_to_handle = ['sub1', 'sub2', 'sub3'] How can a get a directory listining with LocalFS for path "/sub1/sub2/sub3/"? I know I need something like "lfs['sub1']['sub2']['sub3'].fileids". But what if there are more (or less) elements in path_to_handle? I would write it in python, as a recursive function: def goo(lfs, path_to_handle): if len(path_to_handle)==0: return lfs else: lfs=lfs[path_to_handle[0]] path_to_handle=path_to_handle[1:] return goo(lfs, path_to_handle) [EMAIL PROTECTED], [EMAIL PROTECTED] /--\ | `long long long' is too long for GCC | \--/ ___ Zope maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] LocalFS and PathHandler
Ulrich Wisser writes: How can a get a directory listining with LocalFS for path "/sub1/sub2/sub3/"? I know I need something like "lfs['sub1']['sub2']['sub3'].fileids". But what if there are more (or less) elements in path_to_handle? The easiest answer to these types of questions are recursive functions. You may use a "dtml-in", too. Like that: dtml-call "REQUEST.set(curr__,lfs)" dtml-in path_to_handle dtml-call "REQUEST.set(curr__,curr__[_['sequence-item']])" /dtml-in dtml-var "curr__.fileids" Dieter ___ Zope maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )