Exemplo n.º 1
0
    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

        gearshift.widgets.load_widgets()
Exemplo n.º 2
0
    def run(self):
        """Run the sqlobject-admin tool or functions from the sacommand module."""

        if not "--egg" in sys.argv and not gearshift.util.get_project_name():
            print "This doesn't look like a GearShift project."
            return
        else:
            command = sys.argv[1]

            if config.get("sqlalchemy.dburi"):
                try:
                    sacommand(command, sys.argv)
                except Exception:  # NoApplicableMethods:
                    # Anonymous except to avoid making entire
                    # gearshift dependent on peak.rules just to get
                    # this ONE case of NoApplicableMethods...
                    sacommand("help", [])
                return

            try:
                from sqlobject.manager import command
            except ImportError:
                from gearshift.util import missing_dependency_error
                print missing_dependency_error('SQLObject')
                return

            sqlobjcommand = command
            if sqlobjcommand 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 sqlobjcommand 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")

            command.the_runner.run(sys.argv)
Exemplo n.º 3
0
    def run(self):
        """Run the sqlobject-admin tool or functions from the sacommand module."""

        if not "--egg" in sys.argv and not gearshift.util.get_project_name():
            print "This doesn't look like a GearShift project."
            return
        else:
            command = sys.argv[1]

            if config.get("sqlalchemy.dburi"):
                try:
                    sacommand(command, sys.argv)
                except Exception: # NoApplicableMethods:
                    # Anonymous except to avoid making entire
                    # gearshift dependent on peak.rules just to get
                    # this ONE case of NoApplicableMethods...
                    sacommand("help", [])
                return

            try:
                from sqlobject.manager import command
            except ImportError:
                from gearshift.util import missing_dependency_error
                print missing_dependency_error('SQLObject')
                return

            sqlobjcommand = command
            if sqlobjcommand 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 sqlobjcommand 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")

            command.the_runner.run(sys.argv)
Exemplo n.º 4
0
    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

        gearshift.widgets.load_widgets()
Exemplo n.º 5
0
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("gearshift.command"):
        command = entrypoint.load()
        commands[entrypoint.name] = (command.desc, entrypoint)

    def _help():
        """Custom help text for tg-admin."""

        print """
GearShift %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:""" % (gearshift.__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 gearshift.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(gearshift.__version__)
    command.run()
Exemplo n.º 6
0
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("gearshift.command"):
        command = entrypoint.load()
        commands[entrypoint.name] = (command.desc, entrypoint)

    def _help():
        """Custom help text for tg-admin."""

        print """
GearShift %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:""" % (gearshift.__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 gearshift.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(gearshift.__version__)
    command.run()