Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Trac: Users

Confused about "PathOption" in a plugin/macro

 

 

Trac users RSS feed   Index | Next | Previous | View Threaded


dr2chase at mac

Oct 30, 2009, 12:50 PM

Post #1 of 6 (148 views)
Permalink
Confused about "PathOption" in a plugin/macro

I am working on a macro, attempting to make it be more configured from
trac.ini than it originally was.

My Python-wrangling abilities are not extensive, so this is probably
an obvious mistake.
However, I googled and searched my Trac mail, and an answer did not
appear, and the examples that I found did not reduce my confusion.

I am writing:

config.latexpath=PathOption('fss', 'latexroot',None,'Directory
where latex binaries may be found')
#
#
# Paths to executables
config.latex=config.latexpath+'/' + Option
('fss','latex','latex','Name of latex binary')

and it fails

TypeError: unsupported operand type(s) for +: 'PathOption' and
'str'

at the assignment to config.latex.

trac.ini contains:

[fss]
cache = ../htdocs/fortified/tracfss
cacheurl = /Projects/Community/chrome/site/fortified/tracfss
dvipng = dvipng
emacs = /opt/csw/bin/emacs
fortify = newfortify
fortifypath = ../../Fortifier
latex = latex
latexpdf = latexpdf
latexroot = /opt/csw/bin

Uses of PathOption that I find with Google, make it appear that the
result is a string, or certainly acts like one, but it most surely is
not. How do I get the (string) value of the path option out of a
PathOption? I tried applying "str" to it, and that did not work,
either (it did the generic printing for an str object).



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Trac Users" group.
To post to this group, send email to trac-users[at]googlegroups.com
To unsubscribe from this group, send email to trac-users+unsubscribe[at]googlegroups.com
For more options, visit this group at http://groups.google.com/group/trac-users?hl=en
-~----------~----~----~----~------~----~------~--~---


dr2chase at mac

Oct 30, 2009, 1:33 PM

Post #2 of 6 (141 views)
Permalink
Re: Confused about "PathOption" in a plugin/macro [In reply to]

And the apparent answer is, I am doing it all wrong.

config.latexpath=self.config.getpath('fss', 'latexroot')
#
# Paths to executables
config.latex=config.latexpath+'/' + self.config.get
('fss','latex','latex')

This was figured out by poking through the trac hacks until I found
one with a pathname in its configuration, and then I looked at the
source. Monkey-see, monkey-do.

Now if I could get the debug messages to end up in the log....


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Trac Users" group.
To post to this group, send email to trac-users[at]googlegroups.com
To unsubscribe from this group, send email to trac-users+unsubscribe[at]googlegroups.com
For more options, visit this group at http://groups.google.com/group/trac-users?hl=en
-~----------~----~----~----~------~----~------~--~---


noah at coderanger

Oct 30, 2009, 1:42 PM

Post #3 of 6 (141 views)
Permalink
Re: Confused about "PathOption" in a plugin/macro [In reply to]

The *Option classes are accessors, you use them in the context of the class
definition like this:

class Blah(Component):
latex_path = PathOption('fss', etc etc)

def my_plugin_function(self, req):
print self.latex_path

--Noah

> -----Original Message-----
> From: trac-users[at]googlegroups.com [mailto:trac-users[at]googlegroups.com]
> On Behalf Of David Chase
> Sent: Friday, October 30, 2009 12:50 PM
> To: trac-users[at]googlegroups.com
> Subject: [Trac] Confused about "PathOption" in a plugin/macro
>
>
> I am working on a macro, attempting to make it be more configured from
> trac.ini than it originally was.
>
> My Python-wrangling abilities are not extensive, so this is probably
> an obvious mistake.
> However, I googled and searched my Trac mail, and an answer did not
> appear, and the examples that I found did not reduce my confusion.
>
> I am writing:
>
> config.latexpath=PathOption('fss', 'latexroot',None,'Directory
> where latex binaries may be found')
> #
> #
> # Paths to executables
> config.latex=config.latexpath+'/' + Option
> ('fss','latex','latex','Name of latex binary')
>
> and it fails
>
> TypeError: unsupported operand type(s) for +: 'PathOption' and
> 'str'
>
> at the assignment to config.latex.
>
> trac.ini contains:
>
> [fss]
> cache = ../htdocs/fortified/tracfss
> cacheurl = /Projects/Community/chrome/site/fortified/tracfss
> dvipng = dvipng
> emacs = /opt/csw/bin/emacs
> fortify = newfortify
> fortifypath = ../../Fortifier
> latex = latex
> latexpdf = latexpdf
> latexroot = /opt/csw/bin
>
> Uses of PathOption that I find with Google, make it appear that the
> result is a string, or certainly acts like one, but it most surely is
> not. How do I get the (string) value of the path option out of a
> PathOption? I tried applying "str" to it, and that did not work,
> either (it did the generic printing for an str object).
>
>
>
>


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Trac Users" group.
To post to this group, send email to trac-users[at]googlegroups.com
To unsubscribe from this group, send email to trac-users+unsubscribe[at]googlegroups.com
For more options, visit this group at http://groups.google.com/group/trac-users?hl=en
-~----------~----~----~----~------~----~------~--~---


dr2chase at mac

Oct 30, 2009, 2:01 PM

Post #4 of 6 (141 views)
Permalink
Re: Confused about "PathOption" in a plugin/macro [In reply to]

On 2009-10-30, at 4:42 PM, Noah Kantrowitz wrote:

> The *Option classes are accessors, you use them in the context of
> the class
> definition like this:
>
> class Blah(Component):
> latex_path = PathOption('fss', etc etc)
>
> def my_plugin_function(self, req):
> print self.latex_path

Thanks, but that's not actually helping me (and fortunately, I
figured out another way to make this work, but from the POV of did you
explain this in terms that a new-to-Python person could make sense of,
I'm afraid you didn't).

Is there something special about class definition context?

Why would printing "self.latex_path" yield the desired string, instead
of <Pathoption ... > like you get from "str"?

This looks like the same sort of thing I was doing -- treating it as
if it were a String -- but you get a different result. How? Why?

but thanks, even so,

David


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Trac Users" group.
To post to this group, send email to trac-users[at]googlegroups.com
To unsubscribe from this group, send email to trac-users+unsubscribe[at]googlegroups.com
For more options, visit this group at http://groups.google.com/group/trac-users?hl=en
-~----------~----~----~----~------~----~------~--~---


noah at coderanger

Oct 30, 2009, 8:38 PM

Post #5 of 6 (131 views)
Permalink
Re: Confused about "PathOption" in a plugin/macro [In reply to]

On Oct 30, 2009, at 2:01 PM, David Chase wrote:

>
>
> On 2009-10-30, at 4:42 PM, Noah Kantrowitz wrote:
>
>> The *Option classes are accessors, you use them in the context of
>> the class
>> definition like this:
>>
>> class Blah(Component):
>> latex_path = PathOption('fss', etc etc)
>>
>> def my_plugin_function(self, req):
>> print self.latex_path
>
> Thanks, but that's not actually helping me (and fortunately, I
> figured out another way to make this work, but from the POV of did you
> explain this in terms that a new-to-Python person could make sense of,
> I'm afraid you didn't).
>
> Is there something special about class definition context?
>
> Why would printing "self.latex_path" yield the desired string, instead
> of <Pathoption ... > like you get from "str"?
>
> This looks like the same sort of thing I was doing -- treating it as
> if it were a String -- but you get a different result. How? Why?

Yes, when you access it through self (through an object) you get the
value from the config. If you access it via the class
(Blah.latex_path) you get the PathOption object. Its a bit of magic in
how Python does attribute lookups, it ends up invoking code within the
PathOption object which ends up returning the config value. You should
definitely use the *Option classes in favor of the direct self.config
access so you get the auto-magic stuff in the IniAdmin plugin (and
anything else that introspects those, like the TracIni macro).

--Noah

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Trac Users" group.
To post to this group, send email to trac-users[at]googlegroups.com
To unsubscribe from this group, send email to trac-users+unsubscribe[at]googlegroups.com
For more options, visit this group at http://groups.google.com/group/trac-users?hl=en
-~----------~----~----~----~------~----~------~--~---


dr2chase at mac

Nov 2, 2009, 7:33 PM

Post #6 of 6 (106 views)
Permalink
Re: Confused about "PathOption" in a plugin/macro [In reply to]

Works now, including that plugin, thanks very much.

Working code sample (hope this fits...)

class fssMacro(WikiMacroBase):
"""Fortress ASCII/Formatted display macro.
"""

fsspath=PathOption('fss','fortifypath', None,"""Path to the directory
containing the fortify .el and .sty files.""")
basename=Option('fss', 'fortify','newfortify',"""Basename of the .el
and .sty files in the fortify directory.""")
destdir=PathOption('fss', 'cache', '../htdocs/fortified/
tracfss',"""Path to the cache where the generated images are cached.""")
urlbase=Option('fss','cacheurl', '.../chrome/site/fortified/
tracfss',"""URL for the generated images cache.""")
latexpath=PathOption('fss', 'latexroot', None,"""Path to the
directory containing the varies latex binaries.""")
attachments=PathOption('fss', 'attachments','../attachments',"""Path
to the directory where attachments are stored.
The
default setting should work.""")
latex=Option('fss', 'latex', 'latex',"""Name of the latex binary.""")
pdflatex=Option('fss', 'pdflatex', 'pdflatex',"""Name of the pdflatex
binary.""")
dvipng=Option('fss', 'dvipng', 'dvipng',"""Name of the dvipng
binary.""")
emacspath=PathOption('fss','emacs', None,"""Path to the emacs
binary.""")

On 2009-10-30, at 11:38 PM, Noah Kantrowitz wrote:
> On Oct 30, 2009, at 2:01 PM, David Chase wrote:
>> On 2009-10-30, at 4:42 PM, Noah Kantrowitz wrote:
>>
>>> The *Option classes are accessors, you use them in the context of
>>> the class
>>> definition like this:
>>>
>>> class Blah(Component):
>>> latex_path = PathOption('fss', etc etc)
>>>
>>> def my_plugin_function(self, req):
>>> print self.latex_path
>> ...
>
> Yes, when you access it through self (through an object) you get the
> value from the config. If you access it via the class
> (Blah.latex_path) you get the PathOption object. Its a bit of magic in
> how Python does attribute lookups, it ends up invoking code within the
> PathOption object which ends up returning the config value. You should
> definitely use the *Option classes in favor of the direct self.config
> access so you get the auto-magic stuff in the IniAdmin plugin (and
> anything else that introspects those, like the TracIni macro).
>
> --Noah


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Trac Users" group.
To post to this group, send email to trac-users[at]googlegroups.com
To unsubscribe from this group, send email to trac-users+unsubscribe[at]googlegroups.com
For more options, visit this group at http://groups.google.com/group/trac-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Trac users RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact lists@gossamer-threads.com
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.