Added a template directory search list (vs. the previous single option)
authorW. Trevor King <wking@drexel.edu>
Sun, 28 Mar 2010 09:18:55 +0000 (05:18 -0400)
committerW. Trevor King <wking@drexel.edu>
Sun, 28 Mar 2010 09:18:55 +0000 (05:18 -0400)
75 files changed:
pyrisk/graphics.py
setup.py
templates/earth/afg.reg [moved from share/templates/earth/afg.reg with 100% similarity]
templates/earth/ala.reg [moved from share/templates/earth/ala.reg with 100% similarity]
templates/earth/alb.reg [moved from share/templates/earth/alb.reg with 100% similarity]
templates/earth/arg.reg [moved from share/templates/earth/arg.reg with 100% similarity]
templates/earth/bra.reg [moved from share/templates/earth/bra.reg with 100% similarity]
templates/earth/cam.reg [moved from share/templates/earth/cam.reg with 100% similarity]
templates/earth/chi.reg [moved from share/templates/earth/chi.reg with 100% similarity]
templates/earth/con.reg [moved from share/templates/earth/con.reg with 100% similarity]
templates/earth/continent.col [moved from share/templates/earth/continent.col with 100% similarity]
templates/earth/eaf.reg [moved from share/templates/earth/eaf.reg with 100% similarity]
templates/earth/eau.reg [moved from share/templates/earth/eau.reg with 100% similarity]
templates/earth/egy.reg [moved from share/templates/earth/egy.reg with 100% similarity]
templates/earth/eus.reg [moved from share/templates/earth/eus.reg with 100% similarity]
templates/earth/gbr-ire.vrt [moved from share/templates/earth/gbr-ire.vrt with 100% similarity]
templates/earth/gbr-sca.rt [moved from share/templates/earth/gbr-sca.rt with 100% similarity]
templates/earth/gbr-weu.rt [moved from share/templates/earth/gbr-weu.rt with 100% similarity]
templates/earth/gbr.reg [moved from share/templates/earth/gbr.reg with 100% similarity]
templates/earth/gre-ice.rt [moved from share/templates/earth/gre-ice.rt with 100% similarity]
templates/earth/gre-nwt.rt [moved from share/templates/earth/gre-nwt.rt with 100% similarity]
templates/earth/gre-ont.rt [moved from share/templates/earth/gre-ont.rt with 100% similarity]
templates/earth/gre-que.rt [moved from share/templates/earth/gre-que.rt with 100% similarity]
templates/earth/gre.reg [moved from share/templates/earth/gre.reg with 100% similarity]
templates/earth/ice-gbr.rt [moved from share/templates/earth/ice-gbr.rt with 100% similarity]
templates/earth/ice-sca.rt [moved from share/templates/earth/ice-sca.rt with 100% similarity]
templates/earth/ice.reg [moved from share/templates/earth/ice.reg with 100% similarity]
templates/earth/indi.reg [moved from share/templates/earth/indi.reg with 100% similarity]
templates/earth/indo-jav.vrt [moved from share/templates/earth/indo-jav.vrt with 100% similarity]
templates/earth/indo-ngu.rt [moved from share/templates/earth/indo-ngu.rt with 100% similarity]
templates/earth/indo-sia.rt [moved from share/templates/earth/indo-sia.rt with 100% similarity]
templates/earth/indo-sul.vrt [moved from share/templates/earth/indo-sul.vrt with 100% similarity]
templates/earth/indo-sum.vrt [moved from share/templates/earth/indo-sum.vrt with 100% similarity]
templates/earth/indo.reg [moved from share/templates/earth/indo.reg with 100% similarity]
templates/earth/ire.reg [moved from share/templates/earth/ire.reg with 100% similarity]
templates/earth/irk.reg [moved from share/templates/earth/irk.reg with 100% similarity]
templates/earth/jap-kam.rt [moved from share/templates/earth/jap-kam.rt with 100% similarity]
templates/earth/jap-mon.rt [moved from share/templates/earth/jap-mon.rt with 100% similarity]
templates/earth/jap.reg [moved from share/templates/earth/jap.reg with 100% similarity]
templates/earth/jav.reg [moved from share/templates/earth/jav.reg with 100% similarity]
templates/earth/kam.reg [moved from share/templates/earth/kam.reg with 100% similarity]
templates/earth/line.col [moved from share/templates/earth/line.col with 100% similarity]
templates/earth/mad-eaf.rt [moved from share/templates/earth/mad-eaf.rt with 100% similarity]
templates/earth/mad-saf.rt [moved from share/templates/earth/mad-saf.rt with 100% similarity]
templates/earth/mad.reg [moved from share/templates/earth/mad.reg with 100% similarity]
templates/earth/mea.reg [moved from share/templates/earth/mea.reg with 100% similarity]
templates/earth/mon.reg [moved from share/templates/earth/mon.reg with 100% similarity]
templates/earth/naf-bra.rt [moved from share/templates/earth/naf-bra.rt with 100% similarity]
templates/earth/naf.reg [moved from share/templates/earth/naf.reg with 100% similarity]
templates/earth/neu-gbr.rt [moved from share/templates/earth/neu-gbr.rt with 100% similarity]
templates/earth/neu-sca.rt [moved from share/templates/earth/neu-sca.rt with 100% similarity]
templates/earth/neu.reg [moved from share/templates/earth/neu.reg with 100% similarity]
templates/earth/ngu-eau.rt [moved from share/templates/earth/ngu-eau.rt with 100% similarity]
templates/earth/ngu.reg [moved from share/templates/earth/ngu.reg with 100% similarity]
templates/earth/nwt.reg [moved from share/templates/earth/nwt.reg with 100% similarity]
templates/earth/ont.reg [moved from share/templates/earth/ont.reg with 100% similarity]
templates/earth/per.reg [moved from share/templates/earth/per.reg with 100% similarity]
templates/earth/player.col [moved from share/templates/earth/player.col with 100% similarity]
templates/earth/que.reg [moved from share/templates/earth/que.reg with 100% similarity]
templates/earth/saf.reg [moved from share/templates/earth/saf.reg with 100% similarity]
templates/earth/sca.reg [moved from share/templates/earth/sca.reg with 100% similarity]
templates/earth/seu-egy.rt [moved from share/templates/earth/seu-egy.rt with 100% similarity]
templates/earth/seu.reg [moved from share/templates/earth/seu.reg with 100% similarity]
templates/earth/sia.reg [moved from share/templates/earth/sia.reg with 100% similarity]
templates/earth/sib.reg [moved from share/templates/earth/sib.reg with 100% similarity]
templates/earth/sul.reg [moved from share/templates/earth/sul.reg with 100% similarity]
templates/earth/sum.reg [moved from share/templates/earth/sum.reg with 100% similarity]
templates/earth/ukr.reg [moved from share/templates/earth/ukr.reg with 100% similarity]
templates/earth/ura.reg [moved from share/templates/earth/ura.reg with 100% similarity]
templates/earth/ven.reg [moved from share/templates/earth/ven.reg with 100% similarity]
templates/earth/wau-sum.rt [moved from share/templates/earth/wau-sum.rt with 100% similarity]
templates/earth/wau.reg [moved from share/templates/earth/wau.reg with 100% similarity]
templates/earth/weu.reg [moved from share/templates/earth/weu.reg with 100% similarity]
templates/earth/wus.reg [moved from share/templates/earth/wus.reg with 100% similarity]
templates/earth/yak.reg [moved from share/templates/earth/yak.reg with 100% similarity]

index a2fc2504a287babd67733357046f358924589d2a..e83de809afa1fe8f083b89fe3f716022b88149d9 100644 (file)
@@ -28,6 +28,12 @@ import os.path
 from .base import NameMixin, ID_CmpMixin
 
 
+TEMPLATE_DIRS = [
+    './templates',
+    '~/share/pyrisk/templates',
+    '/usr/share/pyrisk/templates/',
+    ]
+
 class Template (NameMixin):
     """Setup regions for a particular world.
     """
@@ -44,8 +50,11 @@ class TemplateLibrary (object):
 
     TODO: explain template data format.
     """
-    def __init__(self, template_dir='share/templates/'):
-        self.template_dir = os.path.abspath(os.path.expanduser(template_dir))
+    def __init__(self, template_dirs=None):
+        if template_dirs == None:
+            template_dirs = TEMPLATE_DIRS
+        self.template_dirs = [os.path.abspath(os.path.expanduser(d))
+                              for d in template_dirs]
     def get(self, name):
         region_pointlists,route_pointlists,continent_colors,line_colors, \
             player_colors = \
@@ -54,10 +63,15 @@ class TemplateLibrary (object):
         return Template(name, regions, continent_colors, line_colors, 
                         player_colors)
     def _get_data(self, name):
-        dirname = os.path.join(self.template_dir, name.lower())
-        try:
-            files = os.listdir(dirname)
-        except IOError:
+        files = None
+        for d in self.template_dirs:
+            dirname = os.path.join(d, name.lower())
+            try:
+                files = os.listdir(dirname)
+                break
+            except IOError:
+                pass
+        if files == None:
             return None
         region_pointlists = {}
         route_pointlists = {}
index 1b210b51639fea519ec72c729255d70c58084ed2..a49a18c8765319dd8f9a1a393113bb400460d5d3 100755 (executable)
--- a/setup.py
+++ b/setup.py
@@ -29,7 +29,7 @@ setup(
     author='W. Trevor King',
     author_email='wking@drexel.edu',
     package_dir={'pyrisk': 'pyrisk'},
-    data_files=recursive_file_list('share/pyrisk', 'share/'),
+    data_files=recursive_file_list('share/pyrisk/templates', 'templates'),
     classifiers = [
         'Development Status :: 3 - Alpha',
         #'Environment :: Console',