Re: Compile Cheetah Template on Windows

2007-11-29 Thread Tim Roberts
brianrpsgt1 [EMAIL PROTECTED] wrote:

Tim, thank you very much for the reply.  The 'cheetah' function is now
working!

I am still having a problem creating the file.  I continually get
errors.  I am sure that it is something very simple.

Below is the code, please guide me in the right direction ::

import psycopg2, psycopg2.extensions
from Cheetah.Template import Template
import operator
import os
from SafetyNet import SafetyNet

filename = open(C:\Python25\Lib\site-packages\PSN
\InstalledDevices.html)

There are three problems here.  First, you have bare backslashes in this
string.  You happened to get lucky with this one, but if your file had been
called ...\textfile.html, it would have failed because \t is the tab
character.  You need to either:
  1. Double all the backslashes (...25\\Lib\\site-...)
  2. Use a raw string (open(rC:\Python25...))
  3. Use forward slashes (open(C:/Python25/Lib/site-...))

Second, later on you try to write to this file, but you have opened it in
read mode.

Third, you should not be doing your development work inside the Python
site-packages directory.  The only thing in there should be the files from
the add-on packages you have installed.  Remember that, when you upgrade,
the site-packages folder will go away.

You need:
  filename = open(C:/Development/InstalledDevices.html, w)

pocmonitors_cur = db.cursor()
pocmonitors_cur.execute(SELECT pocmonitor_name, pocmonitor_sn FROM
pocmonitor ORDER BY pocmonitor_name)

pocmonitors = []

for i in range(pocmonitors_cur.rowcount) :
pocmonitors.append(pocmonitors_cur.fetchone())
pocmonitors_cur.close()
db.close()

What are you trying to do here?  If you just want to turn the query results
into a list, you can just do:

pocmonitors = pocmonitors_cur.fetchall()

output = Template(file='C:\Python25\Lib\site-packages\PSN
\SafetyNet.tmpl', searchList=[nameSpace])

This string also needs to be escaped.
-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza  Boekelheide, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Compile Cheetah Template on Windows

2007-11-28 Thread brianrpsgt1
Tim, thank you very much for the reply.  The 'cheetah' function is now
working!

I am still having a problem creating the file.  I continually get
errors.  I am sure that it is something very simple.

Below is the code, please guide me in the right direction ::

import psycopg2, psycopg2.extensions
from Cheetah.Template import Template
import operator
import os
from SafetyNet import SafetyNet

filename = open(C:\Python25\Lib\site-packages\PSN
\InstalledDevices.html)

db = psycopg2.connect(dbname='XXX' user='XXX' host='XXX')

pocmonitors_cur = db.cursor()
pocmonitors_cur.execute(SELECT pocmonitor_name, pocmonitor_sn FROM
pocmonitor ORDER BY pocmonitor_name)

pocmonitors = []

for i in range(pocmonitors_cur.rowcount) :
pocmonitors.append(pocmonitors_cur.fetchone())
pocmonitors_cur.close()
db.close()

total_results = len(pocmonitors)

nameSpace = {'title': 'First Cheetah Example', 'pocmonitors':
pocmonitors, 'total_results': total_results}

output = Template(file='C:\Python25\Lib\site-packages\PSN
\SafetyNet.tmpl', searchList=[nameSpace])

print output


filename.write(output)



Thanks for the help!

B



Tim Roberts wrote:
 brianrpsgt1 [EMAIL PROTECTED] wrote:
 
 I have been able to successful pull info from a MySQL DB, get the
 results and output them in an HTML format using Cheetah to the screen
 using IDLE.  I am doing this on a Windows Laptop, running WinXP,
 Python 2.5 and the latest version of Cheetah.
 
 I have two questions:
 1. How and where do you compile Cheetah templates in Windows?  The
 command in the docs is cheetah compile a, however, I believe that this
 is for Linux.  This does nothing in a DOS Prompt.  Please provide the
 info for this command in Windows.

 The Cheetah installation should have created scripts called cheetah and
 cheetah-compile in your Python25\Scripts directory.  The issue you have
 is that they aren't on your path.

 One answer is to copy Python25\Scripts\cheetah to \Windows\cheetah.py and
 Python25\Scripts\cheetah-compile to \Windows\cheetah-compile.py.  Then you
 can type cheetah.py compile xxx or cheetah-compile.py xxx.

 However, you don't have to compile them in advance.  You can do from
 Cheetah.Template import Template and compile them on the fly, with
tmpl = Template( file='page.tmpl' )

 2. How do I output the HTML to a file?  I tried the following:
 
 FILE = open(filename, wt)
 FILE.writelines(output)
 FILE.close()
 
 I get an error though that states that writelines() requires an
 interable argument

 Just use FILE.write( output ).
 --
 Tim Roberts, [EMAIL PROTECTED]
 Providenza  Boekelheide, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Compile Cheetah Template on Windows

2007-11-25 Thread Tim Roberts
brianrpsgt1 [EMAIL PROTECTED] wrote:

I have been able to successful pull info from a MySQL DB, get the
results and output them in an HTML format using Cheetah to the screen
using IDLE.  I am doing this on a Windows Laptop, running WinXP,
Python 2.5 and the latest version of Cheetah.

I have two questions:
1. How and where do you compile Cheetah templates in Windows?  The
command in the docs is cheetah compile a, however, I believe that this
is for Linux.  This does nothing in a DOS Prompt.  Please provide the
info for this command in Windows.

The Cheetah installation should have created scripts called cheetah and
cheetah-compile in your Python25\Scripts directory.  The issue you have
is that they aren't on your path.

One answer is to copy Python25\Scripts\cheetah to \Windows\cheetah.py and
Python25\Scripts\cheetah-compile to \Windows\cheetah-compile.py.  Then you
can type cheetah.py compile xxx or cheetah-compile.py xxx.

However, you don't have to compile them in advance.  You can do from
Cheetah.Template import Template and compile them on the fly, with
   tmpl = Template( file='page.tmpl' )

2. How do I output the HTML to a file?  I tried the following:

FILE = open(filename, wt)
FILE.writelines(output)
FILE.close()

I get an error though that states that writelines() requires an
interable argument

Just use FILE.write( output ).
-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza  Boekelheide, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Compile Cheetah Template on Windows

2007-11-24 Thread brianrpsgt1
Newbie here

I have been able to successful pull info from a MySQL DB, get the
results and output them in an HTML format using Cheetah to the screen
using IDLE.  I am doing this on a Windows Laptop, running WinXP,
Python 2.5 and the latest version of Cheetah.

I have two questions:
1. How and where do you compile Cheetah templates in Windows?  The
command in the docs is cheetah compile a, however, I believe that this
is for Linux.  This does nothing in a DOS Prompt.  Please provide the
info for this command in Windows.

2. How do I output the HTML to a file?  I tried the following:

FILE = open(filename, wt)
FILE.writelines(output)
FILE.close()

I get an error though that states that writelines() requires an
interable argument

Thnx for any assistance!

B

-- 
http://mail.python.org/mailman/listinfo/python-list