gnome-schedule r1103 - in branches/x-output-support: . src



Author: gauteh
Date: Tue Oct 21 20:55:49 2008
New Revision: 1103
URL: http://svn.gnome.org/viewvc/gnome-schedule?rev=1103&view=rev

Log:


Added:
   branches/x-output-support/   (props changed)
      - copied from r1102, /trunk/
   branches/x-output-support/src/xwrapper.py
Modified:
   branches/x-output-support/ChangeLog
   branches/x-output-support/src/at.py
   branches/x-output-support/src/crontab.py
   branches/x-output-support/src/mainWindow.py

Modified: branches/x-output-support/src/at.py
==============================================================================
--- /trunk/src/at.py	(original)
+++ branches/x-output-support/src/at.py	Tue Oct 21 20:55:49 2008
@@ -62,7 +62,7 @@
 		# Therefore we unset it in the script.
 		self.POSIXLY_CORRECT_UNSET = "unset POSIXLY_CORRECT\n"
 		
-		self.atdatafileversion = 3
+		self.atdatafileversion = 4
 		self.atdata = self.user_home_dir + "/.gnome/gnome-schedule/at"
 		if os.path.exists (self.user_home_dir + "/.gnome") != True:
 			os.mkdir (self.user_home_dir + "/.gnome", 0700)
@@ -139,7 +139,7 @@
 					class_id = m.groups ()[6]
 					user = m.groups ()[7]
 						
-					title, desc, manual_poscorrect = self.get_job_data (int (job_id))
+					success, title, desc, manual_poscorrect, xoutput, display = self.get_job_data (int (job_id))
 					# manual_poscorrect is only used during preparation of script
 
 					execute = config.getAtbin() + " -c " + job_id
@@ -162,7 +162,7 @@
 						else:
 							done = 1
 
-					return job_id, date, time, class_id, user, script, title, prelen, dangerous
+					return job_id, date, time, class_id, user, script, title, prelen, dangerous, xoutput, display
 					
 		elif (output == False):
 			if len (line) > 1 and line[0] != '#':
@@ -212,14 +212,28 @@
 					manual_poscorrect_b = True
 				elif manual_poscorrect == "false":
 					manual_poscorrect_b = False
+
+			if ver >= 4:
+				xoutput_str = d[8:d.find ("\n")]
+				if (xoutput_str == "0") or (xoutput_str == "1"):
+					xoutput = int (xoutput_str)
+					d = d[d.find ("\n") + 1:]
+				else:
+					xoutput = 0
+				
+				display = d[8:d.find ("\n")]
+				d = d[d.find ("\n") + 1:]
+				if (len (display) < 1) or (xoutput == 0):
+					display = ""
+			
 			fh.close ()
 			
-			return title, desc, manual_poscorrect_b
+			return True, title, desc, manual_poscorrect_b, xoutput, display
 			
 		else: 
-			return "", "", False
+			return False, "", "", False, 0, ""
 			
-	def write_job_data (self, job_id, title, desc):
+	def write_job_data (self, job_id, title, desc, xoutput, display):
 		# Create and write data file
 		f = os.path.join (self.atdata, str(job_id))
 		#print f
@@ -235,6 +249,8 @@
 			fh.write ("manual_poscorrect=true\n")
 		else:
 			fh.write ("manual_poscorrect=false\n")
+		fh.write ("xoutput=" + str(xoutput) + "\n")
+		fh.write ("display=" + display + "\n")
 		fh.close ()
 		os.chown (f, self.uid, self.gid)
 		os.chmod (f, 0600)
@@ -364,7 +380,7 @@
 		return True, "ok"
 
 		
-	def append (self, runat, command, title):
+	def append (self, runat, command, title, xoutput, display):
 		tmpfile = tempfile.mkstemp ()
 		fd, path = tmpfile
 		tmp = os.fdopen(fd, 'w')
@@ -400,12 +416,12 @@
 		#print job_id
 		
 		desc = ""
-		self.write_job_data (job_id, title, desc)
+		self.write_job_data (job_id, title, desc, xoutput, display)
 		
 		os.unlink (path)
 
 
-	def update (self, job_id, runat, command, title):
+	def update (self, job_id, runat, command, title, xoutput, display):
 		#print "update" + str (job_id) + runat + command + title
 		#remove old
 		f = os.path.join (self.atdata, str (job_id))
@@ -448,7 +464,7 @@
 		#print job_id
 		
 		desc = ""
-		self.write_job_data (job_id, title, desc)
+		self.write_job_data (job_id, title, desc, xoutput, display)
 		
 		os.unlink (path)
 		
@@ -473,7 +489,7 @@
 			array_or_false = self.parse (line)
 			#print array_or_false
 			if array_or_false != False:
-				(job_id, date, time, class_id, user, lines, title, prelen, dangerous) = array_or_false
+				(job_id, date, time, class_id, user, lines, title, prelen, dangerous, xoutput, display) = array_or_false
 
 			
 				preview = self.__make_preview__ (lines, prelen)
@@ -490,12 +506,12 @@
 				# TODO: looks like it could be one append
 				if self.root == 1:
 					if self.user == user:
-						data.append([title, timestring_show, preview, lines, int(job_id), timestring, self, None, date, class_id, user, time, _("Once"), "at", self.nooutput, timestring])
+						data.append([title, timestring_show, preview, lines, int(job_id), timestring, self, None, date, class_id, user, time, _("Once"), "at", self.nooutput, timestring, xoutput, display])
 					else: 
 						#print "Record omitted, not current user"
 						pass
 				else:
-					data.append([title, timestring_show, preview, lines, int(job_id), timestring, self, None, date, class_id, user, time, _("Once"), "at", self.nooutput, timestring])
+					data.append([title, timestring_show, preview, lines, int(job_id), timestring, self, None, date, class_id, user, time, _("Once"), "at", self.nooutput, timestring, xoutput, display])
 
 				#print _("added %(id)s") % { "id": job_id	}
 			else:

Modified: branches/x-output-support/src/crontab.py
==============================================================================
--- /trunk/src/crontab.py	(original)
+++ branches/x-output-support/src/crontab.py	Tue Oct 21 20:55:49 2008
@@ -42,7 +42,7 @@
 		self.env_vars = [ ]
 		
 		self.crontabdata = self.user_home_dir + "/.gnome/gnome-schedule/crontab"
-		self.crontabdatafileversion = 3
+		self.crontabdatafileversion = 4
 		
 		if os.path.exists (self.user_home_dir + "/.gnome") != True:
 			os.mkdir (self.user_home_dir + "/.gnome", 0700)
@@ -224,7 +224,7 @@
 					raise ValueError("fixed", self.timenames[type], _("Must be between %(min)s and %(max)s") % { "min": min(timerange), "max": max(timerange) } )
 	
 
-	def update (self, minute, hour, day, month, weekday, command, linenumber, parentiter, nooutput, job_id, comment, title, desc):
+	def update (self, minute, hour, day, month, weekday, command, linenumber, parentiter, nooutput, job_id, comment, title, desc, xoutput = 0, display = ""):
 		if self.check_command (command) == False:
 			return False
 			
@@ -288,6 +288,8 @@
 			fh.write ("nooutput=1\n")
 		else:
 			fh.write ("nooutput=0\n")
+		fh.write ("xoutput=" + str(xoutput) + "\n")
+		fh.write ("display=" + display + "\n")	
 		fh.close ()	
 		os.chown (f, self.uid, self.gid)
 		os.chmod (f, 0600)
@@ -316,7 +318,7 @@
 		self.__write__ ()
 		
 		
-	def append (self, minute, hour, day, month, weekday, command, nooutput, title, desc = None):
+	def append (self, minute, hour, day, month, weekday, command, nooutput, title, desc = None, xoutput = 0, display = ""):
 		if self.check_command (command) == False:
 			return False
 			
@@ -375,7 +377,8 @@
 			fh.write ("nooutput=1\n")
 		else:
 			fh.write ("nooutput=0\n")
-		
+		fh.write ("xoutput=" + str(xoutput) + "\n")
+		fh.write ("display=" + display + "\n")		
 		fh.close ()
 		os.chown (f, self.uid, self.gid)
 		os.chmod (f, 0600)
@@ -425,7 +428,7 @@
 			array_or_false = self.parse (line)
 			if array_or_false != False:
 				if array_or_false[0] == 2:
-					(minute, hour, day, month, weekday, command, comment, job_id, title, desc, nooutput) = array_or_false[1]
+					(minute, hour, day, month, weekday, command, comment, job_id, title, desc, nooutput, xoutput, display) = array_or_false[1]
 					
 					time = minute + " " + hour + " " + day + " " + month + " " + weekday
 
@@ -434,9 +437,9 @@
 				
 					#add task to treemodel in mainWindow
 					if minute == "@reboot":
-						data.append([title, self.__easy__ (minute, hour, day, month, weekday), preview, line, linecount, time, self, None, job_id, "", "","", _("Recurrent"), "crontab", nooutput, _("At reboot")])
+						data.append([title, self.__easy__ (minute, hour, day, month, weekday), preview, line, linecount, time, self, None, job_id, "", "","", _("Recurrent"), "crontab", nooutput, _("At reboot"), xoutput, display])
 					else:
-						data.append([title, self.__easy__ (minute, hour, day, month, weekday), preview, line, linecount, time, self, None, job_id, "", "","", _("Recurrent"), "crontab", nooutput, time])
+						data.append([title, self.__easy__ (minute, hour, day, month, weekday), preview, line, linecount, time, self, None, job_id, "", "","", _("Recurrent"), "crontab", nooutput, time, xoutput, display])
 				
 				
 			linecount = linecount + 1	
@@ -587,12 +590,15 @@
 		# Retrive title and icon data
 		if nofile == False:
 			if job_id:
-				ver, title, desc, nooutput = self.get_job_data (job_id)
+				success, ver, title, desc, nooutput, xoutput, display = self.get_job_data (job_id)
 			else:
+				success = True
 				ver = 1
 				title = ""
 				desc = ""
 				nooutput = 0
+				xoutput = False
+				display = ""
 			
 			if nooutput != 0:
 				# remove devnull part of command
@@ -614,7 +620,7 @@
 			command = command.strip ()	
 				
 				
-			return [2, [minute, hour, dom, moy, dow, command, comment, job_id, title, desc, nooutput]]
+			return [2, [minute, hour, dom, moy, dow, command, comment, job_id, title, desc, nooutput, xoutput, display]]
 		else:
 			return minute, hour, dom, moy, dow, command
 		
@@ -647,18 +653,32 @@
 				nooutput_str = d[9:d.find ("\n")]
 				if (nooutput_str == "0") or (nooutput_str == "1"):
 					nooutput = int (nooutput_str)
+					d = d[d.find ("\n") + 1:]
 				else:
 					nooutput = 0
 			else:
 				nooutput = 0
+				
+			if ver >= 4:
+				xoutput_str = d[8:d.find ("\n")]
+				if (xoutput_str == "0") or (xoutput_str == "1"):
+					xoutput = int (xoutput_str)
+					d = d[d.find ("\n") + 1:]
+				else:
+					xoutput = 0
+				
+				display = d[8:d.find ("\n")]
+				d = d[d.find ("\n") + 1:]
+				if (len (display) < 1) or (xoutput == 0):
+					display = ""
 			
 			fh.close ()
 
-			return ver, title, desc, nooutput
+			return True, ver, title, desc, nooutput, xoutput, display
 			
 			
 		else: 
-			return "", "", "", 0
+			return False, "", "", "", 0, 0, ""
 			
 			
 		

Modified: branches/x-output-support/src/mainWindow.py
==============================================================================
--- /trunk/src/mainWindow.py	(original)
+++ branches/x-output-support/src/mainWindow.py	Tue Oct 21 20:55:49 2008
@@ -22,7 +22,7 @@
 import gtk.glade
 import gobject
 
-# TODO: gnome specific
+# gnome specific
 import gnome
 from gnome import url_show
 
@@ -206,15 +206,15 @@
 				
 		##inittializing the treeview and treemodel
 		## somethins not rite here..:
-		## [0 Title, 1 Frequency, 2 Command, 3 Crontab record, 4 ID, 5 Time, 6 Icon, 7 scheduled instance, 8 icon path, 9 date, 10 class_id, 11 user, 12 time, 13 type, 14 crontab/at, 15 advanced time string]
+		## [0 Title, 1 Frequency, 2 Command, 3 Crontab record, 4 ID, 5 Time, 6 Icon, 7 scheduled instance, 8 icon path, 9 date, 10 class_id, 11 user, 12 time, 13 type, 14 crontab/at, 15 advanced time string, 16 xoutput, 17 display]
 		##for at this would be like: 
 		
-# ["untitled", "12:50 2004-06-25", "preview", "script", "job_id", "12:50", icon, at instance, icon_path, "2004-06-25", "a", "drzap", "at"]
+# ["untitled", "12:50 2004-06-25", "preview", "script", "job_id", "12:50", icon, at instance, icon_path, "2004-06-25", "a", "drzap", "at", xoutput, display]
 
 		##for crontab it would be: 
 		
-# ["untitled", "every hour", "ls /", "0 * * * * ls / # untitled", "5", "0 * * * *", icon, crontab instance,icon_path, 1(job_id), "", "", "crontab"]
-		self.treemodel = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_INT, gobject.TYPE_STRING, gtk.gdk.Pixbuf, gobject.TYPE_PYOBJECT, gobject.TYPE_STRING , gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_INT, gobject.TYPE_STRING)
+# ["untitled", "every hour", "ls /", "0 * * * * ls / # untitled", "5", "0 * * * *", icon, crontab instance,icon_path, 1(job_id), "", "", "crontab", xoutput, display]
+		self.treemodel = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_INT, gobject.TYPE_STRING, gtk.gdk.Pixbuf, gobject.TYPE_PYOBJECT, gobject.TYPE_STRING , gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_INT, gobject.TYPE_STRING, gobject.TYPE_INT)
 		
 		self.treeview = self.xml.get_widget("treeview")
 		
@@ -316,12 +316,12 @@
 
 
 	def __fill__ (self, records):
-		for title, timestring_show, preview, lines, job_id, timestring, scheduler, icon, date, class_id, user, time, typetext, type, nooutput, timestring_advanced in records:
+		for title, timestring_show, preview, lines, job_id, timestring, scheduler, icon, date, class_id, user, time, typetext, type, nooutput, timestring_advanced, xoutput, display in records:
 					
 			if scheduler.get_type() == "crontab":
-				iter = self.treemodel.append([title, timestring_show, preview, lines, job_id, timestring, self.iconcrontab, scheduler, icon, date, class_id, user, time, typetext, type, nooutput, timestring_advanced])
+				iter = self.treemodel.append([title, timestring_show, preview, lines, job_id, timestring, self.iconcrontab, scheduler, icon, date, class_id, user, time, typetext, type, nooutput, timestring_advanced, xoutput, display])
 			elif scheduler.get_type() == "at":
-				iter = self.treemodel.append([title, timestring_show, preview, lines, job_id, timestring, self.iconat, scheduler, icon, date, class_id, user, time, typetext, type, nooutput, timestring_advanced])
+				iter = self.treemodel.append([title, timestring_show, preview, lines, job_id, timestring, self.iconat, scheduler, icon, date, class_id, user, time, typetext, type, nooutput, timestring_advanced, xoutput, display])
 
 			
 		

Added: branches/x-output-support/src/xwrapper.py
==============================================================================
--- (empty file)
+++ branches/x-output-support/src/xwrapper.py	Tue Oct 21 20:55:49 2008
@@ -0,0 +1,105 @@
+# xwrapper.py - wrapper around X applications
+# Copyright (C) 2004 - 2008  Gaute Hope <eg at gaute dot vetsj dot com>
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU Library General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02110-1301, USA.
+
+#python
+import sys
+import os
+import pwd
+
+# g-s modules
+import config
+import crontab
+
+
+##
+## I18N
+##
+import gettext
+gettext.install(config.GETTEXT_PACKAGE(), config.GNOMELOCALEDIR(), unicode=1)
+
+poscorrect_isset = os.getenv ("POSIXLY_CORRECT", False)
+manual_poscorrect = False
+if poscorrect_isset == False:
+	os.putenv ("POSIXLY_CORRECT", "enabled")
+	manual_poscorrect = True
+	
+if (len (sys.argv) < 4):
+	print _("Minium number of arguments is 4.")
+	exit ()
+
+if sys.argv[1] == "c":
+	job_type = 0
+else:
+	print _("Unknown type of job: Wrapper only useful on crontab tasks.")
+	exit ()
+
+try:
+	job_id = int (sys.argv[2])
+except:
+	print _("Invalid job id.")
+	exit ()
+	
+if job_id < 0:
+	print _("Invalid job id.")
+	exit ()
+
+i = 4
+command = ""
+while (i < len (sys.argv)):
+	command = command + sys.argv[i]
+	i = i + 1
+
+if len (command) < 2:
+	print _("Invalid command, must be longer than 2.")
+	exit ()
+
+uid = os.geteuid ()
+gid = os.getegid ()
+user = pwd.getpwuid (uid)[0]
+home_dir = pwd.getpwuid (uid)[5]
+user_shell = pwd.getpwuid (uid)[6]
+if uid == 0:
+	is_root = True
+else:
+	is_root = False
+
+# get data
+if job_type == 0:
+	c = crontab.Crontab (is_root, user, uid, gid, home_dir)
+	success, ver, title, desc, nooutput, xoutput, display = c.get_job_data (job_id)
+	if success == False:
+		print _("Could not get job data, might be an old version - try recreating the task")
+		exit ()
+	
+	print _("Launching %s.." % title)
+	if (xoutput == 0):
+		print _("xoutput==0: Why am I launched?")
+		exit ()
+	if (len (display) < 2):
+		print :("len(display)<2: No proper DISPLAY variable")
+		exit ()
+		
+	#### TODO: LAUNCH ####
+else:
+	print _("I will never be displayed.")
+	exit ()
+	
+print _("xwrapper.py: completed")
+		
+	
+
+



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]