Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add terminal color #40

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 23 additions & 25 deletions Scripts/check_supported.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
"""
This script check if a given part is between the supported modules
and also from which file it cames
This script checks if a given part is among the supported modules
and also identifies the file from which it comes.
"""

import os, pickle, sys
import os
import pickle
import sys
from termcolor import colored

root_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..')
supported_pickle_path = os.path.join(root_path, 'Supported.pickle')
Expand All @@ -16,40 +19,36 @@
def print_match(part):
try:
paths = ['- {0}'.format(i) for i in supported[part]]
print(part + ' found in')
print(*paths, sep = '\n')
print(colored(part, 'green') + ' found in')
for path in paths:
print(colored(path, 'yellow'))
except Exception as e:
print('Error processing {}: '.format(part), e)
print(colored('Error processing {}: '.format(part), 'red'), e)

# Get similar models
def get_similar(string):
similar = list()
for line in supported_str.splitlines():
if line.find(string) != -1:
if string in line:
similar.append(line)
if string in similar: similar.remove(string) # We already printed this
if string in similar:
similar.remove(string) # We already printed this
return similar

# Search
def search(module):
if not module in supported_str:
print('{} not found!'.format(module))

elif module in supported_str and not module in supported: # Typo?
if module not in supported_str:
print(colored('{} not found!'.format(module), 'red'))
elif module in supported_str and module not in supported: # Typo?
similar_part = ', '.join(get_similar(module))
print('{} not found, maybe you meant one of these: {}'.format(module, similar_part))

print(colored('{} not found, maybe you meant one of these: {}'.format(module, similar_part), 'red'))
else:
print_match(module)

# Search also similar parts
count = supported_str.count(module)

if count > 1:
print('\nAlso other {} similar part has been found:\n'.format(count - 1))

print(colored('\nAlso, other {} similar part(s) have been found:\n'.format(count - 1), 'cyan'))
similar_part = get_similar(module)

for part in similar_part:
print_match(part)

Expand All @@ -63,17 +62,16 @@ def search(module):

if len(sys.argv) > 1:
for s in sys.argv[1:]:
print("Searching for " + s)
print("Searching for " + colored(s, 'blue'))
search(s.lower())
else:
# Part to search
print('Write \'exit\' when you want to stop')
to_search = input('Write here the part you are looking for: ').strip().lower()

print(colored('Write \'exit\' when you want to stop', 'magenta'))
to_search = input(colored('Write here the part you are looking for: ', 'magenta')).strip().lower()
while True:
if to_search in ['exit', 'no']:
print('Bye bye')
print(colored('Bye bye', 'magenta'))
sys.exit(0)
elif to_search:
search(to_search)
to_search = input('Would you like to do another search? ').strip().lower()
to_search = input(colored('Would you like to do another search? ', 'magenta')).strip().lower()