[gnome-schedule] Merge 'freebsd': Support for FreeBSD at



commit 1f0efc2385fc7b060241d5373efc4fcabf3479c3
Author: Gaute Hope <eg gaute vetsj com>
Date:   Tue Oct 11 23:02:41 2011 +0200

    Merge 'freebsd': Support for FreeBSD at

 src/at.py |   46 ++++++++++++++++++++++++++++++++--------------
 1 files changed, 32 insertions(+), 14 deletions(-)
---
diff --git a/src/at.py b/src/at.py
index 6ef4c0b..547dc64 100644
--- a/src/at.py
+++ b/src/at.py
@@ -53,12 +53,21 @@ class At:
         #Fri Sep 30 23:40:00 MSK 2011    rm              c    2
 
 
-        self.atRecordRegex = re.compile('^([\d]+)[\t]([\w]{3,3})[\s]([\w]{3,3})[\s]*([\d]+)[\s]([\d]{2,2}[:][\d]{2,2}[:][\d]{2,2})[\s]([\d]{4,4})[\s]([\w])[\s]([\w]+)')
+        self.sysname = os.uname ()[0]
 
+        # FreeBSD atq output, parser ignores time zone information
+        if self.sysname == 'FreeBSD':
+          self.atRecordRegex = re.compile ('^(?P<dow>[\w]{3})[\s](?P<month>[\w]{3})[\s](?P<day>[0-9]+)[\s](?P<time>[0-2][0-9]:[0-5][0-9]:[0-5][0-9])[\s](?:(?P<tzone>.*)[\s]|)(?P<year>[0-9]{4})[\t]+(?P<user>.+)[\s]+(?P<class>[a-z]|[A-Z])[\t](?P<jobid>[0-9]*)$')
+          # after you add a job, this line is printed to stderr
+          # Job 5 will be executed using /bin/sh
+          self.atRecordRegexAdd = re.compile('^Job[\s](?P<jobid>[0-9]+)[\s]will')
 
-        # after you add a job, this line is printed to stderr
-        # job 10 at 2006-09-18 12:38
-        self.atRecordRegexAdd = re.compile('^job\s([0-9]+)\sat')
+        # General Linux atq output
+        else:
+          self.atRecordRegex = re.compile('^(?P<jobid>[\d]+)[\t](?P<dow>[\w]{3,3})[\s](?P<month>[\w]{3,3})[\s]*(?P<day>[\d]+)[\s](?P<time>[\d]{2,2}[:][\d]{2,2}[:][\d]{2,2})[\s](?P<year>[\d]{4,4})[\s](?P<class>[\w])[\s](?P<user>[\w]+)')
+          # after you add a job, this line is printed to stderr
+          # job 10 at 2006-09-18 12:38
+          self.atRecordRegexAdd = re.compile('^job\s(?P<jobid>[0-9]+)\sat')
 
         self.SCRIPT_DELIMITER = "###### ---- GNOME_SCHEDULE_SCRIPT_DELIMITER #####"
 
@@ -137,11 +146,15 @@ fi
                 m = self.atRecordRegex.match(line)
                 if m != None:
                     # Time
-                    time = m.groups ()[4][:-3]
+                    time = m.group('time')
+
+                    # FreeBSD:
+                    # We are ignoring timezone and hope everything works
+                    # out in the end.
 
                     # Date
-                    day = m.groups ()[3]
-                    month = m.groups ()[2]
+                    day = m.group('day')
+                    month = m.group ('month')
 
                     for monthname in self.months:
                         month = month.replace (monthname, self.months[monthname])
@@ -153,9 +166,9 @@ fi
 
                     date = day + "." + month + "." + m.groups ()[5]
 
-                    job_id = m.groups ()[0]
-                    class_id = m.groups ()[6]
-                    user = m.groups ()[7]
+                    job_id = m.group ('jobid')
+                    class_id = m.group ('class')
+                    user = m.group ('user')
 
                     success, title, desc, manual_poscorrect, output, display = self.get_job_data (int (job_id))
                     # manual_poscorrect is only used during preparation of script
@@ -179,7 +192,7 @@ fi
                 if m != None:
                     #print "Parse successfull, groups: "
                     #print m.groups()
-                    job_id = m.groups ()[0]
+                    job_id = m.group('jobid')
                     return int(job_id)
                 else:
                     return False
@@ -503,8 +516,12 @@ fi
         #do 'atq'
         execute = config.getAtqbin ()
         self.lines = os.popen(execute).readlines()
-        for line in self.lines:
 
+        # Skip header: Date..
+        if self.sysname == 'FreeBSD':
+            self.lines = self.lines[1:]
+
+        for line in self.lines:
             array_or_false = self.parse (line)
             #print array_or_false
             if array_or_false != False:
@@ -519,7 +536,7 @@ fi
 
                 timestring = "%s %s" % (date, time)
 
-                date_o = datetime.datetime.strptime (date + " " + time, "%d.%m.%Y %H:%M")
+                date_o = datetime.datetime.strptime (date + " " + time, "%d.%m.%Y %H:%M:%S")
                 timestring_show = _("On %(timestring)s") % { 'timestring' : date_o.strftime ("%c") }
 
 
@@ -535,7 +552,8 @@ fi
 
                 #print _("added %(id)s") % { "id": job_id   }
             else:
-                print _("Warning: a line in atq's output didn't parse")
+                print _("Warning: a line in atq's output didn't parse:")
+                print line
         return data
 
 



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