예제 #1
0
 def exists(self):
     session = get_session()
     engine = get_session().get_bind()
     try:
         ins = sqlalchemy.inspect(engine)
         exists_ = ins.dialect.has_table(engine.connect(), self.table_name)
     except Exception:
         exists_ = False
     finally:
         session.close()
     return exists_
예제 #2
0
    def _query(self, collection, time=None, time_components=None):
        """
        https://stackoverflow.com/questions/8603088/sqlalchemy-in-clause
        """
        self.update()
        start, end = parse_time(time, time_components)

        session = get_session()
        try:
            if len(collection) > 1:
                query_ = (
                    f"SELECT * FROM {self.table_name} WHERE ds_id IN {tuple(collection)} "
                    f"and end_time>='{start}' and start_time<='{end}'")

            else:
                query_ = (
                    f"SELECT * FROM {self.table_name} WHERE ds_id='{collection[0]}' "
                    f"and end_time>='{start}' and start_time<='{end}'")
            result = session.execute(query_).fetchall()

        except Exception:
            result = []
        finally:
            session.close()
        records = {}
        for row in result:
            if row.ds_id not in records:
                records[row.ds_id] = []
            records[row.ds_id].append(row.path)
        return records
예제 #3
0
파일: test_dblog.py 프로젝트: tlvu/pywps
    def setUp(self):

        self.database = configuration.get_config_value('logging', 'database')

        #self.tempfile_db = tempfile.mktemp(prefix="pywps-db", suffix=".sqlite")
        #self.database = "sqlite://{}".format(self.tempfile_db)
        self.session = get_session()
        assert self.session
예제 #4
0
    def test_db_content(self):
        session = get_session()
        null_time_end = session.query(ProcessInstance).filter(ProcessInstance.time_end == None)
        self.assertEqual(null_time_end.count(), 0,
                         'There are no unfinished processes loged')

        null_status = session.query(ProcessInstance).filter(ProcessInstance.status == None)
        self.assertEqual(null_status.count(), 0,
                         'There are no processes without status loged')

        null_percent = session.query(ProcessInstance).filter(ProcessInstance.percent_done == None)
        self.assertEqual(null_percent.count(), 0,
                         'There are no processes without percent loged')
예제 #5
0
    def test_db_content(self):
        session = get_session()
        null_time_end = session.query(ProcessInstance).filter(
            ProcessInstance.time_end == None)
        self.assertEqual(null_time_end.count(), 0,
                         'There are no unfinished processes loged')

        null_status = session.query(ProcessInstance).filter(
            ProcessInstance.status == None)
        self.assertEqual(null_status.count(), 0,
                         'There are no processes without status loged')

        null_percent = session.query(ProcessInstance).filter(
            ProcessInstance.percent_done == None)
        self.assertEqual(null_percent.count(), 0,
                         'There are no processes without percent loged')
예제 #6
0
    def to_db(self):
        df = self.intake_catalog.load()
        # workaround for NaN values when no time axis (fx datasets)
        df = df.fillna({"start_time": MIN_DATETIME, "end_time": MAX_DATETIME})

        # needed when catalog created from catalog_maker instead of above - can remove the above eventually
        df = df.replace({"start_time": {"undefined": MIN_DATETIME}})
        df = df.replace({"end_time": {"undefined": MAX_DATETIME}})

        df = df.set_index("ds_id")

        # db connection
        session = get_session()
        try:
            df.to_sql(
                self.table_name,
                session.connection(),
                if_exists="replace",
                index=True,
                chunksize=500,
            )
            session.commit()
        finally:
            session.close()
예제 #7
0
 def test_0_dblog(self):
     """Test pywps.formats.Format class
     """
     session = get_session()
     self.assertTrue(session)
예제 #8
0
 def test_0_dblog(self):
     """Test pywps.formats.Format class
     """
     session = get_session()
     self.assertTrue(session)