[gnome-schedule] Export and import scripts for scheduled tasks



commit 0a7b6ed0544e85feaa1aa6195d9dddf6725ab1dd
Author: Gaute Hope <eg gaute vetsj com>
Date:   Fri Aug 19 10:32:26 2011 +0200

    Export and import scripts for scheduled tasks
    
    commit 136444062b744cdcacb2f9ac91e8ae04d77e20fd
    Author: Gaute Hope <eg gaute vetsj com>
    Date:   Fri Aug 19 10:31:18 2011 +0200
    
        Note export and import in news
    
    commit c14c0ca2d5c8bb1f81f6efe8e4259c620a27ca8d
    Merge: ab4b907 247f309
    Author: Gaute Hope <eg gaute vetsj com>
    Date:   Fri Aug 19 10:26:20 2011 +0200
    
        Merge branch 'master' into eiup
    
        Conflicts:
        	po/ar.po
        	po/bg.po
        	po/ca.po
        	po/cs.po
        	po/da.po
        	po/de.po
        	po/dz.po
        	po/el.po
        	po/en_CA.po
        	po/en_GB.po
        	po/es.po
        	po/fi.po
        	po/fr.po
        	po/gl.po
        	po/gu.po
        	po/hu.po
        	po/it.po
        	po/lt.po
        	po/nb.po
        	po/ne.po
        	po/nl.po
        	po/nn.po
        	po/oc.po
        	po/pa.po
        	po/pt.po
        	po/pt_BR.po
        	po/ro.po
        	po/ru.po
        	po/rw.po
        	po/sl.po
        	po/sq.po
        	po/sv.po
        	po/uk.po
        	po/vi.po
        	po/zh_CN.po
        	po/zh_HK.po
        	po/zh_TW.po
    
    commit ab4b907940a9b059cc4fc87239547efdba72200b
    Author: Gaute Hope <eg gaute vetsj com>
    Date:   Sun Jun 12 11:03:49 2011 +0200
    
        Fix gettext error by not loading easy-string for crontab tasks
    
    commit d8031824264c254ad45819cbd660206f6cf3a8c5
    Author: Gaute Hope <eg gaute vetsj com>
    Date:   Sun Jun 12 11:01:42 2011 +0200
    
        Revert "Fix gettext error for easy crontab task"
    
        This reverts commit 48e3f6d4c3b51a26d74c1dd6f49f1e6317c2f11d.
    
    commit 4d555691b75132d006da3d1b9be84f5e0fcc4fbc
    Author: Gaute Hope <eg gaute vetsj com>
    Date:   Sun Jun 12 10:18:59 2011 +0200
    
        Update pos
    
    commit 48e3f6d4c3b51a26d74c1dd6f49f1e6317c2f11d
    Author: Gaute Hope <eg gaute vetsj com>
    Date:   Sun Jun 12 10:18:25 2011 +0200
    
        Fix gettext error for easy crontab task
    
    commit 07dd2ced06737f94ee6d18d1c6d5d1d395aef1a2
    Author: Gaute Hope <eg gaute vetsj com>
    Date:   Sun Jun 12 10:14:38 2011 +0200
    
        ignore generated files
    
    commit 03e95b96078df2ce285fb498c6df04423e24b395
    Author: Gaute Hope <eg gaute vetsj com>
    Date:   Sat Jun 11 18:12:32 2011 +0200
    
        fix typo, switchable usage
    
    commit ee6d37a15bbfa18dc7ef55fbd38a2a6b18abf169
    Author: Gaute Hope <eg gaute vetsj com>
    Date:   Sat Jun 11 18:12:16 2011 +0200
    
        ignore pot
    
    commit 5addfc6db8bc5cf73211327d44a8bc402544e3a9
    Author: Gaute Hope <eg gaute vetsj com>
    Date:   Sat Jun 11 15:01:43 2011 +0200
    
        Remove and ignore generated files
    
    commit 558e19024735a1d703e6b47a4d39edaf0999cbc3
    Author: Gaute Hope <eg gaute vetsj com>
    Date:   Sat Jun 11 14:43:20 2011 +0200
    
        Update po and include strings from export/import scripts
    
    commit ec38e415ed09dd5f7dbaa34530b5487c35d5f8a7
    Author: Gaute Hope <eg gaute vetsj com>
    Date:   Sat Jun 11 14:32:08 2011 +0200
    
        Add export and import
    
        Create export and import scripts. Invoked through:
         $ gnome-schedule-export [file] (or nothing for output to stdout)
    
         and
    
         $ gnome-schedule-import [file] (or nothing to read from stdin)
    
         using Pythons 'pickle' to store necessary data.

 NEWS                         |    1 +
 configure.ac                 |    2 +
 src/Makefile.am              |    5 ++-
 src/crontab.py               |    6 +-
 src/db.py                    |   40 +++++++++++++++
 src/gnome-schedule-export.in |    2 +
 src/gnome-schedule-export.py |  114 ++++++++++++++++++++++++++++++++++++++++++
 src/gnome-schedule-import.in |    2 +
 src/gnome-schedule-import.py |  112 +++++++++++++++++++++++++++++++++++++++++
 9 files changed, 280 insertions(+), 4 deletions(-)
---
diff --git a/NEWS b/NEWS
index 9469990..16aa54a 100644
--- a/NEWS
+++ b/NEWS
@@ -1,5 +1,6 @@
 2011-08-19:
   * Applet disabled by default, not supported by GNOME 3
+  * Included export and import functionality
 
 2011-01-29:
   * Released 2.1.3 - updated translations
diff --git a/configure.ac b/configure.ac
index 42281ff..605ffe8 100644
--- a/configure.ac
+++ b/configure.ac
@@ -137,6 +137,8 @@ Makefile
 src/config.py
 src/Makefile
 src/gnome-schedule
+src/gnome-schedule-export
+src/gnome-schedule-import
 icons/Makefile
 po/Makefile.in
 desktop/Makefile
diff --git a/src/Makefile.am b/src/Makefile.am
index bc061c6..dafd594 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,8 +1,11 @@
-bin_SCRIPTS = gnome-schedule
+bin_SCRIPTS = gnome-schedule gnome-schedule-export gnome-schedule-import
 
 gnomescheduledir = $(prefix)/share/gnome-schedule
 gnomeschedule_PYTHON = \
 	gnome-schedule.py \
+	gnome-schedule-export.py \
+	gnome-schedule-import.py \
+	db.py \
 	at.py \
 	config.py \
 	mainWindow.py \
diff --git a/src/crontab.py b/src/crontab.py
index e29f958..3add77f 100644
--- a/src/crontab.py
+++ b/src/crontab.py
@@ -422,7 +422,7 @@ class Crontab:
         return True
 
     #read tasks in crontab
-    def read (self):
+    def read (self, easy = True):
 
         data = []
 
@@ -447,9 +447,9 @@ class Crontab:
 
                     #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", output, _("At reboot")])
+                      data.append([title, (self.__easy__ (minute, hour, day, month, weekday) if easy else "") , preview, line, linecount, time, self, None, job_id, "", "","", _("Recurrent"), "crontab", output, _("At reboot")])
                     else:
-                        data.append([title, self.__easy__ (minute, hour, day, month, weekday), preview, line, linecount, time, self, None, job_id, "", "","", _("Recurrent"), "crontab", output, time])
+                      data.append([title, (self.__easy__ (minute, hour, day, month, weekday) if easy else ""), preview, line, linecount, time, self, None, job_id, "", "","", _("Recurrent"), "crontab", output, time])
 
 
             linecount = linecount + 1
diff --git a/src/db.py b/src/db.py
new file mode 100644
index 0000000..ea65f76
--- /dev/null
+++ b/src/db.py
@@ -0,0 +1,40 @@
+# db.py - db class to store database of crontab and at tasks
+# Copyright (C) 2011 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 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+# Using Pythons pickle to dump tasks
+class GnomeScheduleDB:
+  VERSION = 1
+
+  # Format:
+  # [title, time, preview, line, output]
+  crontab = []
+
+
+  # Format:
+  # [title, date, time, preview, script, output]
+  at = []
+
+  def __init__ (self):
+    pass
+
+  def setcrontab (self, c):
+    self.crontab = c
+
+  def setat (self, a):
+    self.at = a
+
+
diff --git a/src/gnome-schedule-export.in b/src/gnome-schedule-export.in
new file mode 100644
index 0000000..27056e5
--- /dev/null
+++ b/src/gnome-schedule-export.in
@@ -0,0 +1,2 @@
+#! /bin/sh
+PYTHONPATH= PYTHONPATH@/gtk-2.0/:$PYTHONPATH @PYTHON@ @prefix@/share/gnome-schedule/gnome-schedule-export.py $1
diff --git a/src/gnome-schedule-export.py b/src/gnome-schedule-export.py
new file mode 100755
index 0000000..090de57
--- /dev/null
+++ b/src/gnome-schedule-export.py
@@ -0,0 +1,114 @@
+# gnome-schedule-export-py - This exports crontab and at tasks with their info
+# to the file specified.
+#
+# Copyright (C) 2011  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
+import pickle
+
+# g-s modules
+import config
+import crontab
+import at
+from db import *
+
+# NEEDED FOR SUBMODULES
+##
+## 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
+
+sys.stderr.write(_("Gnome Schedule: Export tasks") + "\n")
+if ("-h" in sys.argv) or ("--help" in sys.argv):
+  sys.stderr.write(_("Usage: %s [output file]" % sys.argv[0]) + "\n")
+  sys.stderr.write(_("       No file means export to stdout.") + "\n\n")
+  sys.exit(0)
+
+
+# Parse arguments
+if len(sys.argv) == 2:
+  outf = sys.argv[1]
+  stdo = False
+else:
+  outf = False
+  stdo = True
+
+
+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
+
+# Check file
+if outf != False:
+  if os.access (outf, os.F_OK):
+    sys.stderr.write (_("File exists already.") + "\n")
+    sys.exit (1)
+
+if stdo:
+  of = sys.stdout
+else:
+  try:
+    of = open(outf, 'wb')
+  except:
+    sys.stderr.write (_("Could not open file for writing: %s" % outf) + "\n")
+    sys.exit (1)
+
+d = GnomeScheduleDB ()
+
+c = crontab.Crontab (is_root, user, uid, gid, home_dir)
+tasks = c.read (easy = False)
+crontabc = 0
+cl = []
+for task in tasks:
+  sys.stderr.write(_("Exporting crontab task: %s" % task[0]) + "\n")
+  crontabc = crontabc + 1
+  cl.append([task[0], task[5], task[2], task[3], task[14]])
+
+d.setcrontab (cl)
+
+# AT
+a = at.At(is_root, user, uid, gid, home_dir, manual_poscorrect)
+tasks = a.read ()
+atc = 0
+al = []
+for task in tasks:
+  sys.stderr.write(_("Exporting at task: " % task[0]) + "\n")
+  atc = atc + 1
+  al.append([task[0], task[8], task[11], task[2], task[3], task[14]])
+
+d.setat (al)
+
+pickle.dump(d, of, -1)
+of.flush ()
+of.close ()
+
+sys.stderr.write (_("Finished, exported: %d tasks total" % (atc + crontabc)) + "\n")
+
diff --git a/src/gnome-schedule-import.in b/src/gnome-schedule-import.in
new file mode 100644
index 0000000..f973e56
--- /dev/null
+++ b/src/gnome-schedule-import.in
@@ -0,0 +1,2 @@
+#! /bin/sh
+PYTHONPATH= PYTHONPATH@/gtk-2.0/:$PYTHONPATH @PYTHON@ @prefix@/share/gnome-schedule/gnome-schedule-import.py $1
diff --git a/src/gnome-schedule-import.py b/src/gnome-schedule-import.py
new file mode 100755
index 0000000..aa22703
--- /dev/null
+++ b/src/gnome-schedule-import.py
@@ -0,0 +1,112 @@
+# gnome-schedule-import-py - This import crontab and at tasks and installs
+# them for the current user from the file specified.
+#
+# Copyright (C) 2011  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
+import pickle
+
+# g-s modules
+import config
+import crontab
+import at
+from db import *
+
+# NEEDED FOR SUBMODULES
+##
+## 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
+
+
+# Parse arguments
+if len(sys.argv) == 2:
+  outf = sys.argv[1]
+  stdo = False
+else:
+  outf = False
+  stdo = True
+
+
+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
+
+sys.stderr.write(_("Gnome Schedule: Import tasks") + "\n")
+if ("-h" in sys.argv) or ("--help" in sys.argv):
+  sys.stderr.write(_("Usage: %s [input file]" % sys.argv[0]) + "\n")
+  sys.stderr.write(_("       No file means import from stdin.") + "\n\n")
+  sys.exit(0)
+
+# Check file
+if outf != False:
+  if not os.access (outf, os.F_OK):
+    sys.stderr.write (_("File does not exist.") + "\n")
+    sys.exit (1)
+
+if stdo:
+  of = sys.stdin
+  sys.stderr.write (_("Reading from stdin..") + "\n")
+else:
+  try:
+    of = open(outf, 'rb')
+    # Reading file
+    sys.stderr.write (_("Reading file: %s.." % outf) + "\n")
+  except:
+    sys.stderr.write (_("Could not open file for reading: %s" % outf) + "\n")
+    sys.exit (1)
+
+
+d = pickle.load (of)
+
+c = crontab.Crontab (is_root, user, uid, gid, home_dir)
+c.read (easy = False)
+
+crontabc = 0
+for task in d.crontab:
+  sys.stderr.write(_("Importing crontab task: %s" % task[0]) + "\n")
+  (minute, hour, dom, moy, dow, command) = c.parse (task[3], True)
+  c.append (minute, hour, dom, moy, dow, command, task[4], task[0])
+  crontabc = crontabc + 1
+
+
+# AT
+a = at.At(is_root, user, uid, gid, home_dir, manual_poscorrect)
+a.read ()
+
+atc = 0
+for task in d.at:
+  sys.stderr.write(_("Importing at task: %s" % task[0]) + "\n")
+  a.append (task[2] + " " + task[1], task[4], task[0], task[5])
+  atc = atc + 1
+
+sys.stderr.write (_("Finished, imported: %d tasks total." % (atc + crontabc)) + "\n")
+



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