Use Path.chmod() (#3051)
This commit is contained in:
parent
459b84b6fe
commit
18ef7fd469
|
|
@ -1,5 +1,4 @@
|
||||||
import json
|
import json
|
||||||
import os
|
|
||||||
import readline
|
import readline
|
||||||
import stat
|
import stat
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
@ -117,14 +116,14 @@ class ConfigurationOutput:
|
||||||
if self._is_valid_path(dest_path):
|
if self._is_valid_path(dest_path):
|
||||||
target = dest_path / self._user_config_file
|
target = dest_path / self._user_config_file
|
||||||
target.write_text(self.user_config_to_json())
|
target.write_text(self.user_config_to_json())
|
||||||
os.chmod(target, stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP)
|
target.chmod(stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP)
|
||||||
|
|
||||||
def save_user_creds(self, dest_path: Path) -> None:
|
def save_user_creds(self, dest_path: Path) -> None:
|
||||||
if self._is_valid_path(dest_path):
|
if self._is_valid_path(dest_path):
|
||||||
if user_creds := self.user_credentials_to_json():
|
if user_creds := self.user_credentials_to_json():
|
||||||
target = dest_path / self._user_creds_file
|
target = dest_path / self._user_creds_file
|
||||||
target.write_text(user_creds)
|
target.write_text(user_creds)
|
||||||
os.chmod(target, stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP)
|
target.chmod(stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP)
|
||||||
|
|
||||||
def save(self, dest_path: Path | None = None) -> None:
|
def save(self, dest_path: Path | None = None) -> None:
|
||||||
dest_path = dest_path or self._default_save_path
|
dest_path = dest_path or self._default_save_path
|
||||||
|
|
|
||||||
|
|
@ -257,7 +257,7 @@ class SysCommandWorker:
|
||||||
peek_output_log.write(str(output))
|
peek_output_log.write(str(output))
|
||||||
|
|
||||||
if change_perm:
|
if change_perm:
|
||||||
os.chmod(str(peak_logfile), stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP)
|
peak_logfile.chmod(stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP)
|
||||||
|
|
||||||
sys.stdout.write(str(output))
|
sys.stdout.write(str(output))
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
|
|
@ -317,7 +317,7 @@ class SysCommandWorker:
|
||||||
cmd_log.write(f"{time.time()} {self.cmd}\n")
|
cmd_log.write(f"{time.time()} {self.cmd}\n")
|
||||||
|
|
||||||
if change_perm:
|
if change_perm:
|
||||||
os.chmod(str(history_logfile), stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP)
|
history_logfile.chmod(stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP)
|
||||||
except (PermissionError, FileNotFoundError):
|
except (PermissionError, FileNotFoundError):
|
||||||
# If history_logfile does not exist, ignore the error
|
# If history_logfile does not exist, ignore the error
|
||||||
pass
|
pass
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue