Remove .absolute_path thanks to fspath.
This commit is contained in:
parent
b288cca519
commit
e2fd04ccf1
2 changed files with 13 additions and 14 deletions
|
@ -152,7 +152,7 @@ def download_plan(plan):
|
||||||
raise NotEnoughBytes(message)
|
raise NotEnoughBytes(message)
|
||||||
|
|
||||||
if plan.download_into != plan.real_localname:
|
if plan.download_into != plan.real_localname:
|
||||||
os.rename(plan.download_into.absolute_path, plan.real_localname.absolute_path)
|
os.rename(plan.download_into, plan.real_localname)
|
||||||
|
|
||||||
return plan.real_localname
|
return plan.real_localname
|
||||||
|
|
||||||
|
@ -285,7 +285,7 @@ def prepare_plan(
|
||||||
# Chapter 6: Redeem your meal vouchers here
|
# Chapter 6: Redeem your meal vouchers here
|
||||||
if real_exists:
|
if real_exists:
|
||||||
if overwrite:
|
if overwrite:
|
||||||
os.remove(real_localname.absolute_path)
|
os.remove(real_localname)
|
||||||
|
|
||||||
if user_provided_range:
|
if user_provided_range:
|
||||||
return plan_partial
|
return plan_partial
|
||||||
|
|
|
@ -270,7 +270,7 @@ class Path:
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def exists(self):
|
def exists(self):
|
||||||
return os.path.exists(self.absolute_path)
|
return os.path.exists(self)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def extension(self):
|
def extension(self):
|
||||||
|
@ -318,7 +318,7 @@ class Path:
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_directory(self):
|
def is_directory(self):
|
||||||
return os.path.isdir(self.absolute_path)
|
return os.path.isdir(self)
|
||||||
|
|
||||||
# Aliases for your convenience.
|
# Aliases for your convenience.
|
||||||
is_dir = is_directory
|
is_dir = is_directory
|
||||||
|
@ -326,11 +326,11 @@ class Path:
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_file(self):
|
def is_file(self):
|
||||||
return os.path.isfile(self.absolute_path)
|
return os.path.isfile(self)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_link(self):
|
def is_link(self):
|
||||||
return os.path.islink(self.absolute_path)
|
return os.path.islink(self)
|
||||||
|
|
||||||
def join(self, subpath, **spawn_kwargs):
|
def join(self, subpath, **spawn_kwargs):
|
||||||
'''
|
'''
|
||||||
|
@ -342,7 +342,7 @@ class Path:
|
||||||
return Path(path, **spawn_kwargs)
|
return Path(path, **spawn_kwargs)
|
||||||
|
|
||||||
def listdir(self):
|
def listdir(self):
|
||||||
children = os.listdir(self.absolute_path)
|
children = os.listdir(self)
|
||||||
children = [self.with_child(child, _case_correct=self._case_correct) for child in children]
|
children = [self.with_child(child, _case_correct=self._case_correct) for child in children]
|
||||||
return children
|
return children
|
||||||
|
|
||||||
|
@ -353,14 +353,14 @@ class Path:
|
||||||
return [p for p in self.listdir() if p.is_file]
|
return [p for p in self.listdir() if p.is_file]
|
||||||
|
|
||||||
def makedirs(self, mode=0o777, exist_ok=False):
|
def makedirs(self, mode=0o777, exist_ok=False):
|
||||||
return os.makedirs(self.absolute_path, mode=mode, exist_ok=exist_ok)
|
return os.makedirs(self, mode=mode, exist_ok=exist_ok)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def normcase(self):
|
def normcase(self):
|
||||||
return os.path.normcase(self.absolute_path)
|
return os.path.normcase(self.absolute_path)
|
||||||
|
|
||||||
def open(self, *args, **kwargs):
|
def open(self, *args, **kwargs):
|
||||||
return open(self.absolute_path, *args, **kwargs)
|
return open(self, *args, **kwargs)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def parent(self):
|
def parent(self):
|
||||||
|
@ -431,20 +431,20 @@ class Path:
|
||||||
def size(self):
|
def size(self):
|
||||||
self.assert_exists()
|
self.assert_exists()
|
||||||
if self.is_file:
|
if self.is_file:
|
||||||
return os.path.getsize(self.absolute_path)
|
return os.path.getsize(self)
|
||||||
elif self.is_dir:
|
elif self.is_dir:
|
||||||
return sum(file.size for file in self.walk() if file.is_file)
|
return sum(file.size for file in self.walk() if file.is_file)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def stat(self):
|
def stat(self):
|
||||||
return os.stat(self.absolute_path)
|
return os.stat(self)
|
||||||
|
|
||||||
def touch(self):
|
def touch(self):
|
||||||
'''
|
'''
|
||||||
Update the file's mtime if it exists, or create it.
|
Update the file's mtime if it exists, or create it.
|
||||||
'''
|
'''
|
||||||
try:
|
try:
|
||||||
os.utime(self.absolute_path)
|
os.utime(self)
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
self.open('a').close()
|
self.open('a').close()
|
||||||
|
|
||||||
|
@ -454,8 +454,7 @@ class Path:
|
||||||
'''
|
'''
|
||||||
directories = []
|
directories = []
|
||||||
|
|
||||||
entries = os.scandir(self.absolute_path)
|
for entry in os.scandir(self):
|
||||||
for entry in entries:
|
|
||||||
child = self.with_child(entry.name, _case_correct=self._case_correct)
|
child = self.with_child(entry.name, _case_correct=self._case_correct)
|
||||||
if entry.is_dir():
|
if entry.is_dir():
|
||||||
directories.append(child)
|
directories.append(child)
|
||||||
|
|
Loading…
Reference in a new issue