Ejemplo n.º 1
0
    def handle_search_type(my, node):
        search_type = my.xml.get_attribute(node, "code")
        if not search_type:
            raise TacticException("No code found for search type in manifest")

        path = my.xml.get_attribute(node, "path")
        if not path:
            path = "%s.spt" % search_type.replace("/", "_")

        path = "%s/%s" % (my.plugin_dir, path)

        if os.path.exists(path):
            os.unlink(path)

        # dump out search type registration
        search = Search("sthpw/search_object")
        search.add_filter("search_type", search_type)
        sobject = search.get_sobject()
        if not sobject:
            raise TacticException("Search type [%s] does not exist" % search_type)

        dumper = TableDataDumper()
        dumper.set_delimiter("#-- Start Entry --#", "#-- End Entry --#")
        dumper.set_include_id(False)
        dumper.set_sobjects([sobject])
        dumper.dump_tactic_inserts(path, mode='sobject')


        ignore_columns = Xml.get_attribute(node, "ignore_columns")
        if ignore_columns:
            ignore_columns = ignore_columns.split(",")
            ignore_columns = [x.strip() for x in ignore_columns]
        else:
            ignore_columns = []


        # dump out the table definition
        dumper = TableSchemaDumper(search_type)
        dumper.set_delimiter("#-- Start Entry --#", "#-- End Entry --#")
        dumper.set_ignore_columns(ignore_columns)
        dumper.dump_to_tactic(path, mode='sobject')
Ejemplo n.º 2
0
    def handle_snapshots(my):


        path = "__snapshot_files.spt"
        path = "%s/%s" % (my.plugin_dir, path)
        print "Writing: ", path
        # write out an empty file
        #f = open(path, 'w')

        fmode = 'w'
        if os.path.exists(path):
            fmode = 'a'
        f = codecs.open(path, fmode, 'utf-8')
        f.close()


        # get all of the latest snapshots for this plugin
        search = Search("sthpw/snapshot")
        search.add_parent_filter(my.plugin)
        search.add_filter("is_latest", True)
        snapshots = search.get_sobjects()

        if not snapshots:
            return

        # dump out these snapshots
        dumper = TableDataDumper()
        dumper.set_delimiter("#-- Start Entry --#", "#-- End Entry --#")
        dumper.set_include_id(False)
        dumper.set_sobjects(snapshots)
        dumper.dump_tactic_inserts(path, mode='sobject')

        # get all of the files for all of the snapshots and copy the director
        # structure


        # get all of the latest snapshots for this plugin
        search = Search("sthpw/file")
        search.add_relationship_filters(snapshots)
        files = search.get_sobjects()

        # dump out these snapshots
        dumper = TableDataDumper()
        dumper.set_delimiter("#-- Start Entry --#", "#-- End Entry --#")
        dumper.set_include_id(False)
        dumper.set_sobjects(files)
        dumper.dump_tactic_inserts(path, mode='sobject')

        new_dir = "%s/files" % (my.plugin_dir)
        if not os.path.exists(new_dir):
            os.makedirs(new_dir)

        for snapshot in snapshots:
            paths = snapshot.get_all_lib_paths(mode="lib")
            for path in paths:
                file_name = os.path.basename(path)
                new_path = "%s/%s" % (new_dir, file_name)

                shutil.copy(path, new_path)
Ejemplo n.º 3
0
    def handle_sobject(my, node):
        search_type = my.xml.get_attribute(node, "search_type")

        include_id = my.xml.get_attribute(node, "include_id")
        if include_id in [True, 'true']:
            include_id = True
        else:
            include_id = False


        ignore_columns = Xml.get_attribute(node, "ignore_columns")
        if ignore_columns:
            ignore_columns = ignore_columns.split(",")
            ignore_columns = [x.strip() for x in ignore_columns]
        else:
            ignore_columns = []

        # FIXME:
        # it is possible that the manifest defines sobjects on search types
        # that don't exist.  This is because it uses the manifest of
        # the new pipeline and not the original ... 
        sobjects = my.get_sobjects_by_node(node)
        if not sobjects:
            print "Skipping as no sobjects found for [%s]" %search_type
            return []



        # If there are no sobjects, then no file is created because
        # no path can be extracted.

        path = my.get_path_from_node(node)

        print "Writing: ", path
        fmode = 'w'
        if os.path.exists(path):
            fmode = 'a'
        if not sobjects:
            # write out an empty file
            #f = open(path, 'w')
            f = codecs.open(path, fmode, 'utf-8')
            f.close()
            return []

        dumper = TableDataDumper()
        dumper.set_delimiter("#-- Start Entry --#", "#-- End Entry --#")
        if search_type == 'config/widget_config':
            dumper.set_ignore_columns(['code'])
        dumper.set_include_id(include_id)
        dumper.set_ignore_columns(ignore_columns)
        dumper.set_sobjects(sobjects)
        dumper.dump_tactic_inserts(path, mode='sobject')

        print "\t....dumped [%s] entries" % (len(sobjects))

        return sobjects
Ejemplo n.º 4
0
    def handle_snapshots(my):


        path = "__snapshot_files.spt"
        path = "%s/%s" % (my.plugin_dir, path)
        print "Writing: ", path
        # write out an empty file
        #f = open(path, 'w')

        fmode = 'w'
        if os.path.exists(path):
            fmode = 'a'
        f = codecs.open(path, fmode, 'utf-8')
        f.close()


        # get all of the latest snapshots for this plugin
        search = Search("sthpw/snapshot")
        search.add_parent_filter(my.plugin)
        search.add_filter("is_latest", True)
        snapshots = search.get_sobjects()

        if not snapshots:
            return

        # dump out these snapshots
        dumper = TableDataDumper()
        dumper.set_delimiter("#-- Start Entry --#", "#-- End Entry --#")
        dumper.set_include_id(False)
        dumper.set_sobjects(snapshots)
        dumper.dump_tactic_inserts(path, mode='sobject')

        # get all of the files for all of the snapshots and copy the director
        # structure


        # get all of the latest snapshots for this plugin
        search = Search("sthpw/file")
        search.add_relationship_filters(snapshots)
        files = search.get_sobjects()

        # dump out these snapshots
        dumper = TableDataDumper()
        dumper.set_delimiter("#-- Start Entry --#", "#-- End Entry --#")
        dumper.set_include_id(False)
        dumper.set_sobjects(files)
        dumper.dump_tactic_inserts(path, mode='sobject')

        new_dir = "%s/files" % (my.plugin_dir)
        if not os.path.exists(new_dir):
            os.makedirs(new_dir)

        for snapshot in snapshots:
            paths = snapshot.get_all_lib_paths(mode="lib")
            for path in paths:
                file_name = os.path.basename(path)
                new_path = "%s/%s" % (new_dir, file_name)

                shutil.copy(path, new_path)
Ejemplo n.º 5
0
    def handle_search_type(my, node):
        search_type = my.xml.get_attribute(node, "code")
        if not search_type:
            raise TacticException("No code found for search type in manifest")

        path = my.xml.get_attribute(node, "path")
        if not path:
            path = "%s.spt" % search_type.replace("/", "_")

        path = "%s/%s" % (my.plugin_dir, path)

        if os.path.exists(path):
            os.unlink(path)

        # dump out search type registration
        search = Search("sthpw/search_object")
        search.add_filter("search_type", search_type)
        sobject = search.get_sobject()
        if not sobject:
            raise TacticException("Search type [%s] does not exist" % search_type)

        dumper = TableDataDumper()
        dumper.set_delimiter("#-- Start Entry --#", "#-- End Entry --#")
        dumper.set_include_id(False)
        dumper.set_sobjects([sobject])
        dumper.dump_tactic_inserts(path, mode='sobject')


        ignore_columns = Xml.get_attribute(node, "ignore_columns")
        if ignore_columns:
            ignore_columns = ignore_columns.split(",")
            ignore_columns = [x.strip() for x in ignore_columns]
        else:
            ignore_columns = []


        # dump out the table definition
        dumper = TableSchemaDumper(search_type)
        dumper.set_delimiter("#-- Start Entry --#", "#-- End Entry --#")
        dumper.set_ignore_columns(ignore_columns)
        dumper.dump_to_tactic(path, mode='sobject')
Ejemplo n.º 6
0
    def handle_sobject(my, node):
        search_type = my.xml.get_attribute(node, "search_type")

        include_id = my.xml.get_attribute(node, "include_id")
        if include_id in [True, 'true']:
            include_id = True
        else:
            include_id = False


        ignore_columns = Xml.get_attribute(node, "ignore_columns")
        if ignore_columns:
            ignore_columns = ignore_columns.split(",")
            ignore_columns = [x.strip() for x in ignore_columns]
        else:
            ignore_columns = []

        # FIXME:
        # it is possible that the manifest defines sobjects on search types
        # that don't exist.  This is because it uses the manifest of
        # the new pipeline and not the original ... 
        sobjects = my.get_sobjects_by_node(node)
        if not sobjects:
            print "Skipping as no sobjects found for [%s]" %search_type
            return []



        # If there are no sobjects, then no file is created because
        # no path can be extracted.

        path = my.get_path_from_node(node)

        print "Writing: ", path
        fmode = 'w'
        if os.path.exists(path):
            fmode = 'a'
        if not sobjects:
            # write out an empty file
            #f = open(path, 'w')
            f = codecs.open(path, fmode, 'utf-8')
            f.close()
            return []

        dumper = TableDataDumper()
        dumper.set_delimiter("#-- Start Entry --#", "#-- End Entry --#")
        if search_type == 'config/widget_config':
            dumper.set_ignore_columns(['code'])
        dumper.set_include_id(include_id)
        dumper.set_ignore_columns(ignore_columns)
        dumper.set_sobjects(sobjects)
        dumper.dump_tactic_inserts(path, mode='sobject')

        print "\t....dumped [%s] entries" % (len(sobjects))

        return sobjects
Ejemplo n.º 7
0
    def handle_file_mode(self, base_dir, transaction_code, paths, log, transaction_xml, ticket):
        # drop the transaction into a folder

        timestamp = log.get_value("timestamp")
        timestamp = parser.parse(timestamp)
        timestamp = timestamp.strftime("%Y%m%d_%H%M%S")

        asset_dir = Environment.get_asset_dir()

        # create the transactions dir if it does not exist
        if not os.path.exists("%s/transactions" % base_dir):
            os.makedirs("%s/transactions" % base_dir)

        base_dir = "%s/transactions/%s" % (base_dir, transaction_code)

        is_encrypted = True
        if is_encrypted == True:
            # put the transaction in a temp folder
            tmp_dir = Environment.get_tmp_dir(include_ticket=True)
            tmp_dir = "%s/%s-%s" % (tmp_dir, transaction_code, timestamp)

        else:
            tmp_dir = "%s/%s" % (base_dir, timestamp)

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


        from pyasm.common import EncryptUtil
        encrypt = EncryptUtil(ticket)

        # create a simple manifest file
        f = open("%s/manifest.xml" % tmp_dir, 'wb')
        f.write('''<manifest code='transaction_log' version='1'>\n''')
        f.write('''  <sobject search_type="sthpw/transaction_log"/>\n''')
        f.write('''</manifest>\n''')
        f.close()


        tpath = "%s/sthpw_transaction_log.spt" % tmp_dir

        from pyasm.search import TableDataDumper
        dumper = TableDataDumper()
        dumper.set_delimiter("#-- Start Entry --#", "#-- End Entry --#")
        dumper.set_include_id(False)
        dumper.set_sobjects([log])
        dumper.dump_tactic_inserts(tpath, mode='sobject')


        tpath = "%s/_transaction.xml" % tmp_dir
        #f = open(tpath, 'wb')
        f = codecs.getwriter('utf8')(open(tpath, 'wb'))
        f.write(transaction_xml.to_string())
        f.close()


        # copy the checked in files
        for path in paths:
            rel_path = path.replace(asset_dir, "")
            rel_path = rel_path.lstrip("/")
            to_path = "%s/%s" % (tmp_dir, rel_path)
            to_dir = os.path.dirname(to_path)
            if not os.path.exists(to_dir):
                os.makedirs(to_dir)

            shutil.copy(path, to_dir)


        # zip up and encrypt the transaction
        if is_encrypted:
            zip_path = "%s.zip" % (tmp_dir)
            from pyasm.common import ZipUtil
            zip = ZipUtil()
            zip.zip_dir("%s" % (tmp_dir), zip_path)

            encrypt.encrypt_file(zip_path)


            shutil.move("%s.enc" % zip_path, "%s-%s.zip.enc" % (base_dir, timestamp))
            rmdir = os.path.dirname(tmp_dir)
            shutil.rmtree(rmdir)
            #os.unlink("%s.zip" % tmp_dir)


        job = self.kwargs.get("job")
        job.set_value("error_log", "")
        job.commit()


        return