Ejemplo n.º 1
0
    def dump(self, plugin_code, project_code, search_types):

        xml = Xml()
        self.xml = xml

        xml.create_doc("manifest")
        manifest_node = xml.get_root_node()
        xml.set_attribute(manifest_node, "code", plugin_code)

        # DUMP the data
        for search_type in search_types:

            data_node = xml.create_element("search_type")
            xml.append_child(manifest_node, data_node)
            xml.set_attribute(data_node, "code", search_type)

            # This exports the data
            """
            data_node = xml.create_element("sobject")
            xml.append_child(manifest_node, data_node)
            xml.set_attribute(data_node, "search_type", search_type)

            # find the currval 
            st_obj = SearchType.get(search_type)
            # have to call nextval() to initiate this sequence in the session in psql since Postgres 8.1
            seq_id = st_obj.sequence_nextval()
            
            seq_id = st_obj.sequence_currval()

            seq_id -= 1
            if seq_id > 0:
                st_obj.sequence_setval(seq_id)
            xml.set_attribute(data_node, "seq_max", seq_id)
            """

        print xml.to_string()

        # create a virtual plugin
        plugin = SearchType.create("sthpw/plugin")
        plugin.set_value("version", "1.0.0")
        plugin.set_value("code", "%s_project" % project_code)

        base_dir = "./templates"
        creator = PluginCreator(base_dir=base_dir,
                                plugin=plugin,
                                manifest=xml.to_string())
        creator.execute()
Ejemplo n.º 2
0
    def dump(my, plugin_code, project_code, search_types):

        xml = Xml()
        my.xml = xml

        xml.create_doc("manifest")
        manifest_node = xml.get_root_node()
        xml.set_attribute(manifest_node, "code", plugin_code)

        # DUMP the data
        for search_type in search_types:

            data_node = xml.create_element("search_type")
            xml.append_child(manifest_node, data_node)
            xml.set_attribute(data_node, "code", search_type)

            # This exports the data
            """
            data_node = xml.create_element("sobject")
            xml.append_child(manifest_node, data_node)
            xml.set_attribute(data_node, "search_type", search_type)

            # find the currval 
            st_obj = SearchType.get(search_type)
            # have to call nextval() to initiate this sequence in the session in psql since Postgres 8.1
            seq_id = st_obj.sequence_nextval()
            
            seq_id = st_obj.sequence_currval()

            seq_id -= 1
            if seq_id > 0:
                st_obj.sequence_setval(seq_id)
            xml.set_attribute(data_node, "seq_max", seq_id)
            """
            


        print xml.to_string()

        # create a virtual plugin
        plugin = SearchType.create("sthpw/plugin")
        plugin.set_value("version", "1.0.0")
        plugin.set_value("code", "%s_project" % project_code)

        base_dir = "./templates"
        creator = PluginCreator( base_dir=base_dir, plugin=plugin, manifest=xml.to_string() )
        creator.execute()
Ejemplo n.º 3
0
    def execute(my):

        import datetime
        now = datetime.datetime.now()
        version = now.strftime("%Y%m%d_%H%M%S")

        project_code = my.kwargs.get("project_code")
        if project_code:
            project = Project.get_by_code(project_code)
        else:
            project = Project.get()
        project_code = project.get_code()

        server_code = my.kwargs.get("server")
        assert server_code

        if not isinstance(server_code, basestring):
            server_code = server_code.get_value("code")

        base_dir = my.kwargs.get('base_dir')
        ticket = Environment.get_ticket()
        tmp_dir = "%s/sync_%s" % (Environment.get_tmp_dir(), ticket)
        if not os.path.exists(tmp_dir):
            os.makedirs(tmp_dir)

        server = Search.get_by_code("sthpw/sync_server", server_code)
        if server.get_value("sync_mode") == "file":
            if not base_dir:
                base_dir = server.get_value("base_dir")

        else:
            raise Exception("sync mode [%s] not support" % sync_mode)
            # FIXME: not sure if this is valid anymore
            asset_dir = Environment.get_asset_dir()
            base_dir = "%s/_temp" % asset_dir

        # create the project template
        from tactic.command import ProjectTemplateCreatorCmd
        cmd = ProjectTemplateCreatorCmd(project_code=project_code,
                                        version=version,
                                        base_dir=tmp_dir)
        cmd.execute()

        project_path = cmd.get_zip_path()

        # create zip of the project files
        from pyasm.common import ZipUtil
        zip_util = ZipUtil()
        asset_dir = Environment.get_asset_dir()
        project_dir = "%s/%s" % (asset_dir, project_code)

        zip_dir = "%s/%s" % (tmp_dir, project_code)
        file_path = "%s-files-%s.zip" % (zip_dir, version)

        if os.path.exists(file_path):
            os.unlink(file_path)
        zip_util.zip_dir2(project_dir, zip_path=file_path)

        # create a manifest for all the data in the project.
        xml = Xml()
        my.xml = xml

        xml.create_doc("manifest")
        manifest_node = xml.get_root_node()
        xml.set_attribute(manifest_node, "code", "%s-data" % project_code)

        search_types = project.get_search_types()

        # just dump the data
        for search_type in search_types:
            data_node = xml.create_element("sobject")
            xml.append_child(manifest_node, data_node)
            xml.set_attribute(data_node, "search_type",
                              search_type.get_value("search_type"))

        # dump the note entries
        data_node = xml.create_element("sobject")
        xml.append_child(manifest_node, data_node)
        xml.set_attribute(
            data_node, "expression",
            "@SOBJECT(sthpw/note['project_code','%s'])" % project_code)
        xml.set_attribute(data_node, "search_type", "sthpw/note")

        # dump the task entries
        data_node = xml.create_element("sobject")
        xml.append_child(manifest_node, data_node)
        xml.set_attribute(
            data_node, "expression",
            "@SOBJECT(sthpw/task['project_code','%s'])" % project_code)
        xml.set_attribute(data_node, "search_type", "sthpw/task")

        # dump the snapshot entries
        data_node = xml.create_element("sobject")
        xml.append_child(manifest_node, data_node)
        xml.set_attribute(
            data_node, "expression",
            "@SOBJECT(sthpw/snapshot['project_code','%s'])" % project_code)
        xml.set_attribute(data_node, "search_type", "sthpw/snapshot")

        # dump the file entries
        data_node = xml.create_element("sobject")
        xml.append_child(manifest_node, data_node)
        xml.set_attribute(
            data_node, "expression",
            "@SOBJECT(sthpw/file['project_code','%s'])" % project_code)
        xml.set_attribute(data_node, "search_type", "sthpw/file")

        manifest = xml.to_string()

        # create a virtual plugin sobject
        from tactic.command import PluginCreator
        plugin = SearchType.create("config/plugin")
        plugin.set_value("version", version)
        plugin.set_value("code", "%s_project" % project_code)

        creator = PluginCreator(base_dir=tmp_dir,
                                plugin=plugin,
                                manifest=manifest,
                                version=version)
        creator.execute()

        data_path = creator.get_zip_path()

        # move the files to the appropriate base_dir
        import shutil

        if not os.path.exists(base_dir):
            os.makedirs(base_dir)

        if os.path.exists(project_path):
            basename = os.path.basename(project_path)
            if os.path.exists("%s/%s" % (base_dir, basename)):
                os.unlink("%s/%s" % (base_dir, basename))
            shutil.move(project_path, base_dir)

        if os.path.exists(data_path):
            basename = os.path.basename(data_path)
            if os.path.exists("%s/%s" % (base_dir, basename)):
                os.unlink("%s/%s" % (base_dir, basename))
            shutil.move(data_path, base_dir)

        if os.path.exists(file_path):
            basename = os.path.basename(file_path)
            if os.path.exists("%s/%s" % (base_dir, basename)):
                os.unlink("%s/%s" % (base_dir, basename))
            shutil.move(file_path, base_dir)

        shutil.rmtree(tmp_dir)

        my.handle_manifest(base_dir, project_code, version)
Ejemplo n.º 4
0
    def execute(self):

        import datetime
        now = datetime.datetime.now()
        version = now.strftime("%Y%m%d_%H%M%S")


        project_code = self.kwargs.get("project_code")
        if project_code:
            project = Project.get_by_code(project_code)
        else:
            project = Project.get()
        project_code = project.get_code()

        server_code = self.kwargs.get("server")
        assert server_code

        if not isinstance(server_code, basestring):
            server_code = server_code.get_value("code")


        base_dir = self.kwargs.get('base_dir')
        ticket = Environment.get_ticket()
        tmp_dir = "%s/sync_%s" % (Environment.get_tmp_dir(), ticket)
        if not os.path.exists(tmp_dir):
            os.makedirs(tmp_dir)


        server = Search.get_by_code("sthpw/sync_server", server_code)
        if server.get_value("sync_mode") == "file":
            if not base_dir:
                base_dir = server.get_value("base_dir")

        else:
            raise Exception("sync mode [%s] not support" % sync_mode)
            # FIXME: not sure if this is valid anymore
            asset_dir = Environment.get_asset_dir()
            base_dir = "%s/_temp" % asset_dir


        # create the project template
        from tactic.command import ProjectTemplateCreatorCmd
        cmd = ProjectTemplateCreatorCmd(project_code=project_code, version=version, base_dir=tmp_dir)
        cmd.execute()

        project_path = cmd.get_zip_path()


        # create zip of the project files
        from pyasm.common import ZipUtil
        zip_util = ZipUtil()
        asset_dir = Environment.get_asset_dir()
        project_dir = "%s/%s" % (asset_dir, project_code)

        zip_dir = "%s/%s" % (tmp_dir, project_code)
        file_path = "%s-files-%s.zip" % (zip_dir, version)

        if os.path.exists(file_path):
            os.unlink(file_path)
        zip_util.zip_dir2(project_dir, zip_path=file_path)




        # create a manifest for all the data in the project.
        xml = Xml()
        self.xml = xml

        xml.create_doc("manifest")
        manifest_node = xml.get_root_node()
        xml.set_attribute(manifest_node, "code", "%s-data" % project_code)

        search_types = project.get_search_types()

        # just dump the data
        for search_type in search_types:
            data_node = xml.create_element("sobject")
            xml.append_child(manifest_node, data_node)
            xml.set_attribute(data_node, "search_type", search_type.get_value("search_type"))


        # dump the note entries
        data_node = xml.create_element("sobject")
        xml.append_child(manifest_node, data_node)
        xml.set_attribute(data_node, "expression", "@SOBJECT(sthpw/note['project_code','%s'])" % project_code)
        xml.set_attribute(data_node, "search_type", "sthpw/note")


        # dump the task entries
        data_node = xml.create_element("sobject")
        xml.append_child(manifest_node, data_node)
        xml.set_attribute(data_node, "expression", "@SOBJECT(sthpw/task['project_code','%s'])" % project_code)
        xml.set_attribute(data_node, "search_type", "sthpw/task")


        # dump the snapshot entries
        data_node = xml.create_element("sobject")
        xml.append_child(manifest_node, data_node)
        xml.set_attribute(data_node, "expression", "@SOBJECT(sthpw/snapshot['project_code','%s'])" % project_code)
        xml.set_attribute(data_node, "search_type", "sthpw/snapshot")


        # dump the file entries
        data_node = xml.create_element("sobject")
        xml.append_child(manifest_node, data_node)
        xml.set_attribute(data_node, "expression", "@SOBJECT(sthpw/file['project_code','%s'])" % project_code)
        xml.set_attribute(data_node, "search_type", "sthpw/file")


        manifest = xml.to_string()


        # create a virtual plugin sobject
        from tactic.command import PluginCreator
        plugin = SearchType.create("config/plugin")
        plugin.set_value("version", version)
        plugin.set_value("code", "%s_project" % project_code)

        creator = PluginCreator( base_dir=tmp_dir, plugin=plugin, manifest=manifest, version=version )
        creator.execute()

        data_path = creator.get_zip_path()




        # move the files to the appropriate base_dir
        import shutil

        if not os.path.exists(base_dir):
            os.makedirs(base_dir)


        if os.path.exists(project_path):
            basename = os.path.basename(project_path)
            if os.path.exists("%s/%s" % (base_dir, basename)):
                os.unlink("%s/%s" % (base_dir, basename))
            shutil.move(project_path, base_dir)

        if os.path.exists(data_path):
            basename = os.path.basename(data_path)
            if os.path.exists("%s/%s" % (base_dir, basename)):
                os.unlink("%s/%s" % (base_dir, basename))
            shutil.move(data_path, base_dir)

        if os.path.exists(file_path):
            basename = os.path.basename(file_path)
            if os.path.exists("%s/%s" % (base_dir, basename)):
                os.unlink("%s/%s" % (base_dir, basename))
            shutil.move(file_path, base_dir)


        shutil.rmtree(tmp_dir)


        self.handle_manifest(base_dir, project_code, version)