Beispiel #1
0
def autocrud(nodes, name, modelFQN):

    model = reflect.namedObject(modelFQN)

    schema = [a for a in dir(model) if isinstance(getattr(model, a), PropertyColumn)]

    if "id" not in schema:
        print "Sorry, this code isn't clever enough to auto-crud models with no id"
        return

    listCols = ["id"]
    if "name" in schema:
        listCols.append("name")

    crudCols = schema[:]
    crudCols.remove("id")

    if "name" in crudCols:
        crudCols.remove("name")
        crudCols.insert(0, "name")

    listColumns = ", ".join('"%s"' % c for c in listCols)
    crudColumns = textwrap.fill(", ".join('"%s"' % c for c in crudCols))

    nodeContent = crudTemplate % {
        "listColumns": listColumns,
        "crudColumns": crudColumns,
        "model": modelFQN.rsplit(".", 1)[1],
        "node": name,
    }

    skeleton.createNode(nodes, name, createIndex=False, nodeContent=nodeContent)
Beispiel #2
0
def node(options, name):
    "Create a new node"
    from warp.tools import skeleton
    nodes = getSiteDir(options).child('nodes')
    if not nodes.exists():
        print 'Please run this from a Warp site directory'
        return
    skeleton.createNode(nodes, name)
Beispiel #3
0
    def makeService(self, options):

        siteDir = FilePath(options['siteDir'])

        if options.subCommand == "skeleton":
            print "Creating skeleton..."
            from warp.tools import skeleton
            skeleton.createSkeleton(siteDir)
            raise SystemExit

        elif options.subCommand == "node":
            nodes = siteDir.child("nodes")
            if not nodes.exists():
                print "Please run this from a Warp site directory"
                raise SystemExit

            from warp.tools import skeleton
            skeleton.createNode(nodes, options.subOptions['name'])
            raise SystemExit

        sys.path.insert(0, siteDir.path)

        configModule = __import__('warpconfig')
        config = configModule.config
        runtime.config.update(config)
        runtime.config['siteDir'] = siteDir
        runtime.config['warpDir'] = FilePath(runtime.__file__).parent()
        store.setupStore(config)
        translate.loadMessages()

        if hasattr(configModule, 'startup'):
            configModule.startup()


        if options.subCommand == "console":
            import code
            locals = {'store': runtime.store}
            c = code.InteractiveConsole(locals)
            c.interact()
            raise SystemExit


        factory = site.WarpSite(resource.WarpResourceWrapper())
        service = internet.TCPServer(config["port"], factory)

        if hasattr(configModule, 'mungeService'):
            service = configModule.mungeService(service)

        return service
Beispiel #4
0
def autocrud(nodes, name, modelFQN):

    model = reflect.namedObject(modelFQN)

    schema = [
        a for a in dir(model) if isinstance(getattr(model, a), PropertyColumn)
    ]

    if 'id' not in schema:
        print "Sorry, this code isn't clever enough to auto-crud models with no id"
        return

    listCols = ["id"]
    if 'name' in schema:
        listCols.append("name")

    crudCols = schema[:]
    crudCols.remove('id')

    if 'name' in crudCols:
        crudCols.remove('name')
        crudCols.insert(0, 'name')

    listColumns = ", ".join('"%s"' % c for c in listCols)
    crudColumns = textwrap.fill(", ".join('"%s"' % c for c in crudCols))

    nodeContent = crudTemplate % {
        'listColumns': listColumns,
        'crudColumns': crudColumns,
        'model': modelFQN.rsplit('.', 1)[1],
        'node': name
    }

    skeleton.createNode(nodes,
                        name,
                        createIndex=False,
                        nodeContent=nodeContent)
Beispiel #5
0
    def makeService(self, options):

        siteDir = FilePath(options['siteDir'])

        sys.path.insert(0, siteDir.path)

        if options.subCommand == "skeleton":
            print "Creating skeleton..."
            from warp.tools import skeleton
            skeleton.createSkeleton(siteDir)
            raise SystemExit

        configModule = reflect.namedModule(options['config'])
        config = configModule.config
        runtime.config.update(config)
        runtime.config['siteDir'] = siteDir
        runtime.config['warpDir'] = FilePath(runtime.__file__).parent()
        store.setupStore()
        translate.loadMessages()

        if options.subCommand == "node":
            nodes = siteDir.child("nodes")
            if not nodes.exists():
                print "Please run this from a Warp site directory"
                raise SystemExit

            from warp.tools import skeleton
            skeleton.createNode(nodes, options.subOptions['name'])
            raise SystemExit

        elif options.subCommand == 'crud':
            nodes = siteDir.child("nodes")
            if not nodes.exists():
                print "Please run this from a Warp site directory"
                raise SystemExit

            from warp.tools import autocrud
            autocrud.autocrud(nodes, options.subOptions['name'], options.subOptions['model'])
            raise SystemExit

        elif options.subCommand == 'adduser':
            from warp.tools import adduser
            adduser.addUser()
            raise SystemExit


        factory = site.WarpSite(resource.WarpResourceWrapper())
        runtime.config['warpSite'] = factory

        if hasattr(configModule, 'startup'):
            configModule.startup()

        if options.subCommand == "console":
            import code
            locals = {'store': runtime.store}
            c = code.InteractiveConsole(locals)
            c.interact()
            raise SystemExit

        if options.subCommand == 'command':
            obj = reflect.namedObject(options.subOptions['fqn'])
            if options.subOptions['args']:
                obj(*options.subOptions['args'])
            else:
                obj()
            raise SystemExit

        if config.get('ssl'):
            from warp.webserver import sslcontext
            service = internet.SSLServer(config['port'], factory,
                                         sslcontext.ServerContextFactory())
        else:
            service = internet.TCPServer(config["port"], factory)

        if hasattr(configModule, 'mungeService'):
            service = configModule.mungeService(service)

        return service
Beispiel #6
0
    def makeService(self, options):

        siteDir = FilePath(options['siteDir'])

        sys.path.insert(0, siteDir.path)

        if options.subCommand == "skeleton":
            print "Creating skeleton..."
            from warp.tools import skeleton
            skeleton.createSkeleton(siteDir)
            raise SystemExit

        configModule = reflect.namedModule(options['config'])
        config = configModule.config
        runtime.config.update(config)
        runtime.config['siteDir'] = siteDir
        runtime.config['warpDir'] = FilePath(runtime.__file__).parent()
        store.setupStore()
        translate.loadMessages()

        if options.subCommand == "node":
            nodes = siteDir.child("nodes")
            if not nodes.exists():
                print "Please run this from a Warp site directory"
                raise SystemExit

            from warp.tools import skeleton
            skeleton.createNode(nodes, options.subOptions['name'])
            raise SystemExit

        elif options.subCommand == 'crud':
            nodes = siteDir.child("nodes")
            if not nodes.exists():
                print "Please run this from a Warp site directory"
                raise SystemExit

            from warp.tools import autocrud
            autocrud.autocrud(nodes, options.subOptions['name'],
                              options.subOptions['model'])
            raise SystemExit

        elif options.subCommand == 'adduser':
            from warp.tools import adduser
            adduser.addUser()
            raise SystemExit

        factory = site.WarpSite(resource.WarpResourceWrapper())
        runtime.config['warpSite'] = factory

        if hasattr(configModule, 'startup'):
            configModule.startup()

        if options.subCommand == "console":
            import code
            locals = {'store': runtime.store}
            c = code.InteractiveConsole(locals)
            c.interact()
            raise SystemExit

        if options.subCommand == 'command':
            obj = reflect.namedObject(options.subOptions['fqn'])
            obj()
            raise SystemExit

        if config.get('ssl'):
            from warp.webserver import sslcontext
            service = internet.SSLServer(config['port'], factory,
                                         sslcontext.ServerContextFactory())
        else:
            service = internet.TCPServer(config["port"], factory)

        if hasattr(configModule, 'mungeService'):
            service = configModule.mungeService(service)

        return service