def test_update_settings(self): class MySchema(Schema): foo = IntOption() env = {} parser = SchemaConfigParser(MySchema()) update_settings(parser, env) expected_env = { 'FOO': 0, 'SETTINGS_ENCODING': SETTINGS_ENCODING, '__CONFIGGLUE_PARSER__': parser, } self.assertEqual(env, expected_env)
def execute(self): """ Given the command-line arguments, this figures out which subcommand is being run, creates a parser appropriate to that command, and runs it. """ # Preprocess options to extract --settings and --pythonpath. # These options could affect the commands that are available, so they # must be processed early. parser = LaxOptionParser(usage="%prog subcommand [options] [args]", version=django.get_version(), option_list=BaseCommand.option_list) try: configglue_parser = settings.__CONFIGGLUE_PARSER__ parser, options, args = schemaconfigglue(configglue_parser, op=parser, argv=self.argv) # remove schema-related options from the argv list self.argv = args utils.update_settings(configglue_parser, settings) except AttributeError: # no __CONFIGGLUE_PARSER__ found, fall back to standard django # options parsing options, args = parser.parse_args(self.argv) handle_default_options(options) except: # Ignore any option errors at this point. args = self.argv try: subcommand = self.argv[1] except IndexError: sys.stderr.write("Type '%s help' for usage.\n" % self.prog_name) sys.exit(1) if subcommand == 'help': if len(args) > 2: self.fetch_command(args[2]).print_help(self.prog_name, args[2]) else: parser.print_lax_help() sys.stderr.write(self.main_help_text() + '\n') sys.exit(1) # Special-cases: We want 'django-admin.py --version' and # 'django-admin.py --help' to work, for backwards compatibility. elif self.argv[1:] == ['--version']: # LaxOptionParser already takes care of printing the version. pass elif self.argv[1:] == ['--help']: parser.print_lax_help() sys.stderr.write(self.main_help_text() + '\n') else: self.fetch_command(subcommand).run_from_argv(self.argv)
def execute(self): """Override the base class to handle the schema-related options. """ configglue_parser = getattr(settings, '__CONFIGGLUE_PARSER__', None) if configglue_parser is not None: # We need a lax option parser that: # - allows the '%prog subcommand [options] [args]' format # - will receive the schema options from configglue # - doesn't attempt to recognize django options lax_parser = LaxOptionParser( usage="%prog subcommand [options] [args]") parser, options, args = schemaconfigglue( configglue_parser, op=lax_parser, argv=self.argv) utils.update_settings(configglue_parser, settings) # remove schema-related options from the argv list self.argv = args super(GlueManagementUtility, self).execute()
def execute(self): """Override the base class to handle the schema-related options. """ configglue_parser = getattr(settings, '__CONFIGGLUE_PARSER__', None) if configglue_parser is not None: # We need a lax option parser that: # - allows the '%prog subcommand [options] [args]' format # - will receive the schema options from configglue # - doesn't attempt to recognize django options lax_parser = LaxOptionParser( usage="%prog subcommand [options] [args]") parser, options, args = schemaconfigglue(configglue_parser, op=lax_parser, argv=self.argv) utils.update_settings(configglue_parser, settings) # remove schema-related options from the argv list self.argv = args super(GlueManagementUtility, self).execute()
OPENPROXIMITY_CONFIG_FILE=os.environ.get('OPENPROXIMITY_CONFIG_FILE', "/etc/openproximity.conf") if not os.access(OPENPROXIMITY_CONFIG_FILE, os.W_OK): OPENPROXIMITY_CONFIG_FILE=os.path.expanduser("~/.openproximity.conf") # parse config files parser=SchemaConfigParser(schema.OpenProximitySchema()) parser._interpolate = partial(schema._interpolate, parser) parser.read([ os.path.join(__PATH, 'default.cfg'), os.path.join(__PATH, 'django.cfg'), os.path.join(__PATH, 'cherrypy.cfg'), os.path.join(__PATH, 'rpyc.cfg'), os.path.join(__PATH, 'debug.cfg'), OPENPROXIMITY_CONFIG_FILE]) update_settings(parser, locals()) # fix timeout in DATABASE_OPTIONS if 'timeout' in locals()['DATABASE_OPTIONS']: locals()['DATABASE_OPTIONS']['timeout'] = \ float(locals()['DATABASE_OPTIONS']['timeout']) locals()['DEBUG_DISABLES']=locals()['DEBUG_DISABLES'].split(',') # keep a reference to the parser __CONFIGGLUE_PARSER__ = parser if locals()['DEBUG_FILENAME'] == None: locals()['DEBUG_FILENAME'] = sys.argv[-1] def setmode(self, mode):
import schema OPENPROXIMITY_CONFIG_FILE = os.environ.get('OPENPROXIMITY_CONFIG_FILE', "/etc/openproximity2.conf") # parse config files parser = SchemaConfigParser(schema.OpenProximitySchema()) parser._interpolate = partial(schema._interpolate, parser) parser.read([ os.path.join(__PATH, 'default.cfg'), os.path.join(__PATH, 'django.cfg'), os.path.join(__PATH, 'cherrypy.cfg'), os.path.join(__PATH, 'rpyc.cfg'), os.path.join(__PATH, 'debug.cfg'), OPENPROXIMITY_CONFIG_FILE ]) update_settings(parser, locals()) # fix timeout in DATABASE_OPTIONS if 'timeout' in locals()['DATABASE_OPTIONS']: locals()['DATABASE_OPTIONS']['timeout'] = \ float(locals()['DATABASE_OPTIONS']['timeout']) locals()['DEBUG_DISABLES'] = locals()['DEBUG_DISABLES'].split(',') # keep a reference to the parser __CONFIGGLUE_PARSER__ = parser if locals()['DEBUG_FILENAME'] == None: locals()['DEBUG_FILENAME'] = sys.argv[-1]