def execute(self): project_code = self.kwargs.get("project_code") transaction_code = self.kwargs.get("transaction_code") login = self.kwargs.get("login") session = self.kwargs.get("session") start_time = session.get("start_time") end_time = session.get("end_time") search_keys = session.get("search_keys") if search_keys != None: if search_keys == '': raise TacticException("No search keys passed in") search_keys = search_keys.split("|") if not search_keys: raise TacticException("No search keys passed in") transactions = Search.get_by_search_keys(search_keys) codes = [x.get_code() for x in transactions] assert len(search_keys) == len(codes) expr = '''@SOBJECT(sthpw/transaction_log['code','in','%s']['@ORDER_BY','code asc'])''' % ("|".join(codes)) else: expr = '''@SOBJECT(sthpw/transaction_log['login','%s']['namespace','%s']['timestamp','>','%s']['timestamp','<','%s']['@ORDER_BY','code asc'])''' % (login, project_code, start_time, end_time) manifest_xml = ''' <manifest code='transaction_log' version='1'> <sobject expression="%s" search_type="sthpw/transaction_log"/> </manifest> ''' % (expr) plugin = SearchType.create("sthpw/plugin") plugin.set_value("code", "transaction_log") plugin.set_value("version", "1.0") creator = PluginCreator(manifest=manifest_xml, plugin=plugin) creator.execute() plugin_path = creator.get_plugin_path() plugin_dir = creator.get_plugin_dir() # find all the logs (again!!!) # FIXME: should get from plugin expr = expr.replace(">", ">") expr = expr.replace("<", "<") logs = Search.eval(expr) asset_dir = Environment.get_asset_dir() for log in logs: transaction_xml = log.get_xml_value("transaction").to_string() cmd = TransactionFilesCmd(transaction_xml=transaction_xml) paths = cmd.execute() for path in paths: rel_path = path.replace(asset_dir, "") rel_path = rel_path.lstrip("/") new_path = "%s/assets/%s" % (plugin_dir, rel_path) dirname = os.path.dirname(new_path) if not os.path.exists(dirname): os.makedirs(dirname) print("adding: [%s]" % new_path) shutil.copy(path, new_path)