"AttributeError: 'module' object has no attribute 'scandir'" when running zap -m on Ubuntu 14.04
Created by: zhuowei
Here's the log: Ubuntu 14.04.5, Python 3.4.3, ./pmbootstrap.py zap -m
[00:52:49] Remove /media/zhuowei/redhd/docs/pmbootstrap/chroot_native? (y/n) [n] n
[00:52:53] Remove /media/zhuowei/redhd/docs/pmbootstrap/chroot_buildroot_aarch64? (y/n) [n] n
[00:52:55] Remove /media/zhuowei/redhd/docs/pmbootstrap/chroot_rootfs_huawei-angler? (y/n) [n] n
(014128) [00:52:59] ERROR: 'module' object has no attribute 'scandir'
(014128) [00:52:59] Run 'pmbootstrap log' for details.
(014128) [00:52:59] See also: <https://postmarketos.org/troubleshooting>
(014128) [00:52:59] Traceback (most recent call last):
File "/media/zhuowei/redhd/docs/repos/pmbootstrap/pmb/__init__.py", line 53, in main
getattr(frontend, args.action)(args)
File "/media/zhuowei/redhd/docs/repos/pmbootstrap/pmb/helpers/frontend.py", line 198, in zap
mismatch_bins=args.mismatch_bins)
File "/media/zhuowei/redhd/docs/repos/pmbootstrap/pmb/chroot/zap.py", line 63, in zap
binaries(args)
File "/media/zhuowei/redhd/docs/repos/pmbootstrap/pmb/chroot/zap.py", line 68, in binaries
for arch_dir in os.scandir(os.path.realpath(args.work + "/packages/")):
AttributeError: 'module' object has no attribute 'scandir'
It looks like scandir was introduced in Python 3.5 - should we include a local copy for the few people still using 14.04?
Replacing the scandir with a listdir seems to fix this, by the way.
diff --git a/pmb/chroot/zap.py b/pmb/chroot/zap.py
index 2763835..d7dcf96 100644
--- a/pmb/chroot/zap.py
+++ b/pmb/chroot/zap.py
@@ -65,8 +65,7 @@ def zap(args, confirm=True, packages=False, http=False, mismatch_bins=False):
def binaries(args):
- for arch_dir in os.scandir(os.path.realpath(args.work + "/packages/")):
- arch = arch_dir.name
+ for arch in os.listdir(os.path.realpath(args.work + "/packages/")):
arch_pkg_path = os.path.realpath(args.work) + "/packages/" + arch
bin_apks = pmb.parse.apkindex.parse(args, arch_pkg_path + "/APKINDEX.tar.gz")
for bin_apk in bin_apks: