def on_moved(self, event): isdir = isinstance(event, DirMovedEvent) abs_src_src_path = os.path.abspath(event.src_path) abs_src_dst_path = os.path.abspath(event.dest_path) src_ignore_tag, dst_ignore_tag = (self.is_ignore( abs_src_src_path, isdir), self.is_ignore(abs_src_dst_path, isdir)) relative_src_path = self.get_relative_src_path(event.src_path) relative_dst_path = self.get_relative_src_path(event.dest_path) dst_src_path = os.path.join(self.dst_path, relative_src_path) dst_dst_path = os.path.join(self.dst_path, relative_dst_path) if src_ignore_tag and dst_ignore_tag: return elif dst_ignore_tag: remote_rm(dst_ssh=self.dst_ssh, dst_path=dst_src_path) logger.info("Remove {} remotely".format(dst_src_path)) elif src_ignore_tag: dst_folder_path = dst_dst_path[:-len(dst_dst_path.split("/")[-1])] remote_create_folder(dst_ssh=self.dst_ssh, dst_path=dst_folder_path) rsync(dst_ssh=self.dst_ssh, src_path=abs_src_dst_path, dst_path=dst_dst_path) logger.info("Rsync {} remotely".format(dst_dst_path)) else: remote_mv(dst_ssh=self.dst_ssh, src_path=dst_src_path, dst_path=dst_dst_path) logger.info("Move {} to {} remotely".format( dst_src_path, dst_dst_path)) logger.info("Because of move method, try to update all ignore pattern") self.init_gitignore(self.src_path)
def on_moved(self, event): isdir = isinstance(event, DirMovedEvent) abs_src_src_path = os.path.abspath(event.src_path) abs_src_dst_path = os.path.abspath(event.dest_path) src_ignore_tag, dst_ignore_tag = ( self.is_ignore(abs_src_src_path, isdir), self.is_ignore(abs_src_dst_path, isdir) ) relative_src_path = self.get_relative_src_path(event.src_path) relative_dst_path = self.get_relative_src_path(event.dest_path) dst_src_path = os.path.join(self.dst_path, relative_src_path) dst_dst_path = os.path.join(self.dst_path, relative_dst_path) if src_ignore_tag and dst_ignore_tag: return elif dst_ignore_tag: remote_rm(dst_ssh=self.dst_ssh, dst_path=dst_src_path) logger.info("Remove {} remotely".format(dst_src_path)) elif src_ignore_tag: dst_folder_path = dst_dst_path[:-len(dst_dst_path.split("/")[-1])] remote_create_folder(dst_ssh=self.dst_ssh, dst_path=dst_folder_path) rsync(dst_ssh=self.dst_ssh, src_path=abs_src_dst_path, dst_path=dst_dst_path) logger.info("Rsync {} remotely".format(dst_dst_path)) else: remote_mv(dst_ssh=self.dst_ssh, src_path=dst_src_path, dst_path=dst_dst_path) logger.info("Move {} to {} remotely".format( dst_src_path, dst_dst_path )) logger.info("Because of move method, try to update all ignore pattern") self.init_gitignore(self.src_path)
def on_deleted(self, event): abs_src_path = os.path.abspath(event.src_path) isdir = isinstance(event, DirDeletedEvent) if self.is_ignore(abs_src_path, isdir): return relative_path = self.get_relative_src_path(event.src_path) dst_path = os.path.join(self.dst_path, relative_path) # If the file is `.gitignore`, remove this `gitignore` in dict and list if dst_path.split("/")[-1] == ".gitignore": logger.info( "Remove some ignore pattern, because changed " "file({}) named `.gitignore` locally".format(abs_src_path)) self.del_gitignore(abs_src_path) logger.info("Remove {} remotely".format(dst_path)) remote_rm(dst_ssh=self.dst_ssh, dst_path=dst_path)
def on_deleted(self, event): abs_src_path = os.path.abspath(event.src_path) if self.is_ignore(abs_src_path): return relative_path = self.get_relative_src_path(event.src_path) dst_path = os.path.join(self.dst_path, relative_path) # If the file is `.gitignore`, remove this `gitignore` in dict and list if dst_path.split("/")[-1] == ".gitignore": logger.info("Remove some ignore pattern, because changed " "file({}) named `.gitignore` locally".format( abs_src_path )) self.del_gitignore(abs_src_path) logger.info("Remove {} remotely".format(dst_path)) remote_rm(dst_ssh=self.dst_ssh, dst_path=dst_path)
def test_remote_rm(self, _os): _os.popen.return_value = True remote_rm("user@host", "/a/b.py") _os.popen.assert_called_once_with("ssh user@host \"rm -rf /a/b.py\"")