Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Few questions about paste-script
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  5 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Andrea Crotti  
View profile  
 More options Sep 22 2011, 10:58 am
From: Andrea Crotti <andrea.crott...@gmail.com>
Date: Thu, 22 Sep 2011 07:58:58 -0700 (PDT)
Local: Thurs, Sep 22 2011 10:58 am
Subject: Few questions about paste-script
I'm not completely sure this is the right place to talk about paste-
script, but I didn't find anything else...

Anyway we thought to adopt paste-script in our company to generate and
eventually manipulate our python application (since there is quite a
lot of boiler-plate).

Paste-script seems really to be the right tool, the only thing is that
the documentation is a bit lacking and I'm a bit lost on a few
things...

1. when I create a template with a few variables, I would like to make
one of the variables depending on another one.
   So if I do simply
   var('project'...), var('camelized_project'), the second one should
be assigne d to the camelized version of the first.
   Reading also the code it doesn't seem so easy.

   So I thought to do it with cheetah, and I created and imported a
function.
   I can't, however, import the function (which path should I use),
the name of the module is not in the namespace...

2. a project template should be composed by many smaller templates
(which can be single files or a bunch of files).
   I think that I should use "required_templates" for that, or is
there any other way?
   But the mechanism doesn't look very dynamic too...

Any advise or some nice example code that I could take a look at?
Thanks,
Andrea


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ian Bicking  
View profile  
 More options Sep 22 2011, 1:54 pm
From: Ian Bicking <i...@colorstudy.com>
Date: Thu, 22 Sep 2011 12:54:50 -0500
Local: Thurs, Sep 22 2011 1:54 pm
Subject: Re: [Paste] Few questions about paste-script

On Thu, Sep 22, 2011 at 9:58 AM, Andrea Crotti <andrea.crott...@gmail.com>wrote:

You should probably override the Template.check_vars() method and just
handle it manually.

>   So I thought to do it with cheetah, and I created and imported a
> function.
>   I can't, however, import the function (which path should I use),
> the name of the module is not in the namespace...

With Tempita you can also always do:

{{py:
if not camelized_project:
    camelized_project = camelize(project)

}}

But it would have to be in each .tmpl file I think.  Better to use
check_vars.

> 2. a project template should be composed by many smaller templates
> (which can be single files or a bunch of files).
>   I think that I should use "required_templates" for that, or is
> there any other way?
>   But the mechanism doesn't look very dynamic too...

No, unfortunately it is not, though you could override .run() and import and
execute other templates manually, instead of having pastescript try to
figure out what templates to run through required_templates.

> Any advise or some nice example code that I could take a look at?

ZopeSkel has the largest collection of templates, I think, but I haven't
looked at how specifically they've implemented them.

  Ian


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Andrea Crotti  
View profile  
 More options Sep 23 2011, 4:39 am
From: Andrea Crotti <andrea.crott...@gmail.com>
Date: Fri, 23 Sep 2011 09:39:12 +0100
Local: Fri, Sep 23 2011 4:39 am
Subject: Re: [Paste] Few questions about paste-script

On 09/22/2011 06:54 PM, Ian Bicking wrote:

> You should probably override the Template.check_vars() method and just
> handle it manually.

Makes sense, but how would I do this anyway?
I mean I still have to declare somehow the dependencies in the variables.

The only reasonable way that I see is to modify the "var" class adding
def __init__(self,.... other_var=None, transform_function=None)

And then passing the right function to transform one variable into the
other.
The problem them is that I would have to modify the code in place,
(unless maybe I make a "var" wrapper overriding __init__), which is a
bit hackish solution.

What other possibility would I have?

>     2. a project template should be composed by many smaller templates
>     (which can be single files or a bunch of files).
>       I think that I should use "required_templates" for that, or is
>     there any other way?
>       But the mechanism doesn't look very dynamic too...

> No, unfortunately it is not, though you could override .run() and
> import and execute other templates manually, instead of having
> pastescript try to figure out what templates to run through
> required_templates.

Mmm that's a bit sad, required_template itself might also actually be
fine in theory, but then I would have to find a way to extract a
sub-template in the right (generated) sub-directory for example, which
is also a bit hard to do I reckon...

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ian Bicking  
View profile  
 More options Sep 23 2011, 12:25 pm
From: Ian Bicking <i...@colorstudy.com>
Date: Fri, 23 Sep 2011 11:25:13 -0500
Local: Fri, Sep 23 2011 12:25 pm
Subject: Re: [Paste] Few questions about paste-script

On Fri, Sep 23, 2011 at 3:39 AM, Andrea Crotti <andrea.crott...@gmail.com>wrote:

I wasn't thinking about anything too fancy...

def check_vars(self, vars, cmd):
    vars.setdefault('camelizedproject', camelize(vars['project'])

def run(self, command, output_dir, vars):
    subtemplate = some.other.template.Template('someother')
    new_vars = vars.copy()
    new_vars['something'] = 'another thing'
    subtemplate.run(command, os.path.join(output_dir, 'subdir'), new_vars)
    super(Template, self).run(command, output_dir, vars)

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Andrea Crotti  
View profile  
 More options Sep 27 2011, 9:57 am
From: Andrea Crotti <andrea.crott...@gmail.com>
Date: Tue, 27 Sep 2011 14:57:52 +0100
Local: Tues, Sep 27 2011 9:57 am
Subject: Re: [Paste] Few questions about paste-script

Ian Bicking <i...@colorstudy.com> writes:
> def run(self, command, output_dir, vars):
>     subtemplate = some.other.template.Template('someother')
>     new_vars = vars.copy()
>     new_vars['something'] = 'another thing'
>     subtemplate.run(command, os.path.join(output_dir, 'subdir'),
> new_vars)
>     super(Template, self).run(command, output_dir, vars)
>  

Ok then I followed your advises (I hope) and I did something as below.

So in the run I instantiate three subtemplates and I iterate over them.
Then check_vars has a new variable which is the camelized version.

There are two problems:
- the camelized variable seems as the camelized of the default variable,
  and doesn't change after I set a value. I have the impression that
  without adding some intelligence to "var" is not going to work in this way...

- the template expansion gets stuck here:
    File "/usr/lib/python2.7/site-packages/paste/script/command.py", line 218, in run
    result = self.command()
  File "/usr/lib/python2.7/site-packages/paste/script/create_distro.py", line 133, in command
    vars['egg_plugins'] = egg_plugins
TypeError: 'NoneType' object does not support item assignment

And debugging I see that *vars* is in fact None, but I don't get why,
because right before I call the "super" in check_vars it's actually
still a dictionary...

--8<---------------cut here---------------start------------->8---

....
class PSIEgg(Template):
    summary = 'basic egg template'
    _template_dir = 'psi_egg'
    vars = []

class PSIProject(Template):
    """Template for a new PSI project
    """

    egg_plugins = ['PSIManage']
    summary = 'Template for creating a basic PSI application structure'
    _template_dir = 'template'
    use_cheetah = True
    # the vars should be asked and filled in automatically
    vars = [
        var('application', 'Application Name', default='PSI application'),
        #TODO: another transformation for the plugin name
        var('plugin_name', 'Name of the plugin',
            default='PSI Plugin')
        ]

    def check_vars(self, vars, cmd):
        vars.setdefault('camelized_project', camelize_string(vars['project']))
        to_pass = dict(vars)
        super(PSIProject, self).check_vars(to_pass, cmd)

    # override the "run" method
    # + copy variables
    # + run all the subtemplates in the sub_directory
    def run(self, command, output_dir, vars):
        subtemplates = [PSIApp(), PSIEgg(), PSIProject()]

        new_vars = vars.copy()
        new_vars['something'] = 'another thing'
        # TODO: check that it's actually expanding in the right place
        for sub in subtemplates:
            sub.run(command, output_dir, new_vars)

        super(Template, self).run(command, output_dir, vars)

--8<---------------cut here---------------end--------------->8---


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »