Example #1
0
    def _test_copy_project(self):

        #transaction = Transaction.get(create=True)
        try:
            os.system('dropdb -U postgres "game_copy"')
            from tactic.command import ProjectTemplateInstallerCmd
            cmd =  ProjectTemplateInstallerCmd(project_code='game_copy', template_code='game', mode='copy')
            cmd.execute()
        

            schema_entry = Search.eval("@GET(sthpw/schema['code','game_copy'].code)", single=True)
            self.assertEquals(schema_entry, 'game_copy')
            project_entry = Search.eval("@GET(sthpw/project['code','game_copy'].code)", single=True)
            self.assertEquals(project_entry, 'game_copy')
            Project.set_project('game_copy')

            widget_config_st = Search.eval("@GET(config/widget_config['code','1GAME'].search_type)", single=True) 
            self.assertEquals(widget_config_st, 'game/ticket')

            widget_config_counts = Search.eval("@COUNT(config/widget_config)") 
            self.assertEquals(widget_config_counts, 133)
            Project.set_project('unittest')
        finally:
            
            sql = DbContainer.get('sthpw')
            sql.do_update("delete from project where code ='game_copy'")
            sql.do_update("delete from schema where code ='game_copy'")
            sql.commit()
            
            DbContainer.close_all()
            os.system('dropdb -U postgres "game_copy"')
Example #2
0
    def execute(my):
        project_code = my.kwargs.get("project_code")
        template_code = my.kwargs.get("template_code")
        project_title = my.kwargs.get("project_title")

        # check to see if the template actually exists

        from tactic.command import ProjectTemplateInstallerCmd
        cmd = ProjectTemplateInstallerCmd(**my.kwargs)
        cmd.execute()
Example #3
0
    def execute(my):
        project_code = my.kwargs.get("project_code")
        template_code = my.kwargs.get("template_code")
        project_title = my.kwargs.get("project_title")

        # check to see if the template actually exists

        from tactic.command import ProjectTemplateInstallerCmd

        cmd = ProjectTemplateInstallerCmd(**my.kwargs)
        cmd.execute()
Example #4
0
    def _test_copy_project(self):

        #transaction = Transaction.get(create=True)
        try:
            os.system('dropdb -U postgres "game_copy"')
            from tactic.command import ProjectTemplateInstallerCmd
            cmd = ProjectTemplateInstallerCmd(project_code='game_copy',
                                              template_code='game',
                                              mode='copy')
            cmd.execute()

            schema_entry = Search.eval(
                "@GET(sthpw/schema['code','game_copy'].code)", single=True)
            self.assertEquals(schema_entry, 'game_copy')
            project_entry = Search.eval(
                "@GET(sthpw/project['code','game_copy'].code)", single=True)
            self.assertEquals(project_entry, 'game_copy')
            Project.set_project('game_copy')

            widget_config_st = Search.eval(
                "@GET(config/widget_config['code','1GAME'].search_type)",
                single=True)
            self.assertEquals(widget_config_st, 'game/ticket')

            widget_config_counts = Search.eval("@COUNT(config/widget_config)")
            self.assertEquals(widget_config_counts, 133)
            Project.set_project('unittest')
        finally:

            sql = DbContainer.get('sthpw')
            sql.do_update("delete from project where code ='game_copy'")
            sql.do_update("delete from schema where code ='game_copy'")
            sql.commit()

            DbContainer.close_all()
            os.system('dropdb -U postgres "game_copy"')
Example #5
0
    def execute(my):
        # This will go to a registered remote server and get the project

        #server_code = my.kwargs.get("server")
        #assert server_code
        ## get the registered server
        #server = Search.get_by_code("sthpw/sync_server", server_code)
        #assert server

        project_code = my.kwargs.get("project_code")
        assert project_code

        version = my.kwargs.get("version")
        if not version:
            version = "1.0.0"

        # build the project names
        template_name = "%s-%s.zip" % (project_code, version)
        data_name = "%s-data-%s.zip" % (project_code, version)
        file_name = "%s-files-%s.zip" % (project_code, version)

        tmp_dir = Environment.get_tmp_dir()
        to_dir = tmp_dir
        to_template_path = "%s/%s-%s.zip" % (to_dir, project_code, version)
        to_data_path = "%s/%s-data-%s.zip" % (to_dir, project_code, version)
        to_file_path = "%s/%s-files-%s.zip" % (to_dir, project_code, version)

        #sync_mode = server.get_value("sync_mode")
        sync_mode = "file"

        if sync_mode == "file":
            base_dir = my.kwargs.get("base_dir")

            from_template_path = "%s/%s" % (base_dir, template_name)
            from_data_path = "%s/%s" % (base_dir, data_name)
            from_file_path = "%s/%s" % (base_dir, file_name)
            to_file_path = from_file_path

            # copy the files
            # ???? why are we copying here?
            shutil.copy(from_template_path, to_template_path)
            shutil.copy(from_data_path, to_data_path)

        else:

            # TEST TEST TEST
            ticket = server.get_value("server")

            remote_server = TacticServerStub(
                protocol='xmlrpc',
                server=server,
                project=project_code,
                #user=user,
                #password=password,
                ticket=ticket,
            )

            class_name = 'tactic.ui.sync.SyncCreateTemplateCmd'
            kwargs = {'project_code': project_code}
            remote_server.execute_cmd(class_name, kwargs)

            base_url = "http://%s/assets/_temp/" % server

            # download and install the files

            from_template_path = "%s/%s_template-%s.zip" % (
                base_url, project_code, version)
            from_data_path = "%s/%s_data-%s.zip" % (base_url, project_code,
                                                    version)

            remote_server.download(from_template_path, to_dir)
            remote_server.download(from_data_path, to_dir)

        # This makes the pretty big assumption that this is an official template
        if not os.path.exists(to_template_path):
            raise Exception("Path [%s] does not exist" % to_template_path)

        template_code = project_code

        try:
            new_project = False

            from tactic.command import ProjectTemplateInstallerCmd

            cmd = ProjectTemplateInstallerCmd(project_code=project_code,
                                              path=to_template_path,
                                              template_code=template_code,
                                              new_project=new_project,
                                              version=version)
            cmd.execute()

            Project.set_project(project_code)
            project = Project.get()

            # NOTE: this avoids breaking on search.py, line 203, where it checks
            # for tables.  The caching mechanism for what tables are in the
            # database need to be refreshed once a template is imported
            from pyasm.search import DatabaseImpl, DbContainer
            DatabaseImpl.clear_table_cache()

            # import from a plugin
            kwargs = {
                #'base_dir': base_dir,
                #'manifest': my.xml.to_string(),
                'code': "%s_data" % project_code,
                'zip_path': to_data_path,
            }

            from tactic.command import PluginInstaller
            cmd = PluginInstaller(**kwargs)
            cmd.execute()

            # create zip of the project files
            if os.path.exists(to_file_path):
                from pyasm.common import ZipUtil
                zip_util = ZipUtil()
                asset_dir = Environment.get_asset_dir()
                to_file_dir = os.path.dirname(to_file_path)
                zip_util.extract(to_file_path, base_dir=asset_dir)

        except Exception, e:
            print "Error: ", str(e)
            raise
Example #6
0
    def execute(self):
        # This will go to a registered remote server and get the project

        #server_code = self.kwargs.get("server")
        #assert server_code
        ## get the registered server
        #server = Search.get_by_code("sthpw/sync_server", server_code)
        #assert server


        project_code = self.kwargs.get("project_code")
        assert project_code

        version = self.kwargs.get("version")
        if not version:
            version = "1.0.0"


        # build the project names
        template_name = "%s-%s.zip" % (project_code, version)
        data_name = "%s-data-%s.zip" % (project_code, version)
        file_name = "%s-files-%s.zip" % (project_code, version)

        tmp_dir = Environment.get_tmp_dir()
        to_dir = tmp_dir
        to_template_path = "%s/%s-%s.zip" % (to_dir, project_code, version)
        to_data_path = "%s/%s-data-%s.zip" % (to_dir, project_code, version)
        to_file_path = "%s/%s-files-%s.zip" % (to_dir, project_code, version)




        #sync_mode = server.get_value("sync_mode")
        sync_mode = "file"

        if sync_mode == "file":
            base_dir = self.kwargs.get("base_dir")

            from_template_path = "%s/%s" % (base_dir, template_name)
            from_data_path = "%s/%s" % (base_dir, data_name)
            from_file_path = "%s/%s" % (base_dir, file_name)
            to_file_path = from_file_path

            # copy the files 
            # ???? why are we copying here?
            shutil.copy(from_template_path, to_template_path)
            shutil.copy(from_data_path, to_data_path)

        else:


            # TEST TEST TEST
            ticket = server.get_value("server")

            remote_server = TacticServerStub(
                protocol='xmlrpc',
                server=server,
                project=project_code,
                #user=user,
                #password=password,
                ticket=ticket,
            )


            class_name = 'tactic.ui.sync.SyncCreateTemplateCmd'
            kwargs = {
                'project_code': project_code
            }
            remote_server.execute_cmd(class_name, kwargs)

            base_url = "http://%s/assets/_temp/" % server


            # download and install the files


            from_template_path = "%s/%s_template-%s.zip" % (base_url, project_code, version)
            from_data_path = "%s/%s_data-%s.zip" % (base_url, project_code, version)

            remote_server.download(from_template_path, to_dir)
            remote_server.download(from_data_path, to_dir)



        # This makes the pretty big assumption that this is an official template
        if not os.path.exists(to_template_path):
            raise Exception("Path [%s] does not exist" % to_template_path)

        template_code = project_code

        try:
            new_project = False

            from tactic.command import ProjectTemplateInstallerCmd

            cmd = ProjectTemplateInstallerCmd(project_code=project_code, path=to_template_path,template_code=template_code, new_project=new_project, version=version)
            cmd.execute()

            Project.set_project(project_code)
            project = Project.get()

            # NOTE: this avoids breaking on search.py, line 203, where it checks
            # for tables.  The caching mechanism for what tables are in the
            # database need to be refreshed once a template is imported
            from pyasm.search import DatabaseImpl, DbContainer
            DatabaseImpl.clear_table_cache()


            # import from a plugin
            kwargs = {
                #'base_dir': base_dir,
                #'manifest': self.xml.to_string(),
                'code': "%s_data" % project_code,
                'zip_path': to_data_path,
            }
     

            from tactic.command import PluginInstaller
            cmd = PluginInstaller(**kwargs)
            cmd.execute()



            # create zip of the project files
            if os.path.exists(to_file_path):
                from pyasm.common import ZipUtil
                zip_util = ZipUtil()
                asset_dir = Environment.get_asset_dir()
                to_file_dir = os.path.dirname(to_file_path)
                zip_util.extract(to_file_path, base_dir=asset_dir)





        except Exception as e:
            print("Error: ", str(e))
            raise
Example #7
0
def install(project_code, path=None, template_code=None):
    cmd = ProjectTemplateInstallerCmd(project_code=project_code, path=path, template_code=template_code)
    Command.execute_cmd(cmd)