Beispiel #1
0
 def get_tools(self):
     project_name = get_project_name()
     toolbox = []
     for i in pkg_resources.iter_entry_points("turbogears.toolboxcommand"):
         tool = i.load()
         args = {
             'path': i.name,
             'label': getattr(tool, '__label__', i.name),
             'description': getattr(tool, '__doc__', ''),
             'version': getattr(tool, '__version__', ''),
             'author': getattr(tool, '__author__', ''),
             'email': getattr(tool, '__email__', ''),
             'copyright': getattr(tool, '__copyright__', ''),
             'license': getattr(tool, '__license__', ''),
             'icon': self.tool_icon(tool),
             'disabled': False}
         if project_name or not getattr(tool, 'need_project', False):
             try:
                 setattr(self, i.name, tool())
             except Exception, e:
                 args["description"] = str(e) or 'Tool could not be loaded.'
                 args["disabled"] = 'disabled'
         else:
             args["description"] += '\nNeeds project.'
             args["disabled"] = 'disabled'
         toolbox.append(args)
Beispiel #2
0
 def index(self):
     self.register_static_directory()
     self.model = self.get_model_name()
     model_exists = None
     if self.model:
         model_exists = 1
     return dict(model_exists=model_exists,
                 session_file_exists=self.session_exists(),
                 session_list=self.load_session_list(),
                 model_name=get_project_name())
Beispiel #3
0
 def index(self):
     self.register_static_directory()
     self.model = self.get_model_name()
     model_exists = None
     if self.model:
         model_exists = 1
     return dict(model_exists=model_exists,
         session_file_exists = self.session_exists(),
         session_list = self.load_session_list(),
         model_name=get_project_name())
Beispiel #4
0
 def save_and_create_(self, code, order):
     model_path = os.path.join(get_project_name(), 'tmp2_model.py')
     model_path = os.path.abspath(model_path)
     open(model_path, 'w').write(str)
     package = __import__(get_package_name(), {}, {}, ["tmp2_model"])
     package.tmp2_model.Persona.createTable(ifNotExists=True)
     model = self.get_model_name()
     model.Persona = package.tmp2_model.Persona
     # pk = package.model
     # import tmp_model as pk
     # pk.Persona.createTable(ifNotExists=True)
     return dict(status='Tables ok')
 def save_and_create_(self, code, order):
     model_path = os.path.join(get_project_name(), 'tmp2_model.py')
     model_path = os.path.abspath(model_path)
     open(model_path, 'w').write(str)
     package = __import__(get_package_name(), {}, {}, ['tmp2_model'])
     package.tmp2_model.Persona.createTable(ifNotExists=True)
     model = self.get_model_name()
     model.Persona = package.tmp2_model.Persona
     # pk = package.model
     # import tmp_model as pk
     # pk.Persona.createTable(ifNotExists=True)
     return dict(status='Tables ok')
Beispiel #6
0
    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)
Beispiel #7
0
 def get_model_name(self):
     if not get_project_name():
         return False
     return get_model()
Beispiel #8
0
 def get_model_name(self):
     if not get_project_name():
         return False
     return get_model()
 def index(self):
     return dict(model_exists=bool(self.model),
         session_file_exists=self.session_exists(),
         session_list=self.load_session_list(),
         model_name=get_project_name())
Beispiel #10
0
 def index(self):
     return dict(toolbox = self.arrange_in_pairs(self.toolbox),
         project = get_project_name())
Beispiel #11
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('turbogears.command'):
        command = entrypoint.load()
        commands[entrypoint.name] = (command.desc, entrypoint)
    from turbogears import __version__

    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:""" % (__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 args[0] not in commands:
        _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 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(__version__)
    command.run()