PK! }}tdsc/__init__.py__version__ = "0.1.0" from . import state, utils, strategy, context from .state import State from .strategy import Strategy PK!OgQKKtdsc/context.pyfrom __future__ import unicode_literals, absolute_import, print_function import platform import appdirs class ContextInfo: @property def platform(self): return platform.system() class ContextStore: pass class Context: __store = ContextStore() info = ContextInfo() @property def store(self): return self.__store @staticmethod def paths_for_state(state_name, app_author="tdsc", version=None, roaming=False): return appdirs.AppDirs( state_name, appauthor=app_author, version=version, roaming=roaming ) PK!A´ tdsc/state.pyfrom __future__ import unicode_literals, absolute_import, print_function from abc import ABC, abstractmethod import logging """ Define conventional "state" behaviour. The simplest state is an object that encapsulates a pre-execution guard, ``should_execute``, an action to be performed, ``execute``, and a post-execute callback and transform, ``post_execute``. By default, ``should_execute`` is ``True``, and ``post_execute`` returns the result or raised error from ``execute``, or ``None`` if ``should_execute`` guarded against execution. """ class State(ABC): def _get_logger(self): return logging.getLogger("tdsc.state.{}".format(self.__class__.__name__)) def should_execute(self, ctx): return True @abstractmethod def execute(self, ctx): raise NotImplemented def post_execute(self, ctx, ran_successfully, result): if not ran_successfully: self._get_logger().exception( "State {} did not run successfully.".format(self.__class__.__name__), exc_info=result, ) return result def run(self, ctx): result = None ran_successfully = False try: if self.should_execute(ctx): result = self.execute(ctx) ran_successfully = True except Exception as err: result = err finally: return self.post_execute(ctx, ran_successfully, result) PK!;ptdsc/strategy.pyfrom __future__ import unicode_literals, absolute_import, print_function from .context import Context class Strategy: def __init__(self, strategies=None, states=None): self.strategies = strategies or [] self.states = states or [] def run(self, context=None): context = context or Context() for state in self.states: state.run(context) for strategy in self.strategies: strategy.run(context) PK!jhx((tdsc/utils/__init__.pyfrom .git import git_available, run_git PK!xO))tdsc/utils/git.pyimport subprocess import functools @functools.lru_cache(maxsize=1) def git_available(): """ Indicates whether ``git`` is available on the system. Result is cached by functools.lru_cache """ return ( subprocess.call( ["git", "--version"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL ) == 0 ) def run_git(*args, **kwargs): """Shallow wrapper to run ``git`` with given arguments, return exit code.""" args = ["git"] + list(args) return subprocess.call(args, **kwargs) PK!HMWXtdsc-0.1.0.dist-info/WHEEL A н#Z@Z|Jl~6蓅 Λ MU4[PYBpYD*Mͯ#ڪ/̚?ݭ'%nPK!Hc ktdsc-0.1.0.dist-info/METADATAAK09*.]<4MMRtӭ(\ !w:@'<^\HVъ[τ{wPXZj\kYWcxN-{i69]CamD}?EC7\u jwu` -/oGڀ+ҏXF'΢щσoatlR,"o,G<~̾IA5Ck ERϢPK!H(wtdsc-0.1.0.dist-info/RECORDmI0}m@/P` 7@hdPVoX:$qLkxڎPD,[N՚}-uVq_˸>ZR'8ISӝ0vyAwr|ȍjvF2\6.D$1; 5R y pk37P>7 [>ˢ* Ofkr:w}8/ʣEN-u$ vYREW] `yMl EMRfp[61u!Vyq+3 hYoK >_hO)?M&Κ~\G"lD[T3d.\5 ,?zBުU&H$4\4Օs. 4y{ 8?PK! }}tdsc/__init__.pyPK!OgQKKtdsc/context.pyPK!A´ #tdsc/state.pyPK!;p tdsc/strategy.pyPK!jhx(( tdsc/utils/__init__.pyPK!xO))` tdsc/utils/git.pyPK!HMWX tdsc-0.1.0.dist-info/WHEELPK!Hc kGtdsc-0.1.0.dist-info/METADATAPK!H(w{tdsc-0.1.0.dist-info/RECORDPK SY