Skip to content

Commit 8a9018a

Browse files
committed
Add chown function
1 parent 3108ca4 commit 8a9018a

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

adafruit_shell.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,23 @@ def chmod(self, location, mode):
381381
if os.path.exists(location):
382382
os.chmod(location, mode)
383383

384+
def chown(self, location, user, group=None, recursive=False):
385+
"""
386+
Change the owner of a file or directory
387+
"""
388+
if group is None:
389+
group = user
390+
391+
location = self.path(location)
392+
if recursive and os.path.isdir(location):
393+
for root, dirs, files in os.walk(location):
394+
for dir in dirs:
395+
shutil.chown(os.path.join(root, dir), user, group)
396+
for file in files:
397+
shutil.chown(os.path.join(root, file), user, group)
398+
else:
399+
shutil.chown(location, user, group)
400+
384401
def remove(self, location):
385402
"""
386403
Remove a file or directory if it exists

0 commit comments

Comments
 (0)