def __init__(self, version): self.hostlist = ['127.0.0.1', '::1', '::ffff:127.0.0.1'] parser = optparse.OptionParser( usage="%prog toolbox [options]", version="%prog " + version) parser.add_option("-n", "--no-open", help="don't open browser automatically", dest="noopen", action="store_true", default=False) parser.add_option("-c", "--add-client", help="allow client ip address specified to connect to toolbox" " (can be specified more than once)", dest="host", action="append", default=None) parser.add_option("-p", "--port", help="port to run the Toolbox on", dest="port", default=7654) parser.add_option("--config", help="config file", dest="config", default=self.config or get_project_config()) options, args = parser.parse_args(sys.argv[1:]) self.port = int(options.port) self.noopen = options.noopen self.config = options.config if options.host: self.hostlist = self.hostlist + options.host turbogears.widgets.load_widgets()
def __init__(self, version): self.hostlist = ['127.0.0.1', '::1'] parser = optparse.OptionParser( usage="%prog toolbox [options]", version='%prog ' + version) parser.add_option('-n', '--no-open', help="don't open browser automatically", dest='noopen', action='store_true', default=False) parser.add_option('-c', '--add-client', help="allow client ip address specified to connect to toolbox" " (can be specified more than once)", dest='host', action='append', default=None) parser.add_option('-p', '--port', help="port to run the Toolbox on", dest='port', default=7654) parser.add_option('--config', help="config file to use", dest='config', default=self.config or get_project_config()) options, args = parser.parse_args(sys.argv[1:]) self.port = int(options.port) self.noopen = options.noopen self.config = options.config if options.host: self.hostlist = self.hostlist + options.host widgets.load_widgets()
def run(self): """Run the sqlobject-admin tool or sacommand module functions.""" if not '--egg' in sys.argv and not get_project_name(): print "This doesn't look like a TurboGears project." return else: command = sys.argv[1] if config.get('sqlalchemy.dburi'): try: sacommand(command, sys.argv) except NoApplicableMethods: sacommand('help', []) return try: from sqlobject.manager import command as socommand except ImportError: from turbogears.util import missing_dependency_error print missing_dependency_error('SQLObject') return if command not in no_connection_param: if self.dburi: print "Using database URI %s" % self.dburi sys.argv.insert(2, self.dburi) sys.argv.insert(2, '-c') else: print ("Database URI not specified in the config file" " (%s).\nPlease be sure it's on the command line." % (self.config or get_project_config())) if command not in no_model_param: if not '--egg' in sys.argv: eggname = glob.glob('*.egg-info') if not eggname or not os.path.exists( os.path.join(eggname[0], 'sqlobject.txt')): eggname = self.fix_egginfo(eggname) eggname = eggname[0].replace('.egg-info', '') if not '.' in sys.path: sys.path.append('.') pkg_resources.working_set.add_entry('.') sys.argv.insert(2, eggname) sys.argv.insert(2, '--egg') socommand.the_runner.run(sys.argv)
def run(self): """Executes the sqlobject-admin code.""" if not "--egg" in sys.argv and not turbogears.util.get_project_name(): print "This don't look like a TurboGears project." return else: command = sys.argv[1] if config.get("sqlalchemy.dburi"): try: sacommand(command, sys.argv) except dispatch.interfaces.NoApplicableMethods: sacommand("help", []) return try: from sqlobject.manager import command as socommand except ImportError: print "Error: SQLObject not installed." return if command not in no_connection_param: if self.dburi: print "Using database URI %s" % self.dburi sys.argv.insert(2, self.dburi) sys.argv.insert(2, "-c") else: print ("Database URI not specified in the config file" " (%s).\nPlease be sure it's on the command line." % (self.config or get_project_config())) if command not in no_model_param: if not "--egg" in sys.argv: eggname = glob.glob("*.egg-info") if not eggname or not os.path.exists( os.path.join(eggname[0], "sqlobject.txt")): eggname = self.fix_egginfo(eggname) eggname = eggname[0].replace(".egg-info", "") if not "." in sys.path: sys.path.append(".") pkg_resources.working_set.add_entry(".") sys.argv.insert(2, eggname) sys.argv.insert(2, "--egg") socommand.the_runner.run(sys.argv)
def main(): """Main command runner. Manages the primary command line arguments.""" # add commands defined by entrypoints commands = {} for entrypoint in pkg_resources.iter_entry_points("turbogears.command"): command = entrypoint.load() commands[entrypoint.name] = (command.desc, entrypoint) def _help(): """Custom help text for tg-admin.""" print """ TurboGears %s command line interface Usage: %s [options] <command> Options: -c CONFIG --config=CONFIG Config file to use -e EGG_SPEC --egg=EGG_SPEC Run command on given Egg Commands:""" % (turbogears.__version__, sys.argv[0]) longest = max([len(key) for key in commands.keys()]) format = "%" + str(longest) + "s %s" commandlist = commands.keys() commandlist.sort() for key in commandlist: print format % (key, commands[key][0]) parser = optparse.OptionParser() parser.allow_interspersed_args = False parser.add_option("-c", "--config", dest="config") parser.add_option("-e", "--egg", dest="egg") parser.print_help = _help options, args = parser.parse_args(sys.argv[1:]) # if command is not found display help if not args or not commands.has_key(args[0]): _help() sys.exit() commandname = args[0] # strip command and any global options from the sys.argv sys.argv = [sys.argv[0]] + args[1:] command = commands[commandname][1] command = command.load() if options.egg: egg = pkg_resources.get_distribution(options.egg) os.chdir(egg.location) if hasattr(command,"need_project"): if not turbogears.util.get_project_name(): print "This command needs to be run from inside a project directory" return elif not options.config and not os.path.isfile(get_project_config()): print """No default config file was found. If it has been renamed use: tg-admin --config=<FILE> %s""" % commandname return command.config = options.config command = command(turbogears.__version__) command.run()