Exemple #1
0
    def get_by_path(self, path):
        ''' Get a dictionary containing the fields that belong to
            a project with a specific path.

            path: str (valid path)
                Path for requested project.
        '''
        con = self._get_connection()
        con.row_factory = sqlite3.Row
        cur = con.cursor()
        sql = 'SELECT * from 01-codes WHERE projpath=?'

        cur.execute(sql, (path, ))
        matched_projects = []
        for row in cur:
            matched_projects.append({
                'id': row['id'],
                'projectname': row['projectname'],
                'version': row['version'],
                'description': row['description'],
                'modified': row['modified'],
                'projpath': row['projpath'],
                'active': row['active']
            })

        cur.close()

        if len(matched_projects) < 1:
            print "Error project not found:", path
        # This should never happen!
        elif len(matched_projects) > 1:
            print "Error: Non-unique project ID:"
            print_dict(matched_projects)
        else:
            return matched_projects[0]
    def get_by_path(self, path):
        ''' Get a dictionary containing the fields that belong to
            a project with a specific path.

            path: str (valid path)
                Path for requested project.
        '''
        con = self._get_connection()
        con.row_factory = sqlite3.Row
        cur = con.cursor()
        sql = 'SELECT * from projects WHERE projpath=?'

        cur.execute(sql, (path,))
        matched_projects = []
        for row in cur:
            matched_projects.append({
                'id': row['id'],
                'projectname': row['projectname'],
                'version':     row['version'],
                'description': row['description'],
                'modified':    row['modified'],
                'projpath':    row['projpath'],
                'active':      row['active']
            })

        cur.close()

        if len(matched_projects) < 1:
            print "Error project not found:", path
        # This should never happen!
        elif len(matched_projects) > 1:
            print "Error: Non-unique project ID:"
            print_dict(matched_projects)
        else:
            return matched_projects[0]
    def test_conmin(self):
        div = '-'*70
        
        print div
        print 'LOAD PROJECT'
        path = os.path.dirname(os.path.abspath(__file__))
        self.cserver.load_project(os.path.join(path,'simple_1.proj'))
            
        print div
        print 'CHECK FILES (note paraboloid.py defining Paraboloid)'
        print_dict(self.cserver.get_files())
        
        print div
        print 'IMPORT PARABOLOID'
        self.cserver.onecmd('from paraboloid import Paraboloid')

        print div
        print 'WORKING TYPES'
        print_dict(self.cserver.get_workingtypes())

        print div
        print 'CREATE ASSEMBLY'
        print self.cserver.add_component('prob','openmdao.main.assembly.Assembly','');
        
        print div
        print 'COMPONENTS'
        print_json(self.cserver.get_components())
        
        print div
        print 'ADD CONMIN DRIVER'
        print self.cserver.add_component('driver',
           'openmdao.lib.drivers.conmindriver.CONMINdriver','prob');
        
        print div
        print 'CHECK DRIVER ATTRIBUTES'
        print_json(self.cserver.get_attributes('prob.driver'))

        print div
        print 'CREATE PARABOLOID'
        self.cserver.add_component('p','Paraboloid','prob');
        
        print div
        print 'COMPONENTS'
        print_json(self.cserver.get_components())

        print div
        print 'STRUCTURE'
        print print_json(self.cserver.get_structure('prob'))

        print div
        print 'dir()'
        print self.cserver.onecmd('dir()')
Exemple #4
0
    def get(self, project_id):
        ''' Get a dictionary containing the fields for a project id.

            project_id: int
                Unique id for requested project.
        '''

        con = self._get_connection()
        con.row_factory = sqlite3.Row
        cur = con.cursor()
        sql = 'SELECT * from 01-codes WHERE id=%d' % int(project_id)

        cur.execute(sql)
        matched_projects = []
        for row in cur:
            matched_projects.append({
                'id': row['id'],
                'projectname': row['projectname'],
                'version': row['version'],
                'description': row['description'],
                'modified': row['modified'],
                'created': row['created'],
                'projpath': row['projpath'],
                'active': row['active']
            })

        cur.close()

        if len(matched_projects) < 1:
            print "Error project ID not found:", id

        # This should never happen!
        elif len(matched_projects) > 1:
            print "Error: Non-unique project ID:"
            print_dict(matched_projects)
        else:
            return matched_projects[0]
    def get(self, project_id):
        ''' Get a dictionary containing the fields for a project id.
        
        project_id: int
            unique id for requested project.
        '''
        
        con = self._get_connection()
        con.row_factory = sqlite3.Row
        cur = con.cursor()  
        sql = 'SELECT * from projects WHERE id=%d' % int(project_id)

        cur.execute(sql)
        matched_projects = []
        for row in cur:
            matched_projects.append({
                'id': row['id'],
                'projectname': row['projectname'],
                'version':     row['version'],
                'description': row['description'],
                'modified':    row['modified'],
                'created':     row['created'],
                'filename':    row['filename'],
                'active':      row['active']
            })
            
        cur.close()
        
        if len(matched_projects) < 1:
            print "Error project ID not found:", id
            
        # This should never happen!
        elif len(matched_projects) > 1:
            print "Error: Non-unique project ID:"
            print_dict(matched_projects)
        else:
            return matched_projects[0]
def run_cserver():
    """ create a ZMQ-based console server & exercise it
    """
    server_id = "ConsoleServer"
    classpath = "openmdao.gui.consoleserver.ConsoleServer"
    mgr = ZMQServerManager(classpath)
    cserver = mgr.server(server_id)
    if cserver is not None:
        print "=============================================================="
        print "================= started cserver ============================"
        print "=============================================================="
        # print cserver.onecmd("!!!!!!!!!!!!!!!!!!!  I'm Alive   !!!!!!!!!!!!!")
        print cserver.getcwd()
        # print 'types:'
        # print cserver.get_available_types()

        print "=============================================================="
        print "================= redirecting streams ========================"
        print "=============================================================="
        # subscriber to the cserver output & print to stdout
        out_url = mgr.get_out_socket_url(server_id)
        out_rdr = OutStreamRedirector("CSERVER OUT", out_url, "cserver.out")
        out_rdr.start()

        pub_url = mgr.get_pub_socket_url(server_id)
        pub_rdr = OutStreamRedirector("CSERVER PUB", pub_url, "cserver.pub")
        pub_rdr.start()

        time.sleep(5)  # give them time to start up

        print "=============================================================="
        print "================ load project ================================"
        print "=============================================================="
        path = os.path.dirname(os.path.abspath(__file__))
        proj_file = os.path.join(path, "sellar.proj")
        print cserver.load_project(proj_file)
        print_dict(cserver.get_files())

        print "=============================================================="
        print "================ import from  file ==========================="
        print "=============================================================="
        print cserver.onecmd("from sellar_CO import SellarCO")
        print_dict(cserver.get_workingtypes())
        # print cserver.onecmd('trace')

        print "=============================================================="
        print "=============== execute script to set up the problem ========="
        print "=============================================================="
        script = """
top = SellarCO()
top.z1_t = 5.0
top.dis1.z1 = 5.0
top.dis2.z1 = 5.0

top.z2_t = 2.0
top.dis1.z2 = 2.0
top.dis2.z2 = 2.0

top.x1_t = 1.0
top.dis1.x1 = 1.0

top.y1_t = 3.16
top.y2_t = 0.0
top.dis1.y2 = 0.0
top.dis2.y1 = 3.16
"""
        cserver.onecmd(script)
        # print cserver.onecmd('trace')

        print cserver.onecmd("print dir(top)")
        print_json(cserver.get_structure(""))
        print_json(cserver.get_workflow("top"))
        print cserver.get_value("top.dis1.z1")
        print cserver.get_value("top.dis1.z2")
        print cserver.get_value("top.dis1.x1")

        print "=============================================================="
        print "================= register published vars and run ============"
        print "=============================================================="
        cserver.onecmd("top.register_published_vars(['dis1.z1', 'dis1.z2', 'dis1.x1'])")
        cserver.run()

        print "=============================================================="
        print "================ get results ================================="
        print "=============================================================="
        print cserver.onecmd("trace")
        print cserver.get_value("top.dis1.z1")
        print cserver.get_value("top.dis1.z2")
        print cserver.get_value("top.dis1.x1")

        print "=============================================================="
        print "================ delete server ==============================="
        print "=============================================================="
        time.sleep(15)  # give it time to finish
        mgr.delete_server(server_id)
        out_rdr.terminate()
        pub_rdr.terminate()
Exemple #7
0
def run_cserver():
    ''' create a ZMQ-based console server & exercise it
    '''
    server_id = 'ConsoleServer'
    classpath = 'openmdao.gui.consoleserver.ConsoleServer'
    mgr = ZMQServerManager(classpath)
    cserver = mgr.server(server_id)
    if cserver is not None:
        print '=============================================================='
        print '================= started cserver ============================'
        print '=============================================================='
        #print cserver.onecmd("!!!!!!!!!!!!!!!!!!!  I'm Alive   !!!!!!!!!!!!!")
        print cserver.getcwd()
        #print 'types:'
        #print cserver.get_available_types()

        print '=============================================================='
        print '================= redirecting streams ========================'
        print '=============================================================='
        # subscriber to the cserver output & print to stdout
        out_url = mgr.get_out_socket_url(server_id)
        out_rdr = OutStreamRedirector('CSERVER OUT', out_url, 'cserver.out')
        out_rdr.start()

        pub_url = mgr.get_pub_socket_url(server_id)
        pub_rdr = OutStreamRedirector('CSERVER PUB', pub_url, 'cserver.pub')
        pub_rdr.start()

        time.sleep(5)  # give them time to start up

        print '=============================================================='
        print '================ load project ================================'
        print '=============================================================='
        path = os.path.dirname(os.path.abspath(__file__))
        proj_file = os.path.join(path, 'sellar.proj')
        print cserver.load_project(proj_file)
        print_dict(cserver.get_files())

        print '=============================================================='
        print '================ import from  file ==========================='
        print '=============================================================='
        print cserver.onecmd('from sellar_CO import SellarCO')
        print_dict(cserver.get_workingtypes())
        #print cserver.onecmd('trace')

        print '=============================================================='
        print '=============== execute script to set up the problem ========='
        print '=============================================================='
        script = """
top = SellarCO()
top.z1_t = 5.0
top.dis1.z1 = 5.0
top.dis2.z1 = 5.0

top.z2_t = 2.0
top.dis1.z2 = 2.0
top.dis2.z2 = 2.0

top.x1_t = 1.0
top.dis1.x1 = 1.0

top.y1_t = 3.16
top.y2_t = 0.0
top.dis1.y2 = 0.0
top.dis2.y1 = 3.16
"""
        cserver.onecmd(script)
        #print cserver.onecmd('trace')

        print cserver.onecmd('print dir(top)')
        print_json(cserver.get_structure(''))
        print_json(cserver.get_workflow('top'))
        print cserver.get_value('top.dis1.z1')
        print cserver.get_value('top.dis1.z2')
        print cserver.get_value('top.dis1.x1')

        print '=============================================================='
        print '================= register published vars and run ============'
        print '=============================================================='
        cserver.onecmd(
            "top.register_published_vars(['dis1.z1', 'dis1.z2', 'dis1.x1'])")
        cserver.run()

        print '=============================================================='
        print '================ get results ================================='
        print '=============================================================='
        print cserver.onecmd('trace')
        print cserver.get_value('top.dis1.z1')
        print cserver.get_value('top.dis1.z2')
        print cserver.get_value('top.dis1.x1')

        print '=============================================================='
        print '================ delete server ==============================='
        print '=============================================================='
        time.sleep(15)  # give it time to finish
        mgr.delete_server(server_id)
        out_rdr.terminate()
        pub_rdr.terminate()