/[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 739 by jonathan, Fri Apr 25 09:13:48 2003 UTC revision 1161 by jonathan, Thu Jun 12 12:41:01 2003 UTC
# Line 6  Line 6 
6  # Read the file COPYING coming with Thuban for details.  # Read the file COPYING coming with Thuban for details.
7    
8  import os  import os
9    import os.path
10    
11  import Thuban  import Thuban
12  from Thuban.Model.load import XMLReader  from Thuban import _
13  from Thuban.Model.save import XMLWriter  
14    from Thuban.Lib.fileutil import get_application_dir
15    
16    from Thuban.Model.xmlreader import XMLReader
17    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    
24  usrdir  = os.path.expanduser("~/.thuban")  usrdir  = get_application_dir()
25    
26  PROJ_EXT = ".proj"  PROJ_EXT = ".proj"
27    
28  def ReadProjFile(filename):  has_gdal_support = lambda: False
29    try:
30        import gdal
31        """Return True if the gdal library is available."""
32        has_gdal_support = lambda: True
33    except ImportError:
34        pass
35    
36    def read_proj_file(filename):
37      """Read a single .proj file and return a ProjFile object.      """Read a single .proj file and return a ProjFile object.
38            
39      Raises IOError if the file cannot be opened.      Raises IOError if the file cannot be opened.
# Line 31  def ReadProjFile(filename): Line 45  def ReadProjFile(filename):
45      handler.read(filename)      handler.read(filename)
46      return handler.GetProjFile()      return handler.GetProjFile()
47    
48  def WriteProjFile(pf):  def write_proj_file(pf):
49      """Write a single .proj file      """Write a single .proj file
50    
51      Raises IOError if the file cannot be written.      Raises IOError if the file cannot be written.
# Line 40  def WriteProjFile(pf): Line 54  def WriteProjFile(pf):
54      saver = ProjFileSaver(pf)      saver = ProjFileSaver(pf)
55      saver.write(pf.GetFilename())      saver.write(pf.GetFilename())
56    
57  def GetProjFiles(dir):  def get_proj_files(dir):
58      """Read all .proj files in the given directory and      """Read all .proj files in the given directory and
59      return a list of ProjFile objects.      return a list of ProjFile objects.
60      """      """
# Line 60  def GetProjFiles(dir): Line 74  def GetProjFiles(dir):
74    
75      return list      return list
76    
77  def GetSystemProjFiles():  def get_system_proj_files():
78      """Return a list of ProjFile objects from files that are      """Return a list of ProjFile objects from files that are
79      supplied by Thuban.      supplied by Thuban.
80    
# Line 73  def GetSystemProjFiles(): Line 87  def GetSystemProjFiles():
87      except (OSError, IOError, SAXParseException):      except (OSError, IOError, SAXParseException):
88          return [ProjFile(filename)]          return [ProjFile(filename)]
89    
90  def GetUserProjFiles():  def get_user_proj_files():
91      """Return a list of ProjFile objects from files that are user-defined.      """Return a list of ProjFile objects from files that are user-defined.
92    
93      If no files could not be opened return a list with one      If no files could not be opened return a list with one
# Line 103  class ProjFileReader(XMLReader): Line 117  class ProjFileReader(XMLReader):
117                    
118      def start_projection(self, name, qname, attrs):      def start_projection(self, name, qname, attrs):
119          self.params = []          self.params = []
120          self.name = attrs.get((None, 'name'), "Unknown")          self.name = self.encode(attrs.get((None, 'name'), _("Unknown")))
121    
122      def end_projection(self, name, qname):      def end_projection(self, name, qname):
123          self.__pf.Add(Projection(self.params, self.name))          self.__pf.Add(Projection(self.params, self.name))
# Line 116  class ProjFileReader(XMLReader): Line 130  class ProjFileReader(XMLReader):
130      def GetProjFile(self):      def GetProjFile(self):
131          return self.__pf          return self.__pf
132    
   
133  class ProjFileSaver(XMLWriter):  class ProjFileSaver(XMLWriter):
134    
135      def __init__(self, pf):      def __init__(self, pf):
# Line 126  class ProjFileSaver(XMLWriter): Line 139  class ProjFileSaver(XMLWriter):
139      def write(self, file_or_filename):      def write(self, file_or_filename):
140          XMLWriter.write(self, file_or_filename)          XMLWriter.write(self, file_or_filename)
141    
142          self.write_header("projfile", "thuban.dtd")          self.write_header("projfile", "projfile.dtd")
143          self.write_projfile(self.__pf)          self.write_projfile(self.__pf)
144          self.close()          self.close()
145    

Legend:
Removed from v.739  
changed lines
  Added in v.1161

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26