def write(self): """ Write the manifest to a json encoded file at the specified path. :raise IOError: on I/O errors. :raise ValueError: on json encoding errors """ state = dict( id=self.id, version=self.version, units=self.units, publishing_details=self.publishing_details) with open(self.path, 'w+') as fp: json.dump(state, fp, indent=2)
def write(self): """ Write the manifest to a json encoded file at the specified path. :raise IOError: on I/O errors. :raise ValueError: on json encoding errors """ state = { ID: self.id, VERSION: self.version, UNITS: self.units, PUBLISHING_DETAILS: self.publishing_details } with open(self.path, 'w+') as fp: json.dump(state, fp, indent=2)
def migrate(path): """ Migrate to latest version. :param path: The path to a stored manifest. :type: path: str """ with open(path) as fp: manifest = json.load(fp) version_in = manifest[VERSION] for version in range(version_in, _manifest.MANIFEST_VERSION): migration = MIGRATIONS[version] manifest = migration(manifest) manifest[VERSION] = version + 1 if version_in < manifest[VERSION]: with open(path, 'w+') as fp: json.dump(manifest, fp)