예제 #1
0
	def do_run_script(self, answer):
		answer = answer and answer[1]
		if answer in ("YES", "PAR", "YES_BG", "PAR_BG"):
			if not os.access(self.commando, os.R_OK):
				self.session.open(MessageBox, _("Script '%s' must have read permission to be able to run it") % self.commando, type=MessageBox.TYPE_ERROR, close_on_any_key=True)
				return
			nice = config.plugins.filecommander.script_priority_nice.value or ''
			ionice = config.plugins.filecommander.script_priority_ionice.value or ''
			if nice:
				nice = 'nice -n %d ' %nice
			if ionice:
				ionice = 'ionice -c %d ' %ionice
			priority = '%s%s' %(nice,ionice)
			if self.commando.endswith('.sh'):
				if os.access(self.commando, os.X_OK):
					if 'PAR' in answer:
						cmdline = "%s%s '%s'" %(priority, self.commando, self.parameter)
					else:
						cmdline = "%s%s" %(priority, self.commando)
				else:
					if 'PAR' in answer:
						cmdline = "%s/bin/sh %s '%s'" %(priority, self.commando, self.parameter)
					else:
						cmdline = "%s/bin/sh %s" %(priority, self.commando)
			else:
				if 'PAR' in answer:
					cmdline = "%s/usr/bin/python %s '%s'" %(priority, self.commando, self.parameter)
				else:
					cmdline = "%s/usr/bin/python %s" %(priority, self.commando)
		elif answer == "VIEW":
			try:
				yfile = os.stat(self.commando)
			except OSError as oe:
				self.session.open(MessageBox, _("%s: %s") % (self.commando, oe.strerror), type=MessageBox.TYPE_ERROR)
				return
			if (yfile.st_size < 1000000):
				self.session.open(vEditor, self.commando)

		if answer and answer != "VIEW":
			if answer.endswith('_BG'):
				global task_Stout, task_Sterr
				task_Stout = []
				task_Sterr = []
				if 'PAR' in answer:
					name = '%s%s %s' %(priority, self.commando, self.parameter)
				else:
					name = '%s%s' %(priority, self.commando)
				job = Job(_("Run script") + " ('%s')" %name)
				task = Task(job, name)
				task.postconditions.append(task_postconditions())
				task.processStdout = task_processStdout
				task.processStderr = task_processSterr
				task.setCmdline(cmdline)
				job_manager.AddJob(job, onSuccess=self.finishedCB, onFail=self.failCB)
				self.jobs += 1
				self.onLayout()
			else:
				self.session.open(Console, cmdlist=(cmdline,))