Actually good and working updater
This commit is contained in:
@@ -3,6 +3,7 @@ files = [
|
||||
"core/discord_presence.py",
|
||||
"core/file_search.py",
|
||||
"core/headers.py",
|
||||
"core/updater.py",
|
||||
"core/web_search.py",
|
||||
"main.py"
|
||||
]
|
||||
|
||||
@@ -1,27 +1,33 @@
|
||||
from git import Repo
|
||||
from git import Repo, GitCommandError
|
||||
from pathlib import Path
|
||||
|
||||
REPO_URL = "https://github.com/n0va-bot/CLARA"
|
||||
REPO_DIR = Path(__file__).parent
|
||||
REPO_DIR = Path(__file__).parent.parent
|
||||
|
||||
def update_repository():
|
||||
try:
|
||||
repo = Repo(REPO_DIR)
|
||||
current_branch = repo.active_branch
|
||||
if not (REPO_DIR / ".git").exists():
|
||||
return "FAILED", "Not a git repository. Cannot update."
|
||||
|
||||
print(f"Fetching latest changes from {current_branch}...")
|
||||
repo = Repo(REPO_DIR)
|
||||
origin = repo.remotes.origin
|
||||
|
||||
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()
|
||||
|
||||
print("Repository updated successfully.")
|
||||
return True
|
||||
return "UPDATED", "CLARA has been updated successfully."
|
||||
|
||||
except GitCommandError as e:
|
||||
return "FAILED", f"An error occurred during the update:\n\n{e}"
|
||||
except Exception as e:
|
||||
print(f"Error updating repository: {e}")
|
||||
return False
|
||||
return "FAILED", f"An unexpected error occurred:\n\n{e}"
|
||||
|
||||
if __name__ == "__main__":
|
||||
REPO_DIR = Path(__file__).parent / ".."
|
||||
update_repository()
|
||||
status, message = 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()
|
||||
|
||||
def update_git(self):
|
||||
update_repository()
|
||||
QtWidgets.QMessageBox.information(self, "Update", "Repository updated. Restarting application.")
|
||||
self.restart_application()
|
||||
status, message = update_repository()
|
||||
|
||||
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):
|
||||
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()
|
||||
|
||||
|
||||
@@ -475,8 +494,10 @@ def main():
|
||||
|
||||
pet.show()
|
||||
|
||||
# Gracefully handle shutdown
|
||||
app.aboutToQuit.connect(presence.end)
|
||||
sys.exit(app.exec())
|
||||
presence.end()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user