def save(self, name=None): """Save the Package in the specified file. We expect that the name is a unicode string. """ if name is None: name=self.__uri name = uri2path(name) # handle .azp files. if name.lower().endswith('.azp') or name.endswith('/'): # AZP format if self.__zip is None: # Conversion necessary: we are saving to the new format. z=ZipPackage() z.new() self.__zip = z # Save the content.xml (using binary mode since serialize is handling encoding) stream = open (self.__zip.getContentsFile(), "wb") self.serialize(stream) stream.close () # Generate the statistics self.__zip.update_statistics(self) # Save the whole .azp self.__zip.save(name) else: # Assuming plain XML format stream = open (name, "wb") self.serialize(stream) stream.close ()
def save(self, name=None): """Save the Package in the specified file""" if name is None: name = self.__uri if name.startswith('file:///'): name = name[7:] if re.match('|/', name): # Windows drive: notation. Convert it from # a more URI-compatible syntax name = urllib.url2pathname(name) # handle .azp files. if name.lower().endswith('.azp') or name.endswith('/'): # AZP format if self.__zip is None: # Conversion necessary: we are saving to the new format. z = ZipPackage() z.new() self.__zip = z # Save the content.xml stream = open(self.__zip.getContentsFile(), "w") self.serialize(stream) stream.close() # Generate the statistics self.__zip.update_statistics(self) # Save the whole .azp self.__zip.save(name) else: # Assuming plain XML format stream = open(name, "w") self.serialize(stream) stream.close()
def __init__(self, uri, source=_get_from_uri, importer=None): """Calling the constructor with just a URI tries to read the package from this URI. This can be overidden by providing explicitly the source parameter (a URL or a stream). Providing None for the source parameter creates a new Package. """ self.meta_cache = {} if isinstance(uri, unicode): uri = uri.encode(sys.getfilesystemencoding()) if re.match('[a-zA-Z]:', uri): # Windows drive: notation. Convert it to # a more URI-compatible syntax uri = urllib.pathname2url(uri) self.__uri = uri self.__importer = importer # Possible container self.__zip = None abs_uri = self.getUri(absolute=True) if importer: importer.__pkg_cache[abs_uri] = self self.__pkg_cache = importer.__pkg_cache else: self.__pkg_cache = {abs_uri: self} element = None if source is None: element = self._make_model() else: reader = PyExpat.Reader() if source is _get_from_uri: # Determine the package format (plain XML or AZP) # FIXME: should be done by content rather than extension if abs_uri.lower().endswith('.azp') or abs_uri.endswith('/'): # Advene Zip Package. Do some magic. self.__zip = ZipPackage(abs_uri) f = urllib.pathname2url(self.__zip.getContentsFile()) element = reader.fromUri("file://" + f).documentElement else: element = reader.fromUri(abs_uri).documentElement elif hasattr(source, 'read'): element = reader.fromStream(source).documentElement else: if re.match('[a-zA-Z]:', source): # Windows drive: notation. Convert it to # a more URI-compatible syntax source = urllib.pathname2url(source) source_uri = util.uri.urljoin( 'file:%s/' % urllib.pathname2url(os.getcwd()), str(source)) if source_uri.lower().endswith('.azp') or source_uri.endswith( '/'): # Advene Zip Package. Do some magic. self.__zip = ZipPackage(source_uri) f = urllib.pathname2url(self.__zip.getContentsFile()) element = reader.fromUri("file://" + f).documentElement else: element = reader.fromUri(source_uri).documentElement modeled.Modeled.__init__(self, element, None) self.__imports = None self.__annotations = None self.__queries = None self.__relations = None self.__schemas = None self.__views = None