diff --git a/gitools/gitools.py b/gitools/gitools.py index c6073c1..225d2ea 100644 --- a/gitools/gitools.py +++ b/gitools/gitools.py @@ -1,7 +1,8 @@ import argparse -from os import path from typing import List +from os import path, _exit from .module import Module +from .utils.editor import Editor from .utils.utilities import Utilities from .utils.option_selector import OptionSelector from .modules.update_date import UpdateDateModule @@ -18,6 +19,8 @@ def main(): + checkRequirements() + try: parser = argparse.ArgumentParser() parser.add_argument( @@ -116,4 +119,18 @@ def selectModule(args, module: Module): "Enter a valid index or run with like following command\r\n> gitools -m uh" ) print() - selectModule(args, module) \ No newline at end of file + selectModule(args, module) + + +def checkRequirements(): + if not Utilities.gitExisted(): + print("There is no git to use :(\r\nplease install git then retry :D") + _exit(1) + if len(Utilities.findShell()) == 0: + print("There is no shell application to use :(") + _exit(1) + if len(Editor.findEditor()) == 0: + print( + "There is no text editor to use :(\r\nplease install nano or vim then retry :D" + ) + _exit(1) \ No newline at end of file diff --git a/gitools/module.py b/gitools/module.py index ac9447c..719a726 100644 --- a/gitools/module.py +++ b/gitools/module.py @@ -23,7 +23,7 @@ def __init__( commit_message, ): if commit_count is None: - commit_count = 10 + commit_count = self.getDefaultCommitCount() self.commits = [] self.commit_hash = commit_hash @@ -82,11 +82,16 @@ def getCommits(self): out = out.decode("utf-8") - return re.findall( - r"commit\s([a-zA-Z0-9]*)(.*)\nAuthor:\s*([^<]*)<(.*)>\nDate:\s*(.*)\n\n\s*(.*)", + commits = re.findall( + r"commit\s([a-zA-Z0-9]*)(.*)\nAuthor:\s*([^<]*)<(.*)>\nDate:\s*(.*)\n\n(.*\n{0,1}.*)", out, ) + return [c[:-1] + (c[5].replace(" ", ""),) for c in commits] + + def getDefaultCommitCount(self): + return min(500, int(self.excuteCommand("git rev-list --count HEAD")[0])) + @staticmethod def hasBackup(): return path.exists(path.join(Utilities.cwd, ".git", "refs", "original")) diff --git a/gitools/utils/editor.py b/gitools/utils/editor.py index 37a0155..17eda30 100644 --- a/gitools/utils/editor.py +++ b/gitools/utils/editor.py @@ -66,4 +66,6 @@ def findEditor(): if os.path.exists(editorPath): return [editorPath, "-n"] except: - pass \ No newline at end of file + pass + + return [] \ No newline at end of file diff --git a/gitools/utils/utilities.py b/gitools/utils/utilities.py index 482fa94..e408125 100644 --- a/gitools/utils/utilities.py +++ b/gitools/utils/utilities.py @@ -10,6 +10,23 @@ class Utilities: def ellipsis(input, length): return textwrap.shorten(input, width=length, placeholder="...") + @staticmethod + def gitExisted(): + try: + process = subprocess.Popen( + ["git"], + stderr=subprocess.PIPE, + stdin=subprocess.DEVNULL, + stdout=subprocess.DEVNULL, + ) + _, err = process.communicate() + if not err: + return True + except: + pass + + return False + @staticmethod def findShell(): try: @@ -59,6 +76,8 @@ def findShell(): except: pass + return [] + @staticmethod def clearConsole(): os.system("cls" if os.name == "nt" else "clear") diff --git a/setup.py b/setup.py index 815a45a..b847064 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ setup( name="Gitools", - version="1.5.0", + version="1.5.1", license="MIT", author="AliReza Beigy", author_email="AliRezaBeigyKhu@gmail.com",