czka/archlinux-docker

os.path.commonpath or os.path.commonprefix ??

s0fx2 opened this issue · 5 comments

s0fx2 commented

➜ python tar_fix.py --input archlinux-bootstrap-2016.12.01-x86_64.tar.gz --output bootstrap.tar.gz
Traceback (most recent call last):
File "tar_fix.py", line 67, in
tarball.drop_lead_comp()
File "tar_fix.py", line 22, in drop_lead_comp
lead_comp_name = os.path.commonpath(tarin.getnames())
AttributeError: 'module' object has no attribute 'commonpath'

czka commented

Works like a charm here. Aren't you using Python 2 by any chance? This script assumes Python 3. What does python --version print for you?

commonpath method is present in Python 3 os.path - https://docs.python.org/3/library/os.path.html#os.path.commonpath. In 2 it's apparently absent - https://docs.python.org/2/library/os.path.html.

@czka What about changing the shebang to #!/usr/bin/env python3?

And also changing the README.md from tar_fix.py to ./tar_fix.py to indicate the usage without python?

czka commented

I thought about it, but I'm not 100% sure each and every GNU/Linux distro installation out there will have that python3 executable when they have Python 3 installed. Haven't had time for looking that information up, it's on my TODO. Or maybe you can verify in some authorative source whether the assumption of python3 availability is really a safer default than me assumimg python = python3?

As for tar_fix.py vs ./tar_fix.py: will do.

czka commented

Recently in README.md I have documented the usage as I mean it in a more explicit way, hinted about Python 3 requirement and added the ./ prefix suggestion.

czka commented

As to my #1 (comment), I did my homework and it shows that https://www.python.org/dev/peps/pep-0394 recommends python3 shebang over python, for Python 3 code.