infocalypse

(djk)
2009-11-11: Encapsulated path hacks.

Encapsulated path hacks.

diff --git a/infocalypse/devnotes.txt b/infocalypse/devnotes.txt
--- a/infocalypse/devnotes.txt
+++ b/infocalypse/devnotes.txt
@@ -1,3 +1,9 @@
+!!! experimental branch for testing wiki over hg idea !!!
+
+djk20091111
+Remember to test pathhacks under windows.  If it works, use it to clean
+up the config and fms import hacks.
+
 djk20091003
 Added work around for hg-git bug:
 http://github.com/schacon/hg-git/issues#issue/51
diff --git a/infocalypse/pathhacks.py b/infocalypse/pathhacks.py
new file mode 100644
--- /dev/null
+++ b/infocalypse/pathhacks.py
@@ -0,0 +1,38 @@
+""" Keep hacks in one place.
+
+    Copyright (C) 2009 Darrell Karbott
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU General Public
+    License as published by the Free Software Foundation; either
+    version 2.0 of the License, or (at your option) any later version.
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    General Public License for more details.
+
+    You should have received a copy of the GNU General Public
+    License along with this library; if not, write to the Free Software
+    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+    Author: djk@isFiaD04zgAgnrEC5XJt1i4IE7AkNPqhBG5bONi6Yks
+"""
+
+import os
+import sys
+
+# REDFLAG: do better
+# HACK: but at least it's explict and encapsulated.
+def add_parallel_sys_path(dir_name):
+    """ Add the directory dir_name to the sys.path.
+
+        REQUIRES: dir_name is in a directory parallel to
+        the this module.
+    """
+    target_dir = os.path.abspath(os.path.join(os.path.dirname(
+        os.path.dirname(__file__)),
+                                              dir_name))
+    if not target_dir in sys.path:
+        #print "ADDED: ", target_dir
+        sys.path.append(target_dir)
diff --git a/infocalypse/sitecmds.py b/infocalypse/sitecmds.py
--- a/infocalypse/sitecmds.py
+++ b/infocalypse/sitecmds.py
@@ -22,22 +22,16 @@
 
 import os
 import shutil
-import sys # REDFLAG: DCI
 
 from mercurial import util
 
 from fcpconnection import FCPError
 from fcpclient import FCPClient, get_file_infos, set_index_file
 
-#------------------------------------------------------------
-# REDFLAG: DCI path hacks
-import validate
-ADD_DIR = os.path.join(os.path.dirname(
-    os.path.dirname(os.path.dirname(validate.__file__))),
-                       'clean_piki')
-sys.path.append(ADD_DIR)
+# HACK
+from pathhacks import add_parallel_sys_path
+add_parallel_sys_path('fniki')
 
-#------------------------------------------------------------
 import piki
 
 # REDFLAG: DCI deal with loading hacks for config
diff --git a/infocalypse/wikicmds.py b/infocalypse/wikicmds.py
--- a/infocalypse/wikicmds.py
+++ b/infocalypse/wikicmds.py
@@ -22,25 +22,19 @@
 import os
 import sys
 
-#------------------------------------------------------------
-# REDFLAG: DCI path hacks
-import validate
-ADD_DIR = os.path.join(os.path.dirname(
-    os.path.dirname(os.path.dirname(validate.__file__))),
-                       'clean_piki')
-sys.path.append(ADD_DIR)
-#------------------------------------------------------------
-
-from servepiki import serve_wiki
-from piki import create_empty_wiki
 
 from mercurial import util
 
 from config import write_default_config
 
-# REDFLAG: DCI path hacks
+# HACK
+from pathhacks import add_parallel_sys_path
+add_parallel_sys_path('fniki')
+
+import servepiki
+from piki import create_empty_wiki
+
 # piki's required files are in that directory.
-import servepiki
 PIKI_WWW_SRC = os.path.dirname(servepiki.__file__)
 
 def execute_wiki(ui_, repo, params):
@@ -52,7 +46,7 @@ def execute_wiki(ui_, repo, params):
         if not os.path.exists(os.path.join(repo.root, 'fnwiki.cfg')):
             raise util.Abort("Can't read fnwiki.cfg. Did you forget hg " +
                              "fn-wiki --createconfig?")
-        serve_wiki(params['HTTP_PORT'], params['HTTP_BIND'], out_func)
+        servepiki.serve_wiki(params['HTTP_PORT'], params['HTTP_BIND'], out_func)
         return
 
     # Hmmmm... some basic UI depends on wikitext. not sure