|
1702.
|
|
|
Then we fix some bugs elsewhere, and release versions 1.1 and 1.2 of the application. Later, we decide that we should add some units to the length, so that people can refer to it in inches or meters. Version 1.3 is shipped with the following code:
|
|
|
type: Content of: <html><body><p>
|
|
|
|
(no translation yet)
|
|
|
|
Located in
howto/upgrading.xhtml:106
|
|
1703.
|
|
|
class Thing(Versioned):
persistenceVersion = 1
def __init__(self, length, units):
self.length = "%d %s" % (length, units)
def upgradeToVersion1(self):
self.length = "%d inches" % self.length
|
|
|
type: Content of: <html><body><pre>
|
|
|
represents a line break.
Start a new line in the equivalent position in the translation.
|
|
|
represents a space character.
Enter a space in the equivalent position in the translation.
|
|
|
|
class Thing(Versioned):
persistenceVersion = 1
def __init__(self, length, units):
self.length = "%d %s" % (length, units)
def upgradeToVersion1(self):
self.length = "%d inches" % self.length
|
|
Translated and reviewed by
Patrick Fiquet
|
|
|
|
Located in
howto/upgrading.xhtml:112
|
|
1704.
|
|
|
Note that we must make an assumption about what the previous value meant: in this case, we assume the number was in inches.
|
|
|
type: Content of: <html><body><p>
|
|
|
|
(no translation yet)
|
|
|
|
Located in
howto/upgrading.xhtml:120
|
|
1705.
|
|
|
1.4 and 1.5 are shipped with other changes. Then in version 1.6 we decide that saving the two values as a string was foolish and that it would be better to save the number and the string separately, using a tuple. We ship 1.6 with the following:
|
|
|
type: Content of: <html><body><p>
|
|
|
|
(no translation yet)
|
|
|
|
Located in
howto/upgrading.xhtml:123
|
|
1706.
|
|
|
class Thing(Versioned):
persistenceVersion = 2
def __init__(self, length, units):
self.length = (length, units)
def upgradeToVersion1(self):
self.length = "%d inches" % self.length
def upgradeToVersion2(self):
(length, units) = self.length.split()
self.length = (length, units)
|
|
|
type: Content of: <html><body><pre>
|
|
|
represents a line break.
Start a new line in the equivalent position in the translation.
|
|
|
represents a space character.
Enter a space in the equivalent position in the translation.
|
|
|
|
class Thing(Versioned):
persistenceVersion = 2
def __init__(self, length, units):
self.length = (length, units)
def upgradeToVersion1(self):
self.length = "%d inches" % self.length
def upgradeToVersion2(self):
(length, units) = self.length.split()
self.length = (length, units)
|
|
Translated and reviewed by
Patrick Fiquet
|
|
|
|
Located in
howto/upgrading.xhtml:129
|
|
1707.
|
|
|
Note that we must provide both <code>upgradeToVersion1</code> <em>and</em> <code>upgradeToVersion2</code>. We have to assume that the saved .tap files which will be provided to this class come from a random assortment of old versions: we must be prepared to accept anything ever saved by a released version of our application.
|
|
|
type: Content of: <html><body><p>
|
|
|
|
(no translation yet)
|
|
|
|
Located in
howto/upgrading.xhtml:140
|
|
1708.
|
|
|
Finally, version 2.0 adds multiple dimensions. Instead of merely recording the length of a line, it records the size of an N-dimensional rectangular solid. For backwards compatiblity, all 1.X version of the program are assumed to be dealing with a 1-dimensional line. We change the name of the attribute from <code>.length</code> to <code>.size</code> to reflect the new meaning.
|
|
|
type: Content of: <html><body><p>
|
|
|
|
(no translation yet)
|
|
|
|
Located in
howto/upgrading.xhtml:146
|
|
1709.
|
|
|
class Thing(Versioned):
persistenceVersion = 3
def __init__(self, dimensions):
# dimensions is a list of tuples, each is (length, units)
self.size = dimensions
self.name = ["line", "square", "cube", "hypercube"][len(dimensions)]
def upgradeToVersion1(self):
self.length = "%d inches" % self.length
def upgradeToVersion2(self):
(length, units) = self.length.split()
self.length = (length, units)
def upgradeToVersion3(self):
self.size = [self.length]
del self.length
self.name = "line"
|
|
|
type: Content of: <html><body><pre>
|
|
|
represents a line break.
Start a new line in the equivalent position in the translation.
|
|
|
represents a space character.
Enter a space in the equivalent position in the translation.
|
|
|
|
class Thing(Versioned):
persistenceVersion = 3
def __init__(self, dimensions):
# dimensions est une liste de tuples, chacun contient (length, units)
self.size = dimensions
self.name = ["line", "square", "cube", "hypercube"][len(dimensions)]
def upgradeToVersion1(self):
self.length = "%d inches" % self.length
def upgradeToVersion2(self):
(length, units) = self.length.split()
self.length = (length, units)
def upgradeToVersion3(self):
self.size = [self.length]
del self.length
self.name = "line"
|
|
Translated and reviewed by
Patrick Fiquet
|
|
|
|
Located in
howto/upgrading.xhtml:154
|
|
1710.
|
|
|
If a .tap file from the earliest version of our program were to be loaded by the latest code, the following sequence would occur for each Thing instance contained inside:
|
|
|
type: Content of: <html><body><p>
|
|
|
|
(no translation yet)
|
|
|
|
Located in
howto/upgrading.xhtml:171
|
|
1711.
|
|
|
An instance of Thing would be created, with a __dict__ that contained a single attribute <code>.size</code>, which was an integer, like <q>5</q>.
|
|
|
type: Content of: <html><body><ol><li>
|
|
|
|
(no translation yet)
|
|
|
|
Located in
howto/upgrading.xhtml:177
|