Merge pull request #7 from makermelissa/master

Suppress errors from utf-8 decoding and add copy
This commit is contained in:
Melissa LeBlanc-Williams 2021-01-26 09:27:22 -08:00 committed by GitHub
commit 7ea1ad3312
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -72,7 +72,7 @@ class Shell:
if len(output) == 0 and proc.poll() is not None:
break
if output:
decoded_output = output.decode("utf-8").strip()
decoded_output = output.decode("utf-8", errors="ignore").strip()
if not suppress_message:
self.info(decoded_output)
full_output += decoded_output
@ -84,7 +84,7 @@ class Shell:
err = proc.stderr.read()
if not suppress_message:
self.error(err.decode("utf-8"))
self.error(err.decode("utf-8", errors="ignore"))
if return_output:
return full_output
return False
@ -341,6 +341,18 @@ class Shell:
if os.path.exists(source):
shutil.move(source, destination)
def copy(self, source, destination):
"""
Move a file or directory from source to destination
"""
source = self.path(source)
destination = self.path(destination)
if os.path.exists(source):
if os.path.isdir(source):
shutil.copytree(source, destination)
else:
shutil.copyfile(source, destination)
def remove(self, location):
"""
Remove a file or directory if it exists