예제 #1
0
 def setUpClass(cls):
     'called once, before any tests'
     logPoint('class %s' % cls.__name__)
     cls.files = {}
     xml = "xml/WeatherSchema.xml"
     doc = edmx.Document()
     with open(xml) as f:
         doc.Read(f)
     cls.files["weather"] = doc
     xml = "xml/metadata.xml"
     doc = edmx.Document()
     with open(xml) as f:
         doc.Read(f)
     cls.files["metadata"] = doc
예제 #2
0
def LoadMetadata(path=os.path.join(
    os.path.split(__file__)[0], 'WeatherSchema.xml')):
    """Loads the metadata file from the current directory."""
    doc = edmx.Document()
    with open(path, 'rb') as f:
        doc.Read(f)
    return doc
def main(name_in):
    '''
    Call table creation method on PgSQLEntityContainer extended PySLET OData
    entity container class to get SQL representation of the OData metadata file
    passed as this function’s only argument.
    '''
    doc = edmx.Document()
    with open(name_in, 'rb') as metadata_fh:
        doc.read(metadata_fh)  # would love to be able to cache this but
        # the `doc` object won't pickle
        metadata_fh.seek(0)
    entity_container = doc.root.DataServices[
        os.environ['ODATA_ENTITY_CONTAINER_KEY']]
    if isinstance(entity_container, Schema):
        entity_container = entity_container.EntityContainer[0]
    # we don't define pgsql_options arg here, since the sql won't load directly
    # into a database due to circular constraints (in CDMS anyway)
    container = pgsql_entitycontainer.PgSQLEntityContainer(
        container=entity_container)
    with tempfile.TemporaryFile() as temp_fh:
        # instead we just dump out the sql statements to
        # a file for manual re-ordering
        container.create_all_tables(out=temp_fh)
        # done
        temp_fh.seek(0)
        return temp_fh.read().decode('utf8')
예제 #4
0
 def setUp(self):  # noqa
     path = os.path.join(DATA_DIR, 'blockstore.xml')
     self.doc = edmx.Document()
     with open(path, 'rb') as f:
         self.doc.read(f)
     self.cdef = self.doc.root.DataServices['BlockSchema.BlockContainer']
     self.container = InMemoryEntityContainer(self.cdef)
예제 #5
0
	def __init__(self, name, diagramData = None, doc = None) :
		self.layers = {}
		self.name = name

		if not diagramData :
			self.diagram = dia.new(self.name + ".dia")
			self.data = self.diagram.data
			self.display = self.diagram.display()
		else :
			for diagram in dia.diagrams() :
				if diagram.data == diagramData :
					self.diagram = diagram
			self.data = diagramData
			try:
				self.display = self.diagram.displays[0]
			except:
				self.display = self.diagram.display()
		if doc:
			self.add_document(doc)
		else:
			self.doc = edmx.Document()
			root = self.doc.ChildElement(edmx.Edmx)
			dataservices = root.ChildElement(edmx.DataServices)
			version = dataservices.DataServiceVersion()
			if not version :
				dataservices.SetAttribute("DataServiceVersion","2.0")
		self.add_handlers()
예제 #6
0
def load_metadata(config):
    """Regenerate and load the metadata file and connects the InfluxDBEntityContainer."""
    metadata_filename = config.get('metadata', 'metadata_file')
    influxdb_version = config.getint('metadata', 'influxdb_version')
    try:
        topmax = config.getint('metadata', 'max_items_per_query')
    except:
        topmax = 50

    doc = edmx.Document()
    with open(metadata_filename, 'rb') as f:
        doc.read_from_stream(f)
    container = doc.root.DataServices['InfluxDBSchema.InfluxDB']

    if influxdb_version == 2:
        from influxdbds_v2 import InfluxDBEntityContainer
        conn = dict(config._sections['influxdb2'])
        InfluxDBEntityContainer(container=container,
                                connection=conn,
                                topmax=topmax)
    else:
        from influxdbds import InfluxDBEntityContainer
        dsn = config.get('influxdb', 'dsn')
        InfluxDBEntityContainer(container=container, dsn=dsn, topmax=topmax)

    return doc
예제 #7
0
 def setUp(self):  # noqa
     self.doc = edmx.Document()
     md_path = TEST_DATA_DIR.join('sample_server', 'metadata.xml')
     with md_path.open('rb') as f:
         self.doc.Read(f)
     self.container = self.doc.root.DataServices[
         "SampleModel.SampleEntities"]
예제 #8
0
	def load_metadata(self) :
		"""Loads the metadata file from the current directory."""
		doc = edmx.Document()
		with open(self.config['SERVER_ROOT'] + '/' + self.config['SERVER_NAME'] + '/' + self.config['METADATA'], 'rb') as f:
			doc.Read(f)
		if doc :
			self.metadata = doc
			self.server.SetModel(doc)

		else:
			pass
예제 #9
0
def load_metadata(path=os.path.join(
    os.path.split(__file__)[0], 'fsschema.xml')):
    """Loads the metadata file from the script directory."""
    doc = edmx.Document()
    with open(path, 'rb') as f:
        doc.read(f)
    # next step is to bind our model to it
    container = doc.root.DataServices['FSSchema.FS']
    container['Files'].bind(FSCollection)
    container['Files'].bind_navigation('Files', FSChildren)
    container['Files'].bind_navigation('Parent', FSParent)
    return doc
예제 #10
0
 def setUp(self):  # noqa
     path = os.path.join(DATA_DIR, 'blockstore.xml')
     self.doc = edmx.Document()
     with open(path, 'rb') as f:
         self.doc.read(f)
     self.cdef = self.doc.root.DataServices['BlockSchema.BlockContainer']
     self.container = InMemoryEntityContainer(self.cdef)
     self.mt_lock = threading.Lock()
     self.mt_count = 0
     self.bs = blockstore.EDMBlockStore(entity_set=self.cdef['Blocks'],
                                        max_block_size=64)
     self.ls = blockstore.LockStore(entity_set=self.cdef['BlockLocks'])
예제 #11
0
 def setUp(self):  # noqa
     self.d = FilePath.mkdtemp('.d', 'pyslet-test_blockstore-')
     path = os.path.join(DATA_DIR, 'blockstore.xml')
     self.doc = edmx.Document()
     with open(path, 'rb') as f:
         self.doc.read(f)
     self.cdef = self.doc.root.DataServices['BlockSchema.BlockContainer']
     self.block_size = random.randint(5, 100)
     logging.info("File block size: %i", self.block_size)
     self.f = self.d.join('blockstore.test').open('w+b')
     self.fox = (b"The quick brown fox jumped over the lazy dog " +
                 ul("Caf\xe9").encode('utf-8'))
예제 #12
0
 def import_edmx(self, sFile, diagramData):
     doc = edmx.Document()
     try:
         with open(sFile) as f:
             doc.Read(f)
     except:
         raise TypeError("Must be an Edmx document")
     name = sFile
     self.diagrams[name] = DiaEdmx.DiaEdmx(name, diagramData)
     self.diagrams[name].add_document(doc)
     self.diagrams[name].show()
     return self.diagrams[name]
예제 #13
0
 def setUp(self):  # noqa
     self.cwd = FilePath.getcwd()
     TEST_DATA_DIR.chdir()
     self.doc = edmx.Document()
     md_path = TEST_DATA_DIR.join('sqlds', 'custom.xml')
     with md_path.open('rb') as f:
         self.doc.read(f)
     self.schema = self.doc.root.DataServices['CustomModel']
     self.container = self.doc.root.DataServices[
         "CustomModel.FileContainer"]
     self.d = FilePath.mkdtemp('.d', 'pyslet-test_odata2_sqlds-')
     self.db = CustomisedContainer(file_path=self.d.join('test.db'),
                                   container=self.container)
예제 #14
0
 def setUp(self):  # noqa
     self.cwd = FilePath.getcwd()
     TEST_DATA_DIR.chdir()
     self.doc = edmx.Document()
     md_path = TEST_DATA_DIR.join('sample_server', 'metadata.xml')
     with md_path.open('rb') as f:
         self.doc.read(f)
     self.schema = self.doc.root.DataServices['SampleModel']
     self.container = self.doc.root.DataServices[
         "SampleModel.SampleEntities"]
     self.d = FilePath.mkdtemp('.d', 'pyslet-test_odata2_sqlds-')
     self.db = sqlds.SQLiteEntityContainer(file_path=self.d.join('test.db'),
                                           container=self.container)
예제 #15
0
 def test_valid_metadata_examples(self):
     dpath = os.path.join(TEST_DATA_DIR, 'valid')
     for fName in os.listdir(dpath):
         if fName[-4:] != ".xml":
             continue
         logging.debug("testing valid metadata file %s", fName)
         f = uri.URI.from_path(os.path.join(dpath, fName))
         doc = edmx.Document(base_uri=f)
         doc.read()
         try:
             doc.validate()
         except edm.InvalidMetadataDocument as e:
             self.fail("%s is valid but raised "
                       "InvalidMetadataDocument: %s" % (fName, str(e)))
예제 #16
0
 def parse(xml):
     doc = None
     if isinstance(xml, str):
         doc = edmx.Document()
         try:
             doc.Read(xml)
         except:
             with open(xml) as f:
                 doc.Read(f)
     elif isinstance(xml, Node):
         doc = xml
     else:
         raise Exception("The object is not a valid XML object")
     return doc.root
예제 #17
0
 def test_invalid_metadata_examples(self):
     dpath = os.path.join(TEST_DATA_DIR, 'invalid')
     for fName in os.listdir(dpath):
         if fName[-4:] != ".xml":
             continue
         logging.debug("testing invalid metadata file %s", fName)
         f = uri.URI.from_path(os.path.join(dpath, fName))
         doc = edmx.Document(baseURI=f)
         doc.Read()
         try:
             doc.validate()
             self.fail("%s is invalid but did not raise "
                       "InvalidMetadataDocument" % fName)
         except edm.InvalidMetadataDocument:
             pass
예제 #18
0
파일: mysqldbds.py 프로젝트: saxix/pyslet
    def load_container(self):
        """Loads and returns a default entity container

        The return value is an
        :py:class:`pyslet.odata2.csdl.EntityContainer` instance with
        an EntitySets called 'Blocks', 'Locks' and 'Streams' that are
        suitable for passing to the constructors of
        :py:class:`pyslet.blockstore.BlockStore`,
        :py:class:`pyslet.blockstore.LockStore` and
        :py:class:`pyslet.blockstore.StreamStore`
        respectively."""
        doc = edmx.Document()
        with file(
                os.path.join(os.path.dirname(__file__), 'odata2',
                             'streamstore.xml'), 'r') as f:
            doc.Read(f)
        return doc.root.DataServices['StreamStoreSchema.Container']
예제 #19
0
def load_metadata(config):
    """Regenerate and load the metadata file and connects the PgDBEntityContainer."""
    metadata_filename = config.get('metadata', 'metadata_file')
    dsn = config.get('pgdb', 'dsn')

    doc = edmx.Document()
    with open(metadata_filename, 'rb') as f:
        doc.ReadFromStream(f)
    container = doc.root.DataServices['MyDBSchema.AllOpportunities']
    try:
        topmax = config.getint('pgdb', 'max_items_per_query')
    except:
        topmax = 50
    PgSQLEntityContainer(container=container,
                         dsn=dsn,
                         pgsql_options=DBCONTAINER_ARGS)
    return doc
예제 #20
0
파일: odatadiff.py 프로젝트: saxix/pyslet
def fetch_url(url, username=None, password=None):
    mgr = http.Client()
    url = uri.URI.from_octets(url)
    # does url end with $metadata?
    if url.get_file_name() != "$metadata":
        url = uri.URI.from_octets("$metadata").resolve(url)
    if username:
        cred = auth.BasicCredentials()
        cred.userid = username
        cred.password = password
        cred.protectionSpace = url.get_canonical_root()
        mgr.add_credentials(cred)
    doc = edmx.Document(baseURI=url, reqManager=mgr)
    doc.Read()
    mgr.close()
    if not doc.root.GetBase():
        doc.root.SetBase(url)
    return doc
예제 #21
0
def load_metadata(config):
    """Regenerate and load the metadata file and connects the InfluxDBEntityContainer."""
    metadata_filename = config.get('metadata', 'metadata_file')
    dsn = config.get('influxdb', 'dsn')

    if config.getboolean('metadata', 'autogenerate'):
        logger.info(
            "Generating OData metadata xml file from InfluxDB metadata")
        metadata = generate_metadata(dsn)
        with open(metadata_filename, 'w') as f:
            f.write(metadata)

    doc = edmx.Document()
    with open(metadata_filename, 'r') as f:
        doc.read_from_stream(f)
    container = doc.root.DataServices['InfluxDBSchema.InfluxDB']
    try:
        topmax = config.getint('influxdb', 'max_items_per_query')
    except:
        topmax = 50
    InfluxDBEntityContainer(container=container, dsn=dsn, topmax=topmax)
    return doc
예제 #22
0
def LoadMetadata():
	"""Loads the metadata file from the current directory."""
	doc=edmx.Document()
	with open('MemCacheSchema.xml','rb') as f:
		doc.Read(f)
	return doc
예제 #23
0
 def __init__(self, config):
     self.doc = edmx.Document()
     self.parse_db(config)
     return self.doc
예제 #24
0
def LoadMetadata(path='WeatherSchema.xml'):
    """Loads the metadata file from the current directory."""
    doc = edmx.Document()
    with open(path, 'rb') as f:
        doc.Read(f)
    return doc
예제 #25
0
파일: odatadiff.py 프로젝트: saxix/pyslet
def load_file(filename):
    doc = edmx.Document()
    with open(filename, 'rb') as f:
        doc.Read(f)
    return doc