Example #1
0
    def execute(my):

        force = my.kwargs.get("force")
        clean = my.kwargs.get("clean")
        if clean in [False, 'false']:
            clean = False

        # ensure that plugin dir is empty
        if os.path.exists(my.plugin_dir):
            if clean:
                if force in ['true', True]:
                    shutil.rmtree(my.plugin_dir)
                else:
                    raise Exception("Plugin is already located at [%s]" % my.plugin_dir)
       
        
        if not os.path.exists(my.plugin_dir):
            os.makedirs(my.plugin_dir)


        # build the information from the manifest

        code = my.kwargs.get("code")
        if not code:
            code = my.xml.get_value("manifest/@code")

        version = my.kwargs.get("version")
        if not version:
            version = my.xml.get_value("manifest/@version")

        nodes = my.xml.get_nodes("manifest/*")


        # clean out all of the files
        my.delete_files(nodes)


        has_info = False
        sobjects = []

        # handle all of the nodes in the manifest
        for i, node in enumerate(nodes):
            name = my.xml.get_node_name(node)
            if name == 'sobject':
                dumped_sobjects = my.handle_sobject(node)
                if not dumped_sobjects:
                    dumped_sobjects = []
                sobjects.extend(dumped_sobjects)
            elif name == 'search_type':
                my.handle_search_type(node)
            elif name == 'include':
                my.handle_include(node)
            elif name == 'python':
                my.handle_python(node)


        # make sure there is a data node and handle it
        data_node = my.xml.get_node("manifest/data")
        if data_node is None:
            root_node = my.xml.get_root_node()
            data_node = my.xml.create_element("data")
            child = my.xml.get_first_child(root_node)
            if child is None:
                my.xml.append_child(root_node, data_node)
            else:
                my.xml.insert_before(data_node, child)

        my.handle_data(data_node)
            
 



        manifest_path = "%s/manifest.xml" % (my.plugin_dir)
        file = codecs.getwriter('utf8')(open(manifest_path, 'wb'))
        file.write(my.xml.to_string())
        file.close()

        # FIXME: leaving this out for now
        #my.handle_snapshots()

        dist_dir = my.kwargs.get("dist_dir")
        if not dist_dir:
            dist_dir = Environment.get_dist_dir()

        # get the basename of the code
        basecode = os.path.basename(my.code)

        # zip up the contents
        import zipfile
        if version:
            zip_path = "%s/%s-%s.zip" % (dist_dir, basecode, version)
        else:
            zip_path = "%s/%s.zip" % (dist_dir, basecode)

        print "Zipping up plugin file [%s]" % zip_path
        print "    from [%s]" % my.plugin_dir
        from pyasm.common import ZipUtil
        ignore_dirs = ['.svn']

        # ignore file
        #ignore_path = "%s/.ignore" % (my.plugin_dir)

        parts = my.code.split("/")
        root_dir = "%s/%s" % (my.base_dir, parts[0])
        if len(parts) >= 2:
            include_dirs = ["/".join(parts[1:])]
        else:
            include_dirs = None

        ZipUtil.zip_dir(root_dir, zip_path, ignore_dirs=ignore_dirs, include_dirs=include_dirs)
        print "... done"

        #f = codecs.open(zip_path, 'w')
        #zip = zipfile.ZipFile(f, 'w', compression=zipfile.ZIP_DEFLATED)
        #my.zip_dir(zip, my.plugin_dir, "asset", rel_dir='')

        my.zip_path = zip_path

        # encrypt the file
        """
        print "encrypting!!!!", zip_path
        my.enc_path = "%s.enc" % zip_path
        from pyasm.common import EncryptUtil
        ticket = "OMG"
        encrypt = EncryptUtil(ticket)
        encrypt.encrypt_file(zip_path)
        """


        # register the plugin into the current project
        if my.kwargs.get("register") in [True, 'true']:

            # first check if a plugin with this code already exists
            plugin = Search.get_by_code("config/plugin", my.code)
            if plugin:
                raise TacticException("Plugin [%s] already existed in the project." % my.code)
            # create a new one
            plugin = SearchType.create("config/plugin")
            plugin.set_value("code", my.code)
           
            # update the information
            if version:
                plugin.set_value("version", version)

            # NOTE: not sure if this is desirable
            plugin.set_value("manifest", my.manifest)

            if my.plugin_dir.startswith(my.base_dir):
                rel_dir = my.plugin_dir.replace(my.base_dir, "")
                rel_dir = rel_dir.lstrip("/")
                plugin.set_value("rel_dir", rel_dir)

            plugin.commit()

            # record all of the sobject exported
            if plugin.get_value("type", no_exception=True) == "config":
                for sobject in sobjects:                    
                    plugin_content = SearchType.create("config/plugin_content")
                    plugin_content.set_value("search_type", sobject.get_search_type())
                    plugin_content.set_value("search_code", sobject.get_code())
                    plugin_content.set_value("plugin_code", my.code)
                    plugin_content.commit()
Example #2
0
    def execute(my):

        force = my.kwargs.get("force")
        clean = my.kwargs.get("clean")
        if clean in [False, 'false']:
            clean = False

        # ensure that plugin dir is empty
        if os.path.exists(my.plugin_dir):
            if clean:
                if force in ['true', True]:
                    shutil.rmtree(my.plugin_dir)
                else:
                    raise Exception("Plugin is already located at [%s]" % my.plugin_dir)
       
        
        if not os.path.exists(my.plugin_dir):
            os.makedirs(my.plugin_dir)


        # build the information from the manifest

        code = my.kwargs.get("code")
        if not code:
            code = my.xml.get_value("manifest/@code")

        version = my.kwargs.get("version")
        if not version:
            version = my.xml.get_value("manifest/@version")

        nodes = my.xml.get_nodes("manifest/*")


        # clean out all of the files
        my.delete_files(nodes)


        has_info = False
        sobjects = []

        # handle all of the nodes in the manifest
        for i, node in enumerate(nodes):
            name = my.xml.get_node_name(node)
            if name == 'sobject':
                dumped_sobjects = my.handle_sobject(node)
                if not dumped_sobjects:
                    dumped_sobjects = []
                sobjects.extend(dumped_sobjects)
            elif name == 'search_type':
                my.handle_search_type(node)
            elif name == 'include':
                my.handle_include(node)
            elif name == 'python':
                my.handle_python(node)


        # make sure there is a data node and handle it
        data_node = my.xml.get_node("manifest/data")
        if data_node is None:
            root_node = my.xml.get_root_node()
            data_node = my.xml.create_element("data")
            child = my.xml.get_first_child(root_node)
            if child is None:
                my.xml.append_child(root_node, data_node)
            else:
                my.xml.insert_before(data_node, child)

        my.handle_data(data_node)
            
 



        manifest_path = "%s/manifest.xml" % (my.plugin_dir)
        file = codecs.getwriter('utf8')(open(manifest_path, 'wb'))
        file.write(my.xml.to_string())
        file.close()

        # FIXME: leaving this out for now
        #my.handle_snapshots()

        dist_dir = my.kwargs.get("dist_dir")
        if not dist_dir:
            dist_dir = Environment.get_dist_dir()

        # get the basename of the code
        basecode = os.path.basename(my.code)

        # zip up the contents
        import zipfile
        if version:
            zip_path = "%s/%s-%s.zip" % (dist_dir, basecode, version)
        else:
            zip_path = "%s/%s.zip" % (dist_dir, basecode)

        print "Zipping up plugin file [%s]" % zip_path
        print "    from [%s]" % my.plugin_dir
        from pyasm.common import ZipUtil
        ignore_dirs = ['.svn']

        # ignore file
        #ignore_path = "%s/.ignore" % (my.plugin_dir)

        parts = my.code.split("/")
        root_dir = "%s/%s" % (my.base_dir, parts[0])
        if len(parts) >= 2:
            include_dirs = ["/".join(parts[1:])]
        else:
            include_dirs = None

        ZipUtil.zip_dir(root_dir, zip_path, ignore_dirs=ignore_dirs, include_dirs=include_dirs)
        print "... done"

        #f = codecs.open(zip_path, 'w')
        #zip = zipfile.ZipFile(f, 'w', compression=zipfile.ZIP_DEFLATED)
        #my.zip_dir(zip, my.plugin_dir, "asset", rel_dir='')

        my.zip_path = zip_path

        # encrypt the file
        """
        print "encrypting!!!!", zip_path
        my.enc_path = "%s.enc" % zip_path
        from pyasm.common import EncryptUtil
        ticket = "OMG"
        encrypt = EncryptUtil(ticket)
        encrypt.encrypt_file(zip_path)
        """


        # register the plugin into the current project
        if my.kwargs.get("register") in [True, 'true']:

            # first check if a plugin with this code already exists
            plugin = Search.get_by_code("config/plugin", my.code)
            if plugin:
                raise TacticException("Plugin [%s] already existed in the project." % my.code)
            # create a new one
            plugin = SearchType.create("config/plugin")
            plugin.set_value("code", my.code)
           
            # update the information
            if version:
                plugin.set_value("version", version)

            # NOTE: not sure if this is desirable
            plugin.set_value("manifest", my.manifest)

            if my.plugin_dir.startswith(my.base_dir):
                rel_dir = my.plugin_dir.replace(my.base_dir, "")
                rel_dir = rel_dir.lstrip("/")
                plugin.set_value("rel_dir", rel_dir)

            plugin.commit()

            # record all of the sobject exported
            if plugin.get_value("type", no_exception=True) == "config":
                for sobject in sobjects:                    
                    plugin_content = SearchType.create("config/plugin_content")
                    plugin_content.set_value("search_type", sobject.get_search_type())
                    plugin_content.set_value("search_code", sobject.get_code())
                    plugin_content.set_value("plugin_code", my.code)
                    plugin_content.commit()
Example #3
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