PK!R*}}tdsc/__init__.py__version__ = "0.1.2" 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.2.dist-info/WHEEL A н#Z@Z|Jl~6蓅 Λ MU4[PYBpYD*Mͯ#ڪ/̚?ݭ'%nPK!HhJ;ttdsc-0.1.2.dist-info/METADATAoo0S7#Bj"QV͑lo3uc~a9y݊%L |DEM(XC>*v zDU7BhOtm`FL~/ eAlAtcg+݆(J2A[m2ZgE)_;g*JI] ue" WARSy~~Ɋ'+.^h"}-rϻ2%/׻;9F5)yL/66:ƒ['^l)ȋۃZ>O3lqL}y:9:k6%F{YխU=/= HU'g8+imşirԴj RyiL>QXR(mz '.9$0/;\8zaqX1^(e )ʪ'}Ea<]苽}njXtusUh*.݄xgҢ 7ljۆ7[5>Q1mN(*S Q&@4fz ΀Jb:su\[nk~WyK+OhwkH)\:"Y,;aRKAVзsZԝNNY\A7; 6Ϊ:e,b9{}Yv` C^ѹPK-Qd|=H4NXG4)2}