Actually good and working updater
This commit is contained in:
@@ -3,6 +3,7 @@ files = [
|
|||||||
"core/discord_presence.py",
|
"core/discord_presence.py",
|
||||||
"core/file_search.py",
|
"core/file_search.py",
|
||||||
"core/headers.py",
|
"core/headers.py",
|
||||||
|
"core/updater.py",
|
||||||
"core/web_search.py",
|
"core/web_search.py",
|
||||||
"main.py"
|
"main.py"
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -1,27 +1,33 @@
|
|||||||
from git import Repo
|
from git import Repo, GitCommandError
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
REPO_URL = "https://github.com/n0va-bot/CLARA"
|
REPO_DIR = Path(__file__).parent.parent
|
||||||
REPO_DIR = Path(__file__).parent
|
|
||||||
|
|
||||||
def update_repository():
|
def update_repository():
|
||||||
try:
|
try:
|
||||||
|
if not (REPO_DIR / ".git").exists():
|
||||||
|
return "FAILED", "Not a git repository. Cannot update."
|
||||||
|
|
||||||
repo = Repo(REPO_DIR)
|
repo = Repo(REPO_DIR)
|
||||||
current_branch = repo.active_branch
|
|
||||||
|
|
||||||
print(f"Fetching latest changes from {current_branch}...")
|
|
||||||
origin = repo.remotes.origin
|
origin = repo.remotes.origin
|
||||||
|
|
||||||
origin.fetch()
|
origin.fetch()
|
||||||
|
|
||||||
print(f"Pulling changes for branch {current_branch}...")
|
local_commit = repo.head.commit
|
||||||
|
remote_commit = origin.refs[repo.active_branch.name].commit
|
||||||
|
|
||||||
|
if local_commit == remote_commit:
|
||||||
|
return "UP_TO_DATE", "You are already on the latest version."
|
||||||
|
|
||||||
origin.pull()
|
origin.pull()
|
||||||
|
|
||||||
print("Repository updated successfully.")
|
return "UPDATED", "CLARA has been updated successfully."
|
||||||
return True
|
|
||||||
|
except GitCommandError as e:
|
||||||
|
return "FAILED", f"An error occurred during the update:\n\n{e}"
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error updating repository: {e}")
|
return "FAILED", f"An unexpected error occurred:\n\n{e}"
|
||||||
return False
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
REPO_DIR = Path(__file__).parent / ".."
|
status, message = update_repository()
|
||||||
update_repository()
|
print(f"Status: {status}\nMessage: {message}")
|
||||||
31
main.py
31
main.py
@@ -449,12 +449,31 @@ class MainWindow(QtWidgets.QMainWindow):
|
|||||||
QtWidgets.QApplication.restoreOverrideCursor()
|
QtWidgets.QApplication.restoreOverrideCursor()
|
||||||
|
|
||||||
def update_git(self):
|
def update_git(self):
|
||||||
update_repository()
|
status, message = update_repository()
|
||||||
QtWidgets.QMessageBox.information(self, "Update", "Repository updated. Restarting application.")
|
|
||||||
self.restart_application()
|
if status == "UPDATED":
|
||||||
|
reply = QtWidgets.QMessageBox.question(self, "Update Successful",
|
||||||
|
f"{message}\n\nWould you like to restart now to apply the changes?",
|
||||||
|
QtWidgets.QMessageBox.StandardButton.Yes | QtWidgets.QMessageBox.StandardButton.No,
|
||||||
|
QtWidgets.QMessageBox.StandardButton.Yes)
|
||||||
|
if reply == QtWidgets.QMessageBox.StandardButton.Yes:
|
||||||
|
self.restart_application()
|
||||||
|
|
||||||
|
elif status == "UP_TO_DATE":
|
||||||
|
QtWidgets.QMessageBox.information(self, "No Updates", message)
|
||||||
|
|
||||||
|
elif status == "FAILED":
|
||||||
|
QtWidgets.QMessageBox.critical(self, "Update Failed", message)
|
||||||
|
|
||||||
def restart_application(self):
|
def restart_application(self):
|
||||||
subprocess.Popen([sys.executable] + sys.argv)
|
presence.end()
|
||||||
|
|
||||||
|
args = [sys.executable] + sys.argv
|
||||||
|
if "--restart" not in args:
|
||||||
|
args.append("--restart")
|
||||||
|
|
||||||
|
subprocess.Popen(args)
|
||||||
|
|
||||||
QtWidgets.QApplication.quit()
|
QtWidgets.QApplication.quit()
|
||||||
|
|
||||||
|
|
||||||
@@ -475,8 +494,10 @@ def main():
|
|||||||
|
|
||||||
pet.show()
|
pet.show()
|
||||||
|
|
||||||
|
# Gracefully handle shutdown
|
||||||
|
app.aboutToQuit.connect(presence.end)
|
||||||
sys.exit(app.exec())
|
sys.exit(app.exec())
|
||||||
presence.end()
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
Reference in New Issue
Block a user