Commit a97b009a authored by Jay's avatar Jay Committed by jay
Browse files

Support ISIS serial number generation out of a database.

parent fb46729d
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@ source = autocnet
omit =
    autocnet/fileio/ControlNetFileV0002_pb2.py
    autocnet/vis/graph_view.py
    autocnet/fileio/sqlalchemy_json/*
exclude_lines =
    pragma: no cover
    def __repr__
+9 −0
Original line number Diff line number Diff line
import os

__version__ = "0.1.0"

_ROOT = os.path.abspath(os.path.dirname(__file__))


def get_data(path):
    return os.path.join(_ROOT, 'data', path)
+57 −0
Original line number Diff line number Diff line
from sqlalchemy import Column, Integer, String, create_engine, orm
from sqlalchemy.ext import declarative

from autocnet.fileio.sqlalchemy_json.alchemy import NestedJsonObject

Base = declarative.declarative_base()


def setup_db_session(db):
    """
    Add a database session object to the root namespace

    Parameters
    ----------
    db : str
         Database name

    Returns
    -------
     : object
       A SQLAlchemy session object
    """
    engine = create_engine('sqlite:///{}'.format(db))
    Base.metadata.bind = engine
    Base.metadata.create_all()
    return orm.sessionmaker(bind=engine)()


class Translations(Base):  # pragma: no cover
    """
    Table mapping for the ISIS Translation file table
    """
    __tablename__ = 'isis_translations'
    id = Column(Integer, primary_key=True)
    mission = Column(String)
    instrument = Column(String)
    translation = Column(NestedJsonObject)

    def __init__(self, mission, instrument, translation):
        self.mission = mission
        self.instrument = instrument
        self.translation = translation


class StringToMission(Base):  # pragma: no cover
    """
    Table mapping for the ISIS mission name cleaner table
    """
    __tablename__ = 'isis_mission_to_standard'
    id = Column(Integer, primary_key=True)
    key = Column(String)
    value = Column(String)

    def __init__(self, key, value):
        self.key = key
        self.value = value
+10 −0
Original line number Diff line number Diff line
Copyright (c) 2014, Elmer de Looff <elmer.delooff@gmail.com>
All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+7 −0
Original line number Diff line number Diff line
from .alchemy import NestedJsonObject, NestedMutable, JsonObject

__all__ = (
    'NestedJsonObject',
    'NestedMutable',
    'JsonObject'
)
Loading