Remote PDB and Django

Recently I have had to debug some error in Django system. In fact the problem was somewhere inside views and the debug page did not give any important information (as usually) and randomly show different place in .py files where exception was raised. I could not put standard pdb debugger, cause the problem  appeared only on nginx+uwsgi setup. I could not reproduce it on internal django webserver.
How to put debugger in uwsgi environment? Of course we do not have access to terminal in that case but we can use remote debugger. I have found very small and simply debugger rpdb:

http://tamentis.com/projects/rpdb/ 
Simply install it by pip and then put in the code:
 
import rpdb; rpdb.set_trace()
 
By default, rpdb listen on 4444 port so the next step is to connect to it by e.g. nc:
 
$ nc zuzia 4444

[teodor@zuzia production]$ nc zuzia 4444
--Call--
> /home/teodor/project/test/lib/python2.7/site-packages/rpdb/__init__.py(37)shutdown()
-> def shutdown(self):
(Pdb) w
  /home/teodor/project/test/lib/python2.7/site-packages/django/core/management/commands/runserver.py(107)inner_run()
-> run(self.addr, int(self.port), handler, ipv6=self.use_ipv6)
  /home/teodor/project/test/lib/python2.7/site-packages/django/core/servers/basehttp.py(696)run()
-> httpd.serve_forever()
  /usr/lib64/python2.7/SocketServer.py(227)serve_forever()
-> self._handle_request_noblock()
  /usr/lib64/python2.7/SocketServer.py(284)_handle_request_noblock()
-> self.process_request(request, client_address)
  /usr/lib64/python2.7/SocketServer.py(310)process_request()
-> self.finish_request(request, client_address)
  /usr/lib64/python2.7/SocketServer.py(323)finish_request()
-> self.RequestHandlerClass(request, client_address, self)
  /home/teodor/project/test/lib/python2.7/site-packages/django/core/servers/basehttp.py(570)__init__()
-> BaseHTTPRequestHandler.__init__(self, *args, **kwargs)
  /usr/lib64/python2.7/SocketServer.py(639)__init__()
-> self.handle()
  /home/teodor/project/test/lib/python2.7/site-packages/django/core/servers/basehttp.py(615)handle()
-> handler.run(self.server.get_app())
  /home/teodor/project/test/lib/python2.7/site-packages/django/core/servers/basehttp.py(283)run()
-> self.result = application(self.environ, self.start_response)
  /home/teodor/project/test/lib/python2.7/site-packages/django/contrib/staticfiles/handlers.py(68)__call__()
-> return self.application(environ, start_response)
  /home/teodor/project/test/lib/python2.7/site-packages/django/core/handlers/wsgi.py(273)__call__()
-> response = self.get_response(request)
  /home/teodor/project/test/lib/python2.7/site-packages/django/core/handlers/base.py(111)get_response()
-> response = callback(request, *callback_args, **callback_kwargs)
  /media/Crypted/teodor/projects/test/web/views.py(525)wrapper()
-> return panel_view(request, *args, **kw)
  /media/Crypted/teodor/projects/test/web/views.py(540)test()
-> import rpdb; rpdb.set_trace()
  /home/teodor/project/test/lib/python2.7/site-packages/rpdb/__init__.py(62)set_trace()
-> debugger.shutdown()
> /home/teodor/project/test/lib/python2.7/site-packages/rpdb/__init__.py(37)shutdown()
-> def shutdown(self):
(Pdb) 

Django template tag: display some content in specified time range

Django template tags are very powerful tool for extending this template framework, in fact built-in set of filters and tags is very large but from time to time it is the need to do something custom. 
Recently I have got a task that required to display some content in specified time range. I could not find built in solution so I have prepared template tag that behave like {% if %}{% else %} tag set.

Code is available here: https://github.com/MrTheodor/django-snippets

How to use it?

Usage:
   1. Define in settings dict TIME_BLOCK with names of block that has to be
   shown on certain time:
       TIME_BLOCK = {
           'block1': {
               'from_date': datetime.datetime(2012, 04, 28, 13, 48),
               'to_date': datetime.datetime(2012, 04, 30, 13, 48),
               'show': True
           }
       }
   
   2. In template use it in such way:
       
       {% showtime block1 %}
           content that will be displayed between 2012-04-28 13:48 and 2012-04-30
           13:48
       {% else %}
           content that will be displayed before and after that time
       {% endshowtime %}

  There is also the possibility to do it in the reverse way by using option 'show'
 

Enjoy!

Mendeley with Fedora 16


Few months ago I wrote about my problems with running this very nice software on my Fedora 14.

After while, I've upgrade my Fedora to 15, next to 16 and recently I've noticed that Mendeley again have not worked.
What I've got on console is some memory pointer error:

[teodor@zuzia lib]$ mendeley
Running /home/teodor/download/apps/mendeleydesktop-1.1.3-linux-x86_64/bin/..//lib/mendeleydesktop/libexec/mendeleydesktop.x86_64
loaded the Generic plugin
QSharedPointer: pointer 0x260f550 already has reference counting

Google said that problem is related to the Qt library, again.. this time you can simply run mendeleydesktop with option that switch app to use internal version of library. I've modified running script and set this option on by add after line 199 this statement:

use_system_qt = False

That's all for a while... Mendeley starts but it shows similary error like in previous post.
QSslSocket: cannot call unresolved function d2i_X509
QSslSocket: cannot call unresolved function d2i_X509
QSslSocket: cannot call unresolved function SSLv3_client_method
QSslSocket: cannot call unresolved function SSL_CTX_new
QSslSocket: cannot call unresolved function SSL_library_init
QSslSocket: cannot call unresolved function ERR_get_error
QSslSocket: cannot call unresolved function ERR_error_string
QSslSocket: cannot call unresolved function SSLv3_client_method
QSslSocket: cannot call unresolved function SSL_CTX_new

This time solution is rather different. You need to install package openssl-devel:

su -c 'yum install openssl-devel' 

gnome-shell-ext-icon-manager

Small news. Week ago I've published new version of this plugin. It should work on GNOME 3.2;
https://github.com/MrTheodor/gnome-shell-ext-icon-manager

Gnome 3.2 and two screens

GNOME 3.2 try to be considered as the most user-friendly environment around the Linux world. Maybe that's why most settings has to be set up by dconf-editor or via so very intuitive dialog box:
Guess what, I want to set primary display to Goldstar. And I can't do it by some select box, dialog box or other stuff. So the tip:
To set up primary display, you need to drag this black bar on display which you want to be your primary display.
Next point, of course it works, your topbar is moved on your primary desktop, but what was funny  Message bar (bottom bar) was still on laptop display. So next tip:
You need to move your displays on the same level to set up message bar on primary display

Why it cannot look like here, with small checkbox Primary display ? Or maybe it looks to much complicated for typical GNOME user?