diff --git a/sickbeard/notifiers/synoindex.py b/sickbeard/notifiers/synoindex.py index a376222ec7ebdb25ae495245c74c704c5aabf26a..2eaeedbfb76d91a26bed0c9dabe1cd15e5be6db6 100755 --- a/sickbeard/notifiers/synoindex.py +++ b/sickbeard/notifiers/synoindex.py @@ -35,9 +35,39 @@ class synoIndexNotifier: def notify_download(self, ep_name): pass - def update_library(self, ep_obj): + def moveFolder(self, old_path, new_path): + self.moveObject(old_path, new_path) + + def moveFile(self, old_file, new_file): + self.moveObject(old_file, new_file) + + def moveObject(self, old_path, new_path): + if sickbeard.USE_SYNOINDEX: + synoindex_cmd = ['/usr/syno/bin/synoindex', '-N', ek.ek(os.path.abspath, new_path), ek.ek(os.path.abspath, old_path)] + logger.log(u"Executing command "+str(synoindex_cmd)) + logger.log(u"Absolute path to command: "+ek.ek(os.path.abspath, synoindex_cmd[0]), logger.DEBUG) + try: + p = subprocess.Popen(synoindex_cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, cwd=sickbeard.PROG_DIR) + out, err = p.communicate() #@UnusedVariable + logger.log(u"Script result: "+str(out), logger.DEBUG) + except OSError, e: + logger.log(u"Unable to run synoindex: "+ex(e)) + + def deleteFolder(self, cur_path): + self.makeObject('-D', cur_path) + + def addFolder(self, cur_path): + self.makeObject('-A', cur_path) + + def deleteFile(self, cur_file): + self.makeObject('-d', cur_file) + + def addFile(self, cur_file): + self.makeObject('-a', cur_file) + + def makeObject(self, cmd_arg, cur_path): if sickbeard.USE_SYNOINDEX: - synoindex_cmd = ['/usr/syno/bin/synoindex', '-a', ek.ek(os.path.abspath, ep_obj.location)] + synoindex_cmd = ['/usr/syno/bin/synoindex', cmd_arg, ek.ek(os.path.abspath, cur_path)] logger.log(u"Executing command "+str(synoindex_cmd)) logger.log(u"Absolute path to command: "+ek.ek(os.path.abspath, synoindex_cmd[0]), logger.DEBUG) try: diff --git a/sickbeard/postProcessor.py b/sickbeard/postProcessor.py index 7539779df6faa901867ef4106663f6374067a91b..1c19a27c9f222fdd784dc18f8fd7cc7e6898ddfc 100755 --- a/sickbeard/postProcessor.py +++ b/sickbeard/postProcessor.py @@ -184,6 +184,8 @@ class PostProcessor(object): self._log(u"Deleting file "+cur_file, logger.DEBUG) if ek.ek(os.path.isfile, cur_file): ek.ek(os.remove, cur_file) + # do the library update for synoindex + notifiers.synoindex_notifier.deleteFile(cur_file) def _combined_file_operation (self, file_path, new_path, new_base_name, associated_files=False, action=None): """ @@ -763,6 +765,8 @@ class PostProcessor(object): try: ek.ek(os.mkdir, dest_path) helpers.chmodAsParent(dest_path) + # do the library update for synoindex + notifiers.synoindex_notifier.addFolder(dest_path) except OSError, IOError: raise exceptions.PostProcessingFailed("Unable to create the episode's destination folder: "+dest_path) @@ -815,7 +819,7 @@ class PostProcessor(object): notifiers.plex_notifier.update_library() # do the library update for synoindex - notifiers.synoindex_notifier.update_library(ep_obj) + notifiers.synoindex_notifier.addFile(ep_obj.location) # do the library update for trakt notifiers.trakt_notifier.update_library(ep_obj)