コード例 #1
0
    def execute(self):

        import os
        path = self.kwargs.get("path")
        path = path.replace("\\", "/")
        basename = os.path.basename(path)

        upload_dir = Environment.get_upload_dir()

        path = "%s/%s" % (upload_dir, basename)

        paths = ZipUtil.extract(path)


        # TODO: why do we need to read the manifest here?
        # ... should be automatic
        manifest_path = "%s/transaction_log/manifest.xml" % upload_dir
        if not os.path.exists(manifest_path):
            raise TacticException("Cannot find manifest file [%s]" % manifest_path)
        f = codecs.open(manifest_path, 'r', 'utf-8')
        manifest_xml = f.read()
        f.close()
        creator = PluginInstaller(base_dir=upload_dir, manifest=manifest_xml)
        creator.execute()


        # run the transactions
        logs = creator.get_jobs()
        for log in logs:
            transaction_xml = log.get_value("transaction")
            cmd = RunTransactionCmd(transaction_xml=transaction_xml)
            cmd.execute()

            # This is needed here, because normaly, RunTransactionCmd
            # is run by a sync, so it blocks further syncs.  When
            # a transaction session is installed, we need to propogate
            # this to the other machines
            cmd = TransactionQueueAppendCmd()
            input = {
                'search_type': 'sthpw/transaction_log',
                'sobject': log
            }
            cmd.input = input
            cmd.execute()