Archive for the “Programming” Category

SUSE Studio is  an awesome tool, with a couple of clicks you can create an openSUSE/SUSE based system and deploy to your hard drive, an usb flash,  a live dvd, a VMware/VirtualBox/Xen server and even Amazon EC2 cloud.

Suppose you want to create a tailored SUSE Studio appliance to run a Ruby on Rails app, this is a list of things you have to take care of:

  • install all the gems required by the app (this can be a long list).
  • install and configure the database used by the app.
  • install and configure a webserver.
  • ensure all the required services are started at boot time.

You can save some time by cloning this appliance shared on SUSE Gallery, but this is still going to be boring.

Dister to the rescue!

Dister is a command line tool similar to the one used by Heroku (one of the coolest ways to run your Rails app into the cloud). Within a few steps you will be able to create a SUSE Studio appliance running your rails application, download it and deploy wherever you want.

Dister is named after SUSE Studio robot. It has been created by  Dominik Mayer and me during the latest hackweek.

How it works

We are going to create a SUSE Studio appliance running a rails application called “SUSE history”. The app uses bundler to handle its dependencies.
This is its Gemfile file:

source 'http://rubygems.org'
gem 'rails', '3.0.5'
gem 'pg'
gem "flutie", "~> 1.1"

As you can see the app uses rails3, the flutie gem and PostgreSQL as database.

Appliance creation

Move into the suse_history directory and execute the following command:

dister create suse_history

dister create

Creating a SUSE Studio appliance with dister


As you can see dister has already done a couple of things for you:

  • created an appliance using latest version of openSUSE supported by SUSE Studio (you can use a different base system of course)
  • added the devel:language:ruby:extensions repository to the appliance: this repo contains tons of ruby packages (like mod_passenger)
  • installed a couple of things:
    • devel_C_C++ pattern: this will allow you to build native gems.
    • devel_ruby pattern: provides ruby, rubygems and a couple of development packages needed to build native gems.
    • rubygem-bundler: bundler is required by dister in order to handle the dependencies of your rails application.
    • rubygem-passenger-apache2: dister uses passenger and apache2 to deploy your rails application.
    • postgresql-server: dister noticed suse_history uses PostgreSQL as database, hence it automatically installs it.
    • rubygem-pg: dister noticed suse_history uses PostgreSQL as database, hence it automatically installs the ruby’s library forPostgreSQL.
  • uploaded a custom build script which ensures:
    • mod_passenger module is loaded by Apache
    • both Apache and PostgreSQL are always started at boot time.
    • all dependencies are installed: this is done only during the first boot using bundler.
    • the database user required by your rails app is created. This is done only during the first boot using some SQL code.
    • the database used by the appliance is properly initialized (aka rails db:create db:migrate). This is done only during the first boot.

Upload your code

It’s time to upload suse_history code. This is done using the following command:

dister push

dister push output
As you can see dister packaged the application source code and all its dependencies into a single archive. Then uploaded the archive to SUSE Studio as an overlay file. Dister uploaded also the configuration files required by Apache and by PostgreSQL setup.

Build your appliance

It’s build time!

dister build

dister build
The appliance has automatically being built using the raw disk. You can use different formats of course.

Testdrive

Testdrive is one of the coolest features of SUSE Studio. Unfortunately dister doesn’t support it yet. Just visit your appliance page and start testdrive from your browser.
Just enable testdrive networking and connect to your appliance:
suse history running inside of testdrive

Download

Your appliance is working flawlessly. Download it and deploy it wherever you want.

dister download

Current status

As you can see dister handles pretty fine a simple Rails application, but there’s still room for improvements.

Here’s a small list of the things on my TODO list:

  • The dependency management should install gems using rpm packages. This would make the installation of native gems easier, right now the user has to manually add all the development libraries required by the gem. Moreover it would reduce the size of the overlay files uploaded to SUSE Studio.
  • SUSE Studio Testdrive should be supported.
  • It should be possible to deploy the SUSE Studio directly to EC2.
  • Fix bugs!

Bugs and enhancements are going to be tracked here.

Contribute

Dister code can be found here on github, fork it and start contributing.

If you are a student you can work on dister during the next Google Summer of code, apply now!

Tags: , , ,

Comments No Comments »

Let me introduce a small project I’ve been working on with a friend of mine, Giuseppe Capizzi. The project is called jump and allows you to quickly change directories in the bash shell using bookmarks.

Thanks to Jump, you won’t have to type those long paths anymore.

You can find jump’s source code, detailed documentation and installation instructions here.

SUSE packages can be found here.

Tags: ,

Comments 7 Comments »

Just a quick note, I released a new version of the fastuserswitch plasmoid. This new release implements all the improvements suggested by the users plus some minor fixes.

Code can be downloaded from here. openSUSE packages are already available on the build service.

These are some screenshots illustrating fastuserswitch’s new features.

Comments 8 Comments »

I’m really pleased to announce that latest version of QJson on master is working on Symbian. You can find the installation instruction here.

Since I’m not a Symbian developer it has been a little hard for me to achieve that. I would like to thank Antti Luoma for his help.

There are also good news for Windows developers: now building QJson under Windows is easier. Checkout the new installation instruction page.

I hope this will help all the Windows developers who want to use QJson.

Tags: , ,

Comments 6 Comments »

Just a quick note: I have just moved QJson source code to this git repository hosted by gitorious.

I’ll keep the code on KDE’s svn synchronized with the git repository.

Tags: , ,

Comments 2 Comments »

Some days ago I introduced the possibility to serialize a QObject instance to JSON. Today I’m going to show you the opposite operation: initializing a QObject using a JSON object.

I refactored a bit my latest changes: I created a new class called QObjectHelper that provides the methods required to convert a QObject instance to a QVariantMap and vice-versa.

This class can be used in conjunction with the Serializer and Parser classes to serialize and deserialize QObject instances to and from JSON.

Let me show a quick example, suppose the declaration of Person class looks like this:

class Person : public QObject
{
  Q_OBJECT

  Q_PROPERTY(QString name READ name WRITE setName)
  Q_PROPERTY(int phoneNumber READ phoneNumber WRITE setPhoneNumber)
  Q_PROPERTY(Gender gender READ gender WRITE setGender)
  Q_PROPERTY(QDate dob READ dob WRITE setDob)
  Q_ENUMS(Gender)

public:
    Person(QObject* parent = 0);
    ~Person();

    QString name() const;
    void setName(const QString& name);

    int phoneNumber() const;
    void setPhoneNumber(const int  phoneNumber);

    enum Gender {Male, Female};
    void setGender(Gender gender);
    Gender gender() const;

    QDate dob() const;
    void setDob(const QDate& dob);

  private:
    QString m_name;
    int m_phoneNumber;
    Gender m_gender;
    QDate m_dob;
};

From QObject to JSON

The following code will serialize an instance of Person to JSON :

Person person;
person.setName("Flavio");
person.setPhoneNumber(123456);
person.setGender(Person::Male);
person.setDob(QDate(1982, 7, 12));

QVariantMap variant = QObjectHelper::qobject2qvariant(&person);
Serializer serializer;
qDebug() << serializer.serialize( variant);

The generated output will be:

{ "dob" : "1982-07-12", "gender" : 0, "name" : "Flavio", "phoneNumber" : 123456 }

From JSON to QObject

Suppose you have the following JSON data stored into a QString:

{ "dob" : "1982-07-12", "gender" : 0, "name" : "Flavio", "phoneNumber" : 123456 }

The following code will initialize an already allocated instance of Person using the JSON values:

Parser parser;
QVariant variant = parser.parse(json);

Person person;
QObjectHelper::qvariant2qobject(variant.toMap(), &person);

A new release

These changes have been included inside the new release of QJson: 0.7.0.

Packages for openSUSE are building right now.

Tags: , ,

Comments 27 Comments »

I have just committed into trunk a couple of changes that make easier to serialize a QObject instance to JSON.

This solution relies on the awesome Qt’s property system.

Suppose the declaration of Person class looks like this:

class Person : public QObject
{
  Q_OBJECT

  Q_PROPERTY(QString name READ name WRITE setName)
  Q_PROPERTY(int phoneNumber READ phoneNumber WRITE setPhoneNumber)
  Q_PROPERTY(Gender gender READ gender WRITE setGender)
  Q_PROPERTY(QDate dob READ dob WRITE setDob)
  Q_ENUMS(Gender)

public:
    Person(QObject* parent = 0);
    ~Person();

    QString name() const;
    void setName(const QString& name);

    int phoneNumber() const;
    void setPhoneNumber(const int  phoneNumber);

    enum Gender {Male, Female};
    void setGender(Gender gender);
    Gender gender() const;

    QDate dob() const;
    void setDob(const QDate& dob);

  private:
    QString m_name;
    int m_phoneNumber;
    Gender m_gender;
    QDate m_dob;
};

The following code will serialize an instance of Person to JSON:

Person person;
person.setName("Flavio");
person.setPhoneNumber(123456);
person.setGender(Person::Male);
person.setDob(QDate(1982, 7, 12));

Serializer serializer;
qDebug() << serializer.serialize( &person);

The generated output will be:

{ "dob" : "1982-07-12", "gender" : 0, "name" : "Flavio", "phoneNumber" : 123456 }

I hope you will find this new feature useful. I'm also considering to create a similar method inside the Parser class.

As usual suggestions are welcome.

Tags: , ,

Comments 4 Comments »

Some weeks have passed since the announcement of kaveau. I’m really proud and happy about this project because I received a lot of positive feedback messages and it has been chosen as one of the best Hackweek’s projects.

In the meantime I kept working on kaveau, so let me show you what has changed:

  • rdiff-backup has been replaced by rsync.
  • the setup wizard has been improved according to the feedback messages I received.
  • old backups are now automatically removed.
  • the code has been refactored a lot.

The switch to rsync

Previously kaveau used rdiff-backup as backup back-end. rdiff-backup is a great program but unfortunately it relies on the outdated librsync library. The latest release of librsync is dated 2004. It has a couple of serious bugs still open and, while rsync has reached version three, this library is still stuck at version one.

These are the reasons of the switch from rdiff-backup to rsync. This choice breaks the compatibility with the previous backups but it introduces a lot of advantages.
One of the most important improvements brought by the adoption of rsync is an easier restore procedure: now all the backups can be accessed using a standard file manager, while previously rdiff-backup was needed to access the old backups.

Backup directory structure

On the backup device everything is saved under the kaveau/hostname/username path.

The directory will have a similar structure:

drwxr-xr-x 3 flavio users 4096 2009-09-12 18:50 2009-09-12T18:50:19
drwxr-xr-x 3 flavio users 4096 2009-09-14 23:07 2009-09-14T23:07:46
drwxr-xr-x 3 flavio users 4096 2009-09-14 23:30 2009-09-14T23:30:36
lrwxrwxrwx 1 flavio users   19 2009-09-14 23:30 current -> 2009-09-14T23:30:36

As you can see there’s one directory per backup, plus a symlink called current pointing to the latest backup.

Old backup deletion

Nowadays big external storage devices are pretty cheap, but it’s always good to save some disk space.
Now kaveau keeps:

  • hourly backups for the past 24 hours.
  • daily backups for the past month.
  • weekly backups until the external disk is full.

Thanks to hard links’ magic, old backups can be deleted without causing damages to the other ones.

Plans for the future

Before starting to work on the restore user interface I will spend some time figuring out how to add support for network devices.

A lot of users requested this feature, hence I want to make them happy :) .

I’m planning to use avahi to discover network shares (nfs, samba) or network machines running ssh and use them as backup devices. Honestly, I want to achieve something similar to Apple’s time capsule.

As usual, feedback messages are really appreciated.

Tags: , ,

Comments 17 Comments »

Recently lots of people asked me how to build QJson under Windows. Most of them reported build/link errors, so I decided to try personally.

The good news is that QJson can be successfully built under Window, I can show you proof ;)

I have written the build instructions on QJson website: just take a look here.

One last note: if you have problems with QJson please subscribe to the developer mailing list and post a message.

Tags: , , ,

Comments 26 Comments »

During the last week I had the possibility to work on anything I wanted, Novell’s hackweek is so cool :)

I decided to dedicate myself to an idea that has been obsessing me since a long time. Last December my brand new hard disk suddenly died, making impossible to recover anything. Fortunately I had just synchronized the most important documents between my workstation and my laptop, so I didn’t lose anything important. This incident make me realize that I should perform backups regularly and I immediately started looking for a good solution.

Personally I think that doing backups is pretty boring so I wanted something damned easy to setup and use. Something that once configured runs in the background and does the dirty job without bothering you. Let’s face the truth: I wanted Apple’s Time Machine for KDE.

After some searches I realized that nothing was fitting my requirements and I decided to create something new: kaveau.

What is kaveau?

Kaveau is a backup program that makes backup easy for the average user.

As you will see while coding/planning kaveau I made some assumptions and so only few things are configurable. I really think that sometimes “less is more”.

What does kaveau?

Current features:

  • it performs backups to an external storage device: I don’t think it will ever store backup data on a remote host. If you want to do that just use some good project like Backup pc.
  • it backs up the complete home directory of the user: storage is cheap and average users (like me) keep everything inside their home directory ( but it’s possible to exclude some directories from the backup).
  • it performs incremental backups.
  • the backup data are neither compressed nor stored in fancy formats: in this way you can plug your external disk into another machine and access your data without additional work.
  • backups are performed automatically every hour (of course only if your external disk is plugged).
  • notification messages are shown if your backup is older that a week.

More enhancements are coming…

What technologies does it use?

Backups are performed using rdiff-backup because it’s damned easy to use, well tested (it’s used also in production environments) and packaged by all distributions.

The awesome solid library is used for interacting with the external disks is super easy.

Status of kaveau

I have been working on kaveau just for five days, so there’s still a lot of work to do.

A screenshot tour will give you the right idea of its status.

Right now the code is available on this git repository but I don’t recommend you to try it (unless you want to find and fix bugs ;) ).

I would really appreciate:

  • feedback about the user interface (right now it looks too much like Time Machine).
  • icons: it would be great to have a desktop icon and some system tray icons (contact me for more details).
  • new code, bug fixes, code reviews, hints,…
Tags: ,

Comments 37 Comments »