def set_migration_id(db, mid): try: with db.atomic(): Config.create(id='migration_id', value=mid) except IntegrityError: with db.atomic(): (Config.update(value=mid) .where(Config.id == 'migration_id') .execute())
def set_config(key, value, replace=False): config_value = get_config(key) if config_value is None: db.add(Config(key=key, value=value)) db.commit() return value if config_value != value and replace is True: db.add(Config(key=key, value=value)) db.commit() return value return config_value
def init(): session = DBSession() if session.query(Config).filter().count() == 0: user = USER + ':' + PASSWORD movie_dir_re = os.environ['MOVIE_DIR_RE'] tg_push_on = True if os.environ['TG_ON'] == 'true' else False tg_chatid = os.environ['TG_CHATID'] tg_bot_token = os.environ['TG_BOT_TOKEN'] bark_push_on = True if os.environ['BARK_ON'] == 'true' else False bark_tokens = os.environ['BARK_TOKENS'] server_cyann_on = True if os.environ[ 'SERVER_CYANN'] == 'true' else False server_cyann_token = os.environ['SERVER_CYANN_TOKEN'] proxy_on = False proxy_url = '' config = Config(user=user, root_dir='/mnt/media', movie_dir_re=movie_dir_re, tg_push_on=tg_push_on, tg_chatid=tg_chatid, tg_bot_token=tg_bot_token, bark_push_on=bark_push_on, bark_tokens=bark_tokens, server_cyann_on=server_cyann_on, server_cyann_token=server_cyann_token, proxy_on=proxy_on, proxy_url=proxy_url) session.add(config) session.commit() session.close()
def _get_instances(task, config: ConfigHolder, session: sqlalchemy.orm.Session): if config.manual_query: query = None print( "Manual query chosen. Please fill a query. After finishing the query just end ipython.\n\ Query result must be of type Graph or TaskJobs!") embed() assert query is not None, "query must be filled!" session.add( Config(task=task, value=query.statement(), param="statement")) return query.all() if config.task_id is None: query = session.query(Graph) else: query = session.query(TaskJobs).join(Graph).filter( TaskJobs.task_id == config.task_id) if config.min_n is not None: query = query.filter(Graph.vert_amount >= config.min_n) if config.max_n is not None: query = query.filter(Graph.vert_amount <= config.max_n) if config.min_m is not None: query = query.filter(Graph.edge_amount >= config.min_m) if config.max_m is not None: query = query.filter(Graph.edge_amount <= config.max_m) if config.instance_types: query = query.filter(Graph.i_type.in_(config.instance_types)) if config.max_amount is not None: query = query[:config.max_amount] return query[:]
async def set_mute_role(self, ctx, *, role_name: str): """Set the mute role for the server""" role = discord.utils.get(ctx.guild.roles, name=role_name) if not role: return await ctx.send(":x: I couldn't find that role.") session = self.bot.db.dbsession() try: # Here we go is_mute_setup = session.query(Config).filter_by( guild_id=ctx.guild.id).one() session.close() return await ctx.send( "❌ This server already has a mute role setup.") except: is_mute_setup = None mute_db = Config(guild_id=ctx.guild.id, mute_role_id=role.id) session.merge(mute_db) session.commit() session.close() await ctx.send(f"Successfully set the mute role to {role.name}")
def form_handler(): from database import Config config_text = request.form["name"] config_author = request.form["creator"] config_mutable = request.form["mutable"] config_date = request.form["date"] # Create a new config new_config = Config() new_config.name = config_text new_config.creator = config_author new_config.mutable = config_mutable new_config.date = config_date db.session.add(new_config) db.session.commit() return redirect(url_for("accueil"))
def __init__(self): self.config = Config() self.db = Database() self.device_list = None self.remotes_index = None self._listeners = []
def get_migration_id(db): if 'config' not in db.get_tables(): return 0 return int(Config.get(Config.id == 'migration_id').value)