Timur Izhbulatov — Tech stuff — Projects — Programming — Python — Linux: Tech stuff http://timka.org/tech Entries in the 'Tech stuff' category of Timur Izhbulatov — Tech stuff — Projects — Programming — Python — Linux Avoiding leakage of passwords to log files <p> <code>MaskedString</code> still holds the actuall string data which is accessible via <code>__getitem__</code> but overrides <code>__str__</code> and <code>__repr__</code> so that the string is presented in blinded form. This is useful for preventing leakage of sensitive data (card numbers, passwords etc.) to log files. </p> http://timka.org/tech/2011/06/04/avoiding-leakage-of-passwords-to-log-files http://timka.org/tech/2011/06/04/avoiding-leakage-of-passwords-to-log-files Simple pure Python config <p><blockquote><pre> (lambda path: open(path, 'w').write('path = %r' % path) or globals().__setitem__('__name__', None) or type( repr('config:' + path), (), (lambda d: execfile(path, {}, d) or d )({}) )() )('config.py') </pre></blockquote></p> http://timka.org/tech/2011/04/23/simple-pure-python-config http://timka.org/tech/2011/04/23/simple-pure-python-config Using inline types for mocking objects <p> A code snippet from my recent work: <blockquote><pre> def run_cmd(cmd, pipe=True, dry_run=False): log.debug('%r', cmd) def mock_child(): return type('dummy_child', (), dict(wait=lambda x: None))() if dry_run: return mock_child() stdout = subprocess.PIPE if pipe else None try: child = subprocess.Popen(cmd, stdout=stdout, shell=True) except Exception: log.exception(cmd + ':') return mock_child() return child </pre></blockquote> </p> http://timka.org/tech/2011/04/22/using-inline-types-for-mocking-objects http://timka.org/tech/2011/04/22/using-inline-types-for-mocking-objects Application components under shared namespace <p> It is often desirbale to decompose an application into several components. Perhaps one of the most common approaches is separating a model component that is responsible for data repesenataion and interaction with the database and then use it from other components. For instance, one of the other components can provide a sofisticated web-based UI to the model while another one implements a bare command-line interface. </p> <p> In this situation each component is a subproject that is distributed as a separate package, in the setuptools' sense. And view each component has its corresponding directory in the project's VCS repository which contains a everything that is typicaly necessary to build an <code>.egg</code>, <code>setup.py</code> and whatever else the developer finds approprate. </p> <p> A component, or subproject, usualy includes a number of modules which are organized inside a Python package. While it is possible to name the components' packages like <code>yourappmodel</code>, <code>yourappweb</code>and <code>yourappcli</code>, The Zen of Python says: <blockquote><pre> Namespaces are one honking great idea -- let's do more of those! </pre></blockquote> </p> <p> And applying to our example that means the packages should be named like yourapp.model, yourapp.web and yourapp.cli. </p> <p> Here I'm going to show how I work with a project that uses setuptools' namespace packages. </p> http://timka.org/tech/2010/08/24/application-components-under-shared-namespace http://timka.org/tech/2010/08/24/application-components-under-shared-namespace Haskell is self-hosted <p>I my <a href="/tech/2010/07/23/confession-of-love">previous post</a> I wrote about the technological <a href="/+tags/love">things I love</a>, and this time I am going to make a new addition to that, <a href="http://www.haskell.org">Haskell</a>. </p> <p><a href="http://9gag.com/gag/28126"><img style="display: block; margin: 32px 16px;" alt="Cool Haskell pixel art" src="/img/Haskell-cool-art.png"/></a></p> <p><a href="http://www.haskell.org">Haskell</a> is a very interesting language. It even seems somewhat alien to a person with background mostly in imperative and non-functional declarative programming languages like yours truly.</p> http://timka.org/tech/2010/08/09/haskell-is-self-hosted http://timka.org/tech/2010/08/09/haskell-is-self-hosted qooxdoo ContribLoader <p> Just a short note to myself. There's a bug in qooxdoo tool in <code>generator.action.ContribLoader.getRevision()</code>. The regular expression part should be <blockquote><pre> match = re.compile("\/viewvc\/qooxdoo-contrib\?view\=revision\&amp;revision\=([0-9]+)").search(line) </pre></blockquote> </p> http://timka.org/tech/2010/07/23/qooxdoo-contrib-loader http://timka.org/tech/2010/07/23/qooxdoo-contrib-loader Confession of Love <p>It's been a long time since my previous update, and many things have changed in my life. I've changed my job, quit my job, gone crazy, fallen in love, found myself, had two trips to Crimea, had a psychedelic experience and got a real African djembe from Ghana. </p> <p>But there's one thing I haven't done yet and it's confession of love. Not the kind of love we fall into, no. I'm talking about the professional kind of love.</p> <p>Why do I even talk about love in such an intellectualized high-tech field as information technology? I do this because I it's very important for me. Really, I've been working in IT since 2003, not to mention my earlier programming experience in the university and at school, and only now I fully realize why I'm still here. I simply like it.</p> http://timka.org/tech/2010/07/23/confession-of-love http://timka.org/tech/2010/07/23/confession-of-love Python urllib2 exceptions <p> Yesterday I made a working prototype of my Last.fm stream ripper written in Python. This is my second project that relatively intensively uses <code>urllib2</code> from Python standard library. </p> <p>One of important things that I've learned about <code>urllib2.urlopen()</code> from my previous project is that it does raise some other exceptions besides <code>urllib2.URLError</code> (e.g. <code>http.HTTPException</code> and <code>socket.error</code>) which is the only one mentioned in the <a href="http://docs.python.org/library/urllib2.html#urllib2.urlopen">documentation</a>.</p> http://timka.org/tech/2009/05/17/python-urllib2-exceptions http://timka.org/tech/2009/05/17/python-urllib2-exceptions How to fix font rendering in Firefox 3.5 on Ubuntu 9.04 <p>Yesterday I set up a fresh desktop with Ubuntu 9.04 (Jaunty Jackalope). One of the most pleasant features is Firefox 3.5 beta (Shiretoko) available out of the box, which is important for me since I use <a href="http://labs.mozilla.com/projects/weave/">Mozilla Weave</a> to sync my profiles. The problem is that Firefox 3.5 doesn't seem to use font hinting and therefore looks ugly while the default version (3.0) is OK.</p> http://timka.org/tech/2009/05/02/firefox-3.5-in-jaunty http://timka.org/tech/2009/05/02/firefox-3.5-in-jaunty Singleton in Python <p>Updated 2009-03-03. Arbitrary constructor arguments (Mark's suggestion).</p> <p>Updated 2008-12-30. Thread-safety.</p> <p> A recent <a href="http://www.plurk.com/p/amsvg">discussion</a> has drawn my attention again to the use of the Singleton pattern in Python. Here's how and why I do this. </p> http://timka.org/tech/2008/12/17/singleton-in-python http://timka.org/tech/2008/12/17/singleton-in-python Last.fm tag renaming utility update <p> I've updated my <a href="http://timka.org/svn/timka.org/tech/python/rename_lastfm_tag.py">Last.fm tag renaming utility</a>. </p> http://timka.org/tech/2008/08/15/lastfm-tag-renaming-utility-update http://timka.org/tech/2008/08/15/lastfm-tag-renaming-utility-update Release of watchdogdev <p> One of my projects is a Linux-based embedded device for playing commercials. The software part is a Python application controlling an <a href="http://mplayerhq.hu">MPlayer</a> process in slave mode. </p> <p> To make the whole system more fault-tolerant I wanted to use watchdog timer which would reboot the machine in case of software failure. Thus I needed to talk to Linux watchdog driver from my Python application. The Linux watchdog API defines a number of ioctl commands which can be sent to the driver. So, I wrote <a href="/watchdogdev">an extension module</a> which enables Python programms to use Linux watchdog API. </p> http://timka.org/tech/2008/04/21/watchdogdev-release http://timka.org/tech/2008/04/21/watchdogdev-release TurboGears behind Apache with Virtualmin <p>Recently <a href="http://matvey.org.ru/">Matvey</a> (thanks dude!) has set up a new <a href="http://www.virtualmin.com/">Virtualmin</a> hosting platform on <a href="http://debian.org/">Debian GNU/Linux</a>. When I was migrating <a href="http://timka.org/">timka.org</a> to this new platform I found out that Virtualmin is actually very powerful and nicely integrated with <a href="http://httpd.apache.org/">Apache</a> in Debian. Looking at all these new features and capabilities I thought that I could try to use them for running home-based <a href="http://turbogears.org/">TurboGears</a> applications on Virutalmin's virtual hosts.</p> http://timka.org/tech/2008/03/19/turbogears-behind-apache-with-virtualmin http://timka.org/tech/2008/03/19/turbogears-behind-apache-with-virtualmin Home-based installation of Python libraries <p>Many popular Python libraries are available in various Linux distributions. However, it is not always possible and/or desirable to install them from packages. For instance, sometimes you don't have root access to the target machine or just want to have other vesrion of some library isolated under your home directory.</p> <p>I've been successfully using this approach on my laptop and several development and production sites for about two years so far.</p> http://timka.org/tech/2008/01/30/home-based-installation-of-python-libraries http://timka.org/tech/2008/01/30/home-based-installation-of-python-libraries Blog engine for timka.org <p> I've been looking for some simple static blog engine and stumbled upon <a href="http://vss.73rus.com/wadcomblog/">WadcomBlog</a> by <a href="http://vss.73rus.com/">Vlad Skvortsov</a>. </p> http://timka.org/tech/2008/01/26/blog-engine http://timka.org/tech/2008/01/26/blog-engine GNU Autotools tutorial <p> Have you ever installed any software from source? If you have I bet you've also noticed all that stuff like configure.in and Makefile.in. Want to know what's it for, how it works and how it can be used? I've written a brief <a href="/svn/timka.org/tech/gnu-autotools-tutorial.sh"> tutorial</a>. </p> http://timka.org/tech/2007/03/01/gnu-autotools-tutorial http://timka.org/tech/2007/03/01/gnu-autotools-tutorial Editing ID3 tags with Python and Mutagen <p> Recently I've stumbled upon some <a href="http://en.wikipedia.org/wiki/Mp3">MP3</a> files containing no tags. I tried to tag these files using <a href="http://www.sacredchao.net/quodlibet">Quodlibet</a> but it appeared to be impossible. After a breif investigation of the problem I found out that it's just raw MPEG Layer III streams with no proper <a href="http://id3.org">ID3</a> headers. In order to fix this I decided to write a <a href="http://python.org">Python</a> script. </p> http://timka.org/tech/2007/02/01/editing-id3-tags-with-python-and-mutagen http://timka.org/tech/2007/02/01/editing-id3-tags-with-python-and-mutagen Fixing Last.fm tags using Python standard library <p><span style="color: red;">Updated 2008-08-15.</span> Works with new Last.fm.</p> <p> I've written a Python program for renaming tags on Last.fm. </p> http://timka.org/tech/2007/01/22/fixing-lastfm-tags-using-python-standard-library http://timka.org/tech/2007/01/22/fixing-lastfm-tags-using-python-standard-library