Commits

gastlygem  committed 54c2fa4

Fix: branches lost after sync

  • Participants
  • Parent commits bbcdca4
  • Branches testing

Comments (0)

Files changed (1)

             fh.readline().strip().split(' ', 1))
     return user, comment
 
-def auto_branch_name():
+def auto_branch_name(dest):
     "generates branch name based on datetime.now()"
+    for piece in dest.split(os.path.sep):
+        if piece != '': break
     now = datetime.now()
     d, t = now.date(), now.time()
-    dstr = ''.join([str(d.year)[2:],
+    dstr = '/'.join([str(d.year)[2:],
                     str(d.month).zfill(2),
                     str(d.day).zfill(2)])
-    tstr = ''.join([str(t.hour).zfill(2),
+    tstr = ':'.join([str(t.hour).zfill(2),
                     str(t.minute).zfill(2),
                     str(t.second).zfill(2)])
-    return dstr + '/' + tstr
+    return '-'.join([dstr, tstr, piece])
     
 def hg_modify_config(project_dir):
     "Writes config to do auto update after hg push."
 @log_hg
 def hg_autobranch(u, dest):
     if hg_status_is_changed(u, dest):
-        hg_branch(u, dest, auto_branch_name())
+        hg_branch(u, dest, auto_branch_name(dest))
         hg_commit(u, dest, 'auto commit')
-        return hg_update_branch(u, dest, br_name='default')
+        hg_update_branch(u, dest, br_name='default')
+        return True
     else:
         hg_update_branch(u, dest, br_name='default')
+        return False
 
 @log_hg
 def hg_status_is_changed(u, dest):
     ## else: return False
     # I heard it's always good to return something in your function.
 
+@log_hg
+def autosync(u, project_dir, syncgroup):
+    "Magic"
+    for syncdir in syncgroup:
+        lockflag = os.path.join(syncdir, 'LOCKED.FLG')
+        if os.path.exists(lockflag):
+            logging.info("Skipping locked %s" % syncdir)
+            continue
+        logging.info("Synchronizing %s" % syncdir)
+        hg_push(u, project_dir, syncdir)
+        branched = hg_autobranch(u, syncdir)
+        if branched:
+            logging.info("Auto branch created on %s" % syncdir)
+            logging.info("Synchronizing back..")
+            autosync(u, syncdir, syncgroup)
+            break
+
 def main():
     configfile = 'config.yaml'
     changefile = 'CHANGED.FLG'
                 if os.path.exists(chflag):
                     time.sleep(0.2)
                     user, comment = parse_flag(chflag)
-                    logging.info("User %s changed %s" % (user, project_dir))
+                    os.remove(chflag)
+                    logging.info("%s changed %s" % (user, project_dir))
+                    logging.info("Message: '%s'" % comment)
                     os.environ['HGUSER'] = user
                     u = ui.ui()
-                    os.remove(chflag)
                     logging.info("Commiting changes for %s" % project_dir)
-                    logging.info("Message: '%s'" % comment)
                     hg_commit(u, project_dir, comment)
                     syncgroup = group.copy()
-                    syncgroup.remove(project_dir)
-                    for syncdir in syncgroup:
-                        if os.path.exists(lockflag):
-                            logging.info("Skipping locked %s" % syncdir)
-                            continue
-                        logging.info("Pushing to dir %s" % syncdir)
-                        hg_push(u, project_dir, syncdir)
-                        logging.info("Updating files in dir %s" % syncdir)
-                        hg_autobranch(u, syncdir)
+                    autosync(u, project_dir, syncgroup)
         time.sleep(10)
 
 if __name__ == '__main__':