Strip trailing whitespace

This commit is contained in:
Stefano Rivera 2010-12-02 09:33:54 +02:00
parent 27365f9dd4
commit 516b264a8f

View File

@ -10,7 +10,7 @@
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 3 # as published by the Free Software Foundation; either version 3
# of the License, or (at your option) any later version. # of the License, or (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@ -28,11 +28,10 @@ from ubuntutools.lp.udtexceptions import PocketDoesNotExistError
def system_distribution(): def system_distribution():
""" system_distro() -> string """ system_distro() -> string
Detect the system's distribution and return it as a string. If the Detect the system's distribution and return it as a string. If the
name of the distribution can't be determined, print an error message name of the distribution can't be determined, print an error message
and return None. and return None.
""" """
# We try to avoid calling the "lsb_release" as looking up the value # We try to avoid calling the "lsb_release" as looking up the value
# directly is faster. However, Debian doesn't have /etc/lsb-release # directly is faster. However, Debian doesn't have /etc/lsb-release
@ -52,45 +51,43 @@ def system_distribution():
def host_architecture(): def host_architecture():
""" host_architecture -> string """ host_architecture -> string
Detect the host's architecture and return it as a string. If the Detect the host's architecture and return it as a string. If the
architecture can't be determined, print an error message and return None. architecture can't be determined, print an error message and return None.
""" """
arch = Popen(['dpkg', '--print-architecture'], stdout=PIPE, \ arch = Popen(['dpkg', '--print-architecture'], stdout=PIPE, \
stderr=PIPE).communicate()[0].split() stderr=PIPE).communicate()[0].split()
if not arch or 'not found' in arch[0]: if not arch or 'not found' in arch[0]:
print 'Error: Not running on a Debian based system; could not ' \ print 'Error: Not running on a Debian based system; could not ' \
'detect its architecture.' 'detect its architecture.'
return None return None
return arch[0] return arch[0]
def readlist(filename, uniq=True): def readlist(filename, uniq=True):
""" readlist(filename, uniq) -> list """ readlist(filename, uniq) -> list
Read a list of words from the indicated file. If 'uniq' is True, filter Read a list of words from the indicated file. If 'uniq' is True, filter
out duplicated words. out duplicated words.
""" """
if not os.path.isfile(filename): if not os.path.isfile(filename):
print 'File "%s" does not exist.' % filename print 'File "%s" does not exist.' % filename
return False return False
content = open(filename).read().replace('\n', ' ').replace(',', ' ') content = open(filename).read().replace('\n', ' ').replace(',', ' ')
if not content.strip(): if not content.strip():
print 'File "%s" is empty.' % filename print 'File "%s" is empty.' % filename
return False return False
items = [item for item in content.split() if item] items = [item for item in content.split() if item]
if uniq: if uniq:
items = list(set(items)) items = list(set(items))
return items return items
def splitReleasePocket(release): def splitReleasePocket(release):