Skip to content

Commit

Permalink
fix: fix files permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
clement-pages committed Dec 2, 2023
1 parent 7930e0d commit 8c23db4
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
3 changes: 2 additions & 1 deletion sunbot/SunServer.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def __init__(self, id : int, fun : bool = False) -> None:
SunServer.srv_backup_path = "./save/srv/"
if not os.path.exists(f"{SunServer.srv_backup_path}"):
logging.info("Repertory %s doesn't exist. Creating it", SunServer.srv_backup_path)
os.makedirs(SunServer.srv_backup_path, mode=666)
os.makedirs(SunServer.srv_backup_path)

#if server was already created in the past, load data from corresponding file:
if os.path.isfile(f"{SunServer.srv_backup_path}{id}.json"):
Expand Down Expand Up @@ -177,3 +177,4 @@ def save_srv_data(self):
jsonData = json.dumps(self.__dict__, ensure_ascii=False, indent=2)
serverFile.write(jsonData)
object.__setattr__(self, "usersDict", tmpUsersDict)
os.chmod(f"{SunServer.srv_backup_path}{self.id}.json", mode=0o777)
3 changes: 2 additions & 1 deletion sunbot/SunUser.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def __init__(self, id : int, emoji : str = "", freqEmoji : float = 0.5, favLocat
SunUser.usr_backup_path = "./save/usr/"
if not os.path.exists(SunUser.usr_backup_path):
logging.info("Repertory %s doesn't exist. Creating it.", SunUser.usr_backup_path)
os.makedirs(SunUser.usr_backup_path, mode=666)
os.makedirs(SunUser.usr_backup_path)

# If this user was already created by the past, load its data from the corresponding
# file instead of values passed in arguments of the constructor:
Expand Down Expand Up @@ -115,3 +115,4 @@ def save_usr_data(self) -> None:
with open(f"{SunUser.usr_backup_path}{self.id}.json", "w", encoding="UTF-8") as userFile:
jsonData = json.dumps(self.__dict__, ensure_ascii=False, indent=2)
userFile.write(jsonData)
os.chmod(f"{SunUser.usr_backup_path}{self.id}.json", mode=0o777)
6 changes: 3 additions & 3 deletions sunbot/weather_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ async def save_locations_subscribers(self) -> None:
self.__mutex_access_dict.release()
with open(self.save_file_path, 'w', encoding='UTF-8') as json_file:
json.dump(copy_dict, json_file, ensure_ascii=False, indent=2)
os.chmod(self.save_file_path, mode=666)
os.chmod(self.save_file_path, mode=0o777)
logging.info("Location's subscribers data saved into %s", self.save_file_path)

async def load_locations_subscribers(self, usr_loader, srv_loader) -> None:
Expand All @@ -240,10 +240,10 @@ async def load_locations_subscribers(self, usr_loader, srv_loader) -> None:
* `FileNotFoundError` in the case where save file is not found
"""
logging.info("Loading subscriber data for each location...")
loaded_dict = {}
try:
with open(self.save_file_path, 'r', encoding='UTF-8') as json_file:
loaded_dict = json.load(json_file)
print(loaded_dict)
except FileNotFoundError:
logging.error("Unable to load data from the JSON file at %s : file not found",
self.save_file_path)
Expand All @@ -262,7 +262,7 @@ async def load_locations_subscribers(self, usr_loader, srv_loader) -> None:
logging.error("ID %d does not correspond to any discord entity",
subscriber_id)
continue # Do not add a None subscriber, as it can broke the bot
self.add_sub2location(subscriber, location.name, location.tz)
await self.add_sub2location(subscriber, location.name, location.tz)
logging.info("Subscribers data was successfully loaded")

@abstractmethod
Expand Down

0 comments on commit 8c23db4

Please sign in to comment.