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.
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.
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]
31 from bisect import insort
41 gtk.gdk.threads_init()
50 from os.path import abspath, dirname, join, pardir
51 sys.path.insert(0, join(dirname(__file__), pardir, "plugin"))
53 sys.path.insert(0, join(dirname(__file__), pardir, "plugin", "rsync"))
57 # here we define the path constants so that other modules can use it.
58 # this allows us to get access to the shared files without having to
59 # know the actual location, we just use the location of the current
60 # file and use paths relative to that.
61 SHARED_FILES = os.path.abspath(os.path.join(os.path.dirname(__file__),
64 LOCALE_PATH = os.path.join('/usr', 'share', 'locale')
65 RESOURCE_PATH = os.path.join(SHARED_FILES, 'res')
67 # the name of the gettext domain. because we have our translation files
68 # not in a global folder this doesn't really matter, setting it to the
69 # application name is a good idea tough.
70 GETTEXT_DOMAIN = 'time-slider'
72 # set up the glade gettext system and locales
73 gtk.glade.bindtextdomain(GETTEXT_DOMAIN, LOCALE_PATH)
74 gtk.glade.textdomain(GETTEXT_DOMAIN)
77 from rbac import RBACprofile
81 def __init__(self, mountpoint, rsync_dir = None, fsname= None, snaplabel= None, creationtime= None):
84 self.__init_from_mp (mountpoint)
86 self.rsync_dir = rsync_dir
87 self.mountpoint = mountpoint
89 self.snaplabel = snaplabel
91 self.creationtime = creationtime
93 tm = time.localtime(self.creationtime)
94 self.creationtime_str = unicode(time.strftime ("%c", tm),
95 locale.getpreferredencoding()).encode('utf-8')
97 self.creationtime_str = time.ctime(self.creationtime)
99 def __init_from_mp (self, mountpoint):
100 self.rsyncsmf = rsyncsmf.RsyncSMF("%s:rsync" %(plugin.PLUGINBASEFMRI))
101 rsyncBaseDir = self.rsyncsmf.get_target_dir()
102 sys,nodeName,rel,ver,arch = os.uname()
103 self.rsync_dir = os.path.join(rsyncBaseDir,
104 rsyncsmf.RSYNCDIRPREFIX,
106 self.mountpoint = mountpoint
108 s1 = mountpoint.split ("%s/" % self.rsync_dir, 1)
109 s2 = s1[1].split ("/%s" % rsyncsmf.RSYNCDIRSUFFIX, 1)
110 s3 = s2[1].split ('/',2)
112 self.snaplabel = s3[1]
113 self.creationtime = os.stat(mountpoint).st_mtime
116 ret = "self.rsync_dir = %s\n \
117 self.mountpoint = %s\n \
119 self.snaplabel = %s\n" % (self.rsync_dir,
120 self.mountpoint, self.fsname,
126 return os.path.exists(self.mountpoint)
129 lockFileDir = os.path.join(self.rsync_dir,
131 rsyncsmf.RSYNCLOCKSUFFIX)
133 if not os.path.exists(lockFileDir):
134 os.makedirs(lockFileDir, 0755)
136 lockFile = os.path.join(lockFileDir, self.snaplabel + ".lock")
138 lockFp = open(lockFile, 'w')
139 fcntl.flock(lockFp, fcntl.LOCK_EX | fcntl.LOCK_NB)
141 raise RuntimeError, \
142 "couldn't delete %s, already used by another process" % self.mountpoint
145 trashDir = os.path.join(self.rsync_dir,
147 rsyncsmf.RSYNCTRASHSUFFIX)
148 if not os.path.exists(trashDir):
149 os.makedirs(trashDir, 0755)
151 backupTrashDir = os.path.join (self.rsync_dir,
153 rsyncsmf.RSYNCTRASHSUFFIX,
157 os.rename (self.mountpoint, backupTrashDir)
158 shutil.rmtree (backupTrashDir)
160 log = "%s/%s/%s/%s/%s.log" % (self.rsync_dir,
162 rsyncsmf.RSYNCDIRSUFFIX,
165 if os.path.exists (log):
173 for root, dirs, files in os.walk(rsyncsmf.RsyncSMF("%s:rsync" %(plugin.PLUGINBASEFMRI)).get_target_dir ()):
174 if '.time-slider' in dirs:
175 dirs.remove('.time-slider')
176 backupDir = os.path.join(root, rsyncsmf.RSYNCDIRSUFFIX)
177 if os.path.exists(backupDir):
178 insort(backupDirs, os.path.abspath(backupDir))