71dacbbca33b8fedcc8bf1bbbee04670d81d38f1
[time-slider.git] / usr / share / time-slider / lib / plugin / rsync / rsyncsmf.py
1 #!/usr/bin/python2
2 #
3 # CDDL HEADER START
4 #
5 # The contents of this file are subject to the terms of the
6 # Common Development and Distribution License (the "License").
7 # You may not use this file except in compliance with the License.
8 #
9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 # or http://www.opensolaris.org/os/licensing.
11 # See the License for the specific language governing permissions
12 # and limitations under the License.
13 #
14 # When distributing Covered Code, include this CDDL HEADER in each
15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 # If applicable, add the following below this CDDL HEADER, with the
17 # fields enclosed by brackets "[]" replaced with your own identifying
18 # information: Portions Copyright [yyyy] [name of copyright owner]
19 #
20 # CDDL HEADER END
21 #
22
23 import subprocess
24 import threading
25 #from string import letters, digits
26 from plugin import pluginsmf
27
28 RSYNCPROPGROUP = "rsync"
29 RSYNCDIRPREFIX = "TIMESLIDER"
30 RSYNCDIRSUFFIX = ".time-slider/rsync"
31 RSYNCPARTIALSUFFIX = ".time-slider/.rsync-partial"
32 RSYNCTRASHSUFFIX = ".time-slider/.trash"
33 RSYNCLOCKSUFFIX = ".time-slider/.rsync-lock"
34 RSYNCLOGSUFFIX = ".time-slider/.rsync-log"
35 RSYNCCONFIGFILE = ".rsync-config"
36 RSYNCFSTAG = "org.opensolaris:time-slider-rsync"
37
38 class RsyncSMF(pluginsmf.PluginSMF):
39
40     def __init__(self, instanceName):
41         pluginsmf.PluginSMF.__init__(self, instanceName)
42         self._archivedSchedules = None
43
44     def get_cleanup_threshold(self):
45         result = self.get_prop(RSYNCPROPGROUP, "cleanup_threshold").strip()
46         return int(result)
47
48     def get_target_dir(self):
49         result = self.get_prop(RSYNCPROPGROUP, "target_dir").strip()
50         # Strip out '\' characters inserted by svcprop
51         return result.strip().replace('\\', '')
52
53     def get_target_key(self):
54         return self.get_prop(RSYNCPROPGROUP, "target_key").strip()
55
56     def set_target_dir(self, path):
57         self.set_string_prop(RSYNCPROPGROUP, "target_dir", path)
58
59     def set_target_key(self, key):
60         self.set_string_prop(RSYNCPROPGROUP, "target_key", key)
61
62     def get_archived_schedules(self):
63         #FIXME Use mutex locking to make MT-safe
64         if self._archivedSchedules == None:
65             self._archivedSchedules = []
66             value = self.get_prop(RSYNCPROPGROUP, "archived_schedules")
67             
68             # Strip out '\' characters inserted by svcprop
69             archiveList = value.strip().replace('\\', '').split(',')
70             for schedule in archiveList:
71                 self._archivedSchedules.append(schedule.strip())
72         return self._archivedSchedules
73
74     def get_rsync_verbose(self):
75         value = self.get_prop(RSYNCPROPGROUP, "verbose")
76         if value == "true":
77             return True
78         else:
79             return False
80
81     def __str__(self):
82         ret = "SMF Instance:\n" +\
83               "\tName:\t\t\t%s\n" % (self.instance_name) +\
84               "\tState:\t\t\t%s\n" % (self.svcstate) + \
85               "\tTriggers:\t\t%s\n" % str(self.get_triggers()) + \
86               "\tTarget Dir:\t%s\n" % self.get_target_dir() + \
87               "\tVerbose:\t\t\'%s\'" % str((self.get_verbose()))
88         return ret
89