mirror of
https://git.launchpad.net/ubuntu-dev-tools
synced 2025-03-13 16:11:15 +00:00
43 lines
1.4 KiB
Python
43 lines
1.4 KiB
Python
#
|
|
# misc.py - misc functions for the Ubuntu Developer Tools scripts.
|
|
#
|
|
# Copyright (C) 2008 Jonathan Davies <jpds@ubuntu.com>
|
|
# Copyright (C) 2008 Siegfried-Angel Gevatter Pujals <rainct@ubuntu.com>
|
|
#
|
|
# This program is free software; you can redistribute it and/or
|
|
# modify it under the terms of the GNU General Public License
|
|
# as published by the Free Software Foundation; either version 3
|
|
# of the License, or (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# Please see the /usr/share/common-licenses/GPL file for the full text of
|
|
# the GNU General Public License license.
|
|
#
|
|
|
|
# Modules.
|
|
import os
|
|
|
|
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
|