Esempio n. 1
0
    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()
Esempio n. 2
0
    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()
Esempio n. 3
0
    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()
Esempio n. 4
0
    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()
Esempio n. 5
0
    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
Esempio n. 6
0
    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()
Esempio n. 7
0
    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()
Esempio n. 8
0
    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
Esempio n. 9
0
    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()
Esempio n. 10
0
    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()
Esempio n. 11
0
    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()
Esempio n. 12
0
    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()