-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* modified init files to ensure that a failing module will not crash the entire system * dynamic imports of ccr rules added * dynamic imports for filters as well * dynamic imports for rules
- Loading branch information
1 parent
162e7c8
commit f23f8a2
Showing
4 changed files
with
93 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,24 @@ | ||
import glob | ||
import inspect | ||
import os | ||
|
||
|
||
def is_valid(module): | ||
''' This function attempts to import the applications in order to detect | ||
errors in their implementation . After they are imported, they are garbage collected | ||
when the function returns.''' | ||
try: | ||
_ = __import__(module, globals(), locals()) | ||
return True | ||
except Exception as e: | ||
print( | ||
"Ignoring application '{}'. Failed to load with: ".format(module)) | ||
print(e) | ||
return False | ||
|
||
|
||
modules = glob.glob(os.path.dirname(__file__) + "/*.py") | ||
__all__ = [os.path.basename(f)[:-3] for f in modules if not f.endswith('__init__.py')] | ||
# only valid applications will be added to the list | ||
__all__ = [ | ||
os.path.basename(f)[:-3] for f in modules if (not f.endswith('__init__.py') and is_valid(os.path.basename(f)[:-3])) | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,32 @@ | ||
from bash.bash import Bash | ||
from core.alphabet import Alphabet | ||
from core.nav import Navigation | ||
from core.numbers import Numbers | ||
from core.punctuation import Punctuation | ||
from cpp.cpp import CPP | ||
from csharp.csharp import CSharp | ||
from haxe.haxe import Haxe | ||
from html.html import HTML | ||
from java.java import Java | ||
from javascript.javascript import Javascript | ||
from python.python import Python | ||
from rust.rust import Rust | ||
from sql.sql import SQL | ||
from vhdl.vhdl import VHDL | ||
from prolog.prolog import Prolog | ||
# new modules should be added in the dictionary | ||
# the tupple contains the rules which will be imported | ||
|
||
command_sets = { | ||
"bash.bash": ("Bash", ), | ||
"core.alphabet": ("Alphabet", ), | ||
"core.nav": ("Navigation", ), | ||
"core.numbers": ("Numbers", ), | ||
"core.punctuation": ("Punctuation", ), | ||
"cpp.cpp": ("CPP", ), | ||
"csharp.csharp": ("CSharp", ), | ||
"haxe.haxe": ("Haxe", ), | ||
"html.html": ("HTML", ), | ||
"java.java": ("Java", ), | ||
"javascript.javascript": ("Javascript", ), | ||
"python.python": ("Python", ), | ||
"rust.rust": ("Rust", ), | ||
"sql.sql": ("SQL", ), | ||
"prolog.prolog": ("Prolog", ), | ||
"vhdl.vhdl": ("VHDL", ), | ||
} | ||
|
||
|
||
for module_name,class_name_tup in command_sets.iteritems(): | ||
for class_name in class_name_tup: | ||
try: | ||
module = __import__(module_name, globals(), locals(),[class_name]) #attempts to import the class | ||
globals()[class_name]= module #make the name available globally | ||
|
||
except Exception as e: | ||
print("Ignoring ccr rule '{}'. Failed to load with: ".format(class_name)) | ||
print(e) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,24 @@ | ||
import glob | ||
import inspect | ||
import os | ||
|
||
|
||
def is_valid(module): | ||
''' This function attempts to import the filters in order to detect | ||
errors in their implementation . After they are imported, they are garbage collected | ||
when the function returns.''' | ||
try: | ||
_ = __import__(module, globals(), locals()) | ||
return True | ||
except Exception as e: | ||
print("Ignoring filter '{}'. Failed to load with: ".format(module)) | ||
print(e) | ||
return False | ||
|
||
|
||
modules = glob.glob(os.path.dirname(__file__) + "/*.py") | ||
__all__ = [os.path.basename(f)[:-3] for f in modules if not f.endswith('__init__.py')] | ||
# only valid filters will be added to the list | ||
__all__ = [ | ||
os.path.basename(f)[:-3] for f in modules | ||
if (not f.endswith('__init__.py') and is_valid(os.path.basename(f)[:-3])) | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,25 @@ | ||
import glob | ||
import inspect | ||
import os | ||
|
||
|
||
def is_valid(module): | ||
''' This function attempts to import the rules in order to detect | ||
errors in their implementation . After they are imported, they are garbage collected | ||
when the function returns.''' | ||
try: | ||
_ = __import__(module, globals(), locals()) | ||
return True | ||
except Exception as e: | ||
print("Ignoring application '{}'. Failed to load with: ".format(module)) | ||
print(e) | ||
return False | ||
|
||
|
||
modules = glob.glob(os.path.dirname(__file__) + "/*.py") | ||
__all__ = [os.path.basename(f)[:-3] for f in modules if not f.endswith('__init__.py')] | ||
# only valid rules will be added to the list | ||
__all__ = [ | ||
os.path.basename(f)[:-3] | ||
for f in modules | ||
if (not f.endswith('__init__.py') and is_valid(os.path.basename(f)[:-3])) | ||
] |