Commits

Cédric Bonhomme  committed 3112b0a

Added comments.

  • Participants
  • Parent commits 92de71a

Comments (0)

Files changed (2)

 __author__ = "Cedric Bonhomme"
 __version__ = "$Revision: 0.1 $"
 __date__ = "$Date: 2011/10/03 $"
-__revision__ = "$Date: 2011/10/03 $"
+__revision__ = "$Date: 2011/10/09 $"
 __copyright__ = "Copyright (c) Cedric Bonhomme"
 __license__ = "GPLv3"
 
 from subprocess import *
 
 def execute_command(cmd):
-    p = Popen(cmd, shell=True, bufsize=1024, stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=True)
-    (child_stdin, child_stdout, child_stderr) = (p.stdin, p.stdout, p.stderr)
+    """
+    Execute a command and print the standard and error outputs.
+    """
+    try:
+        p = Popen(cmd, shell=True, bufsize=1024, stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=True)
+        (child_stdin, child_stdout, child_stderr) = (p.stdin, p.stdout, p.stderr)
+    except Exception, e:
+        print e
     print child_stderr.read()
     print child_stdout.read()
 
 
 class HgSync(object):
     """
+    
     """
     def __init__(self, repository_url, local_url, username):
         """
 
     def clone(self):
         """
+        Clone an existing repository.
         """
         execute_command("hg clone " + self.repository_url)
 
-    def get_commits(self, nb=5):
-        """
-        """
-        pass
-
-    def untracked_files(self):
-        """
-        """
-        return self.untracked_files
-
     def add(self, new_file):
         """
+        Add new_file to the list of tracked files.
         """
         execute_command("cd test-balloon; hg add " + new_file)
         execute_command("cd test-balloon; hg commit -u " + self.username + " -m 'Added " + new_file + "'")
     
     def modify(self, the_file):
         """
+        Modify a file.
         """
         execute_command("cd test-balloon; hg commit -u " + self.username + " -m 'Updated " + the_file + "'")
         execute_command("cd test-balloon; hg push")
     
     def remove(self, file_to_remove):
         """
+        Remove a file.
         """
         execute_command("cd test-balloon; hg remove " + file_to_remove)
         execute_command("cd test-balloon; hg commit -u " + self.username + " -m 'Removed " + file_to_remove + "'")
 
     def rename(self, file_from, file_to):
         """
+        Rename a file.
         """
         self.remove(file_from)
         self.add(file_to)
 __author__ = "Cedric Bonhomme"
 __version__ = "$Revision: 0.1 $"
 __date__ = "$Date: 2011/10/03 $"
-__revision__ = "$Date: 2011/10/05 $"
+__revision__ = "$Date: 2011/10/09 $"
 __copyright__ = "Copyright (c) Cedric Bonhomme"
 __license__ = "GPLv3"
 
 import hgsync
 
 
+# files to exclude from the monitoring
 excl_file = os.path.join(os.getcwd(), 'exclude.lst')
 excl = pyinotify.ExcludeFilter(excl_file)
 
 
+# event triggered:
 mask = pyinotify.IN_DELETE | pyinotify.IN_CREATE | pyinotify.IN_MODIFY | pyinotify.IN_MOVED_FROM | pyinotify.IN_MOVED_TO
 
+
 class PTmp(pyinotify.ProcessEvent):
+    """
+    This class represent a watcher for the local repository.
+    """
     def __init__(self, url, local_url, username):
         """
         """
         self.in_from = ""
     
     def process_IN_CREATE(self, event):
+        """
+        Called when a file has been created.
+        """
         if "hg-check" not in event.name:
             print "Create: %s " % os.path.join(event.path, event.name)
             self.repo.add(os.path.join(event.path, event.name))
         
     def process_IN_DELETE(self, event):
+        """
+        Called when a file has been deleted.
+        """
         if "hg-check" not in event.name:
             print "Delete: %s " % os.path.join(event.path, event.name)
             self.repo.remove(os.path.join(event.path, event.name))
         
     def process_IN_MODIFY(self, event):
+        """
+        Called when a file has been modified.
+        """
         if "hg-check" not in event.name:
             print "Modify: %s " % os.path.join(event.path, event.name)
             self.repo.modify(os.path.join(event.path, event.name))
         
     def process_IN_MOVED_FROM(self, event):
+        """
+        Called when a file has been moved from (source).
+        """
         if "hg-check" not in event.name:
             print "Moved From: %s " % os.path.join(event.path, event.name)
             self.in_from = os.path.join(event.path, event.name)
 
     def process_IN_MOVED_TO(self, event):
+        """
+        Called when a file has been moved to (destination).
+        """
         if "hg-check" not in event.name:
             print "Moved To: %s " % os.path.join(event.path, event.name)
             self.repo.rename(self.in_from, os.path.join(event.path, event.name))