Initial attempt at python3 conversion
[time-slider.git] / usr / share / time-slider / lib / plugin / rsync / backup.py
index 2d1779f..0b403cc 100644 (file)
@@ -39,7 +39,7 @@ import copy
 from bisect import insort, bisect_left
 
 from time_slider import util, zfs, dbussvc, autosnapsmf, timeslidersmf
 from bisect import insort, bisect_left
 
 from time_slider import util, zfs, dbussvc, autosnapsmf, timeslidersmf
-import rsyncsmf
+from . import rsyncsmf
 
 
 # Set to True if SMF property value of "plugin/command" is "true"
 
 
 # Set to True if SMF property value of "plugin/command" is "true"
@@ -408,7 +408,7 @@ class BackupQueue():
                         not os.path.islink(d)]
             for d in dirList:
                 mtime = os.stat(d).st_mtime
                         not os.path.islink(d)]
             for d in dirList:
                 mtime = os.stat(d).st_mtime
-                insort(self._backups, [long(mtime), os.path.abspath(d)])
+                insort(self._backups, [int(mtime), os.path.abspath(d)])
                 self._backupTimes[dirName][d] = mtime
 
     def _find_backup_device(self):
                 self._backupTimes[dirName][d] = mtime
 
     def _find_backup_device(self):
@@ -599,7 +599,7 @@ class BackupQueue():
             lockFile = os.path.join(lockFileDir, tail)
 
             if not os.path.exists(lockFileDir):
             lockFile = os.path.join(lockFileDir, tail)
 
             if not os.path.exists(lockFileDir):
-                os.makedirs(lockFileDir, 0755)
+                os.makedirs(lockFileDir, 0o755)
             try:
                 lockFp = open(lockFile, 'w')
                 fcntl.flock(lockFp, fcntl.LOCK_EX | fcntl.LOCK_NB)
             try:
                 lockFp = open(lockFile, 'w')
                 fcntl.flock(lockFp, fcntl.LOCK_EX | fcntl.LOCK_NB)
@@ -620,7 +620,7 @@ class BackupQueue():
             trashDir = os.path.join(trash, tail)
 
             if not os.path.exists(trash):
             trashDir = os.path.join(trash, tail)
 
             if not os.path.exists(trash):
-                os.makedirs(trash, 0755)
+                os.makedirs(trash, 0o755)
 
             util.debug("Deleting rsync backup to recover space: %s"\
                 % (dirName), self._verbose)
 
             util.debug("Deleting rsync backup to recover space: %s"\
                 % (dirName), self._verbose)
@@ -763,7 +763,7 @@ class BackupQueue():
             self._bus.rsync_started(self._rsyncBaseDir)
 
         ctime,snapName = self._currentQueueSet[0]
             self._bus.rsync_started(self._rsyncBaseDir)
 
         ctime,snapName = self._currentQueueSet[0]
-        snapshot = zfs.Snapshot(snapName, long(ctime))
+        snapshot = zfs.Snapshot(snapName, int(ctime))
         # Make sure the snapshot didn't get destroyed since we last
         # checked it.
         remainingList = self._currentQueueSet[1:]
         # Make sure the snapshot didn't get destroyed since we last
         # checked it.
         remainingList = self._currentQueueSet[1:]
@@ -835,18 +835,18 @@ class BackupQueue():
         dirList = []
 
         if not os.path.exists(partialDir):
         dirList = []
 
         if not os.path.exists(partialDir):
-            os.makedirs(partialDir, 0755)
+            os.makedirs(partialDir, 0o755)
         if not os.path.exists(logDir):
         if not os.path.exists(logDir):
-            os.makedirs(logDir, 0755)
+            os.makedirs(logDir, 0o755)
 
         if not os.path.exists(targetDir):
 
         if not os.path.exists(targetDir):
-            os.makedirs(targetDir, 0755)
+            os.makedirs(targetDir, 0o755)
             # Add the new directory to our internal
             # mtime dictionary and sorted list.
             self._backupTimes[targetDir] = {}
             insort(self._backupDirs, targetDir)
         else:
             # Add the new directory to our internal
             # mtime dictionary and sorted list.
             self._backupTimes[targetDir] = {}
             insort(self._backupDirs, targetDir)
         else:
-            for name,value in self._backupTimes[targetDir].items():
+            for name,value in list(self._backupTimes[targetDir].items()):
                 if ctime > value:
                     if nearestOlder == None or \
                        value > nearestOlder[1]:
                 if ctime > value:
                     if nearestOlder == None or \
                        value > nearestOlder[1]:
@@ -876,7 +876,7 @@ class BackupQueue():
                                     link + ".lock")
 
             if not os.path.exists(lockFileDir):
                                     link + ".lock")
 
             if not os.path.exists(lockFileDir):
-                os.makedirs(lockFileDir, 0755)
+                os.makedirs(lockFileDir, 0o755)
 
             try:
                 lockFp = open(lockFile, 'w')
 
             try:
                 lockFp = open(lockFile, 'w')
@@ -902,7 +902,7 @@ class BackupQueue():
         # Set umask temporarily so that rsync backups are read-only to
         # the owner by default. Rync will override this to match the
         # permissions of each snapshot as appropriate.
         # Set umask temporarily so that rsync backups are read-only to
         # the owner by default. Rync will override this to match the
         # permissions of each snapshot as appropriate.
-        origmask = os.umask(0222)
+        origmask = os.umask(0o222)
         util.debug("Starting rsync backup of '%s' to: %s" \
                    % (sourceDir, partialDir),
                    self._verbose)
         util.debug("Starting rsync backup of '%s' to: %s" \
                    % (sourceDir, partialDir),
                    self._verbose)
@@ -977,10 +977,10 @@ class BackupQueue():
         # they match the snapshot creation time. This is extremely important
         # because the backup mechanism relies on it to determine backup times
         # and nearest matches for incremental rsync (linkDest)
         # they match the snapshot creation time. This is extremely important
         # because the backup mechanism relies on it to determine backup times
         # and nearest matches for incremental rsync (linkDest)
-        os.utime(backupDir, (long(ctime), long(ctime)))
+        os.utime(backupDir, (int(ctime), int(ctime)))
         # Update the dictionary and time sorted list with ctime also
         # Update the dictionary and time sorted list with ctime also
-        self._backupTimes[targetDir][snapshot.snaplabel] = long(ctime)
-        insort(self._backups, [long(ctime), os.path.abspath(backupDir)]) 
+        self._backupTimes[targetDir][snapshot.snaplabel] = int(ctime)
+        insort(self._backups, [int(ctime), os.path.abspath(backupDir)]) 
         snapshot.set_user_property(self._propName, "completed")
         snapshot.release(self._propName)
         self._currentQueueSet = remainingList
         snapshot.set_user_property(self._propName, "completed")
         snapshot.release(self._propName)
         self._currentQueueSet = remainingList
@@ -1027,7 +1027,7 @@ class BackupQueue():
                                  snapshot.fsname,
                                  rsyncsmf.RSYNCTRASHSUFFIX)
             if not os.path.exists(trash):
                                  snapshot.fsname,
                                  rsyncsmf.RSYNCTRASHSUFFIX)
             if not os.path.exists(trash):
-                os.makedirs(trash, 0755)
+                os.makedirs(trash, 0o755)
             for mtime,dirName in purgeList:
                 trashDir = os.path.join(trash,
                                         dirName)
             for mtime,dirName in purgeList:
                 trashDir = os.path.join(trash,
                                         dirName)
@@ -1042,7 +1042,7 @@ class BackupQueue():
                                             dirName + ".lock")
 
                     if not os.path.exists(lockFileDir):
                                             dirName + ".lock")
 
                     if not os.path.exists(lockFileDir):
-                        os.makedirs(lockFileDir, 0755)
+                        os.makedirs(lockFileDir, 0o755)
 
                     try:
                         lockFp = open(lockFile, 'w')
 
                     try:
                         lockFp = open(lockFile, 'w')
@@ -1195,7 +1195,7 @@ def list_pending_snapshots(propName):
     outdata,errdata = util.run_command(cmd)
     for line in outdata.rstrip().split('\n'):
         ctimeStr,name = line.split()
     outdata,errdata = util.run_command(cmd)
     for line in outdata.rstrip().split('\n'):
         ctimeStr,name = line.split()
-        insort(sortsnaplist, tuple((long(ctimeStr), name)))
+        insort(sortsnaplist, tuple((int(ctimeStr), name)))
     sortsnaplist.reverse()
     return sortsnaplist
 
     sortsnaplist.reverse()
     return sortsnaplist
 
@@ -1217,7 +1217,7 @@ def main(argv):
     lockFileDir = os.path.normpath(tempfile.gettempdir() + '/' + \
                                                        ".time-slider")
     if not os.path.exists(lockFileDir):
     lockFileDir = os.path.normpath(tempfile.gettempdir() + '/' + \
                                                        ".time-slider")
     if not os.path.exists(lockFileDir):
-            os.makedirs(lockFileDir, 0755)
+            os.makedirs(lockFileDir, 0o755)
     lockFile = os.path.join(lockFileDir, 'rsync-backup.lock')
 
     lockFp = open(lockFile, 'w')
     lockFile = os.path.join(lockFileDir, 'rsync-backup.lock')
 
     lockFp = open(lockFile, 'w')