Ubuntu Accomplishments: Desktop

I have been following the Ubuntu Accomplishments project for a while, but failed to contribute until recently. The first contribution was inspired by a multimedia accomplishment for adding music to your machine. This simple accomplishment will trigger if you add music to your music folder. I keep my music on a NAS so I would never earn that accomplishment. I decided to build a script that would determine if a user had added music to Rhythmbox. This would account for users who keep music in folder other than music as long as they used Rhythmbox as their music player. Here is the code:

#!/usr/bin/python
import commands, sys, os
homeDir = os.getenv("HOME")
path = os.path.join(homeDir,'.local/share/rhythmbox/rhythmdb.xml') 

if os.path.exists(path):
	#user has used Rhythmbox now we need to test for the existence of music
        # test for the existence of <entry type="song"> in the rhythmdb.xml
        file = open(path)

        # convert file to string
        data = file.read()

        # we do not need to keep the file open
        file.close()

        # test for the existence of a song in the file
        if "song" in data:                
                #user has music in Rhythmbox
                sys.exit(0)
                # print "user has music"
        else:
                #user does not have music in Rhythmbox
                sys.exit(0)
                # print "user does not have music"

else:
        # user has not used Rhythmbox
	sys.exit(1)

As I explored this script I noticed that the original script that inspired me was testing positive even if there was only a text file and no audio files. I then decided to improve on the original script. Here is the code:

#!/usr/bin/python
import commands, sys, os
homeDir = os.getenv("HOME")
path = os.path.join(homeDir,'.config/user-dirs.dirs') 
result = open(path, "r")
content = result.readline()
while (content != "" ):
	content.replace( "\n", "" )
	content = result.readline()
	startStr = content[0:13]
	if startStr == 'XDG_MUSIC_DIR':
		musicDir = content

# recursive function to go through sub-directories
def test_for_music(directory):
    dirList = os.listdir(directory)
    for fname in dirList:
        filepath = os.path.join(directory, fname)
        if os.path.isdir(filepath):
            test_for_music(filepath)
        else:
            filetype = commands.getstatusoutput('file -b "' +filepath + '"')
            if "audio" in filetype[1]:
                # audio file present
                sys.exit(0)

# removes extra characters around directory
musicDir = musicDir[21:]
musicDir = musicDir[:-2]

music = os.path.join(homeDir, musicDir)
test_for_music(music)

#user has no music
sys.exit(1)

I hope that the Rhythmbox script can be expanded to include more music players in the future, but I think it is a good start to work with the default music player in Ubuntu. As I worked on both of these items I made several mistakes, but was guided to success by Rafal Cieślak. It was an amazingly easy and rewarding process. This project has finally allowed me to realize my goal of contributing code to the Ubuntu community. If you are looking to get involved in a community project and know a little bit of Python I would recommend Ubuntu Accomplishments.

A Day With Gnome 3

At UDS in Oakland I was asked me what I thought of Gnome 3. I answered honestly that there were parts I liked and parts that I did not. I also expressed that I thought that it would have been better if Gnome and Ubuntu had been able to work together so that efforts were not split on the ‘next generation’ Gnome experience. It had been a while since I had used Gnome 3 so I made a mental note that I should give it another try when I had the chance.

I have been amazingly busy since UDS, but today I found the time to run Fedora 17 and Gnome 3 for the entire day. There was one overall impression I had; I was far less productive. This held true even after I added several Gnome extensions. The dash was missed and as was the ability to minimize apps to a panel or dock. While I liked the dynamic creation of workspaces I found it frustrating to access them by having to go to the left side of the screen and then back to the right side; it was so frustrating I feel like there must be another way that I just missed.

At the end of the day it was with a sigh of relief that I booted back in to Ubuntu (gotta love spare hard drives) and was back in Unity. The experience was a positive one though; it is always good to realize just how good the things you have are in comparison to other options. In my case Unity has made more progress and fits my work style much better than Gnome 3.

Follow

Get every new post delivered to your Inbox.

Join 26 other followers

%d bloggers like this: