Skip to content

Instantly share code, notes, and snippets.

@nedimf
Created August 31, 2019 15:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nedimf/6b0b95a8d95b29df9bd2469aff9bccf9 to your computer and use it in GitHub Desktop.
Save nedimf/6b0b95a8d95b29df9bd2469aff9bccf9 to your computer and use it in GitHub Desktop.
Wraper for FCP (Pascal compiler) on Linux
#!usr/bin/python
# Developer : @nedimf
import sys
import os
from cmd import Cmd
import subprocess
from colorama import Fore,Back,Style
import signal
#Declaration of variables
#.pas extension
pas = '.pas'
#Check if script is run as sudo
user = os.getenv('SUDO_USER')
if user is None:
os.system('clear')
print(Back.RED+Fore.WHITE+Style.BRIGHT+'THIS SHELL NEEDS SUDO PERMISSIONS TO RUN')
exit()
#Check if FPC compiler is present on system
rc = subprocess.call(['which', 'fpc'],stderr=subprocess.STDOUT)
os.system('clear')
if rc == 0:
print ('')
else:
print (Back.RED+Fore.WHITE+Style.BRIGHT+'[2] TEST FAILED: FPC NOT PRESENT')
print ("Run: sudo apt-get install fpc")
exit()
def startFPC(filename):
#Check if user entered .pas
if(pas in filename):
print()
else:
filename = filename + pas
#Shell command 1
shell_1 = 'fpc '+filename
#Shell command 2
shell_2 = './'+filename
shell_2 = shell_2.replace('.pas','')
print(shell_2)
os.system(shell_1)
#Clear shell
os.system('clear')
#Run shell 2
os.system( shell_2)
#Run shell
class MyPrompt(Cmd):
prompt = Fore.GREEN+Style.BRIGHT+'shell> '+Style.RESET_ALL
intro = 'Pascal Shell v1.0 \nType ? for list of commands!'
doc_header = 'Documentation for Pascal Shell v1.0'
undoc_header = 'Not documented commands'
#Disabling raw_input
use_rawinput = False
def do_run(self,inp):
'Run FPC to compile .pas file'
#Start FPC
startFPC(inp)
def do_exit(self, inp):
'Exit shell'
print('Exiting shell!')
return True
def do_clear(self,inp):
'Clear'
os.system('clear')
def default(self, inp):
if inp == 'x' or inp == 'q':
return self.do_exit(inp)
else:
print("Sorry that command is not supported,type ? for help: {}".format(inp))
do_EOF = do_exit
try:
MyPrompt().cmdloop()
except KeyboardInterrupt:
print("\nExiting shell!")
finally:
exit(0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment