Example #1
0
	def start(self):
		"""Start method"""
		if self._config.find("policy").text == 'allow':
			policy = True
		elif self._config.find("policy").text == 'deny':
			policy = False
		apps = [e.text for e in self._config.findall("entry[@type='app']")]
		for D, d, F in os.walk(app_dir):
			for f in F:
				if f.endswith(".desktop"):
					Exec = ''
					try:
						Exec = DesktopParser(os.path.join(D, f)).get('Exec')
						if Exec: Exec = Exec.split()[0]
					except Exception as e:
						print("__ app_permissions error:", e)
					for p in os.environ["PATH"].split(':'):
						b = os.path.join(p, Exec)
						if os.path.isfile(b):
							Exec = b
							break

					if f in apps:
						os.chmod(os.path.join(D, f), modes['app'][not policy])
						if os.path.isfile(Exec):
							os.chmod(Exec, modes['bin'][not policy])
					else:
						os.chmod(os.path.join(D, f), modes['app'][policy])
						if os.path.isfile(Exec):
							os.chmod(Exec, modes['bin'][policy])
	def run(self):
		"""Parse app_dir directory, looking for .desktop files

		And parse this desktop files, creating entries on self.allApps dict
		@param	self		A AppPermissions instance
		"""
		self.cancel = False
		all = []
		for D, d, F in os.walk(app_dir):
			for f in F:
				if f.endswith('.desktop'):
					all.append(os.path.join(D, f))
		self.total = len(all)
		self.concluded = 0.0
		for f in all:
			if self.cancel:
				break
			try:
				d = DesktopParser(f)
				Name = d.get('Name')
				Exec = d.get('Exec')
			except:
				continue

			T = QtGui.QListWidgetItem("{0}".format(Name), self.listWid)
			T.setToolTip(Exec)
			self.allApps[f] = {'name': Name, 'exec': Exec, 'all': T}
			self.concluded += 1
			self.parsed.emit(int(round(100.0*self.concluded/self.total)))
Example #3
0
	def stop(self):
		"""Stop method"""
		for D, d, F in os.walk(app_dir):
			for f in F:
				f = os.path.join(D, f)
				if f.endswith(".desktop"):
					Exec = ''
					try:
						Exec = DesktopParser(f).get('Exec')
						if Exec: Exec = Exec.split()[0]
					except:
						pass
					for p in os.environ["PATH"].split(':'):
						b = os.path.join(p, Exec)
						if os.path.isfile(b):
							Exec = b
							break

					os.chmod(f, modes['app'][1])
					if os.path.isfile(Exec): os.chmod(Exec, modes['bin'][1])