From: W. Trevor King Date: Sun, 28 Mar 2010 09:18:55 +0000 (-0400) Subject: Added a template directory search list (vs. the previous single option) X-Git-Tag: 0.1~2 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=4a2af0e4cd1efb582480df94447187ffff827aa9;p=pyrisk.git Added a template directory search list (vs. the previous single option) --- diff --git a/pyrisk/graphics.py b/pyrisk/graphics.py index a2fc250..e83de80 100644 --- a/pyrisk/graphics.py +++ b/pyrisk/graphics.py @@ -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 = {} diff --git a/setup.py b/setup.py index 1b210b5..a49a18c 100755 --- 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', diff --git a/share/templates/earth/afg.reg b/templates/earth/afg.reg similarity index 100% rename from share/templates/earth/afg.reg rename to templates/earth/afg.reg diff --git a/share/templates/earth/ala.reg b/templates/earth/ala.reg similarity index 100% rename from share/templates/earth/ala.reg rename to templates/earth/ala.reg diff --git a/share/templates/earth/alb.reg b/templates/earth/alb.reg similarity index 100% rename from share/templates/earth/alb.reg rename to templates/earth/alb.reg diff --git a/share/templates/earth/arg.reg b/templates/earth/arg.reg similarity index 100% rename from share/templates/earth/arg.reg rename to templates/earth/arg.reg diff --git a/share/templates/earth/bra.reg b/templates/earth/bra.reg similarity index 100% rename from share/templates/earth/bra.reg rename to templates/earth/bra.reg diff --git a/share/templates/earth/cam.reg b/templates/earth/cam.reg similarity index 100% rename from share/templates/earth/cam.reg rename to templates/earth/cam.reg diff --git a/share/templates/earth/chi.reg b/templates/earth/chi.reg similarity index 100% rename from share/templates/earth/chi.reg rename to templates/earth/chi.reg diff --git a/share/templates/earth/con.reg b/templates/earth/con.reg similarity index 100% rename from share/templates/earth/con.reg rename to templates/earth/con.reg diff --git a/share/templates/earth/continent.col b/templates/earth/continent.col similarity index 100% rename from share/templates/earth/continent.col rename to templates/earth/continent.col diff --git a/share/templates/earth/eaf.reg b/templates/earth/eaf.reg similarity index 100% rename from share/templates/earth/eaf.reg rename to templates/earth/eaf.reg diff --git a/share/templates/earth/eau.reg b/templates/earth/eau.reg similarity index 100% rename from share/templates/earth/eau.reg rename to templates/earth/eau.reg diff --git a/share/templates/earth/egy.reg b/templates/earth/egy.reg similarity index 100% rename from share/templates/earth/egy.reg rename to templates/earth/egy.reg diff --git a/share/templates/earth/eus.reg b/templates/earth/eus.reg similarity index 100% rename from share/templates/earth/eus.reg rename to templates/earth/eus.reg diff --git a/share/templates/earth/gbr-ire.vrt b/templates/earth/gbr-ire.vrt similarity index 100% rename from share/templates/earth/gbr-ire.vrt rename to templates/earth/gbr-ire.vrt diff --git a/share/templates/earth/gbr-sca.rt b/templates/earth/gbr-sca.rt similarity index 100% rename from share/templates/earth/gbr-sca.rt rename to templates/earth/gbr-sca.rt diff --git a/share/templates/earth/gbr-weu.rt b/templates/earth/gbr-weu.rt similarity index 100% rename from share/templates/earth/gbr-weu.rt rename to templates/earth/gbr-weu.rt diff --git a/share/templates/earth/gbr.reg b/templates/earth/gbr.reg similarity index 100% rename from share/templates/earth/gbr.reg rename to templates/earth/gbr.reg diff --git a/share/templates/earth/gre-ice.rt b/templates/earth/gre-ice.rt similarity index 100% rename from share/templates/earth/gre-ice.rt rename to templates/earth/gre-ice.rt diff --git a/share/templates/earth/gre-nwt.rt b/templates/earth/gre-nwt.rt similarity index 100% rename from share/templates/earth/gre-nwt.rt rename to templates/earth/gre-nwt.rt diff --git a/share/templates/earth/gre-ont.rt b/templates/earth/gre-ont.rt similarity index 100% rename from share/templates/earth/gre-ont.rt rename to templates/earth/gre-ont.rt diff --git a/share/templates/earth/gre-que.rt b/templates/earth/gre-que.rt similarity index 100% rename from share/templates/earth/gre-que.rt rename to templates/earth/gre-que.rt diff --git a/share/templates/earth/gre.reg b/templates/earth/gre.reg similarity index 100% rename from share/templates/earth/gre.reg rename to templates/earth/gre.reg diff --git a/share/templates/earth/ice-gbr.rt b/templates/earth/ice-gbr.rt similarity index 100% rename from share/templates/earth/ice-gbr.rt rename to templates/earth/ice-gbr.rt diff --git a/share/templates/earth/ice-sca.rt b/templates/earth/ice-sca.rt similarity index 100% rename from share/templates/earth/ice-sca.rt rename to templates/earth/ice-sca.rt diff --git a/share/templates/earth/ice.reg b/templates/earth/ice.reg similarity index 100% rename from share/templates/earth/ice.reg rename to templates/earth/ice.reg diff --git a/share/templates/earth/indi.reg b/templates/earth/indi.reg similarity index 100% rename from share/templates/earth/indi.reg rename to templates/earth/indi.reg diff --git a/share/templates/earth/indo-jav.vrt b/templates/earth/indo-jav.vrt similarity index 100% rename from share/templates/earth/indo-jav.vrt rename to templates/earth/indo-jav.vrt diff --git a/share/templates/earth/indo-ngu.rt b/templates/earth/indo-ngu.rt similarity index 100% rename from share/templates/earth/indo-ngu.rt rename to templates/earth/indo-ngu.rt diff --git a/share/templates/earth/indo-sia.rt b/templates/earth/indo-sia.rt similarity index 100% rename from share/templates/earth/indo-sia.rt rename to templates/earth/indo-sia.rt diff --git a/share/templates/earth/indo-sul.vrt b/templates/earth/indo-sul.vrt similarity index 100% rename from share/templates/earth/indo-sul.vrt rename to templates/earth/indo-sul.vrt diff --git a/share/templates/earth/indo-sum.vrt b/templates/earth/indo-sum.vrt similarity index 100% rename from share/templates/earth/indo-sum.vrt rename to templates/earth/indo-sum.vrt diff --git a/share/templates/earth/indo.reg b/templates/earth/indo.reg similarity index 100% rename from share/templates/earth/indo.reg rename to templates/earth/indo.reg diff --git a/share/templates/earth/ire.reg b/templates/earth/ire.reg similarity index 100% rename from share/templates/earth/ire.reg rename to templates/earth/ire.reg diff --git a/share/templates/earth/irk.reg b/templates/earth/irk.reg similarity index 100% rename from share/templates/earth/irk.reg rename to templates/earth/irk.reg diff --git a/share/templates/earth/jap-kam.rt b/templates/earth/jap-kam.rt similarity index 100% rename from share/templates/earth/jap-kam.rt rename to templates/earth/jap-kam.rt diff --git a/share/templates/earth/jap-mon.rt b/templates/earth/jap-mon.rt similarity index 100% rename from share/templates/earth/jap-mon.rt rename to templates/earth/jap-mon.rt diff --git a/share/templates/earth/jap.reg b/templates/earth/jap.reg similarity index 100% rename from share/templates/earth/jap.reg rename to templates/earth/jap.reg diff --git a/share/templates/earth/jav.reg b/templates/earth/jav.reg similarity index 100% rename from share/templates/earth/jav.reg rename to templates/earth/jav.reg diff --git a/share/templates/earth/kam.reg b/templates/earth/kam.reg similarity index 100% rename from share/templates/earth/kam.reg rename to templates/earth/kam.reg diff --git a/share/templates/earth/line.col b/templates/earth/line.col similarity index 100% rename from share/templates/earth/line.col rename to templates/earth/line.col diff --git a/share/templates/earth/mad-eaf.rt b/templates/earth/mad-eaf.rt similarity index 100% rename from share/templates/earth/mad-eaf.rt rename to templates/earth/mad-eaf.rt diff --git a/share/templates/earth/mad-saf.rt b/templates/earth/mad-saf.rt similarity index 100% rename from share/templates/earth/mad-saf.rt rename to templates/earth/mad-saf.rt diff --git a/share/templates/earth/mad.reg b/templates/earth/mad.reg similarity index 100% rename from share/templates/earth/mad.reg rename to templates/earth/mad.reg diff --git a/share/templates/earth/mea.reg b/templates/earth/mea.reg similarity index 100% rename from share/templates/earth/mea.reg rename to templates/earth/mea.reg diff --git a/share/templates/earth/mon.reg b/templates/earth/mon.reg similarity index 100% rename from share/templates/earth/mon.reg rename to templates/earth/mon.reg diff --git a/share/templates/earth/naf-bra.rt b/templates/earth/naf-bra.rt similarity index 100% rename from share/templates/earth/naf-bra.rt rename to templates/earth/naf-bra.rt diff --git a/share/templates/earth/naf.reg b/templates/earth/naf.reg similarity index 100% rename from share/templates/earth/naf.reg rename to templates/earth/naf.reg diff --git a/share/templates/earth/neu-gbr.rt b/templates/earth/neu-gbr.rt similarity index 100% rename from share/templates/earth/neu-gbr.rt rename to templates/earth/neu-gbr.rt diff --git a/share/templates/earth/neu-sca.rt b/templates/earth/neu-sca.rt similarity index 100% rename from share/templates/earth/neu-sca.rt rename to templates/earth/neu-sca.rt diff --git a/share/templates/earth/neu.reg b/templates/earth/neu.reg similarity index 100% rename from share/templates/earth/neu.reg rename to templates/earth/neu.reg diff --git a/share/templates/earth/ngu-eau.rt b/templates/earth/ngu-eau.rt similarity index 100% rename from share/templates/earth/ngu-eau.rt rename to templates/earth/ngu-eau.rt diff --git a/share/templates/earth/ngu.reg b/templates/earth/ngu.reg similarity index 100% rename from share/templates/earth/ngu.reg rename to templates/earth/ngu.reg diff --git a/share/templates/earth/nwt.reg b/templates/earth/nwt.reg similarity index 100% rename from share/templates/earth/nwt.reg rename to templates/earth/nwt.reg diff --git a/share/templates/earth/ont.reg b/templates/earth/ont.reg similarity index 100% rename from share/templates/earth/ont.reg rename to templates/earth/ont.reg diff --git a/share/templates/earth/per.reg b/templates/earth/per.reg similarity index 100% rename from share/templates/earth/per.reg rename to templates/earth/per.reg diff --git a/share/templates/earth/player.col b/templates/earth/player.col similarity index 100% rename from share/templates/earth/player.col rename to templates/earth/player.col diff --git a/share/templates/earth/que.reg b/templates/earth/que.reg similarity index 100% rename from share/templates/earth/que.reg rename to templates/earth/que.reg diff --git a/share/templates/earth/saf.reg b/templates/earth/saf.reg similarity index 100% rename from share/templates/earth/saf.reg rename to templates/earth/saf.reg diff --git a/share/templates/earth/sca.reg b/templates/earth/sca.reg similarity index 100% rename from share/templates/earth/sca.reg rename to templates/earth/sca.reg diff --git a/share/templates/earth/seu-egy.rt b/templates/earth/seu-egy.rt similarity index 100% rename from share/templates/earth/seu-egy.rt rename to templates/earth/seu-egy.rt diff --git a/share/templates/earth/seu.reg b/templates/earth/seu.reg similarity index 100% rename from share/templates/earth/seu.reg rename to templates/earth/seu.reg diff --git a/share/templates/earth/sia.reg b/templates/earth/sia.reg similarity index 100% rename from share/templates/earth/sia.reg rename to templates/earth/sia.reg diff --git a/share/templates/earth/sib.reg b/templates/earth/sib.reg similarity index 100% rename from share/templates/earth/sib.reg rename to templates/earth/sib.reg diff --git a/share/templates/earth/sul.reg b/templates/earth/sul.reg similarity index 100% rename from share/templates/earth/sul.reg rename to templates/earth/sul.reg diff --git a/share/templates/earth/sum.reg b/templates/earth/sum.reg similarity index 100% rename from share/templates/earth/sum.reg rename to templates/earth/sum.reg diff --git a/share/templates/earth/ukr.reg b/templates/earth/ukr.reg similarity index 100% rename from share/templates/earth/ukr.reg rename to templates/earth/ukr.reg diff --git a/share/templates/earth/ura.reg b/templates/earth/ura.reg similarity index 100% rename from share/templates/earth/ura.reg rename to templates/earth/ura.reg diff --git a/share/templates/earth/ven.reg b/templates/earth/ven.reg similarity index 100% rename from share/templates/earth/ven.reg rename to templates/earth/ven.reg diff --git a/share/templates/earth/wau-sum.rt b/templates/earth/wau-sum.rt similarity index 100% rename from share/templates/earth/wau-sum.rt rename to templates/earth/wau-sum.rt diff --git a/share/templates/earth/wau.reg b/templates/earth/wau.reg similarity index 100% rename from share/templates/earth/wau.reg rename to templates/earth/wau.reg diff --git a/share/templates/earth/weu.reg b/templates/earth/weu.reg similarity index 100% rename from share/templates/earth/weu.reg rename to templates/earth/weu.reg diff --git a/share/templates/earth/wus.reg b/templates/earth/wus.reg similarity index 100% rename from share/templates/earth/wus.reg rename to templates/earth/wus.reg diff --git a/share/templates/earth/yak.reg b/templates/earth/yak.reg similarity index 100% rename from share/templates/earth/yak.reg rename to templates/earth/yak.reg