python


Installing RatticWeb on Ubuntu 14.04

First a few prerequesites: apt-get update apt-get install git libxslt-dev libxml2-dev libldap2-dev libsasl2-dev libmysqlclient-dev python-dev python-virtualenv   Create a virtual environment and run the actual installation: mkdir ~/venv/RatticWeb mkdir -p ~/venv/RatticWeb virtualenv ~/venv/RatticWeb source ~/venv/RatticWeb/bin/activate git clone https://github.com/tildaslash/RatticWeb.git cd RatticWeb/ pip install -r requirements-mysql.txt -r requirements-dev.txt cat > conf/local.cfg <<EOF [ratticweb] secretkey = [ENTER SOMETHING […]


Installing AWS Cloudformation Scripts on Debian Wheezy

First install needed packages: apt-get install python-pip python-yaml unattended-upgrades These packages are needed to build the AWS package: pip install pystache pip install argparse pip install python-daemon Now get the latest scripts from here: wget https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-latest.tar.gz And install it: tar -xvpf aws-cfn-bootstrap-latest.tar.gz cd aws-cfn-bootstrap-1.4/ python setup.py build python setup.py install When the installation has finished successfully […]


Calculating the size of your S3 bucket using Python

For the following script you need to have installed Python >= 2.6 and Boto: apt-get install -y python-boto Next create a file ~/.boto containing the following lines: [Credentials] region = us-east-1 aws_access_key_id = YOUR_ACCESS_KEY_ID aws_secret_access_key = YOUR_SECRET_ACCCESS_KEY Put in the AWS credentials to access your bucket Then create the script, replace NAME_OF_YOU_BUCKET with your actual […]


Backups to S3 using Duplicity

First install Duplicity with its dependancies: apt-get install haveged python-paramiko python-boto python-gobject-2 duplicity Then generate a gpg key: gpg −−gen-key The output might be like this (just confirm everything with return and keep aside the password you'll have to enter): gpg (GnuPG) 1.4.12; Copyright (C) 2012 Free Software Foundation, Inc. This is free software: you […]


Installing AWS CLI on Debian

First install the Python package: apt-get install python python-pip Then issue the AWS CLI Installation: pip install awscli If all went ok, you should be able to execute for example aws configure which will help you to create an initial configuration file containing your credentials, region and output format. More help type aws help or aws ec2 […]


Verify XML file syntax on a console using Python

Put the following code in a file, for example test.py: #!/usr/bin/python import xml.dom.minidom as dom dom.parse ('test.xml') And make it executable: chmod 755 test.py If you execute ./test.py, if your xml file test.xml is correct, it should output nothing, else it outputs an error! Of course this script may be improved, for example to take […]


Accessing SQLite with Bash, Perl and Python

Perl: #!/usr/bin/perl -w use DBI; use strict; my $db = DBI->connect("dbi:SQLite:test.db", "", "", {RaiseError => 1, AutoCommit => 1}); $db->do("CREATE TABLE n (id INTEGER PRIMARY KEY, f TEXT, l TEXT)"); $db->do("INSERT INTO n VALUES (NULL, 'john', 'smith')"); my $all = $db->selectall_arrayref("SELECT * FROM n"); foreach my $row (@$all) { my ($id, $first, $last) = @$row; […]