You are hereCoding / Python
Python
Linux: Automatically reconnect NetworkManager's VPN Plugin using D-Bus
In a previous post, I talked about how to use D-Bus to get information about network status changes. Now, since I have been using a private VPN with my Ubuntu as a client, I came across another scenario, where a script using D-Bus could help: The VPN works fine, but sometimes just disconnects. It does not happen very often, but when it happens, it is annoying and I'd like to see it reconnecting automatically. Moreover I'd like to stay in the VPN whenever I have a network connection available. Unfortunately, I didn't found any option within the NetworkManager to manage this. I ended up in writing this script which can be invoked like autovpn <VPN_NAME>, where <VPN_NAME> is the name of the VPN which is displayed in the NetworkManager under VPNConnections. You can even run it automatically on system startup by placing it in "Startup Applications". It does two things:
- It tries to connect the VPN whenever it detects an active internet connection.
- It tries to reconnect the VPN, whenever it disconnects unintentionally. The number of attempts is limited to 5 and there is artificial delay of 5 seconds between attempts.
Parser Generator in Python - Quick PLY Introduction
I have been using regular expressions within my Python projects for a while now, but I've never felt the need to use a full-featured parser generator. This changed yesterday and I had a look at PLY, a pythonic implementation for Lex/Yacc. Being used to parser generation in Java using ANTLR or Cup I came across some remarkable differences which I want to point out for you after the stop. You will also see a small calculator code snippet.
Using D-Bus to communicate with Gnome Network Manager
Today, I tried to figure out how to execute scripts in Ubuntu on network connection changes. I came across the D-Bus system, which is used for inter-application communication in Linux. It is indeed very easy to access D-Bus within a Python program. If you read on, you will see the source code of a Python script, that - when launched - receives events from the Gnome Network Manager via the D-Bus interface.
Python Coolness 2: Tips and Tricks
Welcome back Pythoneers! Last time we learned the underlying concepts of the Python programming language and runtime environment. In this second part, I would like to show you some of the Python tricks, that make this programming language so special. I will also briefly highlight some of the areas, which prove to be more difficult or dangerous than in other common languages, such as Java and C++. After this tutorial you will be able to write lines of code that will definitely impress your fellow geeks.
Python Coolness Series, Part 1
Hello fellow coders! Today, I present you the Python Coolness Series, which will (hopefully) show how you can use Python to make cool apps and tools, that would otherwise take days or weeks to create. We will make use of many cool high-level Python APIs, that wrap complex code, and allow you to focus on the aspects that interest you most. So, you won't be seeing any Hello-Worlds in this series, but actually some really cool tools that you can show off to your friends. Take note, that some of these tools will be Mac OS X only. I also recommend all Mac users, who would like to follow this series, to grab a copy of Fink, so that they can install Python modules painlessly.