-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
executable file
·118 lines (107 loc) · 4.94 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import argparse
import os
import platform
import operations
import sys
# Initialising operation module
try:
file_opr = operations.file()
editor_opr = operations.editor()
template_opr = operations.template()
system_settings = operations.system_settings()
except FileNotFoundError:
print("File is not found. Please install the program first.")
VERSION = "1.0.1"
LOGO = '''\
_ _ ____ ____ ____ ____ _ _
/ \ _ _| |_ ___ / ___| _ \| _ \ / ___|___ _ __ ___ _ __ (_) | ___ _ __
/ _ \| | | | __/ _ \ | | | |_) | |_) | | | / _ \| '_ ` _ \| '_ \| | |/ _ \ '__|
/ ___ \ |_| | || (_) | | |___| __/| __/ | |__| (_) | | | | | | |_) | | | __/ |
/_/ \_\__,_|\__\___/ \____|_| |_| \____\___/|_| |_| |_| .__/|_|_|\___|_|
|_|
'''
parser = argparse.ArgumentParser(
prog="Auto CPP Compiler",
formatter_class=argparse.RawDescriptionHelpFormatter,
description=LOGO,
epilog='''\
Example:
> acc prog.cpp
> acc --ct
> acc --ce vim
> acc prog.cpp -eo output.out
For any issue visit:\nhttps://github.com/Bipul-Harsh/auto-cpp-compiler/issues''')
parser.add_argument('file', type=str, default='', help="to create/open file.",nargs='?')
parser.add_argument('-o', action='store_const', const=True, default=False, dest='override_file', help="Override if file exists with template file.")
parser.add_argument('--ct', action='store_const', const=True, default=False, dest='update_template', help="Change file template.")
parser.add_argument('--st', action='store_const', const=True, default=False, dest='show_template', help="Show file template.")
parser.add_argument('--ce', type=str, help="Change text editor of your choice (vim and gedit is preffered).")
parser.add_argument('--se', action='store_const', const=True, default=False, dest='show_editor', help="Show selected text editor.")
parser.add_argument('--version', action='store_const', const=True, default=False, dest='version', help="Show current version.")
parser.add_argument('-eo', type=str, help="For storing the ouput file explicitly. Please output file name after it!")
parser.add_argument('--uninstall', action='store_const', const=True, default=False, dest='uninstall', help="To uninstall %(prog)s program :(")
args = parser.parse_args()
FILE = args.file
OVERRIDE_FILE = args.override_file
CHANGE_EDITOR = bool(args.ce) #Empty string makes false
EDITOR = args.ce
CHANGE_TEMPLATE = args.update_template
SHOW_VERSION = args.version
SHOW_EDITOR = args.show_editor
SHOW_TEMPLATE = args.show_template
OUTPUT_FILE = args.eo
DO_UNINSTALL = args.uninstall
# Check if the user didnt put anything
is_settings_related = bool(CHANGE_EDITOR or DO_UNINSTALL or CHANGE_TEMPLATE or SHOW_VERSION or SHOW_TEMPLATE or SHOW_EDITOR)
assert bool(FILE or is_settings_related),"Please provide a file name"
assert ('-eo' not in FILE), "Please provide an output file name"
# All Query Task
if is_settings_related:
print(LOGO+'Does repetitve compiling task of .cpp file for you :)\n'+"--------------------------------------------------------------------------------------")
if SHOW_VERSION:
print(f'\nVersion : {VERSION}')
if SHOW_EDITOR:
editor_name, editor_location = editor_opr.get_editor()
print("\nCurrently Selected Editor\n"+editor_name+' : '+editor_location)
if CHANGE_EDITOR:
editor_opr.set_editor(EDITOR)
if SHOW_TEMPLATE:
print('\nTemplate\n------------------------------------------------------------------------------------\n'
+ template_opr.get_template()
+ '\n------------------------------------------------------------------------------------')
if CHANGE_TEMPLATE:
template_opr.set_template()
if DO_UNINSTALL:
confirm = ''
while(confirm not in ['y','n']):
confirm = input("Are you sure to uninstall this software (y/n): ").strip().lower()
if confirm=='y':
system_settings.uninstall()
elif confirm=='n':
sys.exit(0)
sys.exit(0)
# File Operations
file_opr.create_file(FILE, OVERRIDE_FILE)
in_loop = True
opr = 'd'
while in_loop:
if platform.system() == 'Windows':
os.system('cls')
else:
os.system('clear')
if opr=='o' or opr=='d':
file_opr.open_file()
file_opr.compile_file(OUTPUT_FILE)
print('Ouput\n------------------------------------------------------------------------------------')
file_opr.execute_output()
print('------------------------------------------------------------------------------------')
opr=''
while opr not in ['e','o','r']:
opr = input('Enter [o open] [e exit] [r rerun]: ').lower()
# Deleting the output file
if opr!='r':
file_opr.delete_output()
if opr == 'e':
sys.exit(0)
elif opr not in ['o','r']:
print('Invalid Input')