Skip to content

Commit

Permalink
Merge branch 'init_targeting_modes'
Browse files Browse the repository at this point in the history
gingeleski committed Mar 17, 2019

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
2 parents 99819d1 + 641155a commit 4648b15
Showing 2 changed files with 83 additions and 0 deletions.
34 changes: 34 additions & 0 deletions targeting/__init__.py
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()

49 changes: 49 additions & 0 deletions targeting/_interfaces.py
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

0 comments on commit 4648b15

Please sign in to comment.