Posted: janeiro 30th, 2007 | Author: coredump | Filed under: Linux e Open Source, Programação | Tags: admin, apache, python, turbogears
E então, muita gente usa frameworks como o Turbogears ou alguns menos legais como o Zope ou mesmo Ruby on Rails. Para garantir um bom serviço web, segurança e disponibilidade nada melhor que deixar essas belezas rodando atrás de um proxy Apache. Com o mod_proxy do Apache2 então, as coisas ficaram ainda mais simples.
Só que as vezes rola uma leseira meio generalizada. Como por exemplo deixar o servidor do framework servir conteúdo estático. Por mais que os servidores sejam confiáveis, melhor deixar para eles a tarefa mais especializada e deixar o trabalho pesado de imagens e javascript (ainda mais nestas épocas de javascripts gigantes) para nosso amigo Apache. Coisa simples na configuração, exemplo abaixo para turbogears:
Alias /static/ /usr/lib/python2.4/site-packages/app/static/
Alias /images/ /usr/lib/python2.4/site-packages/app/static/images/
ProxyPass /static !
ProxyPass /images !
ProxyPass http://127.0.0.1:8080/
ProxyPassReverse http://127.0.0.1:8080/
RequestHeader set CP-Location /
RewriteRule ^(.*) http://localhost:8080/$1 [P]
Basicamente, mandamos os requests de imagens e conteúdo estático direto pelo apache, sem precisar passar pela aplicação rodando no localhost. Ainda tenho de testar isso em ambiente real, mas pela minha experiência, só tem a melhorar a performance de tudo.
intel!
PS: Tive de editar o post umas 3 vezes, mas o boo-box tá mostrando os resultados direitinho. O que é o boo-box? São essas palavrinhas destacadas. Você pode saber mais no site deles. Muito massa a idéia. Eu to no beta testing com a Amazon e tá sendo bem interessante.
tags: turbogears, apache, proxy, boo-box
No Comments »
Posted: novembro 21st, 2006 | Author: coredump | Filed under: Linux e Open Source, Programação | Tags: javascript, turbogears
So, I was trying to make the Turbogears AutoComplete Widget work like the address field from gmail or hotmail. Basically to continue searching after a comma to add values. My javascript is not that good and I felt a little bad on messing with the default widgets, so I did something on the search controller to mimic this behavior. This is the complete controller I use with the Widget:
def complete(self, tagname):
tags = ['linux', 'security', 'love', 'politics', 'sex', 'religion',
'esports', 'programming', 'scifi', 'theories', 'spaced tag']
old_tagname = None
if ‘,’ in tagname:
new_tagname = tagname.replace(‘ ‘, ”).split(‘,’)
tagname = new_tagname.pop().strip()
old_tagname = ‘, ‘.join(new_tagname)
if tagname == ”:
return dict(tag = [])
reslist = []
for tag in tags:
if tag.startswith(tagname):
if old_tagname:
tag = old_tagname + ‘, ‘ + tag
reslist.append(tag)
return dict(tag = reslist)
@expose()
def default(self, *w, **kw):
raise redirect(“/”)
Yes, it’s kinda ugly but it works. In Brazil this is called gambiarra. I’ll elaborate a little more after, there’re too many variables and I’m sure I can make something more compact. Right now I just need this working
cya.Technorati Tags: turbogears, autocomplete, widgets, hacking
No Comments »
Posted: novembro 16th, 2006 | Author: coredump | Filed under: Programação | Tags: mysql, python, turbogears
So, I have this little problem…
- For design reasons, I must use SQLObject. SQLAlchemy is cool but managing all my relations ‘by hand’ is a very time consuming task and TurboGears implementation of ActiveMapper is unstable, at best.
- Turboentity was a good replacement using SQLA, but the project was dropped and merged with ActiveMapper, they’re all working on a new ORM layer for SQLA but right now, there’s not even an unstable one… ITOH, SO is the TG 1.0 official db layer, so it’s better supported.
- I host my turbogears projects on rimuhosting, on a Virtual Machine. The thing is, memory is a little tight and running apache/php/mysql for wordpress consumes most of it. My Trac/SVN system use little resources.
- I’ll finish in some weeks a TG app that, I hope, will attract a considerable ammount of users. I’m developing using a database in SQLite, but there’s no way to use that as a production db to something that can grow fast. And then my problems start…
MySQL/SQLObject UTF support seems to be erratic, I have run into problems before with this combination and on the TG group you can see any people complaining about a lot of problems with utf-8 and how mysql is erratic about it. My other choice is to use Postgres, but I don’t think that would fit on my brain-limited hosting machine, and removing MySQL is a problem because WordPress uses it (my blog…) and has no PGsql port avaiable.
So, anyone uses MySQL + SO or UTF and got some tips on the matter? How to make it work or at least do not be so buggy? I’ll be handling data from a lot of languages and I’ll just hate to spend time and time trying to debug some query that doesn’t work because of utf errors…
Technorati Tags: turbogears, mysql, unicode, sqlobject
2 Comments »
Posted: novembro 11th, 2006 | Author: coredump | Filed under: Linux e Open Source, Programação | Tags: python, turbogears
Tá bom… Vocês ficaram com dó e não me falaram que todo trabalho que eu tive aqui foi a toa porque o TurboGears já inclui uma função que serve pra mesma coisa e faz bem mais bem feito…
:\
intel
Technorati Tags: turbogears
No Comments »
Posted: novembro 9th, 2006 | Author: coredump | Filed under: Programação | Tags: python, turbogears
Tem vezes que eu faço umas coisas que eu acho particularmente bonitinhas. Não chega a ser Programação Arte, mas mesmo assim:
def put_message(message):
try:
cherrypy.session['message_queue'].append(message)
except KeyError:
cherrypy.session['message_queue'] = []
cherrypy.session['message_queue'].append(message)
def get_message():
try:
message = cherrypy.session['message_queue'].pop()
except (KeyError, IndexError):
return None
return message
Pra que isso? Simples assim, usando em turbogears você pode usar essa fila de mensagens para fazer redirects e não se preocupar em como passar dados interessantes para outra página. Sem usar campos hidden (hideous), ou passar a mensagem pela URL. Ou seja:
def redirector(self):
put_message(‘Voce foi redirecionado!’)
raise redirect(‘/’)
def index(self)
return dict(message = get_message())
E na template, criar uma div com um javascript que use essa mensagem de forma bonita e visivelmente simpática. Ou seja, não preciso mais ficar brigando com várias páginas de status
intel.
Technorati Tags: turbogears, cherrypy
1 Comment »
Comentários