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")
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])
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
def reset_mappings(): session = session_factory() session.query(DMXModel).delete() session.query(ArtnetModel).delete() session.query(DisabledPixelsModel).delete() session.commit() session.close()
def drop_dic(): session = session_factory() table = session.query(CellTableModel).all() for cell in table: session.delete(cell) session.commit() session.close()
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()
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()
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))
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()
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()
def get_sunrise_offset(): session = session_factory() conf = session.query(ConfigModel).first() offset = conf.offset_sunrise session.close() return offset
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()
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()
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()
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()
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
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
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()
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()
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()
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.")
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()
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()
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()
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()
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()
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)
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()
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
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)