Exemplo n.º 1
0
 def on_created(self, event):
     abs_src_path = os.path.abspath(event.src_path)
     isdir = isinstance(event, DirCreatedEvent)
     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 isinstance(event, DirCreatedEvent):
         logger.info("Create {} remotely".format(dst_path))
         remote_create_folder(dst_ssh=self.dst_ssh, dst_path=dst_path)
     else:
         dst_path = os.path.join(self.dst_path, relative_path)
         # Create folder of file
         dst_folder_path = dst_path[:-len(dst_path.split("/")[-1])]
         remote_create_folder(dst_ssh=self.dst_ssh,
                              dst_path=dst_folder_path)
         logger.info("Rsync {} remotely".format(dst_path))
         rsync(dst_ssh=self.dst_ssh,
               src_path=abs_src_path,
               dst_path=dst_path)
         if dst_path.split("/")[-1] == ".gitignore":
             logger.info(
                 "Update ignore pattern, because changed "
                 "file({}) named `.gitignore` locally".format(abs_src_path))
             self.update_gitignore(abs_src_path)
Exemplo n.º 2
0
 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)
Exemplo n.º 3
0
 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)
Exemplo n.º 4
0
 def on_created(self, event):
     abs_src_path = os.path.abspath(event.src_path)
     isdir = isinstance(event, DirCreatedEvent)
     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 isinstance(event, DirCreatedEvent):
         logger.info("Create {} remotely".format(dst_path))
         remote_create_folder(dst_ssh=self.dst_ssh, dst_path=dst_path)
     else:
         dst_path = os.path.join(self.dst_path, relative_path)
         # Create folder of file
         dst_folder_path = dst_path[:-len(dst_path.split("/")[-1])]
         remote_create_folder(dst_ssh=self.dst_ssh,
                              dst_path=dst_folder_path)
         logger.info("Rsync {} remotely".format(dst_path))
         rsync(dst_ssh=self.dst_ssh, src_path=abs_src_path,
               dst_path=dst_path)
         if dst_path.split("/")[-1] == ".gitignore":
             logger.info("Update ignore pattern, because changed "
                         "file({}) named `.gitignore` locally".format(
                             abs_src_path
                         ))
             self.update_gitignore(abs_src_path)
Exemplo n.º 5
0
 def on_modified(self, event):
     abs_src_path = os.path.abspath(event.src_path)
     if self.is_ignore(abs_src_path):
         return
     if isinstance(event, FileModifiedEvent):
         relative_path = self.get_relative_src_path(event.src_path)
         dst_path = os.path.join(self.dst_path, relative_path)
         # Create folder of file
         dst_folder_path = dst_path[:-len(dst_path.split("/")[-1])]
         # If the file is `.gitignore`, update gitignore dict and list
         if dst_path.split("/")[-1] == ".gitignore":
             logger.info("Update ignore pattern, because changed "
                         "file({}) named `.gitignore` locally".format(
                             abs_src_path
                         ))
             self.update_gitignore(abs_src_path)
         remote_create_folder(dst_ssh=self.dst_ssh,
                              dst_path=dst_folder_path)
         logger.info("Rsync {} remotely".format(dst_path))
         rsync(dst_ssh=self.dst_ssh, src_path=abs_src_path,
               dst_path=dst_path)
Exemplo n.º 6
0
 def test_rsync(self, _os):
     _os.popen.return_value = True
     rsync("user@host", "/a/b.py", "/c.py")
     _os.popen.assert_called_once_with(
         "rsync -avz /a/b.py user@host:/c.py"
     )
Exemplo n.º 7
0
 def test_rsync(self, _os):
     _os.popen.return_value = True
     rsync("user@host", "/a/b.py", "/c.py")
     _os.popen.assert_called_once_with("rsync -avz /a/b.py user@host:/c.py")