diff contrib/darcs2hg.py @ 2586:bb63d29ce03d

darcs2hg: improved logging
author Sébastien Pierre <sebastien@xprima.com>
date Mon, 10 Jul 2006 09:24:04 -0700
parents 5ec2dded1bda
children 8210cf2ec19d
line wrap: on
line diff
--- a/contrib/darcs2hg.py	Sun Jul 09 21:41:00 2006 -0700
+++ b/contrib/darcs2hg.py	Mon Jul 10 09:24:04 2006 -0700
@@ -4,12 +4,11 @@
 # -----------------------------------------------------------------------------
 # Project   : Basic Darcs to Mercurial conversion script
 # -----------------------------------------------------------------------------
-# Author    : Sebastien Pierre <sebastien@xprima.com>
+# Authors   : Sebastien Pierre                           <sebastien@xprima.com>
+#             TK Soh                                      <teekaysoh@gmail.com>
+# -----------------------------------------------------------------------------
 # Creation  : 24-May-2006
-# Last mod  : 26-May-2006
-# History   :
-#             26-May-2006 - Updated
-#             24-May-2006 - First implementation
+# Last mod  : 01-Jun-2006
 # -----------------------------------------------------------------------------
 
 import os, sys
@@ -35,7 +34,7 @@
 #
 # ------------------------------------------------------------------------------
 
-def cmd(text, path=None):
+def cmd(text, path=None, silent=False):
 	"""Executes a command, in the given directory (if any), and returns the
 	command result as a string."""
 	cwd = None
@@ -43,7 +42,7 @@
 		path = os.path.abspath(path)
 		cwd  = os.getcwd()
 		os.chdir(path)
-	print text
+	if not silent: print "> ", text
 	res = os.popen(text).read()
 	if path:
 		os.chdir(cwd)
@@ -53,6 +52,12 @@
 	"""Writes the given data into the given file."""
 	f = file(path, "w") ; f.write(data)  ; f.close()
 
+def error( *args ):
+	sys.stderr.write("ERROR:")
+	for a in args: sys.stderr.write(str(a))
+	sys.stderr.write("\n")
+	sys.exit(-1)
+
 # ------------------------------------------------------------------------------
 #
 # Darcs interface
@@ -64,7 +69,6 @@
 	chronological list of changes as (change name, change summary)."""
 	changes    = cmd("darcs changes --reverse --xml-output", darcsRepo)
 	doc        = xml_dom.parseString(changes)
-	res        = []
 	for patch_node in doc.childNodes[0].childNodes:
 		name = filter(lambda n:n.nodeName == "name", patch_node.childNodes)
 		comm = filter(lambda n:n.nodeName == "comment", patch_node.childNodes)
@@ -111,7 +115,7 @@
 		sys.exit(-1)
 	# Initializes the target repo
 	if not os.path.isdir(darcs_repo + "/_darcs"):
-		print "No darcs directory found at: " + darc_repo
+		print "No darcs directory found at: " + darcs_repo
 		sys.exit(-1)
 	if not os.path.isdir(hg_repo):
 		os.mkdir(hg_repo)
@@ -128,4 +132,3 @@
 		hg_commit(hg_repo, text, author, epoch)
 
 # EOF
-