diff --git a/common.py b/common.py index 521026c..e52618d 100644 --- a/common.py +++ b/common.py @@ -3,6 +3,7 @@ # ubuntu-dev-tools package. # # Copyright (C) 2008 Jonathan Patrick Davies +# Copyright (C) 2008 Siegfried-Angel Gevatter Pujals # # Some of the functions are based upon code written by Martin Pitt # and Kees Cook . @@ -29,6 +30,37 @@ import os.path import sys import urllib2 +def mkdir(directory): + """ Create the given directory and all its parents recursively, but don't + raise an exception if it already exists. """ + + path = [x for x in directory.split('/') if x] + + for i in xrange(len(path)): + current_path = '/' + '/'.join(path[:i+1]) + if not os.path.isdir(current_path): + os.mkdir(current_path) + +def readlist(filename, uniq=True): + """ Read a list of words from the indicated file. """ + + if not os.path.isfile(filename): + print 'File "%s" does not exist.' % filename + return False + + content = open(filename).read().replace('\n', ' ').replace(',', ' ') + + if not content.strip(): + print 'File "%s" is empty.' % filename + return False + + items = [item for item in content.split() if item] + + if uniq: + items = list(set(items)) + + return items + def prepareLaunchpadCookie(): """ Search for a cookie file in the places as defined by try_globs. We shall use this cookie for authentication with Launchpad. """ diff --git a/debian/changelog b/debian/changelog index 07b2d0d..5e233d0 100644 --- a/debian/changelog +++ b/debian/changelog @@ -10,6 +10,8 @@ ubuntu-dev-tools (0.39ubuntu1) intrepid; urgency=low - Change the license of all scripts from Kees Cook to the GPL version 3 or later. - Order the script names alphabetically in debian/copyright. + * common.py: + - Add functions mkdir and readlist. -- Siegfried-Angel Gevatter Pujals Tue, 12 Aug 2008 20:09:42 +0200