-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
2 changed files
with
83 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
"""__init__.py | ||
For Conspiracy targeting modes' dynamic loading | ||
""" | ||
|
||
import os | ||
import traceback | ||
|
||
|
||
def _import_all_modules(): | ||
""" Dynamically imports all modules in this package""" | ||
global __all__ | ||
__all__ = [] | ||
globals_, locals_ = globals(), locals() | ||
# Dynamically import all the package modules in this directory | ||
for filename in os.listdir(__name__): | ||
# Process all Python files in directory that don't start with underscore | ||
if not filename.startswith('__') and filename.split('.')[-1] in ('py', 'pyw'): | ||
modulename = filename.split('.')[0] # Filename sans extension | ||
package_module = '.'.join([__name__, modulename]) | ||
try: | ||
module = __import__(package_module, globals_, locals_, [modulename]) | ||
except: | ||
traceback.print_exc() | ||
raise | ||
for name in module.__dict__: | ||
if not name.startswith('_'): | ||
globals_[name] = module.__dict__[name] | ||
__all__.append(name) | ||
|
||
|
||
_import_all_modules() | ||
|
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 |
---|---|---|
@@ -0,0 +1,49 @@ | ||
"""_interfaces.py | ||
Interface base classes for writing Conspiracy targeting modes. | ||
""" | ||
|
||
import abc | ||
import logging | ||
|
||
|
||
class ITargetingMode(abc.ABC): | ||
"""Abstract interface base class for a Conspiracy targeting mode. | ||
Params: | ||
name (str) | ||
""" | ||
|
||
@abc.abstractmethod | ||
def __init__(self, name): | ||
"""Abstract - constructor, should set targeting mode name. | ||
Params: | ||
name (str) | ||
""" | ||
pass | ||
|
||
def get_name(self): | ||
"""Get name of this targeting mode. | ||
Returns: | ||
(str) | ||
""" | ||
return self.name | ||
|
||
@abc.abstractmethod | ||
def check_arg_match(self, arg_string): | ||
"""Returns whether the given argument value matches this mode. | ||
Params: | ||
arg_string (str) | ||
Returns: | ||
(bool) | ||
""" | ||
pass | ||
|
||
@abc.abstractmethod | ||
def acquire_targets(self): | ||
"""Run execution logic for this targeting mode.""" | ||
pass |