Skip to content

Commit

Permalink
Check requirement
Browse files Browse the repository at this point in the history
Fix commit message issue
Update default commit count
Bump v1.5.1
  • Loading branch information
AliRezaBeigy committed Feb 17, 2021
1 parent 015da17 commit e3f0864
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 7 deletions.
21 changes: 19 additions & 2 deletions gitools/gitools.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -18,6 +19,8 @@


def main():
checkRequirements()

try:
parser = argparse.ArgumentParser()
parser.add_argument(
Expand Down Expand Up @@ -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)
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)
11 changes: 8 additions & 3 deletions gitools/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"))
Expand Down
4 changes: 3 additions & 1 deletion gitools/utils/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,6 @@ def findEditor():
if os.path.exists(editorPath):
return [editorPath, "-n"]
except:
pass
pass

return []
19 changes: 19 additions & 0 deletions gitools/utils/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -59,6 +76,8 @@ def findShell():
except:
pass

return []

@staticmethod
def clearConsole():
os.system("cls" if os.name == "nt" else "clear")
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

setup(
name="Gitools",
version="1.5.0",
version="1.5.1",
license="MIT",
author="AliReza Beigy",
author_email="[email protected]",
Expand Down

0 comments on commit e3f0864

Please sign in to comment.