Commit 0a7b6ed0 authored by Gaute Hope's avatar Gaute Hope

Export and import scripts for scheduled tasks

commit 13644406
Author: Gaute Hope <eg@gaute.vetsj.com>
Date:   Fri Aug 19 10:31:18 2011 +0200

    Note export and import in news

commit c14c0ca2
Merge: ab4b9079 247f309d
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 ab4b9079
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 d8031824
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 48e3f6d4.

commit 4d555691
Author: Gaute Hope <eg@gaute.vetsj.com>
Date:   Sun Jun 12 10:18:59 2011 +0200

    Update pos

commit 48e3f6d4
Author: Gaute Hope <eg@gaute.vetsj.com>
Date:   Sun Jun 12 10:18:25 2011 +0200

    Fix gettext error for easy crontab task

commit 07dd2ced
Author: Gaute Hope <eg@gaute.vetsj.com>
Date:   Sun Jun 12 10:14:38 2011 +0200

    ignore generated files

commit 03e95b96
Author: Gaute Hope <eg@gaute.vetsj.com>
Date:   Sat Jun 11 18:12:32 2011 +0200

    fix typo, switchable usage

commit ee6d37a1
Author: Gaute Hope <eg@gaute.vetsj.com>
Date:   Sat Jun 11 18:12:16 2011 +0200

    ignore pot

commit 5addfc6d
Author: Gaute Hope <eg@gaute.vetsj.com>
Date:   Sat Jun 11 15:01:43 2011 +0200

    Remove and ignore generated files

commit 558e1902
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 ec38e415
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.
parent 247f309d
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
......
......@@ -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
......
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 \
......
......@@ -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
......
# 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
#! /bin/sh
PYTHONPATH=@PYTHONPATH@/gtk-2.0/:$PYTHONPATH @PYTHON@ @prefix@/share/gnome-schedule/gnome-schedule-export.py $1
# 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")
#! /bin/sh
PYTHONPATH=@PYTHONPATH@/gtk-2.0/:$PYTHONPATH @PYTHON@ @prefix@/share/gnome-schedule/gnome-schedule-import.py $1
# 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")
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment