def setMountForRecording(self, mount): if not self.removeRecordingsDir(): return util.LOG('Setting recording mount to: {0}'.format(util.cleanStrRepr(mount))) self.mount = mount self.mountPath = os.path.join(self.MEDIA_DIR_PATH, mount) self.recordingsPath = os.path.join(self.mountPath, 'recordings') self.timeshiftPath = os.path.join(self.mountPath, 'timeshift') self.mountID = self.writeID(mount) if not self.mountID: util.LOG('Failed to set recording mount to: {0}'.format(util.cleanStrRepr(mount))) return self.initRecordingMount() if not os.path.exists(self.recordingsPath): os.makedirs(self.recordingsPath) if not os.path.exists(self.timeshiftPath): os.makedirs(self.timeshiftPath) os.symlink(self.recordingsPath, self.RECORDINGS_PATH) self.save() self.enableRecording()
def freshenDirectory(path, days=7): if not os.path.exists(path): return util.LOG('emptyDirectory: {0} does not exist'.format(util.cleanStrRepr(path))) threshold = time.time() - days * 86400 for f in os.listdir(path): full = os.path.join(path, f) try: if os.stat(full).st_atime < threshold: if os.path.isfile(full): util.LOG('Removing file: {0}'.format(util.cleanStrRepr(full))) os.remove(full) except: util.ERROR()
def newMount(self, mount): mountPath = os.path.join(self.MEDIA_DIR_PATH, mount) if not os.path.ismount(mountPath): return False self.mounts.append(mount) self.save() util.LOG('New mount detected ({0}): {1}'.format(os.stat(mountPath).st_dev, util.cleanStrRepr(mount))) if mount == self.mount and self.mountID == self.getID(mount): util.LOG('Restoring recording mount: {0}'.format(util.cleanStrRepr(mount))) self.setMountForRecording(mount) return True
def emptyDirectory(path): if not os.path.exists(path): return util.LOG('emptyDirectory: {0} does not exist'.format(util.cleanStrRepr(path))) for sub in os.listdir(path): full = os.path.join(path, sub) try: if os.path.isfile(full): util.LOG('Removing file: {0}'.format(util.cleanStrRepr(full))) os.unlink(full) elif os.path.isdir(full): util.LOG('Removing dir: {0}'.format(util.cleanStrRepr(full))) shutil.rmtree(full) except Exception: util.ERROR()
def mountRemoved(self, mount): if xbmc.Monitor().waitForAbort(10): return if mount in self.mounts: self.mounts.pop(self.mounts.index(mount)) self.save() util.LOG('Mount removed: {0}'.format(util.cleanStrRepr(mount))) if mount == self.mount: self.enableRecording(False) self.unsetRecordingMount()
def check(self): mtime = os.stat(self.MEDIA_DIR_PATH).st_mtime if mtime == self.lastMTime: return if not xbmc.getCondVisibility( 'Pvr.HasTVChannels' ): #This detects shutdown for our purposes - not reliable util.LOG('Waiting for TVH...') return util.LOG('Change detected in {0}'.format( util.cleanStrRepr(self.MEDIA_DIR_PATH))) self.lastMTime = mtime mounts = os.listdir(self.MEDIA_DIR_PATH) if not mounts: if self.mounts: for mount in list(self.mounts): self.mountRemoved(mount) self.mounts = [] return if xbmc.abortRequested: return new = False for mount in mounts: if mount not in self.mounts: new = self.newMount(mount) or new for mount in self.mounts: if mount not in mounts: self.mountRemoved(mount) if xbmc.abortRequested: return if new and not self.savedMountIsMounted(): self.setupMount()
def check(self): mtime = os.stat(self.MEDIA_DIR_PATH).st_mtime if mtime == self.lastMTime: return if not xbmc.getCondVisibility('Pvr.HasTVChannels'): #This detects shutdown for our purposes - not reliable util.LOG('Waiting for TVH...') return util.LOG('Change detected in {0}'.format(util.cleanStrRepr(self.MEDIA_DIR_PATH))) self.lastMTime = mtime mounts = os.listdir(self.MEDIA_DIR_PATH) if not mounts: if self.mounts: for mount in list(self.mounts): self.mountRemoved(mount) self.mounts = [] return if xbmc.abortRequested: return new = False for mount in mounts: if mount not in self.mounts: new = self.newMount(mount) or new for mount in self.mounts: if mount not in mounts: self.mountRemoved(mount) if xbmc.abortRequested: return if new and not self.savedMountIsMounted(): self.setupMount()