Skip to content

Commit

Permalink
Fixing unwanted code for speed improvement.
Browse files Browse the repository at this point in the history
  • Loading branch information
Almas-Ali committed Mar 19, 2023
1 parent 29ac5c9 commit 5065e20
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 15 deletions.
36 changes: 26 additions & 10 deletions src/bin/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,29 @@ def run(self, args: list = None, *arg, **kwargs):
self.__version__()

else:

args = ' '.join(args)
stdout, stderr = subprocess.Popen(
args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True
).communicate()

if stdout.decode('utf-8') != '':
print(stdout.decode('utf-8'))
else:
self.ERRORS.command_not_found(stderr.decode('utf-8'))
if args == ['']:
self.__help__()
return

process = subprocess.Popen(
args,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
universal_newlines=True
)

for line in process.stdout:
print(line, end='')
for line in process.stderr:
self.ERRORS.os_command_not_found(process.stderr)

# args = ' '.join(args)
# stdout, stderr = subprocess.Popen(
# args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True
# ).communicate()

# if stdout.decode('utf-8') != '':
# print(stdout.decode('utf-8'))

# else:
# self.ERRORS.command_not_found(stderr.decode('utf-8'))
7 changes: 5 additions & 2 deletions src/bin/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,11 @@ def run(self, args: list = None, *arg, **kwargs):
elif args[0] == '':
# Listing all the commands in the bin directory and getting their short help
# Getting all the files in the bin directory
lists_ = glob.glob1(os.path.join(
profile['BASE_DIR'], 'bin'), '*.py')
lists_ = glob.glob1(
os.path.join(
profile['BASE_DIR'], 'bin'
), '*.py')

lists_ = [i.replace('.py', '')
for i in lists_] # Removing the .py extension
lists_.remove('__init__') # Removing the __init__.py file
Expand Down
2 changes: 1 addition & 1 deletion src/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"ANT_PATH": ANT_PATH,
"SYSTEM_PATH": SYSTEM_PATH,
"OPERATING_SYSTEM": OPERATING_SYSTEM,
"history": ".ant_history",
"history": ".ant_history", # history file name
"aliases": {
"cls": "clear", # cls is a windows command
"dir": "ls", # dir is a windows command
Expand Down
7 changes: 6 additions & 1 deletion src/lib/backtrack.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
from .userlib import stdlib
from lib.userlib import stdlib
from lib.userlib import SystemConfig


class Errors:
'''Ant errors class.'''

def __init__(self) -> None:
self.output = stdlib().error
self.os = SystemConfig().check_os()

def command_not_found(self, command: str) -> None:
self.output(f'Ant: {command}: command not found!')

def os_command_not_found(self, command: str) -> None:
self.output(f'Ant: {self.os}: {command}: command not found!')

def command_not_found_help(self, command: str) -> None:
self.output(
f'Ant: {command}: command not found. Try "help" for more information.'
Expand Down
2 changes: 1 addition & 1 deletion src/lib/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ def execute(self, input_):
try:
# get modules from python path and reload them to get the latest changes
file = import_module(f'bin.{input_.get_command()}')
# reload(file)
reload(file)
file = getattr(file, 'Exclusive')
file = file()

Expand Down

0 comments on commit 5065e20

Please sign in to comment.