/[thuban]/branches/WIP-pyshapelib-bramz/Thuban/Model/resource.py
ViewVC logotype

Diff of /branches/WIP-pyshapelib-bramz/Thuban/Model/resource.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1149 by frank, Wed Jun 11 10:45:34 2003 UTC revision 1230 by jonathan, Wed Jun 18 14:46:43 2003 UTC
# Line 13  from Thuban import _ Line 13  from Thuban import _
13    
14  from Thuban.Lib.fileutil import get_application_dir  from Thuban.Lib.fileutil import get_application_dir
15    
16  from Thuban.Model.load import XMLReader  from Thuban.Model.xmlreader import XMLReader
17  from Thuban.Model.save import XMLWriter  from Thuban.Model.xmlwriter import XMLWriter
18  from Thuban.Model.proj import Projection, ProjFile  from Thuban.Model.proj import Projection, ProjFile
19  from xml.sax import SAXParseException  from xml.sax import SAXParseException
20    
21  projdir = \  projdir = \
22          os.path.join(Thuban.__path__[0], os.pardir, "Resources", "Projections")          os.path.join(Thuban.__path__[0], os.pardir, "Resources", "Projections")
23    
 usrdir  = get_application_dir()  
24    
25  PROJ_EXT = ".proj"  PROJ_EXT = ".proj"
26    
27  def ReadProjFile(filename):  has_gdal_support = lambda: False
28    try:
29        # first try to see if our extension module is there. if it
30        # wasn't even compiled, we obviously don't have gdal support.
31        import gdalwarp
32    
33        # now try to import the python extension. if this doesn't
34        # exist then we can't do anything.
35        import gdal
36    
37        """Return True if the gdal library is available."""
38        has_gdal_support = lambda: True
39    except ImportError:
40        pass
41    
42    def read_proj_file(filename):
43      """Read a single .proj file and return a ProjFile object.      """Read a single .proj file and return a ProjFile object.
44            
45      Raises IOError if the file cannot be opened.      Raises IOError if the file cannot be opened.
# Line 37  def ReadProjFile(filename): Line 51  def ReadProjFile(filename):
51      handler.read(filename)      handler.read(filename)
52      return handler.GetProjFile()      return handler.GetProjFile()
53    
54  def WriteProjFile(pf):  def write_proj_file(pf):
55      """Write a single .proj file      """Write a single .proj file
56    
57      Raises IOError if the file cannot be written.      Raises IOError if the file cannot be written.
# Line 46  def WriteProjFile(pf): Line 60  def WriteProjFile(pf):
60      saver = ProjFileSaver(pf)      saver = ProjFileSaver(pf)
61      saver.write(pf.GetFilename())      saver.write(pf.GetFilename())
62    
63  def GetProjFiles(dir):  def get_proj_files(dir):
64      """Read all .proj files in the given directory and      """Read all .proj files in the given directory and
65      return a list of ProjFile objects.      return a list of ProjFile objects.
66      """      """
# Line 60  def GetProjFiles(dir): Line 74  def GetProjFiles(dir):
74          for file in filter(lambda s: s.endswith(PROJ_EXT), dirlist):          for file in filter(lambda s: s.endswith(PROJ_EXT), dirlist):
75              try:              try:
76                  filename = os.path.join(dir, file)                  filename = os.path.join(dir, file)
77                  list.append(ReadProjFile(filename))                  list.append(read_proj_file(filename))
78              except (OSError, IOError, SAXParseException):              except (OSError, IOError, SAXParseException):
79                  pass # just move onto the next file                  pass # just move onto the next file
80    
81      return list      return list
82    
83  def GetSystemProjFiles():  def get_system_proj_files():
84      """Return a list of ProjFile objects from files that are      """Return a list of ProjFile objects from files that are
85      supplied by Thuban.      supplied by Thuban.
86    
# Line 75  def GetSystemProjFiles(): Line 89  def GetSystemProjFiles():
89      """      """
90      filename = os.path.join(projdir, "defaults.proj")      filename = os.path.join(projdir, "defaults.proj")
91      try:      try:
92          return [ReadProjFile(filename)]          return [read_proj_file(filename)]
93      except (OSError, IOError, SAXParseException):      except (OSError, IOError, SAXParseException):
94          return [ProjFile(filename)]          return [ProjFile(filename)]
95    
96  def GetUserProjFiles():  def get_user_proj_files():
97      """Return a list of ProjFile objects from files that are user-defined.      """Return a list of ProjFile objects from files that are user-defined.
98    
99      If no files could not be opened return a list with one      If no files could not be opened return a list with one
100      empty projection file set to store data in the default file.      empty projection file set to store data in the default file.
101      """      """
102    
103        usrdir  = get_application_dir()
104      filename = os.path.join(usrdir, "user.proj")      filename = os.path.join(usrdir, "user.proj")
105      try:      try:
106          return [ReadProjFile(filename)]          return [read_proj_file(filename)]
107      except (OSError, IOError, SAXParseException):      except (OSError, IOError, SAXParseException):
108          return [ProjFile(filename)]          return [ProjFile(filename)]
109    
# Line 122  class ProjFileReader(XMLReader): Line 137  class ProjFileReader(XMLReader):
137      def GetProjFile(self):      def GetProjFile(self):
138          return self.__pf          return self.__pf
139    
   
140  class ProjFileSaver(XMLWriter):  class ProjFileSaver(XMLWriter):
141    
142      def __init__(self, pf):      def __init__(self, pf):

Legend:
Removed from v.1149  
changed lines
  Added in v.1230

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26