<s> """<STR_LIT>""" <EOL> import sys <EOL> import logging <EOL> import Bcfg2 . Options <EOL> import Bcfg2 . Server . Plugins <EOL> LOGGER = logging . getLogger ( __name__ ) <EOL> MODELS = [ ] <EOL> INTERNAL_DATABASE_VERSION = None <EOL> class _OptionContainer ( object ) : <EOL> """<STR_LIT>""" <EOL> options = [ Bcfg2 . Options . Common . plugins ] <EOL> @ staticmethod <EOL> def options_parsed_hook ( ) : <EOL> load_models ( ) <EOL> Bcfg2 . Options . get_parser ( ) . add_component ( _OptionContainer ) <EOL> def load_models ( plugins = None ) : <EOL> """<STR_LIT>""" <EOL> from django . db import models <EOL> global MODELS <EOL> if not plugins : <EOL> plugins = Bcfg2 . Options . setup . plugins <EOL> if MODELS : <EOL> for model in MODELS : <EOL> delattr ( sys . modules [ __name__ ] , model ) <EOL> MODELS = [ ] <EOL> for mod in plugins : <EOL> for sym in dir ( mod ) : <EOL> obj = getattr ( mod , sym ) <EOL> if isinstance ( obj , type ) and issubclass ( obj , models . Model ) : <EOL> setattr ( sys . modules [ __name__ ] , sym , obj ) <EOL> MODELS . append ( sym ) <EOL> def internal_database_version ( ) : <EOL> global INTERNAL_DATABASE_VERSION <EOL> if INTERNAL_DATABASE_VERSION is None : <EOL> from django . db import models <EOL> class InternalDatabaseVersion ( models . Model ) : <EOL> """<STR_LIT>""" <EOL> version = models . IntegerField ( ) <EOL> updated = models . DateTimeField ( auto_now_add = True ) <EOL> def __str__ ( self ) : <EOL> return "<STR_LIT>" % ( self . version , <EOL> self . updated . isoformat ( ) ) <EOL> class Meta : <EOL> app_label = "<STR_LIT>" <EOL> get_latest_by = "<STR_LIT:version>" <EOL> INTERNAL_DATABASE_VERSION = InternalDatabaseVersion <EOL> return INTERNAL_DATABASE_VERSION . objects </s>
