-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding new features. Slight change of the code structure.
- Loading branch information
Showing
7 changed files
with
241 additions
and
72 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,206 @@ | ||
import sys | ||
|
||
import TokenManager | ||
import UploadReleaseAsset | ||
import BuildAndArchiveManager | ||
import PushManager | ||
|
||
|
||
class ConsoleManager: | ||
|
||
def __init__(self): | ||
self.pushManager = None | ||
self.tokenManager = None | ||
self.buildAndArchive = None | ||
self.uploadReleaseAsset = None | ||
|
||
def run(self, token: str, zip_file_path: str, project_directory_path: str, owner_name, repo_name): | ||
"""Displaying a dialog box in the console to control its commands.""" | ||
|
||
while True: | ||
userChoice = input("\nSelect the desired command:\n" | ||
"1. Push project with creation of a new commit.\n" | ||
"2. Push project, replacing the last commit.\n" | ||
"3. Create a release of current project.\n" | ||
"4. Add token to project.\n" | ||
"5. Build project.\n" | ||
"6. Archive build.\n" | ||
"7. Delete token from project.\n" | ||
"8. Exit.\n\n" | ||
"Select an option: ") | ||
|
||
# 1. Push project with creation of a new commit | ||
if userChoice == '1': | ||
self.push_with_creation_new_commit() | ||
|
||
# 2. Push project, replacing the last commit | ||
elif userChoice == '2': | ||
self.push_replacing_last_commit() | ||
|
||
# 3. Create a release of current project | ||
elif userChoice == '3': | ||
self.create_release(token=token, project_directory_path=project_directory_path, zip_file_path=zip_file_path, owner_name=owner_name, repo_name=repo_name) | ||
|
||
# 4. Add token to project | ||
elif userChoice == '4': | ||
if self.tokenManager is None: | ||
self.tokenManager = TokenManager.TokenManager(token=token, project_directory_path=project_directory_path) | ||
self.tokenManager.add_token_to_project() | ||
|
||
# 5. Build project | ||
elif userChoice == '5': | ||
if self.buildAndArchive is None: | ||
self.buildAndArchive = BuildAndArchiveManager.BuildAndArchiveManager(project_directory_path=project_directory_path) | ||
self.buildAndArchive.build_project(zip_file_path=zip_file_path) | ||
|
||
# 6. Archive build | ||
elif userChoice == '6': | ||
try: | ||
if self.buildAndArchive is None: | ||
self.buildAndArchive = BuildAndArchiveManager.BuildAndArchiveManager(project_directory_path=project_directory_path) | ||
self.buildAndArchive.archive_build() | ||
print('WARNING: You used "Archive build" directly, be careful as this function makes an archive from a build that was previously created, ' | ||
'its version may not be up to date if you did not use the "Build project" function before.') | ||
except FileNotFoundError as error: | ||
print(error) | ||
|
||
# 7. Delete token from project | ||
elif userChoice == '7': | ||
if self.tokenManager is None: | ||
self.tokenManager = TokenManager.TokenManager(token=token, project_directory_path=project_directory_path) | ||
self.tokenManager.delete_token_from_project() | ||
|
||
# 8. Exit | ||
elif userChoice == '8': | ||
sys.exit() | ||
|
||
else: | ||
print('Invalid input. Try again.') | ||
|
||
def push_with_creation_new_commit(self): | ||
"""Creating a new commit of current project.""" | ||
|
||
while True: | ||
userChoice = input('Are you sure you want to push project with creation of a new commit? (y/n): ') | ||
|
||
# answer is not y/n | ||
if (userChoice.isdigit()) or ((userChoice.lower() != 'y') and (userChoice.lower() != 'n')): | ||
print('\nInvalid input. Try again.') | ||
|
||
# user wants to finish | ||
if userChoice.lower() == 'n': | ||
break | ||
|
||
# user wants to continue | ||
elif userChoice.lower() == 'y': | ||
commit_message = input("\nCommands:" | ||
"\n1. Back\n" | ||
"\nCommit message: ") | ||
|
||
# user wants to finish | ||
if commit_message == '1': | ||
break | ||
|
||
# create new commit | ||
if self.pushManager is None: | ||
self.pushManager = PushManager.PushManager() | ||
self.pushManager.push_new_commit(commit_message=commit_message) | ||
|
||
# loop exit | ||
break | ||
|
||
def push_replacing_last_commit(self): | ||
"""Changing contents of last commit and, if necessary, changing its message.""" | ||
|
||
while True: | ||
userChoice = input('Are you sure you want to push project, replacing the commit? (y/n): ') | ||
|
||
# answer is not y/n | ||
if (userChoice.isdigit()) or ((userChoice.lower() != 'y') and (userChoice.lower() != 'n')): | ||
print('\nInvalid input. Try again.') | ||
|
||
# user wants to finish | ||
if userChoice.lower() == 'n': | ||
break | ||
|
||
# user wants to continue | ||
elif userChoice.lower() == 'y': | ||
while True: | ||
userChoice = input('\nCommands:' | ||
"\n1. Back\n" | ||
'\nAre you want to change last commit message? (y/n): ') | ||
|
||
# user wants to finish | ||
if userChoice == '1': | ||
break | ||
|
||
# creating an instance of a class | ||
if self.pushManager is None: | ||
self.pushManager = PushManager.PushManager() | ||
|
||
# answer is not y/n | ||
if (userChoice.isdigit()) or ((userChoice.lower() != 'y') and (userChoice.lower() != 'n')): | ||
print('\nInvalid input. Try again.') | ||
|
||
# user does not want to change commit message | ||
if userChoice.lower() == 'n': | ||
self.pushManager.push_replacing_last_commit() | ||
break | ||
|
||
# user wants to change last commit message | ||
elif userChoice.lower() == 'y': | ||
replacing_commit_message = input('\nCommands:' | ||
"\n1. Back\n" | ||
'\nAre you want to change last commit message? (y/n): ') | ||
|
||
# user wants to finish | ||
if replacing_commit_message == '1': | ||
break | ||
|
||
# replace last commit | ||
self.pushManager.push_replacing_last_commit(commit_message=replacing_commit_message) | ||
|
||
# loop exit | ||
break | ||
|
||
# loop exit | ||
break | ||
|
||
def create_release(self, token, project_directory_path, zip_file_path, owner_name, repo_name): | ||
"""Create a release of current project.""" | ||
|
||
while True: | ||
userChoice = input('Are you sure you want to upload current project to repository? (y/n): ') | ||
|
||
# # answer is not y/n | ||
if (userChoice.isdigit()) or ((userChoice.lower() != 'y') and (userChoice.lower() != 'n')): | ||
print('\nInvalid input. Try again.') | ||
|
||
# user wants to finish | ||
if userChoice.lower() == 'n': | ||
break | ||
|
||
# user wants to change last commit message | ||
elif userChoice.lower() == 'y': | ||
|
||
# add token | ||
if self.tokenManager is None: | ||
self.tokenManager = TokenManager.TokenManager(token=token, project_directory_path=project_directory_path) | ||
self.tokenManager.add_token_to_project() | ||
|
||
# build and archive | ||
if self.buildAndArchive is None: | ||
self.buildAndArchive = BuildAndArchiveManager.BuildAndArchiveManager(project_directory_path=project_directory_path) | ||
self.buildAndArchive.build_project(zip_file_path=zip_file_path) | ||
self.buildAndArchive.archive_build() | ||
|
||
# upload release | ||
if self.uploadReleaseAsset is None: | ||
self.uploadReleaseAsset = UploadReleaseAsset.UploadReleaseAsset(owner_name=owner_name, repo_name=repo_name, zip_file_path=zip_file_path, token=token) | ||
self.uploadReleaseAsset.run() | ||
|
||
# delete token | ||
self.tokenManager.delete_token_from_project() | ||
|
||
# loop exit | ||
break |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import subprocess | ||
import time | ||
|
||
|
||
class PushManager: | ||
|
||
@staticmethod | ||
def __git_add(): | ||
"""Executing terminal command - git add .""" | ||
|
||
subprocess.run(["git", "add", "."]) | ||
|
||
def push_new_commit(self, commit_message: str): | ||
"""Commands to create a new commit.""" | ||
|
||
self.__git_add() | ||
subprocess.run(["git", "commit", "-m", commit_message]) | ||
subprocess.run(["git", "push", "origin", "master"]) | ||
time.sleep(3) | ||
|
||
def push_replacing_last_commit(self, commit_message: str = None): | ||
"""Commands to replace last commit and possibly its message.""" | ||
|
||
self.__git_add() | ||
|
||
# without replacing commit message | ||
if commit_message is None: | ||
subprocess.run(["git", "commit", "--amend", "-C", "HEAD"]) | ||
|
||
# replacing commit message | ||
else: | ||
subprocess.run(["git", "commit", "--amend", "-m", commit_message]) | ||
|
||
subprocess.run(["git", "push", "--force"]) | ||
time.sleep(3) |
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.