Commits

Wojciech Walczak  committed 143fa02

Preparation to connect paragraphs in repo with paragraphs in fixes database

  • Participants
  • Parent commits 18c5762

Comments (0)

Files changed (2)

File sphinx/builders/webapp/webapp.py

 from sphinx.builders.html import StandaloneHTMLBuilder
 from sphinx.errors import SphinxError
 from sphinx.web.reposums import PickleLoadSave
+from sphinx.web.webconfig import WebConfig
 from sphinx.writers.html import HTMLTranslator
 
 try:
 
         self.copy_files(os.getcwd(), self.orig_outdir, (piddbfile,))
         self.create_repo()
+        self.add_pids_to_paragraphs()
 
     def init_translator_class(self):
         self.translator_class = WebappHTMLTranslator
                     commands.add(self.ui, repo, dstfile)
         path.walk(self.srcdir, callback, '')
 
+    def add_pids_to_paragraphs(self):
+        conffile = path.join(self.orig_outdir, 'webapp.conf')
+        dirbase = path.join(self.orig_outdir, self.webconfig.repodir)
+        self.webconfig = WebConfig(conffile)
+        self.piddb = PidDb(piddbfile)
+        files = self.piddb.get_filenames()
+        for f in files:
+            fullpath = path.join(dirbase, f)
+            print fullpath, path.isfile(fullpath)
+            # XXX: the logic for adding paragraph IDs to paragraphs in the
+            # repository goes here
+
+    ###
+    ### general use functions
+    ###
     def copy_files(self, srcdir, dstdir, files):
         """Copy files from a list/tuple 'files' from 'srcdir' source
         directory to destination directory 'dstdir'."""
             except Exception, err:
                 raise SphinxError(err)
 
-
     ###
     ### webapp templates
     ###
                 shutil.copytree(src_dir, dst_dir)
             except Exception, err:
                 raise SphinxError(err)
-            
+
+
     ###
     ### Xapian search engine
     ###
         else:
             data[filename][pid] = paragraph
         self.dbsave(self.dbfile, data)
-        
+
+    def get_record(self, filename, pid):
+        data = self.dbread(self.dbfile)
+        if filename in data and pid in data[filename]:
+            return data[filename][pid]
+        return None
+
+    def get_filenames(self):
+        data = self.dbread(self.dbfile)
+        return filter(lambda x: x.endswith('.rst'), data.keys())
 
 def cutcwd(fpath):
     """For path which starts with the value returned by os.getcwd() 

File sphinx/web/webconfig.py

 from ConfigParser import ConfigParser
 
 class WebConfig(object):
-    def __init__(self):
+    def __init__(self, configfile='webapp.conf'):
+        self.configfile = configfile
         self.conf = ConfigParser()
-        self.conf.read('webapp.conf')
+        self.conf.read(self.configfile)
 
         self.repodir = self.conf.get('Repository', 'repodir')
         self.reposums = self.conf.get('Repository', 'reposums')