Thread: [Rest2web-develop] Re: Enhancement suggestion to rest2web
Brought to you by:
mjfoord
From: V. <Gae...@no...> - 2006-04-09 22:12:22
|
On Sun, Apr 09, 2006 at 10:42:26PM +0100, Michael Foord wrote: > > * A inlined function, such as <# print(2*2) #> should be able to a= dd > > files to the restindex['file'] list. That should probably be > > rather easy to add. > There are several ways of doing this (including writing your own=20 > function and just importing it in the template). I am reluctant to modify the rest2web files. But maybe I missed a way of doing this without modifying them. Currently I am only coding embedded code in the template. > Where do you want to move files from and to ? Currently the 'file'=20 > keyword only moves files into the same directory as the target file=20 > being created. Is this what you want to do ? You mean if the file keyword is "foo/bar" rest2web won't create a foo subdirectory in the target directory and copy bar there ? If so then I think it would be an interesting feature to add. > I'm sure there is an easy function you could write to do this - I would= =20 > be happy to include it in the set of standard functions if it was=20 > general enough. I have been trying to, but I cannot find a way of retrieving the target directory with embedded code. Are you suggesting that I modify function.py to add such a function and send you a patch ? I'll have a look at that. If you can give me some advice on implementing that I am more then happy to do it. > I've been planning to add hashing for a while. > I am now busy implementing it - it jumped the queue ! > It might still take a couple of weeks to get right, maybe less. The more I think about it the more I think there is a certain amount of work. But I think it will be a very useful feature. Thanks for such quick feedback (I joined the sourceforge mailing list and saw your mail). --=20 Ga=EBl |
From: Michael F. <fuz...@vo...> - 2006-04-09 22:27:23
|
Gaël Varoquaux wrote: > On Sun, Apr 09, 2006 at 10:42:26PM +0100, Michael Foord wrote: > >>> * A inlined function, such as <# print(2*2) #> should be able to add >>> files to the restindex['file'] list. That should probably be >>> rather easy to add. >>> > > > >> There are several ways of doing this (including writing your own >> function and just importing it in the template). >> > > I am reluctant to modify the rest2web files. But maybe I missed a > way of doing this without modifying them. Currently I am only coding > embedded code in the template. > > But you can import anything inside the templates - so keep it in an external file somewhere on ``sys.path`` (e.g. your ``site-packages`` folder) and import it. If you wanted to make this easily available, the file to add it to is functions.py. If you write a general enough function I will add it to the distribution. Ah.. I can see below that you are aware of this file. >> Where do you want to move files from and to ? Currently the 'file' >> keyword only moves files into the same directory as the target file >> being created. Is this what you want to do ? >> > > You mean if the file keyword is "foo/bar" rest2web won't create a > foo subdirectory in the target directory and copy bar there ? If so then > I think it would be an interesting feature to add. > > I *don't* do this so that you can copy relative files into the target directory using the ``file`` keyword. I think it would be easy enough to create a standard function that does this - so modifying the file keyword shouldn't be necessary. >> I'm sure there is an easy function you could write to do this - I would >> be happy to include it in the set of standard functions if it was >> general enough. >> > I have been trying to, but I cannot find a way of retrieving the > target directory with embedded code. Are you suggesting that I modify > function.py to add such a function and send you a patch ? I'll have a > look at that. > If you can give me some advice on implementing that I am more then > happy to do it. > > The full path to the page being generated is ``pagepath``. You should find that ``os.path.dirname(pagepath)`` gives you the directory. Let me know how you get on with this. >> I've been planning to add hashing for a while. >> >> I am now busy implementing it - it jumped the queue ! >> >> It might still take a couple of weeks to get right, maybe less. >> > The more I think about it the more I think there is a certain amount > of work. But I think it will be a very useful feature. > > Thanks for such quick feedback (I joined the sourceforge mailing > list and saw your mail). > > Well, I've started work on it. It might not be that easy because I need to pickle the data structures in use by rest2web. This means I need to check that there are no complicated cross references that won't be restored properly if I just copy data for individual pages from the pickle. All the best, Fuzzyman http://www.voidspace.org.uk/python/index.shtml |
From: V. <gae...@no...> - 2006-04-09 22:38:18
|
On Sun, Apr 09, 2006 at 11:28:01PM +0100, Michael Foord wrote: > > You mean if the file keyword is "foo/bar" rest2web won't create a > >foo subdirectory in the target directory and copy bar there ? If so th= en > >I think it would be an interesting feature to add. > I *don't* do this so that you can copy relative files into the target=20 > directory using the ``file`` keyword. Fare enough. You have a point. > I think it would be easy enough to create a standard function that does= =20 > this - so modifying the file keyword shouldn't be necessary. > The full path to the page being generated is ``pagepath``. Well unless I am wrong this is the relative path from the root of the web site. To be able to copy the file from the source tree to the target tree I also need to know their roots. The root of the source tree seems to be the current working dir of the script, that I can get with os.getcwd(), but I have not found a way of accessing the root of the target directory. > You should find that ``os.path.dirname(pagepath)`` gives you the=20 > directory. Let me know how you get on with this. I get the source directory with : fullpath=3Dos.path.dirname(os.getcwd()+"/"+pagepath) If you know a way of finding out the target directory or the root of the target tree from either functions.py or embedded code than I can code a appropriate function. Cheers, Ga=EBl |
From: Michael F. <fuz...@vo...> - 2006-04-09 22:50:41
|
Gaël Varoquaux wrote: > On Sun, Apr 09, 2006 at 11:28:01PM +0100, Michael Foord wrote: > >>> You mean if the file keyword is "foo/bar" rest2web won't create a >>> foo subdirectory in the target directory and copy bar there ? If so then >>> I think it would be an interesting feature to add. >>> > > > >> I *don't* do this so that you can copy relative files into the target >> directory using the ``file`` keyword. >> > > Fare enough. You have a point. > > >> I think it would be easy enough to create a standard function that does >> this - so modifying the file keyword shouldn't be necessary. >> > > >> The full path to the page being generated is ``pagepath``. >> > > Well unless I am wrong this is the relative path from the root of > the web site. To be able to copy the file from the source tree to the > target tree I also need to know their roots. The root of the source tree > seems to be the current working dir of the script, that I can get with > os.getcwd(), but I have not found a way of accessing the root of the > target directory. > > >> You should find that ``os.path.dirname(pagepath)`` gives you the >> directory. Let me know how you get on with this. >> > > I get the source directory with : > fullpath=os.path.dirname(os.getcwd()+"/"+pagepath) > > If you know a way of finding out the target directory or the root of > the target tree from either functions.py or embedded code than I can > code a appropriate function. > > Ahh.... good point, you need the target directory as well. You can find this using ``Processor.target``, which is kind of a hack - but why I included access to the Processor object. What values would you like (they are very easy to add into the namespace) ? Fuzzyman http://www.voidspace.org.uk/python/index.shtml > Cheers, > > Gaël > > > ------------------------------------------------------- > This SF.Net email is sponsored by xPML, a groundbreaking scripting language > that extends applications into web and mobile media. Attend the live webcast > and join the prime developer group breaking into this new coding territory! > http://sel.as-us.falkag.net/sel?cmd=k&kid0944&bid$1720&dat1642 > _______________________________________________ > Rest2web-develop mailing list > Res...@li... > https://lists.sourceforge.net/lists/listinfo/rest2web-develop > > |
From: V. <gae...@no...> - 2006-04-09 22:56:45
|
On Sun, Apr 09, 2006 at 11:51:25PM +0100, Michael Foord wrote: > > If you know a way of finding out the target directory or the root = of > >the target tree from either functions.py or embedded code than I can > >code a appropriate function. > You can find this using ``Processor.target``, which is kind of a hack -= =20 > but why I included access to the Processor object. Ha ! I should have investigator the processor object a bit more ( I had seen that it was in the the namespace) > What values would you like (they are very easy to add into the namespac= e) ? Well, you know as well as I do that it is hard to know in advance what a user might need. I think the root of the target tree would be enough. Do you confirm that os.getcwd will give me the root of the source tree or is this just a coincidence that it does on my tests. I'll write a function to copy file from the source tree to the target tree that can be included in functions.py . I'll just wait until tomorrow in order to have a clearer idea of what options/features might be wanted for such function. Suggestions welcomed. Ga=EBl |
From: Michael F. <fuz...@vo...> - 2006-04-09 23:02:47
|
Gaël Varoquaux wrote: > On Sun, Apr 09, 2006 at 11:51:25PM +0100, Michael Foord wrote: > >>> If you know a way of finding out the target directory or the root of >>> the target tree from either functions.py or embedded code than I can >>> code a appropriate function. >>> >> You can find this using ``Processor.target``, which is kind of a hack - >> but why I included access to the Processor object. >> > > Ha ! I should have investigator the processor object a bit more ( I > had seen that it was in the the namespace) > > >> What values would you like (they are very easy to add into the namespace) ? >> > > Well, you know as well as I do that it is hard to know in advance > what a user might need. I think the root of the target tree would be > enough. Do you confirm that os.getcwd will give me the root of the > source tree or is this just a coincidence that it does on my tests. > > The current working directory is explicitly set at the start - so you can rely on this behaviour. I'll probably add the target directory as an explicit value. > I'll write a function to copy file from the source tree to the > target tree that can be included in functions.py . I'll just wait until > tomorrow in order to have a clearer idea of what options/features might > be wanted for such function. > > Suggestions welcomed. > Ok. The file keyword isn't actually one I use (currently), I guess being able to specify a list of source files and a single target directory (relative to the current target directory I guess). All the best, Fuzzyman http://www.voidspace.org.uk/python/index.shtml > Gaël > > > ------------------------------------------------------- > This SF.Net email is sponsored by xPML, a groundbreaking scripting language > that extends applications into web and mobile media. Attend the live webcast > and join the prime developer group breaking into this new coding territory! > http://sel.as-us.falkag.net/sel?cmd=k&kid0944&bid$1720&dat1642 > _______________________________________________ > Rest2web-develop mailing list > Res...@li... > https://lists.sourceforge.net/lists/listinfo/rest2web-develop > > |
From: V. <gae...@no...> - 2006-04-10 07:34:32
|
On Mon, Apr 10, 2006 at 12:03:26AM +0100, Michael Foord wrote: > > I'll write a function to copy file from the source tree to the > >target tree that can be included in functions.py . I'll just wait unti= l > >tomorrow in order to have a clearer idea of what options/features migh= t > >be wanted for such function. > > Suggestions welcomed. > Ok. The file keyword isn't actually one I use (currently), I guess bein= g=20 > able to specify a list of source files and a single target directory=20 > (relative to the current target directory I guess). OK, now that I am using Processor.target in my embedded scripts I can do what I want. But it would be nicer to have a function for do this. Something like : def add_file(source, targetdir=3Dos.path.dirname(Processor.target+"/"+pag= epath) Where source could be either a string or a tuple of strings. Trying to implement this I realize I do not know how to access pagepath or Processor in functions.py . Maybe it would be nice if the namespace accessible to the embedded functions was also accessible in functions.py (note that I have no clue how to code this). On a side note: it might be a good idea to have a config entry in the config file to add a user file where he could define his functions without modifying functions.py . For large project it could prove usefull. Regards, Ga=EBl |
From: Michael F. <fuz...@vo...> - 2006-04-22 22:21:33
|
Gaël Varoquaux wrote: > On Mon, Apr 10, 2006 at 12:03:26AM +0100, Michael Foord wrote: > >>> I'll write a function to copy file from the source tree to the >>> target tree that can be included in functions.py . I'll just wait until >>> tomorrow in order to have a clearer idea of what options/features might >>> be wanted for such function. >>> > > >>> Suggestions welcomed. >>> > > >> Ok. The file keyword isn't actually one I use (currently), I guess being >> able to specify a list of source files and a single target directory >> (relative to the current target directory I guess). >> > > OK, now that I am using Processor.target in my embedded scripts I > can do what I want. But it would be nicer to have a function for do > this. Something like : > > def add_file(source, targetdir=os.path.dirname(Processor.target+"/"+pagepath) > I *haven't* yet added the target path to the standard namespace. I will do this very soon. I have however made the namespace (and the 'uservalues') accessible to the functions (both as dictionaries). > Where source could be either a string or a tuple of strings. > > Trying to implement this I realize I do not know how to access > pagepath or Processor in functions.py . Maybe it would be nice if the > namespace accessible to the embedded functions was also accessible in > functions.py (note that I have no clue how to code this). > > On a side note: it might be a good idea to have a config entry in > the config file to add a user file where he could define his functions > without modifying functions.py . For large project it could prove > usefull. > Hmm... I'll think about the best way of doing this. Currently you can import whatever you want at the start of the templates, but maybe a way to specify a list of modules to automatically import would be good too. Fuzzyman http://www.vidspace.org.uk/python/index.shtml > Regards, > > Gaël > > > ------------------------------------------------------- > This SF.Net email is sponsored by xPML, a groundbreaking scripting language > that extends applications into web and mobile media. Attend the live webcast > and join the prime developer group breaking into this new coding territory! > http://sel.as-us.falkag.net/sel?cmd=k&kid0944&bid$1720&dat1642 > _______________________________________________ > Rest2web-develop mailing list > Res...@li... > https://lists.sourceforge.net/lists/listinfo/rest2web-develop > > |