- Add functions mkdir and readlist.

This commit is contained in:
Siegfried-Angel Gevatter Pujals 2008-08-12 23:42:44 +02:00
commit 91f62881df
2 changed files with 34 additions and 0 deletions

View File

@ -3,6 +3,7 @@
# ubuntu-dev-tools package. # ubuntu-dev-tools package.
# #
# Copyright (C) 2008 Jonathan Patrick Davies <jpds@ubuntu.com> # Copyright (C) 2008 Jonathan Patrick Davies <jpds@ubuntu.com>
# Copyright (C) 2008 Siegfried-Angel Gevatter Pujals <rainct@ubuntu.com>
# #
# Some of the functions are based upon code written by Martin Pitt # Some of the functions are based upon code written by Martin Pitt
# <martin.pitt@ubuntu.com> and Kees Cook <kees@ubuntu.com>. # <martin.pitt@ubuntu.com> and Kees Cook <kees@ubuntu.com>.
@ -29,6 +30,37 @@ import os.path
import sys import sys
import urllib2 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(): def prepareLaunchpadCookie():
""" Search for a cookie file in the places as defined by try_globs. """ Search for a cookie file in the places as defined by try_globs.
We shall use this cookie for authentication with Launchpad. """ We shall use this cookie for authentication with Launchpad. """

2
debian/changelog vendored
View File

@ -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 - Change the license of all scripts from Kees Cook to the GPL version 3
or later. or later.
- Order the script names alphabetically in debian/copyright. - Order the script names alphabetically in debian/copyright.
* common.py:
- Add functions mkdir and readlist.
-- Siegfried-Angel Gevatter Pujals <rainct@ubuntu.com> Tue, 12 Aug 2008 20:09:42 +0200 -- Siegfried-Angel Gevatter Pujals <rainct@ubuntu.com> Tue, 12 Aug 2008 20:09:42 +0200