[Piuparts-devel] Bug#523950: piuparts: Piuparts uses Python built-in functions as common variables
Carl Chenet
chaica at ohmytux.com
Mon Apr 13 20:48:51 UTC 2009
Package: piuparts
Version: 0.35
Severity: minor
Tags: patch
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Piuparts uses Python built-in functions names as variables. This could
lead to serious unexpected errors while trying to use this function
after it has been redefined.
I can illustrate the problem with the following examples :
>>> list('foo')
['f', 'o', 'o']
>>> list = 0
>>> list
0
>>> list('foo')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'int' object is not callable
>>>
This patch tries to clean this situation for list, dict and file
built-in functions, which should not be used as common variables.
Regards,
Carl Chenet
- -- System Information:
Debian Release: lenny/sid
APT prefers hardy-updates
APT policy: (500, 'hardy-updates'), (500, 'hardy-security'), (500, 'hardy')
Architecture: amd64 (x86_64)
Kernel: Linux 2.6.24-23-generic (SMP w/4 CPU cores)
Locale: LANG=fr_FR.UTF-8, LC_CTYPE=fr_FR.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
iD8DBQFJ46Uz8lge+lYYJUgRArUhAJ9ufNxawqoHq+QZWi6TBzE7cC535gCfR8to
I0k2byUV4+L1jlhjI+JSFDc=
=rnYj
-----END PGP SIGNATURE-----
-------------- next part --------------
Les sous-r?pertoires piuparts-0.35/debian et piuparts-new/debian sont identiques.
Les sous-r?pertoires piuparts-0.35/piupartslib et piuparts-new/piupartslib sont identiques.
diff -u piuparts-0.35/piuparts.py piuparts-new/piuparts.py
--- piuparts-0.35/piuparts.py 2009-03-10 00:30:28.000000000 +0100
+++ piuparts-new/piuparts.py 2009-04-13 22:25:35.000000000 +0200
@@ -747,11 +747,11 @@
def get_selections(self):
"""Get current package selections in a chroot."""
(status, output) = self.run(["dpkg", "--get-selections", "*"])
- list = [line.split() for line in output.split("\n") if line.strip()]
- dict = {}
- for name, status in list:
- dict[name] = status
- return dict
+ sellist = [line.split() for line in output.split("\n") if line.strip()]
+ seldict = {}
+ for name, status in sellist:
+ seldict[name] = status
+ return seldict
def remove_or_purge(self, operation, packages):
"""Remove or purge packages in a chroot."""
@@ -811,7 +811,7 @@
def save_meta_data(self):
"""Return the filesystem meta data for all objects in the chroot."""
root = os.path.join(self.name, ".")
- dict = {}
+ metadict = {}
proc = os.path.join(root, "proc")
for dirpath, dirnames, filenames in os.walk(root):
assert dirpath[:len(root)] == root
@@ -824,8 +824,8 @@
target = os.readlink(name)
else:
target = None
- dict[name[len(root):]] = (st, target)
- return dict
+ metadict[name[len(root):]] = (st, target)
+ return metadict
def relative(self, pathname):
if pathname.startswith('/'):
@@ -835,19 +835,19 @@
def get_files_owned_by_packages(self):
"""Return dict[filename] = [packagenamelist]."""
dir = self.relative("var/lib/dpkg/info")
- dict = {}
+ metadict = {}
for basename in os.listdir(dir):
if basename.endswith(".list"):
pkg = basename[:-len(".list")]
f = file(os.path.join(dir, basename), "r")
for line in f:
pathname = line.strip()
- if pathname in dict:
- dict[pathname].append(pkg)
+ if pathname in metadict:
+ metadict[pathname].append(pkg)
else:
- dict[pathname] = [pkg]
+ metadict[pathname] = [pkg]
f.close()
- return dict
+ return metadict
def install_packages_by_name(self, packages):
if packages:
@@ -931,7 +931,7 @@
it returns the list of files. """
dir = self.relative("var/lib/dpkg/info")
- list = []
+ pathlist = []
has_cronfiles = False
for p in packages:
basename = p + ".list"
@@ -950,25 +950,25 @@
if (mode & stat.S_IEXEC):
if not has_cronfiles:
has_cronfiles = True
- list.append(pathname)
+ pathlist.append(pathname)
logging.info("Package " + p + " contains cron file: " + pathname)
f.close()
- return has_cronfiles, list
+ return has_cronfiles, pathlist
- def check_output_cronfiles (self, list):
+ def check_output_cronfiles (self, filelist):
"""Check if a given list of cronfiles has any output. Executes
cron file as cron would do (except for SHELL)"""
failed = False
- for file in list:
+ for cronfile in filelist:
- if not os.path.exists(self.relative(file.strip("/"))):
+ if not os.path.exists(self.relative(cronfile.strip("/"))):
continue
- (retval, output) = self.run([file])
+ (retval, output) = self.run([cronfile])
if output:
failed = True
- logging.error("Cron file %s has output with package removed" % file)
+ logging.error("Cron file %s has output with package removed" % cronfile)
if failed:
panic()
@@ -980,9 +980,9 @@
basepath = self.relative("tmp/scripts/")
list_scripts = os.listdir(basepath)
list_scripts.sort()
- for file in list_scripts:
- if file.startswith(step):
- script = os.path.join("tmp/scripts", file)
+ for script in list_scripts:
+ if script.startswith(step):
+ script = os.path.join("tmp/scripts", script)
self.run([script])
@@ -1162,7 +1162,7 @@
'p': stat.S_IFIFO,
}
- dict = {}
+ metadict = {}
tf = self._execute_getoutput(['find','/','-xdev','-printf',
"%y %m %U %G %s %p %l \\n".replace(' ','\\0')])
@@ -1189,13 +1189,13 @@
st.st_mode = mode_map[splut[0]] | int(splut[1],8)
(st.st_uid, st.st_gid, st.st_size) = map(int, splut[2:5])
- dict[splut[5]] = (st, splut[6])
+ metadict[splut[5]] = (st, splut[6])
f.close()
finally:
os.remove(tf)
- return dict
+ return metadict
def get_files_owned_by_packages(self):
tf = self._execute_getoutput(['bash','-ec','''
@@ -1204,22 +1204,22 @@
xargs -r0 egrep . /dev/null
test "${PIPESTATUS[*]}" = "0 0"
'''])
- dict = {}
+ filedict = {}
try:
f = file(tf)
for l in f:
(lf,pathname) = l.rstrip('\n').split(':',1)
assert lf.endswith('.list')
pkg = lf[:-5]
- if pathname in dict:
- dict[pathname].append(pkg)
+ if pathname in filedict:
+ filedict[pathname].append(pkg)
else:
- dict[pathname] = [pkg]
+ filedict[pathname] = [pkg]
f.close()
finally:
os.remove(tf)
- return dict
+ return filedict
def check_for_broken_symlinks(self):
if not settings.check_broken_symlinks:
@@ -1309,15 +1309,15 @@
"""Return list of indented filenames."""
meta_infos = meta_infos[:]
meta_infos.sort()
- list = []
+ metalist = []
for name, data in meta_infos:
- list.append(" %s\t" % name)
+ metalist.append(" %s\t" % name)
if name in file_owners:
- list.append(" owned by: %s\n" % ", ".join(file_owners[name]))
+ metalist.append(" owned by: %s\n" % ", ".join(file_owners[name]))
else:
- list.append(" not owned\n")
+ metalist.append(" not owned\n")
- return "".join(list)
+ return "".join(metalist)
def offending_packages(meta_infos, file_owners):
@@ -1335,10 +1335,10 @@
list of removed elements.
"""
warn = []
- for file in depsfiles:
- if file in files:
- files.remove(file)
- warn.append(file)
+ for depsfile in depsfiles:
+ if depsfile in files:
+ files.remove(depsfile)
+ warn.append(depsfile)
return warn
@@ -1360,13 +1360,13 @@
def get_package_names_from_package_files(filenames):
"""Return list of package names given list of package file names."""
- list = []
+ filelist = []
for filename in filenames:
(status, output) = run(["dpkg", "--info", filename])
for line in [line.lstrip() for line in output.split("\n")]:
if line[:len("Package:")] == "Package:":
- list.append(line.split(":", 1)[1].strip())
- return list
+ filelist.append(line.split(":", 1)[1].strip())
+ return filelist
def check_results(chroot, root_info, file_owners, deps_info=None):
@@ -1895,9 +1895,9 @@
if settings.scriptsdir is not None:
dest = chroot.relative("tmp/scripts/")
os.mkdir(dest)
- for file in os.listdir(settings.scriptsdir):
- if (file.startswith("post_") or file.startswith("pre_")) and os.path.isfile(os.path.join((settings.scriptsdir), file)):
- shutil.copy(os.path.join((settings.scriptsdir), file), dest)
+ for filename in os.listdir(settings.scriptsdir):
+ if (filename.startswith("post_") or filename.startswith("pre_")) and os.path.isfile(os.path.join((settings.scriptsdir), filename)):
+ shutil.copy(os.path.join((settings.scriptsdir), filename), dest)
if not install_purge_test(chroot, root_info, selections,
args, packages):
diff -u piuparts-0.35/piuparts-slave.py piuparts-new/piuparts-slave.py
--- piuparts-0.35/piuparts-slave.py 2007-12-22 16:05:58.000000000 +0100
+++ piuparts-new/piuparts-slave.py 2009-04-13 22:28:08.000000000 +0200
@@ -195,12 +195,12 @@
create_file(self._reserved_filename(name, version), "")
def get_reserved(self):
- list = []
+ tmplist = []
for basename in os.listdir("reserved"):
if "_" in basename and basename.endswith(".log"):
name, version = basename[:-len(".log")].split("_", 1)
- list.append((name, version))
- return list
+ tmplist.append((name, version))
+ return tmplist
def forget_reserved(self, name, version):
try:
More information about the Piuparts-devel
mailing list