Commits

Wojciech Walczak  committed d163356

Basic commit possible now

  • Participants
  • Parent commits f9d4256

Comments (0)

Files changed (8)

File sphinx/builders/webapp/templates/webapp.conf

 
 [Repository]
 repodir={{ repodir }}
+reporoot={{ reporoot }}
+repopath={{ reporoot }}/{{ repodir }}
 reposums={{ reposums }}
 piddbfile={{ piddbfile }}

File sphinx/builders/webapp/webapp.py

         self.public_dir = path.join(self.outdir, 'public')
         
         # _build/webapp/repo - reST source files as a repository
-        self.repodir = path.join(self.outdir, 'repo')
+        self.reporoot = path.join(self.outdir, 'repo')
         
         # _build/webapp/html - HTML templates for webapp/middleware
         self.html_dir = path.join(self.outdir, 'html')
             repo = self.detect_repo()
             if repo:
                 # currently - only mercurial
-                commands.clone(self.ui, repo.base_path, self.repodir)
+                commands.clone(self.ui, repo.base_path, self.reporoot)
             else:
                 self.new_repo()
         except Exception, err:
         return get_workdir_manager_for_path(self.srcdir)
 
     def new_repo(self):
-        commands.init(self.ui, self.repodir)
-        repo = repository(self.ui, self.repodir)
+        commands.init(self.ui, self.reporoot)
+        repo = repository(self.ui, self.reporoot)
         builddir = path.join(self.srcdir, '_build')
         def callback(arg, directory, files):
             srclen = len(self.srcdir)
             for elem in files:
                 srcfile = path.join(directory, elem)
                 subdir = directory[srclen+1:]
-                dstfile = path.join(path.join(self.repodir, subdir), elem)
+                dstfile = path.join(path.join(self.reporoot, subdir), elem)
                 if path.isdir(srcfile):
                     os.mkdir(dstfile)
                 elif not path.exists(dstfile):
 
     def add_pids_to_paragraphs(self):
         def add_pids_to_lines(filename):
-            dirbase = path.join(self.orig_outdir, self.webconfig.repodir)
+            dirbase = path.join(self.orig_outdir, self.webconfig.repopath)
             fullpath = path.join(dirbase, filename)
             try:
                 w = codecs.open(fullpath, 'r', self.encoding)
                                 { 'licence': self.config.licence,
                                   'piddbfile': self.config.piddbfile,
                                   'repodir': self.config.repodir,
+                                  'reporoot': self.config.reporoot,
                                   'reposums': self.config.reposums })
             conf_dst = path.join(self.outdir, 'webapp.conf')
             w = codecs.open(conf_dst, 'w', self.encoding)
 
 class WebappHTMLTranslator(HTMLTranslator):
     licence = None
-    repodir = None
+    repopath = None
     piddbfile = None
     def __init__(self, *args, **kwds):
         self.templ_env = None # templates environment
         self.piddb = PidDb(self.piddbfile)
         HTMLTranslator.__init__(self, *args, **kwds)
 
-    def init_attributes(self, repodir, piddbfile, licence):
-        self.repodir = repodir
+    def init_attributes(self, repopath, piddbfile, licence):
+        self.repopath = repopath
         self.piddbfile = piddbfile
         self.licence = licence
 
         HTMLTranslator.depart_paragraph(self, node)
         if not self.should_be_compact_paragraph(node) and node.source:
            nodename = cutcwd(node.source)
-           if self.repodir:
-               nodename = nodename[len(self.repodir)+1:]
+           if self.repopath:
+               nodename = nodename[len(self.repopath)+1:]
            self.body.append(comm_template.render({ 'licence': self.licence,
                                                    'node': nodename,
                                                    'paragraph_id': self.pid,

File sphinx/config.py

 
         # Web application options
         xapian_db = ('xapian_db', 'webapp'),
-        repodir = ('repo/doc', 'webapp'),
+        repodir = ('doc', 'webapp'),
+        reporoot = ('repo', 'webapp'),
         reposums = ('reposums.pkl', None),
         piddbfile = ('piddb.pkl', None),
         licence = ('BSD', 'webapp'),

File sphinx/quickstart.py

 # -- Options for WebApp --------------------------------------------------------
 # configuration options for Xapian:
 xapian_db = 'xapian_db'
-repodir = 'repo/doc'
+reporoot = 'repo'
+repodir = 'doc'
 reposums = 'reposums.pkl'
 piddbfile = 'piddb.pkl'
 licence = 'BSD'

File sphinx/themes/basic/static/comments.js

  *                                       located in 'id' file under
  *                                       'comment_no' index
  *
- * commit_fix(id, fix_no) -> commit a fix located in 'id' file under
- *                           'fix_no' index to the repository
+ * commit_fix(node, id, fix_no) -> commit a fix located in 'id' file under
+ *                                 'fix_no' index to the repository
  *
  **
  *** general-use functions ************************************************
    var c_flag = (what == 'comments') ? true : false;
    var singular = (what == 'comments') ? 'comment' : 'fix';
    var isdev = is_developer();
+   var node = $('div[class=submitFixFields_' + id + ']').attr('value');
    
    if(what == 'comments') {
       empty_comments(id);
       return '<a href="#" onclick="delete_comment(\'' + db + '\', \'' + id +  '\', \'' + comment_no + '\')">delete</a>' 
    } 
 
-   function commit_button(id, fix_no) {
-      return '<a href="#" onclick="commit_fix(\'' + id + '\', \''
+   function commit_button(node, id, fix_no) {
+      return '<a href="#" onclick="commit_fix(\'' + node + '\', \'' +  id + '\', \''
                   + fix_no + '\')">commit</a>'
    }
 
              +    'Admin actions: '
              +    delete_comment_button(what, id, data[i].comment_no)
              +    ', '
-             +    commit_button(id, data[i].comment_no)
+             +    commit_button(node, id, data[i].comment_no)
              +    '.'
              +  '</td>'
              + '</tr>' 
          +  '</tr>'
          +  (isdev ? developers_actions(what, id, data, i) : '')
          +  '<tr><td>&nbsp;</td></tr>'
-         +  proposed_fix(c_flag, data[i].paragraph)
+         +  proposed_fix(c_flag, data[i].paragraph_diff)
          +  "<tr>"
          +    "<td>"
          +      'Comment: ' + data[i].comment
          });
 }
 
-function commit_fix(id, fix_no) {
+function commit_fix(node, id, fix_no) {
    var c_path = location.protocol + "//" + location.host + "/commit_fix";
    $.ajax({ url: c_path,
             type: 'GET',
-            data: "id=" + id + "&fix_no=" + fix_no,
+            data: "node=" + node + "&id=" + id + "&fix_no=" + fix_no,
             success: function() { load_func(id)}
          });
 }

File sphinx/web/middleware/appserver.py

 from difflib import Differ
 from hashlib import md5
 
+from anyvc import workdir
 from jinja2 import Environment, FileSystemLoader, Template
 from webob import Request, Response
 
         self.piddb = PidDb(self.webconfig.piddbfile)
         self.webauth = WebAuth()
         self.webauth.developers_load('developers.txt')
+        self.repo = workdir.get_workdir_manager_for_path(self.webconfig.repopath)
         self.reposums = RepoSums(self.webconfig.reposums)
         self.htmlbuilder = SinglefileHTMLBuilder(self.www_dir,
-                                                 self.webconfig.repodir,
+                                                 self.webconfig.repopath,
                                                  self.webconfig.piddbfile,
                                                  self.webconfig.licence)
         self.init_templates()
 
     def doCommitFix(self, req, resp):
         """Commit fix"""
-        p_id, fix_no = req.GET['id'], req.GET['fix_no']
+        def new_file_to_commit(file_path, record):
+            """Open a file 'file_path' and in its content change a paragraph
+            'paragraph_orig' with 'paragraph_submitted' from the 'record'
+            dict. Then overwrite the 'file_path' file with a new version
+            of a file and commit it to the repository."""
+            try:
+                w = open(file_path)
+                file_contents = w.read()
+                w.close()
+            except Exception, err:
+                raise SphinxError(err)
+
+            filesub = re.sub(re.escape(record['paragraph_orig']),
+                             record['paragraph_submitted'],
+                             file_contents)
+
+            try:
+                w = open(file_path, 'w')
+                w.write(filesub)
+                w.close()
+            except Exception, err:
+                raise SphinxError(err)
+
+            olddir = os.getcwd()
+            os.chdir(path.join(olddir, self.webconfig.reporoot))
+            self.repo.commit(message='need to add textarea for '\
+                                     'message in the post form',
+                             paths=(path.join('doc', path.basename(file_path)),))
+            os.chdir(olddir)
+
+        node, p_id, fix_no = req.GET['node'], req.GET['id'], int(req.GET['fix_no'])
         fixes_db_path = get_fixes_db_path(p_id)
         data = load_comments(fixes_db_path)
-        fix_index = index_by_key_val(data, 'comment_no', int(fix_no))
-        print '>>>', p_id, fix_no, data[fix_index]['paragraph_orig']
+        fix_index = index_by_key_val(data, 'comment_no', fix_no)
+        file_path = path.join(self.webconfig.repopath, node)
+        new_file_to_commit(file_path, data[fix_index])
+        delete_comment(fixes_db_path, p_id, fix_no)
+        self.piddb.add_record(node, p_id, data[fix_index]['paragraph_submitted'],
+                              save=True)
+        # need to reload the page to see the changes
         return resp
 
     def doAddComment(self, req, resp):
 
             d = Differ()
             pdiff = list(d.compare(p2, p1))
-            db_rec['paragraph'] = modify_diff(pdiff)
-            db_rec['paragraph_orig'] = pdiff
+            db_rec['paragraph_submitted'] = req.POST.get(p_str)
+            db_rec['paragraph_diff'] = modify_diff(pdiff)
+            db_rec['paragraph_orig'] = req.POST.get(p_orig_str)
             db_path = get_fixes_db_path(p_id)
         else:
             db_path = get_comments_db_path(p_id)
         resp.charset = 'utf8' 
         file_path = self.constructPath(req)
 
-        repo_file = path.join(self.webconfig.repodir,file_path[:-5] + '.rst')
+        repo_file = path.join(self.webconfig.repopath,file_path[:-5] + '.rst')
         if check_rst_sum(repo_file):
             self.htmlbuilder.render_page(file_path[:-5])
 

File sphinx/web/singlebuilder.py

 class SinglefileHTMLBuilder(StandaloneHTMLBuilder, Sphinx):
     """Render a file when requested using data from a pickled archive.
     Handle theming."""
-    def __init__(self, www_dir, repodir, piddbfile, licence):
+    def __init__(self, www_dir, repopath, piddbfile, licence):
         self.outdir = www_dir
-        self.srcdir = repodir
+        self.srcdir = repopath
         self.piddbfile = piddbfile
         self.licence = licence
         self.cwd = os.getcwd()
     def init_translator_class(self):
         WebappHTMLTranslator.licence = self.licence
         WebappHTMLTranslator.piddbfile = self.piddbfile
-        WebappHTMLTranslator.repodir = self.srcdir
+        WebappHTMLTranslator.repopath = self.srcdir
         self.translator_class = WebappHTMLTranslator
 
     def render_page(self, docname):

File sphinx/web/webconfig.py

 
         self.piddbfile = self.conf.get('Repository', 'piddbfile')
         self.repodir = self.conf.get('Repository', 'repodir')
+        self.reporoot = self.conf.get('Repository', 'reporoot')
+        self.repopath = self.conf.get('Repository', 'repopath')
         self.reposums = self.conf.get('Repository', 'reposums')