def test_event_several_callbacks_tuple(): clb1 = Mock() clb2 = Mock() event((clb1, clb2)) assert clb1.mock_calls == [call()] assert clb2.mock_calls == [call()]
def test_event_several_callbacks_list(): clb1 = Mock() clb2 = Mock() event([clb1, clb2]) assert clb1.mock_calls == [call()] assert clb2.mock_calls == [call()]
def restart(self): if self.is_service_running(): self._exec_action('restart') event(self.on_restart) else: info('Service %s is requested to be restarted, but it is not running. Restarting.' % self.name) self._exec_action('start') event(self.on_start)
def install(): info("Installing packages %s" % packs_to_install) event(self.before_install) provider.install_packages(packs_to_install) not_installed_packs = provider.get_not_installed(packs_to_install) if len(not_installed_packs) > 0: error('The following packages was not installed on some reason: %s' % not_installed_packs) else: event(self.after_install) info('All packages installed: %s' % packs_to_install)
def _apply(): debug('Write ini settings to %s' % filename) debug(config) cfg = ConfigParser() cfg.read(filename) for section, values in config.items(): if not cfg.has_section(section): if strict_sections: raise Exception('No section %s in ini file %s' % (section, filename)) else: cfg.add_section(section) for key, val in values.items(): cfg.set(section, key, val) with open(filename, 'w') as configfile: cfg.write(configfile) event(on_apply)
def test_event_single_callback(): clb = Mock() event(clb) assert clb.mock_calls == [call()]
def test_event_single_callback_non_callable(): event("hello")
def stop(self): if not self.is_service_running(): self._exec_action('stop') event(self.on_stop)
def remove_file(): os.remove(self.path) event(self.on_remove)
def remove_dir(): try: os.rmdir(self.path) except OSError as e: info(e) event(self.on_remove)
def create_file(): with open(self.path, 'w') as f: f.write(content_compiled) event(self.on_create)
def create_dir(): os.makedirs(self.path) event(self.on_create)
def update_content(): # s.file_write(self.path, content_compiled, self.mode, self.owner, self.group) with open(self.path, 'w') as f: f.write(content_compiled) event(self.on_update)