Beispiel #1
0
def import_bootstrap():
    print "Importing bootstrap ..."
    vendor = "SQLServer"

    impl = DatabaseImpl.get(vendor)
    impl.create_database("sthpw")


    upgrade_dir = Environment.get_upgrade_dir()

    for category in ['bootstrap', 'sthpw', 'config']:
        f = open("%s/%s/%s_schema.sql" % (upgrade_dir, vendor.lower(), category) )
        data = f.read()
        f.close()

        data = data.split(";")

        cmds = []
        for cmd in data:
            cmd = cmd.strip()
            if cmd == '':
                continue
            cmds.append(cmd)

        from pyasm.search import DbContainer
        sql = DbContainer.get("sthpw")
        for cmd in cmds:
            sql.do_update(cmd)
Beispiel #2
0
def import_bootstrap():
    print "Importing bootstrap ..."
    vendor = "MySQL"

    impl = DatabaseImpl.get(vendor)
    impl.create_database("sthpw")

    upgrade_dir = Environment.get_upgrade_dir()

    for category in ['bootstrap', 'sthpw', 'config']:
        f = open("%s/%s/%s_schema.sql" %
                 (upgrade_dir, vendor.lower(), category))
        data = f.read()
        f.close()

        data = data.split(";")

        cmds = []
        for cmd in data:
            cmd = cmd.strip()
            if cmd == '':
                continue
            cmds.append(cmd)

        from pyasm.search import DbContainer
        sql = DbContainer.get("sthpw")
        for cmd in cmds:
            sql.do_update(cmd)
Beispiel #3
0
    def database_exists(my):
        '''returns whether a database exists for this project'''
        if not my.get_value("code"):
            return False

        db_resource = my.get_project_db_resource()
        impl = DatabaseImpl.get()
        return impl.database_exists(db_resource)
Beispiel #4
0
    def database_exists(my):
        '''returns whether a database exists for this project'''
        if not my.get_value("code"):
            return False

        db_resource = my.get_project_db_resource()
        impl = DatabaseImpl.get()
        return impl.database_exists(db_resource)
Beispiel #5
0
    def init_cache(my):
        from pyasm.search import DatabaseImpl, DbContainer
        my.caches = {}

        data = {}
        for table in my.tables:
            column_data = DatabaseImpl.get().get_column_info(my.database, table)
            data[table] = column_data
        my.caches['data'] = data

        # get the order columns
        columns = {}
        sql = DbContainer.get(my.database)
        for table in my.tables:
            column_list = sql.get_columns(table)
            columns[table] = column_list

        my.caches = {}
        my.caches['data'] = data
        my.caches['columns'] = columns
Beispiel #6
0
    def load_bootstrap(my):
        impl = DatabaseImpl.get()
        exists = impl.database_exists("sthpw")
        print "exists: ", exists

        vendor = impl.get_database_type()

        if not exists:
            print "Running bootstrap"

            install_dir = Environment.get_install_dir()
            python = Config.get_value("services", "python")
            if not python:
                python = "python"

            # create the database and inject the bootstrap data
            impl.create_database("sthpw")

            cmd = "%s %s/src/pyasm/search/upgrade/%s/bootstrap_load.py" % (python, install_dir, vendor.lower())
            os.system(cmd)
Beispiel #7
0
    def load_bootstrap(my):
        impl = DatabaseImpl.get()
        exists = impl.database_exists("sthpw")
        print "exists: ", exists

        vendor = impl.get_database_type()

        if not exists:
            print "Running bootstrap"

            install_dir = Environment.get_install_dir()
            python = Config.get_value("services", "python")
            if not python:
                python = "python"

            # create the database and inject the bootstrap data
            impl.create_database("sthpw")

            cmd = "%s %s/src/pyasm/search/upgrade/%s/bootstrap_load.py" % (
                python, install_dir, vendor.lower())
            os.system(cmd)
Beispiel #8
0
    def init_cache(my):
        from pyasm.search import DatabaseImpl, DbContainer
        my.caches = {}

        data = {}
        for table in my.tables:
            column_data = DatabaseImpl.get().get_column_info(
                my.database, table)
            data[table] = column_data
        my.caches['data'] = data

        # get the order columns
        columns = {}
        sql = DbContainer.get(my.database)
        for table in my.tables:
            column_list = sql.get_columns(table)
            columns[table] = column_list

        my.caches = {}
        my.caches['data'] = data
        my.caches['columns'] = columns
Beispiel #9
0
def import_bootstrap():
    print "Importing bootstrap ..."
    vendor = "PostgreSQL"

    plugin_dir = Environment.get_plugin_dir()
    sys.path.insert(0, plugin_dir)

    impl = DatabaseImpl.get(vendor)
    impl.create_database("sthpw")


    upgrade_dir = Environment.get_upgrade_dir()

    for category in ['bootstrap', 'sthpw', 'config']:
        f = open("%s/%s/%s_schema.sql" % (upgrade_dir, vendor.lower(), category) )
        data = f.read()
        f.close()

        data = data.split(";")

        cmds = []
        for cmd in data:
            lines = cmd.split("\n")
            lines2 = []
            for line in lines:
                if line.startswith("--"):
                    continue
                lines2.append(line)
            cmd = "\n".join(lines2)

            cmd = cmd.strip()
            if cmd == '':
                continue
            cmds.append(cmd)

        from pyasm.search import DbContainer, DbResource
        sql = DbContainer.get("sthpw")
        for cmd in cmds:
            sql.do_update(cmd)
Beispiel #10
0
def import_bootstrap():
    print "Importing bootstrap ..."
    vendor = "PostgreSQL"

    plugin_dir = Environment.get_plugin_dir()
    sys.path.insert(0, plugin_dir)

    impl = DatabaseImpl.get(vendor)
    impl.create_database("sthpw")

    upgrade_dir = Environment.get_upgrade_dir()

    for category in ['bootstrap', 'sthpw', 'config']:
        f = open("%s/%s/%s_schema.sql" %
                 (upgrade_dir, vendor.lower(), category))
        data = f.read()
        f.close()

        data = data.split(";")

        cmds = []
        for cmd in data:
            lines = cmd.split("\n")
            lines2 = []
            for line in lines:
                if line.startswith("--"):
                    continue
                lines2.append(line)
            cmd = "\n".join(lines2)

            cmd = cmd.strip()
            if cmd == '':
                continue
            cmds.append(cmd)

        from pyasm.search import DbContainer
        sql = DbContainer.get("sthpw")
        for cmd in cmds:
            sql.do_update(cmd)
Beispiel #11
0
    def execute(self, install_db=True, install_defaults=False, database_type='PostgresSQL', port_num='5432'):
        self.tactic_base_dir = None
        self.tactic_data_base_dir = None
        self.tactic_install_dir = None
        self.tmp_dir = None
        self.tactic_site_dir = None
        self.tactic_apache_user = '******'
        self.apache_conf_path = None
        self.database_type = database_type
        self.port_num = port_num

        self.backup_msg = None
        self.non_default_install = False
        project_code = "sthpw"
        project_type = "sthpw"

        self.print_header()

        # verification
        try:
            if install_db:
                self.check_db_program()

                self.check_db_exists(project_code)
            # install the necessary files to python directory
            self.install_to_python(install_defaults)
        
        except InstallException as e:
            print("Error: %s" %e.__str__())
            print()
            print("Exiting...")
            print()
            sys.exit(2)

        self.update_tactic_configs()

        # check modules
        try:
            import tacticenv
        except ImportError:
            print('Error: Failed to "import tacticenv"')
            return
        self.check_modules(install_db)

        # create the asset_dir
        from pyasm.common import Environment
        asset_dir = Environment.get_asset_dir()
        if not os.path.exists(asset_dir):
            os.makedirs(asset_dir)



        # check that the main directories exists
        install_dir = os.getenv("TACTIC_INSTALL_DIR")
        data_dir = os.getenv("TACTIC_DATA_DIR")
        if not os.path.exists(install_dir):
            print("Environment variable TACTIC_INSTALL_DIR '%s' does not exist" % install_dir)
            return
        if not os.path.exists(data_dir):
            print("Environment variable TACTIC_DATA_DIR '%s' does not exist" % data_dir)
            return


        # create the dist folder
        dist_dir = Environment.get_dist_dir()
        if not os.path.exists(dist_dir):
            os.makedirs(dist_dir)




        self.create_temp_directory()

        self.change_directory_ownership()

        self.install_win32_service()


        if install_db == False:
            print("TACTIC setup successful.  Next, the TACTIC database needs to be configured.")
            return

        # dynamically load modules now that we know where they are
        from pyasm.search import DatabaseImpl, DbContainer

        # create the sthpw database
        database = DatabaseImpl.get()

     

        # check if database exists
        print("Creating database '%s' ..." % project_code)
        print()

        db_exists = False
        from pyasm.search import DatabaseException
        try:
            if database.database_exists(project_code):
                print("... already exists. Please remove first")
                raise InstallException("Database '%s' already exists" % project_code)
                db_exists = True
        except DatabaseException as e:
            pass
            
        if not db_exists:
            # create the database
            database.create_database(project_code)

        # import the default schema
        database.import_schema(project_code, project_type)

        # import the default data
        database.import_default_data(project_code, project_type)

        # add the default user (admin)
        self.run_sql('''
      
        --add in admin group
INSERT INTO login_group (login_group, description)
VALUES ('admin', 'Site Administration');

        --add in admin user, default password 'tactic'
INSERT INTO "login" ("login", "password", "upn", first_name, last_name)
VALUES ('admin', '39195b0707436a7ecb92565bf3411ab1', 'admin', 'Admin', '');

        --add the admin user to the admin group
INSERT INTO login_in_group ("login", login_group) VALUES ('admin', 'admin');
        ''')


        # add in the necessary triggers for email notification
        self.run_sql('''
        --register notification
INSERT INTO notification (code, description, "type", search_type, event)
VALUES ('asset_attr_change', 'Attribute Changes For Assets', 'email', 'prod/asset', 'update|prod/asset');
INSERT INTO notification (code, description, "type", search_type, event)
VALUES ('shot_attr_change', 'Attribute Changes For Shots', 'email', 'prod/shot', 'update|prod/shot');
        ''')

       
        print("Upgrading the database schema in quiet mode...")
        print()

        from pyasm.search.upgrade import Upgrade
        from pyasm.security import Batch


         
        Batch()
        version = self.get_version()
        version.replace('.', '_')
        upgrade = Upgrade(version, is_forced=True, project_code=None, quiet=True)
        upgrade.execute()
        #print(os.system('python \"%s/src/bin/upgrade_db.py\" -f -q -y'%install_dir))

        print()
        print()
        print("*** Installation of TACTIC completed at [%s] ***" %self.tactic_base_dir)
        print()
        print()
        #if self.backup_msg:
        #    print(self.backup_msg)

        if os.name != 'nt':
            print("Next, please install the Apache Web Server and then copy the Apache config extension [%s] to the Apache web server config area. e.g. /etc/httpd/conf.d/"%self.apache_conf_path)

        else:
            print("Next, please install the Apache Web Server and then copy the Apache config extension [%s] to the Apache web server config area. e.g. C:/Program Files/Apache Software Foundation/Apache2.2/conf/"%self.apache_conf_path)
    
        print()
        print("Depending on the OS, you may need to add the following line to the main config file [httpd.conf] shipped with Apache as well:")


        print()
        if os.name == 'nt':
            print("Include conf/tactic_win32.conf")
        else:
            print("Include conf.d/*.conf")
        print()
Beispiel #12
0
        my.create_temp_directory()

        my.change_directory_ownership()

        my.install_win32_service()


        if install_db == False:
            print "TACTIC setup successful.  Next, the TACTIC database needs to be configured."
            return

        # dynamically load modules now that we know where they are
        from pyasm.search import DatabaseImpl, DbContainer

        # create the sthpw database
        database = DatabaseImpl.get()

     

        # check if database exists
        print "Creating database '%s' ..." % project_code
        print

        db_exists = False
        from pyasm.search import DatabaseException
        try:
            if database.database_exists(project_code):
                print "... already exists. Please remove first"
                raise InstallException("Database '%s' already exists" % project_code)
                db_exists = True
        except DatabaseException, e:
Beispiel #13
0
    def test_postgres(my, vendor):
        web = WebContainer.get_web()

        defaults = DEFAULTS[vendor]

        default_server = defaults['server']
        default_port = defaults['port']
        default_user = defaults['user']
        default_password = defaults['password']

        server = web.get_form_value("server")
        if not server:
            server = default_server
        port = web.get_form_value("port")
        if not port:
            port = default_port
        else:
            port = int(port)
        user = web.get_form_value("user")
        if not user:
            user = default_user
        password = web.get_form_value("password")
        if not password:
            password = default_password


        # Need to access remote database
        create = False
        impl = DatabaseImpl.get(vendor)
        exists = impl.database_exists("sthpw", host=server, port=port)

        if not create:
            if not exists:
                my.info['error'] = "Database [sthpw] does not exist.  This is required for TACTIC to function."

                return

        else:
            print "Running bootstrap"

            install_dir = Environment.get_install_dir()
            python = Config.get_value("services", "python")
            if not python:
                python = "python"

            # create the database and inject the bootstrap data
            impl.create_database("sthpw", host=server, port=port)

            cmd = "%s %s/src/pyasm/search/upgrade/%s/bootstrap_load.py" % (python, install_dir, vendor.lower())
            os.system(cmd)




        from pyasm.search import Sql
        sql = Sql("sthpw", server, user, password=password, vendor=vendor, port=port)
        try:
            # attempt
            sql.connect()
            sql.do_query("select id from transaction_log limit 1")
        except Exception, e:
            my.info['error'] = "Could not connect to database with (vendor=%s, server=%s, user=%s, port=%s)" % (vendor, server, user, port)
            my.info['message'] = str(e)
            print e
Beispiel #14
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
Beispiel #15
0
    def import_template(my):

        if my.path:
            base_dir = os.path.dirname(my.path)
        else:
            base_dir = Environment.get_template_dir()

        version = my.kwargs.get("version")
        if version:
            template_dir = "%s/%s-%s" % (base_dir, my.template_code, version)
        else:
            template_dir = "%s/%s" % (base_dir, my.template_code)

        template_dir = my.get_template_dir(template_dir)

        # if the directory does not exist then look for a zip file
        use_zip = False
        if not os.path.exists(template_dir):
            template_zip = "%s.zip" % (template_dir)
            if os.path.exists(template_zip):
                use_zip = True
            else:
                hint = "Please check if you have created the Template already using the Update button in the Template Project view."
                if version:
                    raise TacticException(
                        "No template found for [%s] version [%s]. %s" %
                        (my.template_code, version, hint))
                else:
                    raise TacticException("No template found for [%s]. %s" %
                                          (my.template_code, hint))

        # check to see if the database exists in the default
        # database implementation
        from pyasm.search import DbContainer, DatabaseImpl
        impl = DatabaseImpl.get()
        exists = impl.database_exists(my.project_code)

        # if the database already exists, then raise an exception
        if exists and my.new_project:
            msg = "WARNING: Database [%s] already exists" % my.project_code
            print msg
            raise TacticException(msg)

        # this is the overriding factor:
        if my.is_template == True:
            title = Common.get_display_title(my.project_code)
        elif my.is_template == False:
            title = Common.get_display_title(my.project_code)
        elif my.is_template == None:
            # these 2 is for old usage using the command line script create_template.py
            if my.template_project_code != my.project_code:
                my.is_template = False
                title = Common.get_display_title(my.project_code)
            else:
                my.is_template = True
                title = Common.get_display_title(my.template_project_code)

        # create a new project if this was desired
        if my.new_project == True:
            from create_project_cmd import CreateProjectCmd
            project_image_path = my.kwargs.get("project_image_path")

            # the project_type will get updated properly by the PluginInstaller
            # but that break the ties to the project_type entry created though,
            # which is ok
            creator = CreateProjectCmd(project_code=my.project_code,
                                       project_title=title,
                                       project_type=my.template_project_code,
                                       is_template=my.is_template,
                                       use_default_side_bar=False,
                                       project_image_path=project_image_path)
            creator.execute()

        # set the project
        Project.set_project(my.project_code)

        # import from a plugin
        if use_zip:
            kwargs = {'zip_path': template_zip, 'code': my.project_code}

        else:
            kwargs = {'plugin_dir': template_dir}

        kwargs['filter_line_handler'] = my.filter_line_handler
        kwargs['filter_sobject_handler'] = my.filter_sobject_handler

        from plugin import PluginCreator, PluginInstaller
        installer = PluginInstaller(**kwargs)
        installer.execute()
Beispiel #16
0
    def execute(my):
        error_list = []
        from pyasm.biz import Project
        Project.clear_cache()

        sthpw_search = Search("sthpw/project")
        sthpw_search.add_filter('code', 'sthpw')
        sthpw_search.set_show_retired(True)
        sthpw_proj = sthpw_search.get_sobject()

        search = Search("sthpw/project")
        if my.project_code:
            search.add_filter("code", my.project_code)
        else:
            #search.add_enum_order_by("type", ['sthpw','prod','game','design','simple', 'unittest'])
            search.add_enum_order_by("code", ['sthpw'])
        projects = search.get_sobjects()

        project_codes = SObject.get_values(projects, 'code')
        # append sthpw project in case it's retired
        if 'sthpw' not in project_codes and sthpw_proj:
            if not my.project_code:
                projects.insert(0, sthpw_proj)
            sthpw_proj.reactivate()

        current_dir = os.getcwd()
        tmp_dir = Environment.get_tmp_dir()
        output_file = '%s/upgrade_output.txt' % tmp_dir
        if not os.path.exists(tmp_dir):
            os.makedirs(tmp_dir)
        elif os.path.exists(output_file):
            os.unlink(output_file)
        ofile = open(output_file, 'w')

        import datetime
        ofile.write('Upgrade Time: %s\n\n' % datetime.datetime.now())

        # dynamically generate
        #sql = DbContainer.get(code)
        database_type = Sql.get_default_database_type()
        #if database_type in ['Sqlite', 'MySQL']:
        if database_type != "PostgreSQL":
            # general an upgrade
            import imp

            namespaces = ['default', 'simple', 'sthpw', 'config']
            for namespace in namespaces:
                if database_type == 'Sqlite':
                    from pyasm.search.upgrade.sqlite import convert_sqlite_upgrade
                    file_path = convert_sqlite_upgrade(namespace)
                elif database_type == 'MySQL':
                    from pyasm.search.upgrade.mysql import convert_mysql_upgrade
                    file_path = convert_mysql_upgrade(namespace)
                elif database_type == 'SQLServer':
                    from pyasm.search.upgrade.sqlserver import convert_sqlserver_upgrade
                    file_path = convert_sqlserver_upgrade(namespace)
                elif database_type == 'Oracle':
                    file_path = convert_oracle_upgrade(namespace)
                else:
                    raise Exception("Database type not implemented here")

                (path, name) = os.path.split(file_path)
                (name, ext) = os.path.splitext(name)
                (file, filename, data) = imp.find_module(name, [path])
                module = imp.load_module(name, file, filename, data)

                class_name = "%s%sUpgrade" % (database_type,
                                              namespace.capitalize())
                exec("%s = module.%s" % (class_name, class_name))

        # load all the default modules
        from pyasm.search.upgrade.project import *

        for project in projects:

            code = project.get_code()
            if code == "sthpw":
                type = "sthpw"
            else:
                type = project.get_type()

            if not type:
                type = 'default'

            if not my.quiet:
                print project.get_code(), type
                print "-" * 30

            # if the project is admin, the just ignore for now
            if code == 'admin':
                continue

            if not project.database_exists():
                ofile.write("*" * 80 + '\n')
                msg = "Project [%s] does not have a database\n" % project.get_code(
                )
                ofile.write(msg)
                print msg
                ofile.write("*" * 80 + '\n\n')
                continue

            upgrade = None

            if database_type != 'PostgreSQL':
                upgrade_class = "%s%sUpgrade" % (database_type,
                                                 type.capitalize())
                conf_upgrade = eval("%sConfigUpgrade()" % database_type)
            else:
                upgrade_class = "%sUpgrade" % type.capitalize()
                conf_upgrade = eval("ConfigUpgrade()")
            upgrade = eval("%s()" % upgrade_class)

            # upgrade config (done for every project but sthpw)
            conf_upgrade.set_project(project.get_code())
            conf_upgrade.set_to_version(my.to_version)
            conf_upgrade.set_forced(my.is_forced)
            conf_upgrade.set_quiet(my.quiet)
            conf_upgrade.set_confirmed(my.is_confirmed)
            conf_upgrade.execute()

            # append the errors for each upgrade
            key = '%s|%s' % (project.get_code(),
                             conf_upgrade.__class__.__name__)
            error_list.append((conf_upgrade.__class__.__name__, project.get_code(), \
                Container.get_seq(key)))

            # perform the upgrade to the other tables
            if upgrade:
                upgrade.set_project(project.get_code())
                upgrade.set_to_version(my.to_version)
                upgrade.set_forced(my.is_forced)
                upgrade.set_quiet(my.quiet)
                upgrade.set_confirmed(my.is_confirmed)
                #Command.execute_cmd(upgrade)
                # put each upgrade function in its own transaction
                # carried out in BaseUpgrade
                upgrade.execute()

                # append the errors for each upgrade
                key = '%s|%s' % (project.get_code(),
                                 upgrade.__class__.__name__)
                error_list.append((upgrade.__class__.__name__, project.get_code(), \
                    Container.get_seq(key)))

            from pyasm.search import DatabaseImpl
            project.set_value("last_db_update",
                              DatabaseImpl.get().get_timestamp_now(),
                              quoted=False)

            if project.has_value('last_version_update'):
                last_version = project.get_value('last_version_update')
                if my.to_version > last_version:
                    project.set_value("last_version_update", my.to_version)
            else:
                # it should be getting the upgrade now, redo the search
                print "Please run upgrade_db.py again, the sthpw db has just been updated"
                return
            project.commit(triggers=False)

        # print the errors for each upgrade
        for cls_name, project_code, errors in error_list:
            if not my.quiet:
                print
                print "Errors for %s [%s]:" % (project_code, cls_name)
            ofile.write("Errors for %s [%s]:\n" % (project_code, cls_name))
            if not my.quiet:
                print "*" * 80
            ofile.write("*" * 80 + '\n')
            for func, error in errors:
                if not my.quiet:
                    print '[%s]' % func
                    print "-" * 70
                    print error
                ofile.write('[%s]\n' % func)
                ofile.write("-" * 70 + '\n')
                ofile.write('%s\n' % error)
        ofile.close()

        if my.quiet:
            print "Please refer to the file [%s] for any upgrade messages." % output_file
            print
        # handle sthpw database separately.  This ensures that the project entry
        # gets created if none exists.
        #print "sthpw"
        #print "-"*30
        #upgrade = SthpwUpgrade()
        #upgrade.set_project("sthpw")
        #Command.execute_cmd(upgrade)

        # update the template zip files
        data_dir = Environment.get_data_dir(manual=False)
        dest_dir = '%s/templates' % data_dir
        if os.path.exists(dest_dir):
            install_dir = Environment.get_install_dir()
            src_code_template_dir = '%s/src/install/start/templates' % install_dir
            if os.path.exists(src_code_template_dir):
                zip_files = os.listdir(src_code_template_dir)
                io_errors = False
                for zip_file in zip_files:
                    if not zip_file.endswith(".zip"):
                        continue
                    try:
                        src_file = '%s/%s' % (src_code_template_dir, zip_file)
                        dest_file = '%s/%s' % (dest_dir, zip_file)
                        shutil.copyfile(src_file, dest_file)
                    except IOError, e:
                        print e
                        io_errors = True
                if not io_errors:
                    print "Default project template files have been updated."
                else:
                    print "There was a problem copying the default template files to <TACTIC_DATA_DIR>/templates."
Beispiel #17
0
 def get_database_type(my):
     db_resource = my.get_project_db_resource()
     impl = DatabaseImpl.get()
     return impl.get_database_type()
Beispiel #18
0
    def execute(self):

        if not self.sobject.is_insert():
            # do nothing
            return

        project = self.sobject
        project_code = project.get_code()
        project_type = project.get_base_type()

        database = DatabaseImpl.get()

        # check if database exists
        print "Creating database '%s' ..." % project_code

        if database.database_exists(project_code):
            print "... already exists"
        else:
            # create the datbase
            database.create_database(project_code)

        # import the appropriate schema
        database.import_schema(project_code, project_type)

        # import the appropriate data
        database.import_default_data(project_code, project_type)

        # copy files from the default template
        site_dir = Environment.get_site_dir()
        install_dir = Environment.get_install_dir()
        template_dir = "%s/src/tactic_sites/template" % install_dir
        template_dir = template_dir.replace("\\","/")
        project_dir = "%s/sites/%s" % (site_dir, project_code)
        project_dir = project_dir.replace("\\","/")


        # set the update of the database to current
        project.set_value("last_db_update", Sql.get_timestamp_now(), quoted=False)
        project.commit()



        # copy all of the files from the template to the template directory
        print "Creating project directories [%s]..." % project_dir
        if not os.path.exists(template_dir):
            print "... skipping: template dir [%s] does not exist" % template_dir
            return 

        if not os.path.exists(project_dir):
            for root, dirs, files in os.walk(template_dir):
                root = root.replace("\\","/")

                # ignore ".svn"
                if root.find("/.svn") != -1:
                    continue

                for file in files:
                    # ignore compiled python files
                    if file.endswith(".pyc"):
                        continue

                    old = "%s/%s" % (root, file)
                    new = old.replace(template_dir, project_dir)

                    dirname = os.path.dirname(new)
                    System().makedirs(dirname)

                    shutil.copyfile(old,new)
        else:
            print "... skipping.  Already exists."

        print "Done."
Beispiel #19
0
    def test_postgres(my, vendor):
        web = WebContainer.get_web()

        defaults = DEFAULTS[vendor]

        default_server = defaults['server']
        default_port = defaults['port']
        default_user = defaults['user']
        default_password = defaults['password']

        server = web.get_form_value("server")
        if not server:
            server = default_server
        port = web.get_form_value("port")
        if not port:
            port = default_port
        else:
            port = int(port)
        user = web.get_form_value("user")
        if not user:
            user = default_user
        password = web.get_form_value("password")
        if not password:
            password = default_password

        # Need to access remote database
        create = False
        impl = DatabaseImpl.get(vendor)
        exists = impl.database_exists("sthpw", host=server, port=port)

        if not create:
            if not exists:
                my.info[
                    'error'] = "Database [sthpw] does not exist.  This is required for TACTIC to function."

                return

        else:
            print "Running bootstrap"

            install_dir = Environment.get_install_dir()
            python = Config.get_value("services", "python")
            if not python:
                python = "python"

            # create the database and inject the bootstrap data
            impl.create_database("sthpw", host=server, port=port)

            cmd = "%s %s/src/pyasm/search/upgrade/%s/bootstrap_load.py" % (
                python, install_dir, vendor.lower())
            os.system(cmd)

        from pyasm.search import Sql
        sql = Sql("sthpw",
                  server,
                  user,
                  password=password,
                  vendor=vendor,
                  port=port)
        try:
            # attempt
            sql.connect()
            sql.do_query("select id from transaction_log limit 1")
        except Exception, e:
            my.info[
                'error'] = "Could not connect to database with (vendor=%s, server=%s, user=%s, port=%s)" % (
                    vendor, server, user, port)
            my.info['message'] = str(e)
            print e
Beispiel #20
0
    def import_template(my):

        if my.path:
            base_dir = os.path.dirname(my.path)
        else:
            base_dir = Environment.get_template_dir()


        version = my.kwargs.get("version")
        if version:
            template_dir = "%s/%s-%s" % (base_dir, my.template_code, version)
        else:
            template_dir = "%s/%s" % (base_dir, my.template_code)

        template_dir = my.get_template_dir(template_dir)
        
        # if the directory does not exist then look for a zip file
        use_zip = False
        if not os.path.exists(template_dir):
            template_zip = "%s.zip" % (template_dir)
            if os.path.exists(template_zip):
                use_zip = True
            else:
                hint = "Please check if you have created the Template already using the Update button in the Template Project view."
                if version:
                    raise TacticException("No template found for [%s] version [%s]. %s" % (my.template_code, version, hint))
                else:
                    raise TacticException("No template found for [%s]. %s" % (my.template_code, hint))
                    



        # check to see if the database exists in the default
        # database implementation
        from pyasm.search import DbContainer, DatabaseImpl
        impl = DatabaseImpl.get()
        exists = impl.database_exists(my.project_code)

        # if the database already exists, then raise an exception
        if exists and my.new_project:
            msg = "WARNING: Database [%s] already exists" % my.project_code
            print msg
            raise TacticException(msg)


        # this is the overriding factor:
        if my.is_template == True:
            title = Common.get_display_title(my.project_code)
        elif my.is_template == False:
            title = Common.get_display_title(my.project_code)
        elif my.is_template == None:
            # these 2 is for old usage using the command line script create_template.py
            if my.template_project_code != my.project_code:
                my.is_template = False
                title = Common.get_display_title(my.project_code)
            else:
                my.is_template = True
                title = Common.get_display_title(my.template_project_code)


        # create a new project if this was desired
        if my.new_project == True:
            from create_project_cmd import CreateProjectCmd
            project_image_path = my.kwargs.get("project_image_path")

            # the project_type will get updated properly by the PluginInstaller
            # but that break the ties to the project_type entry created though,
            # which is ok
            creator = CreateProjectCmd(
                project_code=my.project_code,
                project_title=title,
                project_type=my.template_project_code,
                is_template=my.is_template,
                use_default_side_bar=False,
                project_image_path=project_image_path
            )
            creator.execute()


        # set the project
        Project.set_project(my.project_code)

        # import from a plugin
        if use_zip:
            kwargs = {
                'zip_path': template_zip,
                'code': my.project_code
            }

        else:
            kwargs = {
                'plugin_dir': template_dir
            }


        kwargs['filter_line_handler'] = my.filter_line_handler
        kwargs['filter_sobject_handler'] = my.filter_sobject_handler

        from plugin import PluginCreator, PluginInstaller
        installer = PluginInstaller( **kwargs )
        installer.execute()
Beispiel #21
0
 def get_database_type(my):
     db_resource = my.get_project_db_resource()
     impl = DatabaseImpl.get()
     return impl.get_database_type()
Beispiel #22
0
    def execute(my):

        if not my.sobject.is_insert():
            # do nothing
            return

        project = my.sobject
        project_code = project.get_code()
        project_type = project.get_base_type()

        database = DatabaseImpl.get()

        # check if database exists
        print "Creating database '%s' ..." % project_code

        if database.database_exists(project_code):
            print "... already exists"
        else:
            # create the datbase
            database.create_database(project_code)

        # import the appropriate schema
        database.import_schema(project_code, project_type)

        # import the appropriate data
        database.import_default_data(project_code, project_type)

        # copy files from the default template
        site_dir = Environment.get_site_dir()
        install_dir = Environment.get_install_dir()
        template_dir = "%s/src/tactic_sites/template" % install_dir
        template_dir = template_dir.replace("\\","/")
        project_dir = "%s/sites/%s" % (site_dir, project_code)
        project_dir = project_dir.replace("\\","/")


        # set the update of the database to current
        project.set_value("last_db_update", Sql.get_timestamp_now(), quoted=False)
        project.commit()



        # copy all of the files from the template to the template directory
        print "Creating project directories [%s]..." % project_dir
        if not os.path.exists(template_dir):
            print "... skipping: template dir [%s] does not exist" % template_dir
            return 

        if not os.path.exists(project_dir):
            for root, dirs, files in os.walk(template_dir):
                root = root.replace("\\","/")

                # ignore ".svn"
                if root.find("/.svn") != -1:
                    continue

                for file in files:
                    # ignore compiled python files
                    if file.endswith(".pyc"):
                        continue

                    old = "%s/%s" % (root, file)
                    new = old.replace(template_dir, project_dir)

                    dirname = os.path.dirname(new)
                    System().makedirs(dirname)

                    shutil.copyfile(old,new)
        else:
            print "... skipping.  Already exists."

        print "Done."
Beispiel #23
0
    def execute(my):
        error_list = []
        from pyasm.biz import Project
        Project.clear_cache()

        sthpw_search = Search("sthpw/project")
        sthpw_search.add_filter('code','sthpw')
        sthpw_search.set_show_retired(True)
        sthpw_proj = sthpw_search.get_sobject()

        search = Search("sthpw/project")
        if my.project_code:
            search.add_filter("code", my.project_code)
        else:
            #search.add_enum_order_by("type", ['sthpw','prod','game','design','simple', 'unittest'])
            search.add_enum_order_by("code", ['sthpw'])
        projects = search.get_sobjects()

        project_codes = SObject.get_values(projects, 'code')
        # append sthpw project in case it's retired
        if 'sthpw' not in project_codes and sthpw_proj:
            if not my.project_code:
                projects.insert(0, sthpw_proj)
            sthpw_proj.reactivate()



        current_dir = os.getcwd()
        tmp_dir = Environment.get_tmp_dir()
        output_file = '%s/upgrade_output.txt' % tmp_dir
        if not os.path.exists(tmp_dir):
            os.makedirs(tmp_dir)
        elif os.path.exists(output_file):
            os.unlink(output_file)
        ofile = open(output_file, 'w')

        import datetime
        ofile.write('Upgrade Time: %s\n\n' %datetime.datetime.now())



        # dynamically generate
        #sql = DbContainer.get(code)
        database_type = Sql.get_default_database_type()
        #if database_type in ['Sqlite', 'MySQL']:
        if database_type != "PostgreSQL":
            # general an upgrade
            import imp

            namespaces = ['default', 'simple', 'sthpw', 'config']
            for namespace in namespaces:
                if database_type == 'Sqlite':
                    from pyasm.search.upgrade.sqlite import convert_sqlite_upgrade
                    file_path = convert_sqlite_upgrade(namespace)
                elif database_type == 'MySQL':
                    from pyasm.search.upgrade.mysql import convert_mysql_upgrade
                    file_path = convert_mysql_upgrade(namespace)
                elif database_type == 'SQLServer':
                    from pyasm.search.upgrade.sqlserver import convert_sqlserver_upgrade
                    file_path = convert_sqlserver_upgrade(namespace)
                elif database_type == 'Oracle':
                    file_path = convert_oracle_upgrade(namespace)
                else:
                    raise Exception("Database type not implemented here")

                (path, name) = os.path.split(file_path)
                (name, ext) = os.path.splitext(name)
                (file, filename, data) = imp.find_module(name, [path])
                module = imp.load_module(name, file, filename, data)

                class_name = "%s%sUpgrade" % (database_type,namespace.capitalize())
                exec("%s = module.%s" % (class_name, class_name) )



        # load all the default modules
        from pyasm.search.upgrade.project import *

        for project in projects:
            
            code = project.get_code()
            if code == "sthpw":
                type = "sthpw"
            else:
                type = project.get_type()

            if not type:
                type = 'default'


            if not my.quiet:
                print project.get_code(), type
                print "-"*30

            # if the project is admin, the just ignore for now
            if code == 'admin':
                continue
            
            if not project.database_exists():
                ofile.write("*" * 80 + '\n')
                msg =  "Project [%s] does not have a database\n"% project.get_code()
                ofile.write(msg)
                print msg
                ofile.write("*" * 80 + '\n\n')
                continue


            upgrade = None

            if database_type != 'PostgreSQL':
                upgrade_class = "%s%sUpgrade" % (database_type, type.capitalize())
                conf_upgrade = eval("%sConfigUpgrade()" % database_type)
            else:
                upgrade_class = "%sUpgrade" % type.capitalize()
                conf_upgrade = eval("ConfigUpgrade()")
            upgrade = eval("%s()" % upgrade_class)

            # upgrade config (done for every project but sthpw)
            conf_upgrade.set_project(project.get_code())
            conf_upgrade.set_to_version(my.to_version)
            conf_upgrade.set_forced(my.is_forced)
            conf_upgrade.set_quiet(my.quiet)
            conf_upgrade.set_confirmed(my.is_confirmed)
            conf_upgrade.execute()
            
            # append the errors for each upgrade
            key = '%s|%s' %(project.get_code(), conf_upgrade.__class__.__name__)
            error_list.append((conf_upgrade.__class__.__name__, project.get_code(), \
                Container.get_seq(key)))


            # perform the upgrade to the other tables
            if upgrade:
                upgrade.set_project(project.get_code() )
                upgrade.set_to_version(my.to_version)
                upgrade.set_forced(my.is_forced)
                upgrade.set_quiet(my.quiet)
                upgrade.set_confirmed(my.is_confirmed)
                #Command.execute_cmd(upgrade)
                # put each upgrade function in its own transaction
                # carried out in BaseUpgrade
                upgrade.execute()
                
                # append the errors for each upgrade
                key = '%s|%s' %(project.get_code(), upgrade.__class__.__name__)
                error_list.append((upgrade.__class__.__name__, project.get_code(), \
                    Container.get_seq(key)))

            from pyasm.search import DatabaseImpl
            project.set_value("last_db_update", DatabaseImpl.get().get_timestamp_now(), quoted=False)
            
            if project.has_value('last_version_update'):
                last_version = project.get_value('last_version_update')
                if my.to_version > last_version:
                    project.set_value("last_version_update", my.to_version)
            else: 
                # it should be getting the upgrade now, redo the search
                print "Please run upgrade_db.py again, the sthpw db has just been updated"
                return
            project.commit(triggers=False)



        # print the errors for each upgrade
        for cls_name, project_code, errors in error_list:
            if not my.quiet:
                print
                print "Errors for %s [%s]:" %(project_code, cls_name)
            ofile.write("Errors for %s [%s]:\n" %(project_code, cls_name))
            if not my.quiet:
                print "*" * 80
            ofile.write("*" * 80 + '\n')
            for func, error in errors:
                if not my.quiet:
                    print '[%s]' % func
                    print "-" * 70
                    print error
                ofile.write('[%s]\n' % func)
                ofile.write("-" * 70 + '\n')
                ofile.write('%s\n' %error)
        ofile.close()

        if my.quiet:
            print "Please refer to the upgrade_output.txt file for any upgrade messages."
            print
        # handle sthpw database separately.  This ensures that the project entry
        # gets created if none exists.
        #print "sthpw"
        #print "-"*30
        #upgrade = SthpwUpgrade()
        #upgrade.set_project("sthpw")
        #Command.execute_cmd(upgrade)

        # update the template zip files
        data_dir = Environment.get_data_dir(manual=False)
        dest_dir = '%s/templates' %data_dir
        if os.path.exists(dest_dir):
            install_dir = Environment.get_install_dir()
            src_code_template_dir = '%s/src/install/start/templates' %install_dir
            if os.path.exists(src_code_template_dir):
                zip_files = os.listdir(src_code_template_dir)
                io_errors = False
                for zip_file in zip_files:
                    if not zip_file.endswith(".zip"):
                        continue
                    try:
                        src_file = '%s/%s' %(src_code_template_dir, zip_file)
                        dest_file = '%s/%s' %(dest_dir, zip_file)
                        shutil.copyfile(src_file, dest_file)
                    except IOError, e:
                        print e
                        io_errors = True
                if not io_errors:
                    print "Default project template files have been updated."
                else:
                    print "There was a problem copying the default template files to <TACTIC_DATA_DIR>/templates."
Beispiel #24
0
        self.create_temp_directory()

        self.change_directory_ownership()

        self.install_win32_service()

        if install_db == False:
            print "TACTIC setup successful.  Next, the TACTIC database needs to be configured."
            return

        # dynamically load modules now that we know where they are
        from pyasm.search import DatabaseImpl, DbContainer

        # create the sthpw database
        database = DatabaseImpl.get()

        # check if database exists
        print "Creating database '%s' ..." % project_code
        print

        db_exists = False
        from pyasm.search import DatabaseException
        try:
            if database.database_exists(project_code):
                print "... already exists. Please remove first"
                raise InstallException("Database '%s' already exists" %
                                       project_code)
                db_exists = True
        except DatabaseException, e:
            pass
Beispiel #25
0
 def get_database_type(self):
     db_resource = self.get_project_db_resource()
     impl = DatabaseImpl.get()
     return impl.get_database_type()
Beispiel #26
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