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

Contents of /branches/WIP-pyshapelib-bramz/Thuban/Model/data.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 984 - (show annotations)
Thu May 22 16:37:48 2003 UTC (21 years, 9 months ago) by bh
Original Path: trunk/thuban/Thuban/Model/data.py
File MIME type: text/x-python
File size: 3473 byte(s)
Implement a way to discover dependencies between tables and
shapestores.

* Thuban/Model/transientdb.py (TransientTableBase.Dependencies)
(TransientJoinedTable.Dependencies)
(AutoTransientTable.SimpleQuery): New. Implement the dependencies
interface
(TransientJoinedTable.__init__): Keep tack of the original table
objects in addition to the corresponding transient tables.

* Thuban/Model/table.py (DBFTable.Dependencies)
(MemoryTable.Dependencies): New. Implement the dependencies
interface

* Thuban/Model/data.py (ShapeTable): New. Helper class for
ShapefileStore
(ShapefileStore.__init__): Use ShapeTable instead of
AutoTransientTable
(ShapefileStore.Table, ShapefileStore.Shapefile): Add doc-strings
(ShapefileStore.FileName, ShapefileStore.FileType): New. Accessor
methods for filename and type
(ShapefileStore.Dependencies): New. Implement the dependencies
interface
(DerivedShapeStore): New class to replace SimpleStore. The main
difference to SimpleStore is that it depends not on a shapefile
but another shapestore which expresses the dependencies a bit
better
(SimpleStore.__init__): Add deprecation warning.

* test/test_dbf_table.py (TestDBFTable.test_dependencies): New.
Test for the Dependencies method.

* test/test_memory_table.py (TestMemoryTable.test_dependencies):
New. Test for the Dependencies method.

* test/test_transientdb.py
(TestTransientTable.test_auto_transient_table_dependencies): New.
Test for the Dependencies method.
(TestTransientTable.test_transient_joined_table): Add test for the
Dependencies method.

* test/test_session.py (TestSessionSimple.setUp)
(TestSessionSimple.tearDown): New. Implement a better way to
destroy the sessions.
(TestSessionSimple.test_initial_state)
(TestSessionSimple.test_add_table): Bind session to self.session
so that it's destroyed by tearDown
(TestSessionSimple.test_open_shapefile): New. Test for
OpenShapefile and the object it returns

1 # Copyright (C) 2003 by Intevation GmbH
2 # Authors:
3 # Bernhard Herzog <[email protected]>
4 #
5 # This program is free software under the GPL (>=v2)
6 # Read the file COPYING coming with the software for details.
7
8 """Data source abstractions"""
9
10 __version__ = "$Revision$"
11 # $Source$
12 # $Id$
13
14 import os
15 import warnings
16 import weakref
17
18 import shapelib
19 import table
20 import transientdb
21
22
23 class ShapeTable(transientdb.AutoTransientTable):
24
25 """A Table that depends on a ShapefileStore
26
27 Intended use is by the ShapefileStore for the table associated with
28 the shapefiles.
29 """
30
31 def __init__(self, store, db, table):
32 """Initialize the ShapeTable.
33
34 Parameters:
35 store -- the ShapefileStore the table is to depend on
36 db -- The transient database to use
37 table -- the table
38 """
39 transientdb.AutoTransientTable.__init__(self, db, table)
40 self.store = weakref.ref(store)
41
42 def Dependencies(self):
43 """Return a tuple containing the shapestore"""
44 return (self.store(),)
45
46
47 class ShapefileStore:
48
49 """Combine a shapefile and the corresponding DBF file into one object"""
50
51 def __init__(self, session, filename):
52 # Make the filename absolute. The filename will be
53 # interpreted relative to that anyway, but when saving a
54 # session we need to compare absolute paths and it's usually
55 # safer to always work with absolute paths.
56 self.filename = os.path.abspath(filename)
57
58 self.shapefile = shapelib.ShapeFile(self.filename)
59 self.dbftable = table.DBFTable(filename)
60 self.table = ShapeTable(self, session.TransientDB(), self.dbftable)
61
62 def Table(self):
63 """Return the table containing the attribute data"""
64 return self.table
65
66 def Shapefile(self):
67 """Return the shapefile object"""
68 return self.shapefile
69
70 def FileName(self):
71 """Return the filename used to open the shapefile"""
72 return self.filename
73
74 def FileType(self):
75 """Return the filetype. This is always the string 'shapefile'"""
76 return "shapefile"
77
78 def Dependencies(self):
79 """Return the empty tuple.
80
81 The ShapefileStore doesn't depend on anything else.
82 """
83 return ()
84
85
86 class DerivedShapeStore:
87
88 """A ShapeStore derived from other shapestores or tables"""
89
90 def __init__(self, shapestore, table):
91 """Initialize the derived shapestore.
92
93 The arguments are a shapestore for the shapedata and a table for
94 the tabular data.
95 """
96 self.shapestore = shapestore
97 self.table = table
98
99 def Table(self):
100 """Return the table"""
101 return self.table
102
103 def Shapefile(self):
104 """Return the shapefile of he underlying shapestore"""
105 return self.shapestore.Shapefile()
106
107 def Dependencies(self):
108 """Return a tuple containing the shapestore and the table"""
109 return (self.shapestore, self.table)
110
111
112 class SimpleStore:
113
114 """Combine a shapefile and a table object"""
115
116 def __init__(self, shapefile, table):
117 warnings.warn("The SimpleStore is deprecated."
118 " Use DerivedShapeStore instead",
119 DeprecationWarning, stacklevel = 2)
120 self.shapefile = shapefile
121 self.table = table
122 self.filename = None
123
124 def Table(self):
125 return self.table
126
127 def Shapefile(self):
128 return self.shapefile

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26