<s> from __future__ import unicode_literals <EOL> import logging <EOL> import sqlalchemy as sa <EOL> from h . db import Base <EOL> log = logging . getLogger ( __name__ ) <EOL> FEATURES = { <EOL> '<STR_LIT>' : "<STR_LIT>" , <EOL> '<STR_LIT>' : "<STR_LIT>" , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> FEATURES_PENDING_REMOVAL = { <EOL> '<STR_LIT>' : "<STR_LIT>" , <EOL> '<STR_LIT>' : "<STR_LIT>" , <EOL> } <EOL> class Feature ( Base ) : <EOL> """<STR_LIT>""" <EOL> __tablename__ = '<STR_LIT>' <EOL> id = sa . Column ( sa . Integer , autoincrement = True , primary_key = True ) <EOL> name = sa . Column ( sa . Text ( ) , nullable = False , unique = True ) <EOL> everyone = sa . Column ( sa . Boolean , <EOL> nullable = False , <EOL> default = False , <EOL> server_default = sa . sql . expression . false ( ) ) <EOL> admins = sa . Column ( sa . Boolean , <EOL> nullable = False , <EOL> default = False , <EOL> server_default = sa . sql . expression . false ( ) ) <EOL> staff = sa . Column ( sa . Boolean , <EOL> nullable = False , <EOL> default = False , <EOL> server_default = sa . sql . expression . false ( ) ) <EOL> @ property <EOL> def description ( self ) : <EOL> return FEATURES [ self . name ] <EOL> @ classmethod <EOL> def all ( cls ) : <EOL> """<STR_LIT>""" <EOL> results = [ ] <EOL> for name in FEATURES : <EOL> feat = cls . query . filter ( cls . name == name ) . first ( ) <EOL> if feat is None : <EOL> feat = cls ( name = name ) <EOL> cls . query . session . add ( feat ) <EOL> results . append ( feat ) <EOL> return results <EOL> @ classmethod <EOL> def remove_old_flags ( cls ) : <EOL> """<STR_LIT>""" <EOL> known = set ( FEATURES ) | set ( FEATURES_PENDING_REMOVAL ) <EOL> unknown_flags = cls . query . filter ( sa . not_ ( cls . name . in_ ( known ) ) ) <EOL> count = unknown_flags . delete ( synchronize_session = False ) <EOL> if count > <NUM_LIT:0> : <EOL> log . info ( '<STR_LIT>' , count ) <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' . format ( f = self ) </s>
