Exemplo n.º 1
0
def _set_admin_credentials():
    session = session_factory()
    conf = session.query(ConfigModel).first()
    click.echo(
        "Please choose your admin password (More than 8 characters, space-free)..."
    )

    while True:
        login = input("Admin login: "******"Admin username must contain at least 4 characters")
        elif login != login.strip():
            click.echo("Admin username cannot start or end with spaces")
        else:
            break

    while True:
        password = getpass("Admin password:"******"Password must contain at least 8 characters")
        elif password != password.strip():
            click.echo("Password cannot start or end with spaces")
        else:
            password2 = getpass("Retype password:"******"Passwords do not match")
            else:
                break

    conf.admin_login = login
    conf.admin_hash = hash_password(password)
    session.commit()
    session.close()
    click.echo("Backend initialized")
Exemplo n.º 2
0
    def get_address_by_id(user: AddressBook) -> AddressBook:
        """
        Receives address_id data from the AddressBook object,
        on their basis searches for records in the oc_address table
        and returns them as an AddressBook object.

        :param user: object AddressBook with address_id.
        :return: object AddressBook with data from oc_address table.
        """
        session = session_factory()
        logging.info("Query address entry from oc_address table.")
        query = session.query(Address)
        address = query.filter(Address.address_id == user.address_id).first()
        zone = session.query(
            Zone.name).filter(Zone.zone_id == address.zone_id).first()
        country = session.query(Country.name).filter(
            Country.country_id == address.country_id).first()
        session.close()
        return AddressBook(address_id=address.address_id,
                           first_name=address.firstname,
                           last_name=address.lastname,
                           company=address.company,
                           address_1=address.address_1,
                           address_2=address.address_2,
                           city=address.city,
                           country=country[0],
                           region_state=zone[0])
Exemplo n.º 3
0
 def get_admin_credentials():
     session = session_factory()
     conf = session.query(ConfigModel).first()
     login = conf.admin_login
     hash = conf.admin_hash
     session.close()
     return login, hash
Exemplo n.º 4
0
 def reset_mappings():
     session = session_factory()
     session.query(DMXModel).delete()
     session.query(ArtnetModel).delete()
     session.query(DisabledPixelsModel).delete()
     session.commit()
     session.close()
Exemplo n.º 5
0
 def drop_dic():
     session = session_factory()
     table = session.query(CellTableModel).all()
     for cell in table:
         session.delete(cell)
     session.commit()
     session.close()
Exemplo n.º 6
0
 def set_offset_time_on(offset=0):
     if isinstance(offset, int):
         session = session_factory()
         conf = session.query(ConfigModel).first()
         conf.offset_time_on = offset
         session.commit()
         session.close()
Exemplo n.º 7
0
 def set_forced_off_time(at):
     session = session_factory()
     conf = session.query(ConfigModel).first()
     conf.forced_sunrise = at
     conf.offset_sunrise = 0
     session.commit()
     session.close()
Exemplo n.º 8
0
 def init(self):
     session = session_factory()
     rows = session.query(DimensionsModel).first().rows
     cols = session.query(DimensionsModel).first().cols
     self.mapping = [[[] for c in range(cols)] for r in range(rows)]
     for row in range(rows):
         for col in range(cols):
             artnets = session.query(ArtnetModel).filter_by(
                 row=row, column=col).first()
             if artnets is None:
                 continue
             for dmx_model in artnets.children:
                 dmx_mapping = {}
                 dmx_mapping["universe"] = dmx_model.universe
                 dmx_mapping["dmx"] = dmx_model.address
                 self.mapping[row][col].append(dmx_mapping)
                 universe = dmx_model.universe
                 if universe not in self.frames:
                     # Declare a new universe with 512 DMX addresses = 0
                     self.frames[universe] = [0]*512
     # e.g. universes 4,5 will create universes 0,1,2,3,4,5
     if len(self.frames) == 0:
         raise EnvironmentError("Artnet configuration is not set")
     else:
         self.num_universes = max(self.frames) + 1
     self.dmx = dmx.Controller(
         self.ARTNET_BROADCAST_IP, universes=self.num_universes, fps=self.FPS)
     self.dmx.start()
     self.logger.info("Created {} DMX universes".format(self.num_universes))
Exemplo n.º 9
0
 def set_day_table(dates):
     session = session_factory()
     session.query(SunriseSunset).delete()
     for date in dates:
         session.add(SunriseSunset(date, dates[date]))
         session.commit()
     session.close()
Exemplo n.º 10
0
 def set_sunrise_offset(offset=0):
     session = session_factory()
     conf = session.query(ConfigModel).first()
     conf.forced_sunrise = ""
     conf.offset_sunrise = offset
     session.commit()
     session.close()
Exemplo n.º 11
0
    def get_sunrise_offset():
        session = session_factory()
        conf = session.query(ConfigModel).first()
        offset = conf.offset_sunrise
        session.close()

        return offset
Exemplo n.º 12
0
 def set_enable_state(value):
     # redis.set(SchedulerState.KEY_USABLE, str(value))
     session = session_factory()
     conf = session.query(ConfigModel).first()
     conf.state = value
     session.commit()
     session.close()
Exemplo n.º 13
0
    def add_cell(x, y, mac_address, ind):
        print_flush("Considering {0} at (({1}, {2}), {3})".format(
            mac_address, x, y, ind))
        session = session_factory()
        table = session.query(CellTableModel).all()
        isInTable = False
        for cell in table:
            if (cell.X == x and cell.Y == y):
                print_flush("Found its position : updating mac and ind...")
                isInTable = True
                cell.MacAddress = mac_address
                cell.Ind = ind
            elif (cell.MacAddress == mac_address):
                print_flush("Found its mac : updating position and ind...")
                isInTable = True
                cell.Ind = ind
                cell.X == x
                cell.Y == y
        if (isInTable == False):
            print_flush("Not found : adding to table")
            cell = CellTableModel(x, y, mac_address, ind)
            session.add(cell)
            session.commit()

        session.close()
Exemplo n.º 14
0
 def modify_cell_address(x, y, mac_address):
     session = session_factory()
     table = session.query(CellTableModel).all()
     for cell in table:
         if (cell.X == x and cell.Y == y):
             cell.MacAddress = mac_address
     session.commit()
     session.close()
Exemplo n.º 15
0
 def set_time_off(at):
     session = session_factory()
     conf = session.query(ConfigModel).first()
     conf.time_off = at
     if conf.time_off not in ['sunrise', 'sunset']:
         conf.offset_time_off = 0
     session.commit()
     session.close()
Exemplo n.º 16
0
 def get_pixels_dic():
     session = session_factory()
     table = session.query(CellTableModel).all()
     dic = {}
     for cell in table:
         dic[cell.MacAddress] = ((cell.X, cell.Y), cell.Ind)
     session.close()
     return dic
Exemplo n.º 17
0
 def get_disabled():
     session = session_factory()
     disabled_model = session.query(DisabledPixelsModel).all()
     disabled = []
     for disabled_pixel in disabled_model:
         disabled.append([disabled_pixel.row, disabled_pixel.col])
     session.close()
     return disabled
Exemplo n.º 18
0
    def set_default_scheduled_app_state(app_name, state):
        if app_name not in SchedulerState.get_available_apps():
            raise ValueError('Bad Name')

        session = session_factory()
        app = session.query(FappModel).filter_by(name=app_name).first()
        app.is_scheduled = state
        session.commit()
        session.close()
Exemplo n.º 19
0
 def modify_cell_position(x, y, mac_address):
     session = session_factory()
     table = session.query(CellTableModel).all()
     for cell in table:
         if (cell.MacAddress == mac_address):
             cell.X = x
             cell.Y = y
     session.commit()
     session.close()
Exemplo n.º 20
0
 def set_activated(apps):
     session = session_factory()
     fapps = session.query(FappModel).all()
     for app in fapps:
         if app.name in apps:
             app.activated = True
         else:
             app.activated = False
     session.commit()
     session.close()
Exemplo n.º 21
0
    def check_db():
        if engine.dialect.has_table(engine.connect(), ConfigModel.__tablename__):
            session = session_factory()
            conf = session.query(ConfigModel).first()
            if conf is not None:
                return

        raise ValueError("Arbalet backend database has not been initialized. "
                         "Please run 'docker-compose run --rm app init' before starting the scheduler. "
                         "See INSTALL instructions for more information.")
Exemplo n.º 22
0
 def set_default_drawing(self):
     # Set the current model as the default drawing in database
     session = session_factory()
     try:
         fap = session.query(FappModel).filter_by(name='Drawing').first()
         if not fap:
             return False
         fap.default_params = dumps({"model": self.model.json()})
         session.commit()
     finally:
         session.close()
Exemplo n.º 23
0
def initiate_db_dimensions():
    session = session_factory()
    conf = session.query(DimensionsModel).first()

    if not conf:
        click.echo("No dimensions found, initiating dimensions creation...")
        conf = DimensionsModel()
        session.add(conf)

    session.commit()
    session.close()
Exemplo n.º 24
0
def initiate_db_config():
    session = session_factory()
    conf = session.query(ConfigModel).first()

    if not conf:
        click.echo("No configuration found, initiating config creation...")
        conf = ConfigModel()
        session.add(conf)

    session.commit()
    session.close()
Exemplo n.º 25
0
 def get_day_table():
     session = session_factory()
     dates = session.query(SunriseSunset).all()
     sunset = {}
     for date in dates:
         sunset[date.date] = {
             "sunset": date.sunset,
             "sunrise": date.sunrise
         }
     redis.set(SchedulerState.KEY_DAY_TABLE, json.dumps(sunset))
     session.close()
Exemplo n.º 26
0
def initiate_db_dimensions():
    session = session_factory()
    height, width = 1, 1
    conf = DimensionsModel(height, width)
    session.add(conf)

    # To disable some pixels do this method !
    # dis_pix = DisabledPixelsModel(row, col)
    # session.add(dis_pix)

    session.commit()
    session.close()
Exemplo n.º 27
0
    def get_id_list_from_db():
        """
        Get id's from db.

        :return: list with id's.
        """
        session = session_factory()
        query = session.query(Address.address_id).all()
        session.close()
        id_data = []
        for data in query:
            id_data.append(data[0])
        return sorted(id_data)
Exemplo n.º 28
0
    def get_default_scheduled_app_params(app_name, serialized=True):
        session = session_factory()
        try:
            fap = session.query(FappModel).filter_by(name=app_name).first()
            if not fap:
                return False

            fap_dict = to_dict(fap)
            if serialize:
                return serialize(fap_dict)
            else:
                return fap_dict
        finally:
            session.close()
Exemplo n.º 29
0
    def get_default_scheduled_apps(serialized=False):
        # Get model form DB
        apps = []
        session = session_factory()
        for f in session.query(FappModel).filter_by(is_scheduled=True).all():
            if serialized:
                apps.append(serialize(to_dict(f)))
            else:
                app = to_dict(f)
                app['default_params'] = json.loads(app['default_params'])
                apps.append(app)

        session.close()
        return apps
Exemplo n.º 30
0
    def get_salt_by_email(user: PersonalDetails) -> Password:
        """
        Take email data from PersonalDetails object, on its basis,
        make a request to the database and return the value of the salt.

        :param user: PersonalDetails object with email data.
        :return: Password object with salt data.
        """
        session = session_factory()
        logging.info("Query customer's salt from oc_customer table.")
        query = session.query(Customer.salt)
        data = query.filter(Customer.email == user.email).first()
        session.close()
        return Password(salt=data.salt)