def test_default_without_helpers(self): view = DefaultView(self.out) view.assign("args", ArgsMock()) view.assign( "applications", ApplicationsCollection([ Application({ "type": "application", "name": "foo", "helper": None }), Application({ "type": "application", "name": "bar", "helper": None }), Application({ "type": "application", "name": "baz", "helper": None }), ])) view.render() self.assertEquals(self.out.getvalue(), ("You should restart:\n" " * These applications manually:\n" " bar\n" " baz\n" " foo\n"))
def test_default_with_helpers(self): view = DefaultView(self.out) view.assign("args", ArgsMock()) view.assign( "applications", ApplicationsCollection([ Application({ "type": "application", "helper": "first helper", "name": None }), Application({ "type": "application", "helper": "second helper", "name": None }), Application({ "type": "application", "helper": "third helper", "name": None }), ])) view.render() self.assertEquals(self.out.getvalue(), ("You should restart:\n" " * Some applications using:\n" " first helper\n" " second helper\n" " third helper\n"))
def test_default_note_only(self): view = DefaultView(self.out) view.assign("args", ArgsMock()) view.assign( "applications", ApplicationsCollection([ Application({ "type": "session", "name": "foo", "helper": "h1" }), Application({ "type": "session", "name": "bar", "helper": "h2" }), Application({ "type": "static", "name": "baz", "helper": "h3" }), ])) view.render() self.assertEquals(self.out.getvalue(), ( "You should restart:\n" "There are:\n" " - 2 processes requiring restart of your session (i.e. Logging out & Logging in again)\n" " - 1 processes requiring reboot\n"))
def test_default_all_static(self): view = DefaultView(self.out) view.assign("args", ArgsMock(all=True)) view.assign( "applications", ApplicationsCollection([ Application({ "type": "static", "name": "foo", "helper": "h1" }), Application({ "type": "static", "name": "bar", "helper": "h2" }), Application({ "type": "static", "name": "baz", "helper": "h3" }), ])) view.render() self.assertEquals(self.out.getvalue(), ("You should restart:\n" " * These applications rebooting your computer:\n" " bar\n" " baz\n" " foo\n"))
def _load_definitions(): Applications._apps = ApplicationsCollection() for file in Applications.DEFINITIONS: try: Applications._load(file) except PathNotFound as ex: if not os.path.dirname(file) in USER_CONFIG_DIRS: raise ex
def trace_affected(self, user=None): """ Returns collection of applications which uses some files that have been modified @TODO This function should be hardly optimized """ memory = self._memory(user) packages = self._modified_packages() affected = {} found = [] for package in packages.unique_newest(): for file in self._PACKAGE_MANAGER.package_files(package.name): file = FilenameCleaner.strip(file) if not file in memory: continue for p in memory[file]: if p.pid in found: continue try: if p.create_time() <= package.modified: found.append(p.pid) p = self._apply_rules(p) a = self._applications.find(p.name()) if not a.ignore: if a.name not in affected: if self._erased and not self._PACKAGE_MANAGER.provided_by( a.name): a.type = Applications.TYPES["ERASED"] affected[a.name] = AffectedApplication( a._attributes) affected[ a. name].affected_instances = AffectedProcessesCollection( ) self._call_hook(affected[a.name]) affected[a.name].affected_instances.append(p) except NoSuchProcess: pass if self._has_updated_kernel( ) and not self._applications.find('kernel').ignore: # Add fake AffectedApplication affected['kernel'] = AffectedApplication({ "name": "kernel", "type": Applications.TYPES["STATIC"], "helper": _("You will have to reboot your computer") }) return ApplicationsCollection(affected.values())
def test_default_not_all(self): view = DefaultView(self.out) view.assign("args", ArgsMock()) view.assign( "applications", ApplicationsCollection([ Application({ "type": "application", "helper": "first helper", "name": None }), Application({ "type": "application", "helper": "second helper", "name": None }), Application({ "type": "application", "name": "foo", "helper": None }), Application({ "type": "application", "name": "bar", "helper": None }), Application({ "type": "session", "name": "baz", "helper": "h1" }), Application({ "type": "session", "name": "qux", "helper": "h2" }), Application({ "type": "static", "name": "aaa", "helper": "h3" }), ])) view.render() self.assertEquals(self.out.getvalue(), ( "You should restart:\n" " * Some applications using:\n" " first helper\n" " second helper\n" "\n" " * These applications manually:\n" " bar\n" " foo\n" "\n" "Additionally to those process above, there are:\n" " - 2 processes requiring restart of your session (i.e. Logging out & Logging in again)\n" " - 1 processes requiring reboot\n"))
def test_applications_sorted(self): default_type = Applications.DEFAULT_TYPE a1 = Application({'name': 'foo', 'helper': 'bar', 'type': default_type}) a2 = Application({'name': 'baz', 'helper': 'qux', 'type': default_type}) a3 = Application({'name': 'quux', 'helper': 'corge', 'type': default_type}) collection = ApplicationsCollection([a1, a2, a3]) self.assertEqual(collection.sorted('name'), ApplicationsCollection([a2, a1, a3])) self.assertEqual(collection.sorted('helper'), ApplicationsCollection([a1, a3, a2])) self.assertIsInstance(collection, ApplicationsCollection)
def trace_affected(self, user=None): """ Returns collection of applications which uses some files that have been modified @TODO This function should be hardly optimized """ memory = self._memory(user) packages = self._modified_packages() affected = {} found = [] for package in packages.unique_newest(): for file in self._PACKAGE_MANAGER.package_files(package.name): file = FilenameCleaner.strip(file) if not file in memory: continue for p in memory[file]: if p.pid in found: continue try: if p.create_time() <= package.modified: found.append(p.pid) p = self._apply_rules(p) a = self._applications.find(p.name()) if a.name not in affected: if self._erased and not self._PACKAGE_MANAGER.provided_by( a.name): a.type = Applications.TYPES["ERASED"] affected[a.name] = a affected[ a. name].affected_instances = AffectedProcessesCollection( ) self._call_hook(a) affected[a.name].affected_instances.append(p) except NoSuchProcess: pass return ApplicationsCollection(affected.values())
def test_default_none(self): view = DefaultView(self.out) view.assign("args", ArgsMock()) view.assign("applications", ApplicationsCollection([])) view.render() self.assertEquals(self.out.getvalue(), "")
def test_default_all(self): view = DefaultView(self.out) view.assign("args", ArgsMock(all=True)) view.assign( "applications", ApplicationsCollection([ Application({ "type": "application", "helper": "first helper", "name": None }), Application({ "type": "application", "helper": "second helper", "name": None }), Application({ "type": "application", "name": "foo", "helper": None }), Application({ "type": "application", "name": "bar", "helper": None }), Application({ "type": "session", "name": "baz", "helper": "h1" }), Application({ "type": "session", "name": "qux", "helper": "h2" }), Application({ "type": "static", "name": "aaa", "helper": "h3" }), Application({ "type": "static", "name": "bbb", "helper": "h4" }), ])) view.render() self.assertEquals(self.out.getvalue(), ("You should restart:\n" " * Some applications using:\n" " first helper\n" " second helper\n" "\n" " * These applications manually:\n" " bar\n" " foo\n" "\n" " * These applications restarting your session:\n" " baz\n" " qux\n" "\n" " * These applications rebooting your computer:\n" " aaa\n" " bbb\n"))