Exemplo n.º 1
0
def add_shape(self, table_name):

    # Associate the dataset with this celery task so we can check on the task's status
    meta = session.query(ShapeMetadata).get(table_name)
    meta.celery_task_id = self.request.id
    session.commit()

    # Ingest the shapefile
    ShapeETL(meta=meta).import_shapefile()
    return "Finished adding shape dataset {} from {}.".format(meta.dataset_name, meta.source_url)
Exemplo n.º 2
0
def delete_dataset(self, source_url_hash):
    md = session.query(MetaTable).get(source_url_hash)
    try:
        dat_table = Table(
            "dat_%s" % md.dataset_name, Base.metadata, autoload=True, autoload_with=engine, keep_existing=True
        )
        dat_table.drop(engine, checkfirst=True)
    except NoSuchTableError:
        pass
    master_table = MasterTable.__table__
    delete = master_table.delete().where(master_table.c.dataset_name == md.dataset_name)
    conn = engine.contextual_connect()
    try:
        conn.execute(delete)
        session.delete(md)
        session.commit()
    except InternalError, e:
        raise delete_dataset.retry(exc=e)
Exemplo n.º 3
0
def delete_dataset(self, source_url_hash):
    md = session.query(MetaTable).get(source_url_hash)
    try:
        dat_table = Table('dat_%s' % md.dataset_name, Base.metadata, 
            autoload=True, autoload_with=engine, keep_existing=True)
        dat_table.drop(engine, checkfirst=True)
    except NoSuchTableError:
        pass
    master_table = MasterTable.__table__
    delete = master_table.delete()\
        .where(master_table.c.dataset_name == md.dataset_name)
    conn = engine.contextual_connect()
    try:
        conn.execute(delete)
        session.delete(md)
        session.commit()
    except InternalError, e:
        raise delete_dataset.retry(exc=e)
Exemplo n.º 4
0
def delete_shape(self, table_name):
    shape_meta = session.query(ShapeMetadata).get(table_name)
    shape_meta.remove_table(caller_session=session)
    session.commit()
    return "Removed {}".format(table_name)