def rogueFiles(self): from RogueFileCheck import RogueFileCheck check = RogueFileCheck(config.suomipoeka.movie_homepath.value, config.suomipoeka.movie_trashpath.value) spTasker.shellExecute( check.getScript(config.suomipoeka.movie_trashpath.value)) self.session.open(MessageBox, check.getStatistics(), MessageBox.TYPE_INFO)
def execFileOp(self, targetPath, selectedlist, op="move", purgeTrash=False): mvCmd = "" rmCmd = "" association = [] for service in selectedlist: name = os.path.splitext( self["list"].getFileNameOfService(service))[0] if name is not None: if op == "delete": # target == trashcan if purgeTrash or self.currentPathSel == targetPath or mountpoint( self.currentPathSel) != mountpoint(targetPath): # direct delete from the trashcan or network mount (no copy to trashcan from different mountpoint) rmCmd += '; rm -f "' + self.currentPathSel + "/" + name + '."*' else: # create a time stamp with touch mvCmd += '; touch "' + self.currentPathSel + "/" + name + '."*' # move movie into the trashcan mvCmd += '; mv "' + self.currentPathSel + "/" + name + '."* "' + targetPath + '/"' association.append( (service, self.delCB )) # put in a callback for this particular movie self["list"].highlightService(True, "del", service) if config.suomipoeka.movie_hide_del.value: self["list"].removeService(service) elif op == "move": #if mountpoint(self.currentPathSel) == mountpoint(targetPath): # #self["list"].removeService(service) # normal direct move # pass #else: # different mountpoint? -> reset user&group if mountpoint(targetPath) != mountpoint( config.suomipoeka.movie_homepath.value ): # CIFS to HDD is ok! # need to change file ownership to match target filesystem file creation tfile = targetPath + "/owner_test" sfile = "\"" + self.currentPathSel + "/" + name + ".\"*" mvCmd += "; touch %s;ls -l %s | while read flags i owner group crap;do chown $owner:$group %s;done;rm %s" % ( tfile, tfile, sfile, tfile) mvCmd += '; mv "' + self.currentPathSel + "/" + name + '."* "' + targetPath + '/"' association.append( (service, self.moveCB )) # put in a callback for this particular movie self["list"].highlightService(True, "move", service) if config.suomipoeka.movie_hide_mov.value: self["list"].removeService(service) self.moveRecCheck(service, targetPath) self.lastPlayedCheck(service) if (mvCmd + rmCmd) != "": spTasker.shellExecute( (mvCmd + rmCmd)[2:], association ) # first move, then delete if expiration limit is 0
def createLinksCB(self, targetPath): try: if self.currentPathSel == targetPath or targetPath == None: return cmd = "" for x in self.selections: name = self.mlist.getFileNameOfService(x) cmd += '; ln -s "' + self.currentPathSel + "/" + name + '" "' + targetPath + name + '"' if cmd != "": spTasker.shellExecute( cmd[2:] ) # first move, then delete if expiration limit is 0 self.close(None) except Exception, e: spDebugOut("[spMM] createLinks exception:\n" + str(e))
def delPathSel(self, path): if path != "..": path = self.currentPathSel + "/" + path if os.path.exists(path): if len(os.listdir(path)) > 0: self.session.open(MessageBox, _("Directory is not empty."), MessageBox.TYPE_ERROR, 10) else: spTasker.shellExecute('rmdir "' + path + '"') return True else: self.session.open(MessageBox, _("Cannot delete the parent directory."), MessageBox.TYPE_ERROR, 10) return False
def recEvent(self, timer): # StateWaiting=0, StatePrepared=1, StateRunning=2, StateEnded=3 try: if timer.justplay: return inform = False try: timer.Filename except: timer.calculateFilename() filename = os.path.split(timer.Filename)[1] if timer.state == timer.StatePrepared: pass elif timer.state == timer.StateRunning: # timer.isRunning() if not filename in self.recList: self.recList.append(filename) inform = True spDebugOut("[spRC] REC START for: " + filename) else: #timer.state == timer.StateEnded: if filename in self.recList: try: os.rename(timer.Filename + ".ts.cuts", timer.Filename + ".ts.cutsr") # switch to unwatched except: pass self.recList.remove(filename) inform = True spDebugOut("[spRC] REC END for: " + filename) try: spTasker.shellExecute(timer.fixMoveCmd) spDebugOut( "[spRC] File had been moved while recording was in progress, moving left over files.." ) except: pass if config.suomipoeka.timer_autocln.value: DelayedFunction( 2000, NavigationInstance.instance.RecordTimer.cleanup ) # postpone to avoid crash in basic timer delete by user if inform: self.recFileUpdate() self.recStateChange(self.recList) #DelayedFunction(500, self.recStateChange, self.recList) except Exception, e: spDebugOut("[spRC] recEvent exception:\n" + str(e))
def suomipoekaStartup(session): if not os.path.exists(config.suomipoeka.folder.value): spTasker.shellExecute("mkdir " + config.suomipoeka.folder.value) spDebugOut("+++ Suomipoeka " + SuomipoekaVersion + " startup") if config.suomipoeka.epglang.value: eServiceEvent.setEPGLanguage(config.suomipoeka.epglang.value) setupKeyResponseValues() DelayedFunction(5000, trashCleanSetup) # Go into standby if the reason for restart was Suomipoeka auto-restart if os.path.exists(config.suomipoeka.folder.value + "/suomipoeka_standby_flag.tmp"): spDebugOut("+++ Going into Standby mode after auto-restart") Notifications.AddNotification(Screens.Standby.Standby) spTasker.shellExecute("rm -f " + config.suomipoeka.folder.value + "/suomipoeka_standby_flag.tmp")
def scriptCB(self, result=None): if result is None: return env = "export SP_OUTDIR=%s" % config.suomipoeka.folder.value env += " SP_HOME=%s" % config.suomipoeka.movie_homepath.value env += " SP_PATH_LIMIT=%s" % config.suomipoeka.movie_pathlimit.value env += " SP_TRASH=%s" % config.suomipoeka.movie_trashpath.value env += " SP_TRASH_DAYS=%s" % config.suomipoeka.movie_trashcan_limit.value current = self["list"].getCurrentSelPath().replace(" ", "\ ") if os.path.exists(result[1]): if result[1].endswith(".sh"): spTasker.shellExecute( "%s; sh %s %s %s" % (env, result[1], self.currentPathSel, current)) elif result[1].endswith(".py"): spTasker.shellExecute( "%s; python %s %s %s" % (env, result[1], self.currentPathSel, current))
def purgeExpiredFromTrash(self): try: if os.path.exists(config.suomipoeka.movie_trashpath.value): purgeCmd = "" dirlist = os.listdir(config.suomipoeka.movie_trashpath.value) for movie in dirlist: if movie[-3:] != ".ts": continue fullpath = config.suomipoeka.movie_trashpath.value + "/" + movie currTime = localtime() expTime = localtime( os.stat(fullpath).st_mtime + 24 * 60 * 60 * config.suomipoeka.movie_trashcan_limit.value) if currTime > expTime: purgeCmd += "; rm -f \"%s\"*" % fullpath.replace( ".ts", "") if purgeCmd != "": spTasker.shellExecute(purgeCmd[2:]) spDebugOut("[spMS] trashcan cleanup activated") else: spDebugOut("[spMS] trashcan cleanup: nothing to delete...") except Exception, e: spDebugOut("[spMS] purgeExpiredFromTrash exception:\n" + str(e))
def dbgChange(self, value): if value == True: pass else: spTasker.shellExecute("rm -f " + config.suomipoeka.folder.value + config.suomipoeka.debugfile.value)
def emptyTrashCB(self, confirmed): if confirmed: spTasker.shellExecute("rm -f %s/*" % config.suomipoeka.movie_trashpath.value) self.close(None)