León Domingo | 18 Jul 13:26 2011
Picon

Terminal stuff

Hi,
I'm writing an script inside my TG2 app which I want to run in the
terminal and I'm not able to access the ugettext or lazy_ugettext
functions.

from pylons.i18n import ugettext as _, lazy_ugettext as l_

I'm getting this error

TypeError: No object (name: translator) has been registered for this
thread

The script looks like this:

import os
from argparse import ArgumentParser
from paste.deploy import appconfig
from sapns.config.environment import load_environment
from sapns.lib.sapns.util import update_metadata

def load_config(filename):
    conf = appconfig('config:' + os.path.abspath(filename))
    load_environment(conf.global_conf, conf.local_conf)

def parse_args():
    parser = ArgumentParser(description=__doc__)
    parser.add_argument('conf_file', help='configuration to use')

    return parser.parse_args()

(Continue reading)

Diez B. Roggisch | 18 Jul 14:03 2011
Picon

Re: Terminal stuff

On Monday, July 18, 2011 01:26:15 pm León Domingo wrote:
> Hi,
> I'm writing an script inside my TG2 app which I want to run in the
> terminal and I'm not able to access the ugettext or lazy_ugettext
> functions.
> 
> from pylons.i18n import ugettext as _, lazy_ugettext as l_
> 
> I'm getting this error
> 
> TypeError: No object (name: translator) has been registered for this
> thread

You need to register the translator for the given thread. This is from some of 
our code that works:

import pylons
from pylons.i18n.translation import _get_translator

# this is a hook that is needed to set up some
# things that are needed inside transaction hooks
 <at> contextmanager
def set_language_context_manager(language=None, **kwargs):
    # this is stolen from the pylons test setup.
    # it will make sure the gettext-stuff is working
    translator = _get_translator(language, **kwargs)
    pylons.translator._push_object(translator)
    try:
        yield
    finally:
(Continue reading)

León Domingo | 18 Jul 14:11 2011
Picon

Re: Terminal stuff

Thanks a lot, Diez

León Domingo

ender
LA FACTORÍA DE SOFTWARE

Av. Cerro del Águila 7, 2ª planta - S23
28703 S.S. de los Reyes
Madrid

tlf. y fax: 902 01 44 01
www.ender.es


On 18 July 2011 14:03, Diez B. Roggisch <deets <at> web.de> wrote:
On Monday, July 18, 2011 01:26:15 pm León Domingo wrote:
> Hi,
> I'm writing an script inside my TG2 app which I want to run in the
> terminal and I'm not able to access the ugettext or lazy_ugettext
> functions.
>
> from pylons.i18n import ugettext as _, lazy_ugettext as l_
>
> I'm getting this error
>
> TypeError: No object (name: translator) has been registered for this
> thread

You need to register the translator for the given thread. This is from some of
our code that works:

import pylons
from pylons.i18n.translation import _get_translator

# this is a hook that is needed to set up some
# things that are needed inside transaction hooks
<at> contextmanager
def set_language_context_manager(language=None, **kwargs):
   # this is stolen from the pylons test setup.
   # it will make sure the gettext-stuff is working
   translator = _get_translator(language, **kwargs)
   pylons.translator._push_object(translator)
   try:
       yield
   finally:
       pylons.translator._pop_object()


HTH,

Diez

--
You received this message because you are subscribed to the Google Groups "TurboGears" group.
To post to this group, send email to turbogears <at> googlegroups.com.
To unsubscribe from this group, send email to turbogears+unsubscribe <at> googlegroups.com.
For more options, visit this group at http://groups.google.com/group/turbogears?hl=en.


--
You received this message because you are subscribed to the Google Groups "TurboGears" group.
To post to this group, send email to turbogears <at> googlegroups.com.
To unsubscribe from this group, send email to turbogears+unsubscribe <at> googlegroups.com.
For more options, visit this group at http://groups.google.com/group/turbogears?hl=en.
León Domingo | 11 Aug 09:06 2011
Picon

Re: Terminal stuff

Hi,
I need the same thing for tmpl_context.

I've built the skeleton of the decorator but I need more information
to fill in the gaps.

 <at> contextmanager
def set_tmpl_context_cm():
    tc = ????
    pylons.tmpl_context._push_object(tc)
    try:
        yield
    finally:
        pylons.tmpl_context._pop_object()

Where can I get the "tc" (tmpl_context)? Which parameters do I need?

Thanks

León

On Jul 18, 2:11 pm, León Domingo <leon.domi... <at> ender.es> wrote:
> Thanks a lot, Diez
>
> León Domingo
>
> *ender*
> *LA FACTORÍA DE SOFTWARE*
>
> Av. Cerro del Águila 7, 2ª planta - S23
> 28703 S.S. de los Reyes
> Madrid
>
> tlf. y fax: 902 01 44 01
> *www.ender.es*
>
> On 18 July 2011 14:03, Diez B. Roggisch <de... <at> web.de> wrote:
>
>
>
>
>
>
>
> > On Monday, July 18, 2011 01:26:15 pm León Domingo wrote:
> > > Hi,
> > > I'm writing an script inside my TG2 app which I want to run in the
> > > terminal and I'm not able to access the ugettext or lazy_ugettext
> > > functions.
>
> > > from pylons.i18n import ugettext as _, lazy_ugettext as l_
>
> > > I'm getting this error
>
> > > TypeError: No object (name: translator) has been registered for this
> > > thread
>
> > You need to register the translator for the given thread. This is from some
> > of
> > our code that works:
>
> > import pylons
> > from pylons.i18n.translation import _get_translator
>
> > # this is a hook that is needed to set up some
> > # things that are needed inside transaction hooks
> >  <at> contextmanager
> > def set_language_context_manager(language=None, **kwargs):
> >    # this is stolen from the pylons test setup.
> >    # it will make sure the gettext-stuff is working
> >    translator = _get_translator(language, **kwargs)
> >    pylons.translator._push_object(translator)
> >    try:
> >        yield
> >    finally:
> >        pylons.translator._pop_object()
>
> > HTH,
>
> > Diez
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "TurboGears" group.
> > To post to this group, send email to turbogears <at> googlegroups.com.
> > To unsubscribe from this group, send email to
> > turbogears+unsubscribe <at> googlegroups.com.
> > For more options, visit this group at
> >http://groups.google.com/group/turbogears?hl=en.

--

-- 
You received this message because you are subscribed to the Google Groups "TurboGears" group.
To post to this group, send email to turbogears <at> googlegroups.com.
To unsubscribe from this group, send email to turbogears+unsubscribe <at> googlegroups.com.
For more options, visit this group at http://groups.google.com/group/turbogears?hl=en.

León Domingo | 11 Aug 11:05 2011
Picon

Re: Terminal stuff

Hi,
In fact I need to know how setup TG so I can execute scripts (shell)
using all the stuff I've already available in my app

The problem now is tmpl_context, as I said before, and logging. The
message is:

  No handlers could be found for logger "foo"

in a line like this

  logger = logging.getLogger('foo')

Thanks

León

On Aug 11, 9:06 am, León Domingo <leon.domi... <at> ender.es> wrote:
> Hi,
> I need the same thing for tmpl_context.
>
> I've built the skeleton of the decorator but I need more information
> to fill in the gaps.
>
>  <at> contextmanager
> def set_tmpl_context_cm():
>     tc = ????
>     pylons.tmpl_context._push_object(tc)
>     try:
>         yield
>     finally:
>         pylons.tmpl_context._pop_object()
>
> Where can I get the "tc" (tmpl_context)? Which parameters do I need?
>
> Thanks
>
> León
>
> On Jul 18, 2:11 pm, León Domingo <leon.domi... <at> ender.es> wrote:
>
>
>
>
>
>
>
> > Thanks a lot, Diez
>
> > León Domingo
>
> > *ender*
> > *LA FACTORÍA DE SOFTWARE*
>
> > Av. Cerro del Águila 7, 2ª planta - S23
> > 28703 S.S. de los Reyes
> > Madrid
>
> > tlf. y fax: 902 01 44 01
> > *www.ender.es*
>
> > On 18 July 2011 14:03, Diez B. Roggisch <de... <at> web.de> wrote:
>
> > > On Monday, July 18, 2011 01:26:15 pm León Domingo wrote:
> > > > Hi,
> > > > I'm writing an script inside my TG2 app which I want to run in the
> > > > terminal and I'm not able to access the ugettext or lazy_ugettext
> > > > functions.
>
> > > > from pylons.i18n import ugettext as _, lazy_ugettext as l_
>
> > > > I'm getting this error
>
> > > > TypeError: No object (name: translator) has been registered for this
> > > > thread
>
> > > You need to register the translator for the given thread. This is from some
> > > of
> > > our code that works:
>
> > > import pylons
> > > from pylons.i18n.translation import _get_translator
>
> > > # this is a hook that is needed to set up some
> > > # things that are needed inside transaction hooks
> > >  <at> contextmanager
> > > def set_language_context_manager(language=None, **kwargs):
> > >    # this is stolen from the pylons test setup.
> > >    # it will make sure the gettext-stuff is working
> > >    translator = _get_translator(language, **kwargs)
> > >    pylons.translator._push_object(translator)
> > >    try:
> > >        yield
> > >    finally:
> > >        pylons.translator._pop_object()
>
> > > HTH,
>
> > > Diez
>
> > > --
> > > You received this message because you are subscribed to the Google Groups
> > > "TurboGears" group.
> > > To post to this group, send email to turbogears <at> googlegroups.com.
> > > To unsubscribe from this group, send email to
> > > turbogears+unsubscribe <at> googlegroups.com.
> > > For more options, visit this group at
> > >http://groups.google.com/group/turbogears?hl=en.

--

-- 
You received this message because you are subscribed to the Google Groups "TurboGears" group.
To post to this group, send email to turbogears <at> googlegroups.com.
To unsubscribe from this group, send email to turbogears+unsubscribe <at> googlegroups.com.
For more options, visit this group at http://groups.google.com/group/turbogears?hl=en.

Michael Pedersen | 12 Aug 05:20 2011

Re: Re: Terminal stuff

First: tmpl_context. This is a variable that's filled in on a per-request basis. It simply does not make sense for a command line application. I'm not fond of saying that, but it really doesn't. So much so that attempting to use it for a command line application makes me think something is possibly wrong/broken with your design for the command line.

What are you actually trying to accomplish, and why does it seem to require tmpl_context? If you can answer those questions, we can devise better answers for how to get you what you need, without trying to use something that should only be used in the web.

For the logging, that's not so much fun. Logging is handled by the Python logging module. Check out http://docs.python.org/library/logging.html for an overview of the whole process. This will help to explain what handlers are, why you need them, and how they fit into the whole process. Next, check out http://docs.python.org/library/logging.handlers.html#module-logging.handlers for documentation on what handlers come with Python. You can write your own, but these are a good start. Finally, check out http://docs.python.org/library/logging.config.html#module-logging.config for a detailed explanation of ways to do configuration, including how to add handlers to your .ini file to make things work the way you expect.

You see, the problem with the "no handlers could be found" bit is that you need to add a handler for logging, or it won't work. All of those links I gave will go over the process in great detail, and are very helpful. I recommend using them, rather than asking me to retype everything from them here :)

On Thu, Aug 11, 2011 at 5:05 AM, León Domingo <leon.domingo <at> ender.es> wrote:
Hi,
In fact I need to know how setup TG so I can execute scripts (shell)
using all the stuff I've already available in my app

The problem now is tmpl_context, as I said before, and logging. The
message is:

 No handlers could be found for logger "foo"

in a line like this

 logger = logging.getLogger('foo')

Thanks

León

On Aug 11, 9:06 am, León Domingo <leon.domi... <at> ender.es> wrote:
> Hi,
> I need the same thing for tmpl_context.
>
> I've built the skeleton of the decorator but I need more information
> to fill in the gaps.
>
> <at> contextmanager
> def set_tmpl_context_cm():
>     tc = ????
>     pylons.tmpl_context._push_object(tc)
>     try:
>         yield
>     finally:
>         pylons.tmpl_context._pop_object()
>
> Where can I get the "tc" (tmpl_context)? Which parameters do I need?
>
> Thanks
>
> León
>
> On Jul 18, 2:11 pm, León Domingo <leon.domi... <at> ender.es> wrote:
>
>
>
>
>
>
>
> > Thanks a lot, Diez
>
> > León Domingo
>
> > *ender*
> > *LA FACTORÍA DE SOFTWARE*
>
> > Av. Cerro del Águila 7, 2ª planta - S23
> > 28703 S.S. de los Reyes
> > Madrid
>
> > tlf. y fax: 902 01 44 01
> > *www.ender.es*
>
> > On 18 July 2011 14:03, Diez B. Roggisch <de... <at> web.de> wrote:
>
> > > On Monday, July 18, 2011 01:26:15 pm León Domingo wrote:
> > > > Hi,
> > > > I'm writing an script inside my TG2 app which I want to run in the
> > > > terminal and I'm not able to access the ugettext or lazy_ugettext
> > > > functions.
>
> > > > from pylons.i18n import ugettext as _, lazy_ugettext as l_
>
> > > > I'm getting this error
>
> > > > TypeError: No object (name: translator) has been registered for this
> > > > thread
>
> > > You need to register the translator for the given thread. This is from some
> > > of
> > > our code that works:
>
> > > import pylons
> > > from pylons.i18n.translation import _get_translator
>
> > > # this is a hook that is needed to set up some
> > > # things that are needed inside transaction hooks
> > > <at> contextmanager
> > > def set_language_context_manager(language=None, **kwargs):
> > >    # this is stolen from the pylons test setup.
> > >    # it will make sure the gettext-stuff is working
> > >    translator = _get_translator(language, **kwargs)
> > >    pylons.translator._push_object(translator)
> > >    try:
> > >        yield
> > >    finally:
> > >        pylons.translator._pop_object()
>
> > > HTH,
>
> > > Diez
>
> > > --
> > > You received this message because you are subscribed to the Google Groups
> > > "TurboGears" group.
> > > To post to this group, send email to turbogears <at> googlegroups.com.
> > > To unsubscribe from this group, send email to
> > > turbogears+unsubscribe <at> googlegroups.com.
> > > For more options, visit this group at
> > >http://groups.google.com/group/turbogears?hl=en.

--
You received this message because you are subscribed to the Google Groups "TurboGears" group.
To post to this group, send email to turbogears <at> googlegroups.com.
To unsubscribe from this group, send email to turbogears+unsubscribe <at> googlegroups.com.
For more options, visit this group at http://groups.google.com/group/turbogears?hl=en.




--
Michael J. Pedersen
My IM IDs: Jabber/pedersen <at> icelus.tzo.com, AIM/pedermj022171
          Yahoo/pedermj2002, MSN/pedermj022171 <at> hotmail.com
My LinkedIn Profile: http://www.linkedin.com/in/michaeljpedersen
Twitter: pedersentg

--
You received this message because you are subscribed to the Google Groups "TurboGears" group.
To post to this group, send email to turbogears <at> googlegroups.com.
To unsubscribe from this group, send email to turbogears+unsubscribe <at> googlegroups.com.
For more options, visit this group at http://groups.google.com/group/turbogears?hl=en.

Gmane