def check_modules(profile): if 'hooks' in profile: for hook in profile['hooks']: obj = get_obj('hooks', hook) if obj is None: raise DputConfigurationError( "Error: no such hook '%s'" % ( hook ) )
def __init__(self, profile): self._config = profile interface = 'cli' if 'interface' in profile: interface = profile['interface'] logger.trace("Using interface %s" % (interface)) interface_obj = get_obj('interfaces', interface) if interface_obj is None: raise DputConfigurationError("No such interface: `%s'" % ( interface )) self.interface = interface_obj() self.interface.initialize()
def uploader(uploader_method, profile, simulate=True): """ Context-managed uploader implementation. Invoke sorta like:: with uploader() as obj: obj.upload_file('filename') This will automatically call that object's :meth:`dput.uploader.AbstractUploader.initialize`, pre-hook, yield the object, call the post hook and invoke it's :meth:`dput.uploader.AbstractUploader.shutdown`. """ cls = get_obj('uploaders', uploader_method) if not cls: logger.error( "Failed to resolve method %s to an uploader class" % ( uploader_method ) ) raise DputConfigurationError( "Failed to resolve method %s to an uploader class" % ( uploader_method ) ) obj = cls(profile) if not simulate or simulate >= 2: obj.initialize() obj._pre_hook() try: yield obj finally: if not simulate: obj._post_hook() if not simulate or simulate >= 2: obj.shutdown()