96a4cc60e57d webui

Start adding infrastructure for the web interface.
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Tue, 13 Oct 2009 18:50:22 -0400
parents 7c9d165e0cd1
children 9539fb54320e
branches/tags webui
files review/api.py review/extension_ui.py review/file_templates.py review/messages.py review/templates.py review/tests/util.py review/web_ui.py

Changes

--- a/review/api.py	Tue Oct 13 18:34:55 2009 -0400
+++ b/review/api.py	Tue Oct 13 18:50:22 2009 -0400
@@ -3,7 +3,7 @@
 """The API for interacting with code review data."""
 
 import datetime, operator, os
-import messages, templates
+import file_templates, messages
 from mercurial import cmdutil, error, hg, patch, util
 from mercurial.node import hex
 
@@ -560,7 +560,7 @@
         """
         rendered_date = util.datestr(self.hgdate)
         lines = ','.join(self.lines)
-        return templates.COMMENT_FILE_TEMPLATE % ( self.author, rendered_date,
+        return file_templates.COMMENT_FILE_TEMPLATE % ( self.author, rendered_date,
             self.node, self.filename, lines, self.message )
     
     def __str__(self):
@@ -631,6 +631,6 @@
         
         """
         rendered_date = util.datestr(self.hgdate)
-        return templates.SIGNOFF_FILE_TEMPLATE % ( self.author, rendered_date,
+        return file_templates.SIGNOFF_FILE_TEMPLATE % ( self.author, rendered_date,
             self.node, self.opinion, self.message )
     
--- a/review/extension_ui.py	Tue Oct 13 18:34:55 2009 -0400
+++ b/review/extension_ui.py	Tue Oct 13 18:50:22 2009 -0400
@@ -11,6 +11,11 @@
 from mercurial import help, templatefilters, util
 from mercurial.node import short
 
+def _web_command(ui, repo, **opts):
+    ui.note(messages.WEB_START)
+    
+    import web_ui
+    web_ui.load_interface(repo)
 
 def _init_command(ui, repo, **opts):
     ui.note(messages.INIT_START)
@@ -227,7 +232,9 @@
     comments and signoffs so other people can view them.
     
     """
-    if opts.pop('init'):
+    if opts.pop('web'):
+        return _web_command(ui, repo, **opts)
+    elif opts.pop('init'):
         return _init_command(ui, repo, **opts)
     elif opts.pop('comment'):
         return _comment_command(ui, repo, *fnames, **opts)
@@ -251,6 +258,7 @@
         ('r', 'rev',         '.',   'the revision to review'),
         ('l', 'lines',       '',    'the line(s) of the file to comment on'),
         ('U', 'unified',     '5',   'number of lines of context to show'),
+        ('w', 'web',         False, 'launch the web interface'),
     ],
     'hg review')
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/review/file_templates.py	Tue Oct 13 18:50:22 2009 -0400
@@ -0,0 +1,18 @@
+"""Templates for hg-review's data files."""
+
+COMMENT_FILE_TEMPLATE = """\
+author:%s
+hgdate:%s
+node:%s
+filename:%s
+lines:%s
+
+%s"""
+
+SIGNOFF_FILE_TEMPLATE = """\
+author:%s
+hgdate:%s
+node:%s
+opinion:%s
+
+%s"""
\ No newline at end of file
--- a/review/messages.py	Tue Oct 13 18:34:55 2009 -0400
+++ b/review/messages.py	Tue Oct 13 18:50:22 2009 -0400
@@ -102,4 +102,8 @@
 
 COMMIT_COMMENT = """Add a comment on changeset %s"""
 COMMIT_SIGNOFF = """Sign off on changeset %s"""
-DELETE_SIGNOFF = """Remove sign off on changeset %s"""
\ No newline at end of file
+DELETE_SIGNOFF = """Remove sign off on changeset %s"""
+
+WEB_START = """\
+starting CherryPy web server
+"""
\ No newline at end of file
--- a/review/templates.py	Tue Oct 13 18:34:55 2009 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,18 +0,0 @@
-"""Templates for hg-review's data files."""
-
-COMMENT_FILE_TEMPLATE = """\
-author:%s
-hgdate:%s
-node:%s
-filename:%s
-lines:%s
-
-%s"""
-
-SIGNOFF_FILE_TEMPLATE = """\
-author:%s
-hgdate:%s
-node:%s
-opinion:%s
-
-%s"""
\ No newline at end of file
--- a/review/tests/util.py	Tue Oct 13 18:34:55 2009 -0400
+++ b/review/tests/util.py	Tue Oct 13 18:50:22 2009 -0400
@@ -9,7 +9,7 @@
 _ui = ui.ui()
 def review(init=False, comment=False, signoff=False, yes=False, no=False,
     force=False, message='', rev='.', local_path='', remote_path='', lines='',
-    files=None, unified='5'):
+    files=None, unified='5', web=False):
     
     files = files if files else []
     
@@ -17,7 +17,7 @@
     extension_ui.review(_ui, get_sandbox_repo(), *files,
         init=init, comment=comment, signoff=signoff, yes=yes, no=no, 
         force=force, message=message, rev=rev, local_path=local_path,
-        remote_path=remote_path, lines=lines, unified=unified )
+        remote_path=remote_path, lines=lines, unified=unified, web=web)
     output = _ui.popbuffer()
     
     print output
--- a/review/web_ui.py	Tue Oct 13 18:34:55 2009 -0400
+++ b/review/web_ui.py	Tue Oct 13 18:50:22 2009 -0400
@@ -20,5 +20,6 @@
 
 app = web.application(urls, globals())
 
-if __name__ == "__main__":
+def load_interface(repo):
+    sys.argv = sys.argv[:1]    # Seriously, web.py?  This is such a hack.
     app.run()
\ No newline at end of file