Skip to content
This repository has been archived by the owner on Sep 19, 2023. It is now read-only.

Commit

Permalink
Merge pull request #7 from GalaxeTV/feature/cleanup-files
Browse files Browse the repository at this point in the history
Add local and remote deletion of files during runtime
  • Loading branch information
garrettsummerfi3ld authored Apr 11, 2023
2 parents ea8036f + f9ffaf9 commit e2142dc
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"""

import os
import shutil
import sys
import time
import requests
Expand All @@ -28,8 +29,10 @@ def main():
"""
download_ftp()
stop_server()
delete_remote_files()
upload_files()
start_server()
delete_local_files()


def download_ftp():
Expand Down Expand Up @@ -92,6 +95,25 @@ def start_server():
api.client.servers.send_power_action(server, "start")
print("Server started")

def delete_remote_files():
"""_summary_ Deletes files from the files directory
"""
print("Deleting files on mirrored instance...")
dict_files = api.client.servers.files.list_files(server, "/")
file_names = []
for file in dict_files["data"]:
file_names.append(file["attributes"]["name"])

api.client.servers.files.delete_files(server, file_names, "/")

print("Files deleted")

def delete_local_files():
"""_summary_ Deletes files from the files directory
"""
print("Deleting local files...")
shutil.rmtree("./files")
print("Local files deleted")

if __name__ == "__main__":
main()

0 comments on commit e2142dc

Please sign in to comment.