From 9bcebbce4852dc7f348eebb94d06f5775036c2d1 Mon Sep 17 00:00:00 2001 From: Clayton Wilson Date: Fri, 3 Nov 2017 12:56:25 -0400 Subject: [PATCH] Did some work on update() --- .gitignore | 1 - actions.py | 29 ++++++++++++++++++++++++++++- launcher.py | 4 ++-- test.py | 3 --- 4 files changed, 30 insertions(+), 7 deletions(-) delete mode 100644 test.py diff --git a/.gitignore b/.gitignore index 9c4e788..6f812cb 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,3 @@ login.json api info.txt __pycache__ -menuLayout.txt diff --git a/actions.py b/actions.py index 3f531c5..c758fb6 100644 --- a/actions.py +++ b/actions.py @@ -4,6 +4,7 @@ import json import datetime import dateutil import os +import subprocess from checks import checkTimestamp from checks import getToken @@ -62,7 +63,7 @@ def clearLogin(): except Exception as e: pass -def clearFolders():# TODO implement this +def clearFolders(): # TODO implement this folders = ["banner", "fanart", "poster"] for folder in folders: if os.path.exists(folder): @@ -127,3 +128,29 @@ def download(imageType, parsed_respObj): else: quit() return saveNameList + + # The following code is from Red-DiscordBot + # https://github.com/Cog-Creators/Red-DiscordBot +def is_git_installed(): + try: + subprocess.call(["git", "--version"], stdout=subprocess.DEVNULL, + stdin =subprocess.DEVNULL, + stderr=subprocess.DEVNULL) + except FileNotFoundError: + return False + else: + return True + +def update(): + try: + code = subprocess.call(("git", "pull", "--ff-only")) + except FileNotFoundError: + print("\nError: Git not found. It's either not installed or you did " + "not clone this using git. Install instructions are on the GitHub: " + "https://github.com/ClaytonWWilson/Image-fetcher-for-theTVDB.com") + return + if code == 0: + print("\nProgram has been updated.") + else: + print("\nThere was an error while updating. This may be caused by edits " + "you have made to the code.") diff --git a/launcher.py b/launcher.py index 0b18ad3..58e34cb 100644 --- a/launcher.py +++ b/launcher.py @@ -45,7 +45,7 @@ while True: print("install requirements") break elif choice == "6": - print("update") - break + update() + wait() elif choice == "0": exit() diff --git a/test.py b/test.py deleted file mode 100644 index bb8b8a3..0000000 --- a/test.py +++ /dev/null @@ -1,3 +0,0 @@ -from login import login - -login()