Lukasz Szybalski wrote:
> On Wed, Jul 9, 2008 at 8:26 PM, Ian Bicking <[EMAIL PROTECTED]> wrote:
>> Lukasz Szybalski wrote:
>>> On Wed, Jul 9, 2008 at 6:36 PM, Ian Bicking <[EMAIL PROTECTED]> wrote:
>>>> Lukasz Szybalski wrote:
>>>>> One more question on +var_name+:
>>>>> - Do I actually call the file "+var_name+.txt_tmpl" ? Which variable
>>>>> is it going to use? (there were license, description, myurl.....many
>>>>> more)?
>>>> Yes, +var_name+.txt_tmpl will name the file whatever the value of the
>>>> variable "var_name" is.  It's like $var_name, except easier to put in
>>>> filenames.
>>>>
>>>>> - Or do I call it +myurl+.txt_tmpl . If this is the case since
>>>>> "var[myurl] is a list how is it going to loop through the
>>>>> vars['myurl'] ?
>>>> If you have a list then this won't work -- you'll have to do something
>>>> like
>>>> (in a post method):
>>>>
>>>> for filename in vars['myurl']:
>>>>   # or whatever you have to do to instantiate this, I'm not sure:
>>>>   content = Template(filename=source_filename).substitute(**vars)
>>> What would be the "source_filename" here?
>>> Would it be the "+var_name+.txt_tmpl"? or "+package+/+var_name+.txt_tmpl"
>> You'll have to calculate it yourself.  Maybe like:
>>
> 
> One last question before I start coding this:
> 
> which __file__ is it? Does it exists when this will run or do I have
> to import it?
> 
> If I have to import it how do I do it?
> from paste import __file__
> or
> from myapp import __file__
> or??

You don't import __file__, it's the filename of the current Python 
module.  So this gives a filename relative to where your module is located.

> 
>> source_filename = os.path.join(os.path.dirname(__file__),
>> 'urlfile'+os.path.splitext(filename)[1])
>>
>>> for filename in vars['myurl']:
>>>  if filename=='txt':
>>>    source_filename="+package+/+package+/+var_name+.txt_tmpl" ???
>>>    content = Template(filename=source_filename).substitute(**vars)
>>>    self.ensure_file(filename, content)
>>>  elif filename=='csv':
>>>    source_filename="+package+/+var_name+.csv_tmpl" ???
>>>    content = Template(filename=source_filename).substitute(**vars)
>>>    self.ensure_file(filename, content)
>>>
>>> If 'txt' was provided only, how will paste know not to fill and copy
>>> rest of the templates, which I think is a default behavior if all of
>>> them are under +package+?
>>> myapp
>>> |-- __init__.py
>>> |-- __init__.pyc
>>> |-- myapp
>>> |   |-- __init__.py
>>> |   |-- __init__.pyc
>>> |   `-- templates
>>> |       |-- +package+
>>> |       |   `-- +var_name+.txt_tmpl
>>> |       |   `-- +var_name+.csv_tmpl
>>> |       |   `-- +var_name+.tsv_tmpl
>>> |       |   `-- +var_name+.sh_tmpl
>> You should put those files outside the templates/ directory.
> 
> What directory would you recommend I put it in?

Inside myapp/

-- 
Ian Bicking : [EMAIL PROTECTED] : http://blog.ianbicking.org

_______________________________________________
Paste-users mailing list
[email protected]
http://webwareforpython.org/cgi-bin/mailman/listinfo/paste-users

Reply via email to