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



Author: gauteh
Date: Sat Feb 14 21:01:41 2009
New Revision: 1123
URL: http://svn.gnome.org/viewvc/gnome-schedule?rev=1123&view=rev

Log:

	* X support ready for testing
	* xwrapper.py: checks for X connection in both crontab and at
	* xwrapper.py: works for at




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/xwrapper.py

Modified: branches/x-output-support/src/at.py
==============================================================================
--- branches/x-output-support/src/at.py	(original)
+++ branches/x-output-support/src/at.py	Sat Feb 14 21:01:41 2009
@@ -56,11 +56,21 @@
         self.atRecordRegexAdded = re.compile('[^\s]+\s([0-9]+)\sat')
         self.SCRIPT_DELIMITER = "###### ---- GNOME_SCHEDULE_SCRIPT_DELIMITER #####"
         
-        self.DISPLAY = "DISPLAY=%s; export DISPLAY\n"
+        self.DISPLAY = "DISPLAY=%s; export DISPLAY;\n"
+        self.DISPLAY = self.DISPLAY + config.xwrapper_exec + " a\n"
+        self.DISPLAY = self.DISPLAY + """
+xwrapper=$?;
+if [ $xwrapper -eq 0 ]; then
+    echo "all fine";
+else
+    echo "xwrapper failed.";
+    exit;
+fi
+"""
 
         # If normally this variable is unset the user would not expect it 
         # to be set, which it will be because Gnome Schedule needs it.
-        # Therefore we unset it in the script.
+        # Therefore we unset it in the script. 
         self.POSIXLY_CORRECT_UNSET = "unset POSIXLY_CORRECT\n"
         
         self.atdatafileversion = 5
@@ -396,7 +406,7 @@
         display = ""
         if output > 0:
             display = os.getenv ('DISPLAY')
-            tmp.write (self.DISPLAY % display)
+            tmp.write (self.DISPLAY %  display )
             
         tmp.write (command + "\n")
         tmp.close ()
@@ -453,7 +463,7 @@
         display = ""
         if output > 0:
             display = os.getenv ('DISPLAY')
-            tmp.write (self.DISPLAY % display)
+            tmp.write (self.DISPLAY %  display )
 
         tmp.write (command + "\n")
         tmp.close ()

Modified: branches/x-output-support/src/crontab.py
==============================================================================
--- branches/x-output-support/src/crontab.py	(original)
+++ branches/x-output-support/src/crontab.py	Sat Feb 14 21:01:41 2009
@@ -47,7 +47,7 @@
         self.env_vars = [ ]
         
         self.crontabdata = self.user_home_dir + "/.gnome/gnome-schedule/crontab"
-        self.crontabdatafileversion = 4
+        self.crontabdatafileversion = 5
         
         if os.path.exists (self.user_home_dir + "/.gnome") != True:
             os.mkdir (self.user_home_dir + "/.gnome", 0700)
@@ -273,13 +273,9 @@
             record = record + space + self.output[1]
         elif (output == 2) or (output == 3):
             display = os.getenv ('DISPLAY')
+            record = config.xwrapper_exec + " c " + str (job_id)
             if output == 3:
-                space = " " 
-                if record[len (record) - 1] == " ":
-                    space = ""
-                record = record + space + self.output [3]
-
-            record = config.xwrapper_exec + " c " + str (job_id) + " " + record
+                record = record + " " + self.output [3]
 
         if minute == "@reboot":
             record = "@reboot " + record 
@@ -301,6 +297,7 @@
         fh.write ("desc=" + desc + "\n")
         fh.write ("output=" + str (output) + "\n")
         fh.write ("display=" + display + "\n")  
+        fh.write ("command_d=" + command + "\n")
         fh.close () 
         os.chown (f, self.uid, self.gid)
         os.chmod (f, 0600)
@@ -374,12 +371,9 @@
             record = record + space + self.output[1]
         elif (output == 2) or (output == 3):
             display = os.getenv ('DISPLAY')
+            record = config.xwrapper_exec + " c " + str (job_id)
             if output == 3:
-                space = " " 
-                if record[len (record) - 1] == " ":
-                    space = ""
-                record = record + space + self.output [3]
-            record = config.xwrapper_exec + " c " + str (job_id) + " " + record
+                record = record + " " + self.output [3]
 
         if minute == "@reboot":
             record = "@reboot " + record
@@ -399,6 +393,7 @@
         fh.write ("desc=" + desc + "\n")
         fh.write ("output=" + str(output) + "\n")
         fh.write ("display=" + display + "\n")      
+        fh.write ("command_d=" + command + "\n")
         fh.close ()
         os.chown (f, self.uid, self.gid)
         os.chmod (f, 0600)
@@ -606,7 +601,7 @@
         # Retrive title and icon data
         if nofile == False:
             if job_id:
-                success, ver, title, desc, output, display = self.get_job_data (job_id)
+                success, ver, title, desc, output, display, command_d = self.get_job_data (job_id)
             else:
                 success = True
                 ver = 1
@@ -614,6 +609,7 @@
                 desc = ""
                 output = 0
                 display = ""
+                command_d = ""
             
             if (output == 0) or (output == 3):
                 # remove devnull part of command
@@ -621,10 +617,10 @@
                 pos = command.rfind (self.output[1])
                 if pos != -1:
                     command = command[:pos]
-            if output == 2:
-                s = config.xwrapper_exec + " c " + str (job_id) + " "
-                command = command[len (s):]
-            
+            if output >= 2:
+                # rely on command from datafile, command from crontab line only contains xwrapper stuff
+                command = command_d            
+
             # support older datafiles/entries without removing the no output tag    
             if ver <= 1:
                 # old version, no output declaration in datafile, migration
@@ -680,12 +676,18 @@
             if ver >= 4:
                 display = d[8:d.find ("\n")]
                 d = d[d.find ("\n") + 1:]
-                if (len (display) < 1) or (output == 0):
+                if (len (display) < 1) or (output < 2):
                     display = ""
+
+            if ver >= 5:
+                command_d = d[10:d.find ("\n")]
+                d = d[d.find ("\n") + 1:]
+                if (len (command_d) < 1) or (output < 2):
+                    command_d = ""
             
             fh.close ()
 
-            return True, ver, title, desc, output, display
+            return True, ver, title, desc, output, display, command_d
             
             
         else: 

Modified: branches/x-output-support/src/xwrapper.py
==============================================================================
--- branches/x-output-support/src/xwrapper.py	(original)
+++ branches/x-output-support/src/xwrapper.py	Sat Feb 14 21:01:41 2009
@@ -20,6 +20,7 @@
 import os
 import pwd
 
+
 # g-s modules
 import config
 import crontab
@@ -31,43 +32,59 @@
 import gettext
 gettext.install(config.GETTEXT_PACKAGE(), config.GNOMELOCALEDIR(), unicode=1)
 
+def check_X (display):
+    #Checking if I can use X 
+    os.putenv ('DISPLAY', display)
+
+    try:
+        import pygtk
+        pygtk.require("2.0")
+
+    except:
+        pass
+
+    try:
+        import gtk
+
+    except:
+        print _("You need to install pyGTK or GTKv2,\n"
+                "or set your PYTHONPATH correctly.\n"
+                "try: export PYTHONPATH= ")
+        sys.exit(1)
+
+    try:
+        gtk.init_check () 
+
+    except Exception as e: 
+        print _("Could not open a  connection to X!")
+        print e
+        sys.exit (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 3.")
-    
+if (len (sys.argv) < 2):
+    print _("Wrong number of arguments.")
+
     print _("Wrapper script for Gnome-schedule (http://gnome-schedule.sf.net) for applications to be run from crontab under X. Use through gnome-schedule.")
-    sys.exit ()
+    sys.exit (1)
 
 if sys.argv[1] == "c":
     job_type = 0
-else:
-    print _("Unknown type of job: Wrapper only useful on crontab tasks.")
-    sys.exit ()
+    if (len (sys.argv) != 3):
+        print _("Wrong number of arguments.")
 
-try:
-    job_id = int (sys.argv[2])
-except:
-    print _("Invalid job id.")
-    sys.exit ()
-    
-if job_id < 0:
-    print _("Invalid job id.")
-    sys.exit ()
-
-i = 3
-command = ""
-while (i < len (sys.argv)):
-    command = command + sys.argv[i]
-    i = i + 1
+        print _("Wrapper script for Gnome-schedule (http://gnome-schedule.sf.net) for applications to be run from crontab under X. Use through gnome-schedule.")
+        sys.exit (1)
 
-if len (command) < 2:
-    print _("Invalid command, must be longer than 2.")
-    sys.exit ()
+elif sys.argv[1] == "a":
+    job_type = 1
+else:
+    print _("Unknown type of job.")
+    sys.exit (1)
 
 uid = os.geteuid ()
 gid = os.getegid ()
@@ -79,35 +96,60 @@
 else:
     is_root = False
 
-# get data
+# CRONTAB
 if job_type == 0:
+
+    try:
+        job_id = int (sys.argv[2])
+    except:
+        print _("Invalid job id.")
+        sys.exit (1)
+
+    if job_id < 0:
+        print _("Invalid job id.")
+        sys.exit (1)
+
     c = crontab.Crontab (is_root, user, uid, gid, home_dir)
-    success, ver, title, desc, output, display = c.get_job_data (job_id)
+    success, ver, title, desc, output, display, command = c.get_job_data (job_id)
+
     if success == False:
         print _("Could not get job data, the task might have been created with an old version - try recreating the task.")
-        sys.exit ()
-    
-    if ver < 4:
+        sys.exit (1)
+
+    if ver < 5:
         print _("Data file too old. Recreate task.")
-        sys.exit ()
-    
+        sys.exit (1)
+
+
     print _("Launching %s.." % title)
-    if (int (output) == 0):
-        print _("output==0: Why am I launched?")
-        sys.exit ()
+    if (output < 2):
+        print _("output<0: Why am I launched?")
+        sys.exit (1)
     if (len (display) < 2):
         print _("len(display)<2: No proper DISPLAY variable")
-        sys.exit ()
-        
-    #TODO: Check for DISPLAY and user
-    ex = "/bin/sh -c \"DISPLAY=" + display + " " + command + "\""
-    print ex
-    os.system (ex)
+        sys.exit (1)
+
+
+    check_X (display)
+
+    # Execute task
+    sh = os.popen ("/bin/sh -s", 'w')
+    sh.write ("export DISPLAY=" + display + "\n")
+    sh.write (command + "\n")
+    sh.close ()
+
     sys.exit ()
-    
+
+# AT
+elif (job_type == 1):
+    display = os.getenv ('DISPLAY')
+    check_X (display)
+    sys.exit (0) # All fine
+
 else:
     print _("I will never be displayed.")
-    sys.exit ()
-    
+    sys.exit (1)
+
 print _("xwrapper.py: completed")
 
+



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