Skip to content
This repository has been archived by the owner on Feb 6, 2022. It is now read-only.

Commit

Permalink
Refactor files and set for 0.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
alphaX86 committed Dec 14, 2020
1 parent 8c791df commit fb228a6
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 24 deletions.
18 changes: 16 additions & 2 deletions codeit/codeit.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
import os
from clint.textui import colored
from codeit.codeitHelp import help
from codeit.codeitInit import init
from codeit.codeitMeta import template_cp, get_filename
from codeit.codeitInit import init, init_noerror
from codeit.codeitMeta import template_cp, get_filename, get_fn_beginner

def main():
if len(sys.argv) < 2:
help()

else:
countArg = 0

for arg in sys.argv:
countArg+=1

Expand All @@ -22,6 +23,19 @@ def main():
init_single_file(f'{fileName}.cpp', template)
print(colored.yellow(f'Created {fileName}.cpp'))
break
elif sys.argv[countArg] == '-b':
if sys.argv[countArg+1] == '-ne':
contestName = sys.argv[countArg+2]
fileNames = get_fn_beginner()
init_noerror(contestName, fileNames)
else:
contestName = sys.argv[countArg+1]
fileNames = get_fn_beginner()
init(contestName, fileNames)
elif sys.argv[countArg] == '-ne':
contestName = sys.argv[countArg+1]
fileNames = get_filename()
init_noerror(contestName, fileNames)
else:
contestName = sys.argv[countArg]
fileNames = get_filename()
Expand Down
29 changes: 16 additions & 13 deletions codeit/codeitHelp.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,22 @@
def help():
print('\n')

print(colored.green("""
.d88b .d88b. 888b. 8888 w w
8P 8P Y8 8 8 8www w w8ww
8b 8b d8 8 8 8 8 8
`Y88P `Y88P' 888P' 8888 8 Y8P
"""))
print('\n')
print(colored.white(""" ██████╗ ██████╗ ██████╗ ███████╗██╗████████╗
██╔════╝██╔═══██╗██╔══██╗██╔════╝██║╚══██╔══╝
██║ ██║ ██║██║ ██║█████╗ ██║ ██║
██║ ██║ ██║██║ ██║██╔══╝ ██║ ██║
╚██████╗╚██████╔╝██████╔╝███████╗██║ ██║
╚═════╝ ╚═════╝ ╚═════╝ ╚══════╝╚═╝ ╚═╝
"""))

print(colored.cyan("A CLI Script tool to help you initialize CPP files for any contest"))
print('\nCommands:\n')
print(colored.yellow("codeit -h -------------------- To display help menu"))
print(colored.yellow("codeit -i <contest> ---------- To initialize a contest directory"))
print(colored.yellow("codeit -i -n <file> ---------- To initialize only a single file"))
print(colored.yellow("codeit -v -------------------- To print version number"))
print(colored.yellow("codeit -p -------------------- To parse and compile the program"))
print(colored.magenta("codemon <flags> <args>\n"))
print(colored.red('Args list\n'))
print(colored.yellow("-h \n" + colored.blue("To display help menu")))
print(colored.yellow("-i <contest> \n" + colored.blue("To initialize a contest directory")))
print(colored.yellow("-i -b <contest> \n" + colored.blue("To initialize a contest directory for practice and beginner level")))
print(colored.yellow("-i <args> -ne <contest> \n" + colored.blue("To initialize a contest directory without error.txt file")))
print(colored.yellow("-i -n <file> \n" + colored.blue("To initialize only a single file")))
print(colored.yellow("-v \n" + colored.blue("To print version number")))
print(colored.yellow("-p \n" + colored.blue("To parse and compile the program")))
24 changes: 20 additions & 4 deletions codeit/codeitInit.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
from clint.textui import colored
from codemon.CodemonMeta import template_cpp
from codeit.codeitMeta import template_cp

def write_to_file(filename, text, contestName=None):
full_filename = os.path.join(os.getcwd(), filename)
Expand All @@ -15,14 +15,30 @@ def init(contestName,fileNames):
print(colored.blue('Making files and folders for ' + colored.magenta(contestName)))
os.makedirs(os.path.join(os.getcwd(), contestName))
except OSError:
print(colored.red("Failed! This directory cannot be created."))
print(colored.red("Failed! This directory cannot be created as it exists."))
else:
print(colored.yellow('Directory is made'))
# create files for contest (should be 6 cpp files)
for files in range(len(fileNames)):
write_to_file(fileNames[files], template_cpp(), contestName)
write_to_file(fileNames[files], template_cp(), contestName)
# create input file
write_to_file('input.txt', '', contestName)
write_to_file('output.txt', '', contestName)
write_to_file('error.txt', '', contestName)
print(colored.green('Files have been created. Happy Coding!'))
print(colored.green('Files have been created. Happy Coding!'))

def init_noerror(contestName, fileNames):
try:
print(colored.blue('Making files and folders for ' + colored.magenta(contestName)))
os.makedirs(os.path.join(os.getcwd(), contestName))
except OSError:
print(colored.red("Failed! This directory cannot be created as it exists."))
else:
print(colored.yellow('Directory is made'))
# create files for contest (should be 6 cpp files)
for files in range(len(fileNames)):
write_to_file(fileNames[files], template_cp(), contestName)
# create input file
write_to_file('input.txt', '', contestName)
write_to_file('output.txt', '', contestName)
print(colored.green('Files have been created without error TXT file. Happy Coding!'))
13 changes: 9 additions & 4 deletions codeit/codeitMeta.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,27 @@ def template_cp():
freopen("input.txt", "r", stdin);
freopen("error.txt", "w", stderr);
freopen("output.txt", "w", stdout);
//If you do not need error txt, remove it accordingly
#endif
int t = 1;
/*is Single Test case?*/
cin >> t;
while (t--) {
//Code here
cout << "\n";
cout << endl;
}
cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl;
cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl; //Optional
return 0;
} """

return template

def get_filename():
fileNames = ['A.cpp','B.cpp','C.cpp','D.cpp','E.cpp','F.cpp']
return fileNames
fileNames = ['A.cpp','B.cpp','C.cpp','D.cpp','E.cpp','F.cpp']
return fileNames

def get_fn_beginner():
fileNames = ['A.cpp','B.cpp','C.cpp']
return fileNames
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name='codeit',
version='0.0.1',
version='0.0.2',
author='Aadhitya A',
packages=find_packages(),
install_requires=[
Expand Down

0 comments on commit fb228a6

Please sign in to comment.