Basic tool for manage git
import os
import sys
import time
import platform
# Draw logo
logo = """
+-------------------------+
| Git Manager v1.0 |
+------------------------->
- By -
Moncho Varela/@nakome
"""
# draw bye bye logo
byebye = """
+-------------------------+
| Git Manager v1.0 |
+------------------------->
BYE BYE
"""
# Draw menu
menu = """
+-------------------------+
| Git Manager v1.0 |
+------------------------->
| |
| 1 -> Clone repo |
| |
| 2 -> Change Folder |
| |
| 3 -> Add Files |
| |
| 4 -> Commit Changes |
| |
| 5 -> Push Changes |
| |
| 6 -> Exit app |
| |
+-------------------------+
"""
"""
Class git manager
"""
class git_manager:
"""
Clear Console
"""
def clear_console(self):
if platform.system() == 'Windows':
os.system('cls')
else:
os.system('clear')
"""
Init app
clear console, print logo wait 2 seconds
clear console and print menu
"""
def init(self):
self.clear_console()
print(logo)
time.sleep(2)
self.clear_console()
print(menu)
"""
Clone url
Ask de url to clone and change dir.
"""
def clone_url(self):
# check if error
try:
clone_url = str(input('- Paste valid url to clone: '))
# check empty url
if clone_url:
os.system('git clone '+clone_url)
change_folder = clone_url.split('/')[-1].replace('.git','')
time.sleep(1)
os.chdir(change_folder)
print('- Success to clone repo -')
time.sleep(1)
print('- Enter on new folder -')
else:
print('- Empty or not repo url')
except:
print('- Error to clone url')
time.sleep(2)
self.clear_console()
print(menu)
"""
Add changes
use command git add
"""
def add_changes(self):
# check error changes
try:
add_changes = str(input(' - add file, use * for all: '))
# empty stdin
if add_changes:
os.system('git add '+add_changes)
print(' - Success to add file/s - ')
else:
print('Error empty field')
except:
print('Error on add changes')
time.sleep(2)
self.clear_console()
print(menu)
"""
Commit changes
use command to commit changes
"""
def commit_changes(self):
# error commit changes
try:
commit_changes = str(input(' - Write the commit: '))
# empty commit
if commit_changes:
os.system('git commit -m "'+commit_changes+'"')
print(' - Success to commit changes - ')
else:
print('Error empty field')
except:
print('Error on commit changes')
time.sleep(2)
self.clear_console()
print(menu)
"""
Push changes
push changes on github
"""
def push_changes(self):
# error push changes
try:
push_chg = str(input(' - Write the branch here example master: '))
# error stdin
if push_chg:
os.system('git push -u origin '+push_chg)
print(' - Success to push changes - ')
else:
print('Error empty field')
except:
print('Error on push changes')
time.sleep(2)
self.clear_console()
print(menu)
"""
Change folder
Change dir with os.chdir()
"""
def change_folder(self):
# error change folder
try:
folder = str(input(' - Write name of folder: '))
# empty stdin
if folder:
os.chdir(folder)
print(' - Success to change folder - ')
else: print('Error empty folder')
except:
print(' - folder not exists - ')
time.sleep(2)
self.clear_console()
print(menu)
"""
Exit app
"""
def exit_app(self):
self.clear_console()
print(byebye)
time.sleep(2)
self.clear_console()
"""
Get info error if not write correct number.
"""
def info_error(self):
print(' - Number not correct please choose number - ')
time.sleep(2)
clear()
print(menu)
# init git manager
gm = git_manager()
gm.init()
# questions
nav = True;
while nav:
# asking the number
ask = int(input('- Choose number of menu: '))
# clone
if ask == 1: gm.clone_url()
# Change folder
elif ask == 2: gm.change_folder()
# add changes
elif ask == 3: gm.add_changes()
# comit changes
elif ask == 4: gm.commit_changes()
# push changes
elif ask == 5: gm.push_changes()
# exit
elif ask == 6:
gm.exit_app()
nav = False
# Error number
else: gm.info_error()