Commits

Sheng Mao committed b78d460

finish basic parsing
TODO: wrap parsed data into objects

  • Participants
  • Parent commits 310db22

Comments (0)

Files changed (1)

File issue-lit.py

     an extension of light-weight file-based issue tracker of mercurial
 '''
 
+#imports
 from mercurial import hg, commands, node
 from mercurial import commands
 
+#constants
 log_template = '''issue #%s
 description: %s
 '''
 status:%s
 '''
 
+labels = [
+    'ID:', # id_label
+    'node:', # node_label
+    'status:' # status_label
+    ]
+
 issue_file_name = '.hgissue'
 
 status_list = [
     'OF'  # for close
     ]
 
-
 # functions
 def pretxncommithook(ui, repo, **kwargs):
     ctx = repo[kwargs['node']]
     id = uuid.uuid1()
     log_msg = log_template % (id, msg)
     file_msg = file_template % (id, node.hex(repo['.'].node()), "ON")
-    f = open(issue_file_name, 'a+')
-    f.write(file_msg)
-    commands.commit(ui, repo, issue_file_name, message=log_msg, addremove=True)
+    fp = open(issue_file_name, 'a+')
+    parse_hgissue_file(issue_file_name)
+    #fp.write(file_msg)
+    fp.close()
+    #commands.commit(ui, repo, issue_file_name, message=log_msg, addremove=True)
     pass
 
 def issue_list(ui, repo, id, rev, useid):
 def issue_close(ui, repo, id, rev, useid = True):
     pass
 
+def parse_hgissue_file(fname):
+    with open(issue_file_name) as fp:
+        all_lines = fp.readlines()
+        if len(all_lines) % 3 != 0:
+            raise IOError('line number of .hgignore is not right')
+        on_line = 0
+        line_count = 0
+        for line in all_lines:
+            line_count = line_count + 1
+            pos = line.find(labels[on_line])
+            if pos == -1:
+                raise IOError('parsing %s error: line %d' % (id_label, line_count))
+            val = line[pos+len(labels[on_line]):]
+            print val
+            on_line = (on_line + 1) % 3
+
 cmdtable = {
     # "command-name": (function-call, options-list, help-string)
     'issue':