Mercurial > public > mercurial-scm > hg
comparison 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 |
comparison
equal
deleted
inserted
replaced
2585:5ec2dded1bda | 2586:bb63d29ce03d |
---|---|
2 # Encoding: iso-8859-1 | 2 # Encoding: iso-8859-1 |
3 # vim: tw=80 ts=4 sw=4 noet | 3 # vim: tw=80 ts=4 sw=4 noet |
4 # ----------------------------------------------------------------------------- | 4 # ----------------------------------------------------------------------------- |
5 # Project : Basic Darcs to Mercurial conversion script | 5 # Project : Basic Darcs to Mercurial conversion script |
6 # ----------------------------------------------------------------------------- | 6 # ----------------------------------------------------------------------------- |
7 # Author : Sebastien Pierre <sebastien@xprima.com> | 7 # Authors : Sebastien Pierre <sebastien@xprima.com> |
8 # TK Soh <teekaysoh@gmail.com> | |
9 # ----------------------------------------------------------------------------- | |
8 # Creation : 24-May-2006 | 10 # Creation : 24-May-2006 |
9 # Last mod : 26-May-2006 | 11 # Last mod : 01-Jun-2006 |
10 # History : | |
11 # 26-May-2006 - Updated | |
12 # 24-May-2006 - First implementation | |
13 # ----------------------------------------------------------------------------- | 12 # ----------------------------------------------------------------------------- |
14 | 13 |
15 import os, sys | 14 import os, sys |
16 import tempfile | 15 import tempfile |
17 import xml.dom.minidom as xml_dom | 16 import xml.dom.minidom as xml_dom |
33 # | 32 # |
34 # Utilities | 33 # Utilities |
35 # | 34 # |
36 # ------------------------------------------------------------------------------ | 35 # ------------------------------------------------------------------------------ |
37 | 36 |
38 def cmd(text, path=None): | 37 def cmd(text, path=None, silent=False): |
39 """Executes a command, in the given directory (if any), and returns the | 38 """Executes a command, in the given directory (if any), and returns the |
40 command result as a string.""" | 39 command result as a string.""" |
41 cwd = None | 40 cwd = None |
42 if path: | 41 if path: |
43 path = os.path.abspath(path) | 42 path = os.path.abspath(path) |
44 cwd = os.getcwd() | 43 cwd = os.getcwd() |
45 os.chdir(path) | 44 os.chdir(path) |
46 print text | 45 if not silent: print "> ", text |
47 res = os.popen(text).read() | 46 res = os.popen(text).read() |
48 if path: | 47 if path: |
49 os.chdir(cwd) | 48 os.chdir(cwd) |
50 return res | 49 return res |
51 | 50 |
52 def writefile(path, data): | 51 def writefile(path, data): |
53 """Writes the given data into the given file.""" | 52 """Writes the given data into the given file.""" |
54 f = file(path, "w") ; f.write(data) ; f.close() | 53 f = file(path, "w") ; f.write(data) ; f.close() |
54 | |
55 def error( *args ): | |
56 sys.stderr.write("ERROR:") | |
57 for a in args: sys.stderr.write(str(a)) | |
58 sys.stderr.write("\n") | |
59 sys.exit(-1) | |
55 | 60 |
56 # ------------------------------------------------------------------------------ | 61 # ------------------------------------------------------------------------------ |
57 # | 62 # |
58 # Darcs interface | 63 # Darcs interface |
59 # | 64 # |
62 def darcs_changes(darcsRepo): | 67 def darcs_changes(darcsRepo): |
63 """Gets the changes list from the given darcs repository. This returns the | 68 """Gets the changes list from the given darcs repository. This returns the |
64 chronological list of changes as (change name, change summary).""" | 69 chronological list of changes as (change name, change summary).""" |
65 changes = cmd("darcs changes --reverse --xml-output", darcsRepo) | 70 changes = cmd("darcs changes --reverse --xml-output", darcsRepo) |
66 doc = xml_dom.parseString(changes) | 71 doc = xml_dom.parseString(changes) |
67 res = [] | |
68 for patch_node in doc.childNodes[0].childNodes: | 72 for patch_node in doc.childNodes[0].childNodes: |
69 name = filter(lambda n:n.nodeName == "name", patch_node.childNodes) | 73 name = filter(lambda n:n.nodeName == "name", patch_node.childNodes) |
70 comm = filter(lambda n:n.nodeName == "comment", patch_node.childNodes) | 74 comm = filter(lambda n:n.nodeName == "comment", patch_node.childNodes) |
71 if not name:continue | 75 if not name:continue |
72 else: name = name[0].childNodes[0].data | 76 else: name = name[0].childNodes[0].data |
109 else: | 113 else: |
110 print USAGE | 114 print USAGE |
111 sys.exit(-1) | 115 sys.exit(-1) |
112 # Initializes the target repo | 116 # Initializes the target repo |
113 if not os.path.isdir(darcs_repo + "/_darcs"): | 117 if not os.path.isdir(darcs_repo + "/_darcs"): |
114 print "No darcs directory found at: " + darc_repo | 118 print "No darcs directory found at: " + darcs_repo |
115 sys.exit(-1) | 119 sys.exit(-1) |
116 if not os.path.isdir(hg_repo): | 120 if not os.path.isdir(hg_repo): |
117 os.mkdir(hg_repo) | 121 os.mkdir(hg_repo) |
118 else: | 122 else: |
119 print "Given HG repository must not exist. It will be created" | 123 print "Given HG repository must not exist. It will be created" |
126 darcs_pull(hg_repo, darcs_repo, hash) | 130 darcs_pull(hg_repo, darcs_repo, hash) |
127 epoch = int(mktime(strptime(date, '%Y%m%d%H%M%S'))) | 131 epoch = int(mktime(strptime(date, '%Y%m%d%H%M%S'))) |
128 hg_commit(hg_repo, text, author, epoch) | 132 hg_commit(hg_repo, text, author, epoch) |
129 | 133 |
130 # EOF | 134 # EOF |
131 |