def main(): args = parse_args() db.get_engine() type = db.query(AccountType, AccountType.AccountType == args.type).first() with db.begin(): user = db.create(User, Username=args.username, Email=args.email, Passwd=args.password, RealName=args.realname, IRCNick=args.ircnick, PGPKey=args.pgp_key, AccountType=type) if args.ssh_pubkey: pubkey = args.ssh_pubkey.strip() # Remove host from the pubkey if it's there. pubkey = ' '.join(pubkey.split(' ')[:2]) with db.begin(): db.create(SSHPubKey, User=user, PubKey=pubkey, Fingerprint=get_fingerprint(pubkey)) print(user.json()) return 0
async def app_startup(): # https://stackoverflow.com/questions/67054759/about-the-maximum-recursion-error-in-fastapi # Test failures have been observed by internal starlette code when # using starlette.testclient.TestClient. Looking around in regards # to the recursion error has really not recommended a course of action # other than increasing the recursion limit. For now, that is how # we handle the issue: an optional TEST_RECURSION_LIMIT env var # provided by the user. Docker uses .env's TEST_RECURSION_LIMIT # when running test suites. # TODO: Find a proper fix to this issue. recursion_limit = int( os.environ.get("TEST_RECURSION_LIMIT", sys.getrecursionlimit() + 1000)) sys.setrecursionlimit(recursion_limit) backend = aurweb.config.get("database", "backend") if backend not in aurweb.db.DRIVERS: raise ValueError( f"The configured database backend ({backend}) is unsupported. " f"Supported backends: {str(aurweb.db.DRIVERS.keys())}") session_secret = aurweb.config.get("fastapi", "session_secret") if not session_secret: raise Exception("[fastapi] session_secret must not be empty") if not os.environ.get("PROMETHEUS_MULTIPROC_DIR", None): logger.warning("$PROMETHEUS_MULTIPROC_DIR is not set, the /metrics " "endpoint is disabled.") app.mount("/static/css", StaticFiles(directory="web/html/css"), name="static_css") app.mount("/static/js", StaticFiles(directory="web/html/js"), name="static_js") app.mount("/static/images", StaticFiles(directory="web/html/images"), name="static_images") # Add application middlewares. app.add_middleware(AuthenticationMiddleware, backend=BasicAuthBackend()) app.add_middleware(SessionMiddleware, secret_key=session_secret) # Add application routes. def add_router(module): app.include_router(module.router) util.apply_all(APP_ROUTES, add_router) # Initialize the database engine and ORM. get_engine()
def main(): db.get_engine() now = time.utcnow() start = aurweb.config.getint("tuvotereminder", "range_start") filter_from = now + start end = aurweb.config.getint("tuvotereminder", "range_end") filter_to = now + end query = db.query(TUVoteInfo.ID).filter( and_(TUVoteInfo.End >= filter_from, TUVoteInfo.End <= filter_to)) for voteinfo in query: notif = notify.TUVoteReminderNotification(voteinfo.ID) notif.send()
def main(): db.get_engine() action = sys.argv[1] action_map = { 'send-resetkey': ResetKeyNotification, 'welcome': WelcomeNotification, 'comment': CommentNotification, 'update': UpdateNotification, 'flag': FlagNotification, 'adopt': AdoptNotification, 'disown': DisownNotification, 'comaintainer-add': ComaintainerAddNotification, 'comaintainer-remove': ComaintainerRemoveNotification, 'delete': DeleteNotification, 'request-open': RequestOpenNotification, 'request-close': RequestCloseNotification, 'tu-vote-reminder': TUVoteReminderNotification, } with db.begin(): notification = action_map[action](*sys.argv[2:]) notification.send()
def main(): db.get_engine() with db.begin(): _main()
def main(): db.get_engine() run_variable()
def main(force: bool = False): db.get_engine() _main(force)
def main(): db.get_engine() comment_id = int(sys.argv[1]) comment = db.query(PackageComment).filter( PackageComment.ID == comment_id).first() update_comment_render(comment)