Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • scs/ipaaca
  • ramin.yaghoubzadeh/ipaaca
2 results
Show changes
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# This file is part of IPAACA, the
# "Incremental Processing Architecture
# for Artificial Conversational Agents".
#
# Copyright (c) 2009-2015 Social Cognitive Systems Group
# CITEC, Bielefeld University
#
# http://opensource.cit-ec.de/projects/ipaaca/
# http://purl.org/net/ipaaca
#
# This file may be licensed under the terms of of the
# GNU Lesser General Public License Version 3 (the ``LGPL''),
# or (at your option) any later version.
#
# Software distributed under the License is distributed
# on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
# express or implied. See the LGPL for the specific language
# governing rights and limitations.
#
# You should have received a copy of the LGPL along with this
# program. If not, go to http://www.gnu.org/licenses/lgpl.html
# or write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# The development of this software was supported by the
# Excellence Cluster EXC 277 Cognitive Interaction Technology.
# The Excellence Cluster EXC 277 is a grant of the Deutsche
# Forschungsgemeinschaft (DFG) in the context of the German
# Excellence Initiative.
from __future__ import division, print_function
import logging
import os
import platform
import re
import sys
import time
import ipaaca
def event_type_color(typ):
colors = {
'ADDED': '32;1',
'RETRACTED': '31;1',
'UPDATED': '33;1',
'MESSAGE': '34;1',
'COMMITTED': '35;1',
'LINKSUPDATED': '36;1',
'RETRACTED': '37;1',
}
return colors.get(typ, '1')
def highlight_if_color(s, c='1'):
return s if arguments.color else '[' + c + 'm' + s +''
def pretty_printed_dict(d):
s='{\n'
for k, v in d.items():
if isinstance(v, unicode) or isinstance(v, str):
v = "'"+unicode(v)+"'"
else:
v = unicode(v)
v2 = v if len(v) <= arguments.max_size else v[:arguments.max_size] + '<excess length omitted>'
v2.replace('\\','\\\\').replace('\n', highlight_if_color('\\n'))
s += "\t '%s': %s,\n" % (highlight_if_color(unicode(k),'1'), unicode(v2))
s+='}'
return s
def pretty_printed_iu_event(iu, event_type, local):
s = ''
t = time.time()
lt = time.localtime(t)
s += highlight_if_color('%.3f' % t, '1')
s += ' %02d:%02d:%02d' % (lt.tm_hour, lt.tm_min, lt.tm_sec)
s += ' ' + highlight_if_color('%-9s' % event_type, event_type_color(event_type))
s += ' category=' + highlight_if_color(iu.category,event_type_color(event_type))
s += ' channel=' + iu.buffer._channel
s += ' uid=' + iu.uid
s += ' owner=' + iu.owner_name
if event_type is not 'MESSAGE':
s += '\nlinks=' + pretty_printed_dict(iu.get_all_links())
s += '\npayload=' + pretty_printed_dict(iu.payload)
return s
def machine_formatted_iu_event(iu, event_type, local):
return repr({
'time': time.time(),
'uid': iu.uid,
'category': iu.category,
'type': event_type,
'payload': iu.payload,
#'links': iu.links,
}).encode('utf-8')
def iu_event_recorder_handler(logfile, iu, event_type, local):
if arguments.regex:
for cat in arguments.categories: # actually now regexs, not categories
if re.match(cat, iu.category):
break
else:
return
if logfile is None:
# requested log to stdout, only printing the structured data
print(machine_formatted_iu_event(iu, event_type, local)+'\n')
else:
# write structured data to log file
logfile.write(machine_formatted_iu_event(iu, event_type, local)+'\n')
# duplicate human-readable on terminal (unless data being sent there)
print(pretty_printed_iu_event(iu, event_type, local), end='\n\n')
def exit(code):
ipaaca.exit(code)
#if platform.system() == 'Windows':
# os._exit(code)
#else:
# sys.exit(code)
parser = ipaaca.IpaacaArgumentParser(description='Ipaaca IU Session Recorder -- Selectively record [and print] IU streams')
parser.add_argument(
'-o', '--output-file',
dest='output_file',
default=['default.ipaacasession'],
metavar='OUTPUT-FILE',
nargs=1,
help="set the channels to listen on (otherwise 'default')")
parser.add_argument(
'--channels',
dest='channels',
default=['default'],
metavar='CHANNEL',
nargs='+',
help="set the channels to listen on (otherwise 'default')")
parser.add_argument(
'-c', '--categories',
default=[''],
dest='categories',
metavar='CATEGORY',
nargs='+',
help='set categories (or regex patterns) to be matched')
parser.add_argument(
'-e', '--event-types',
default=None,
dest='event_types',
metavar='EVENT-TYPE',
nargs='+',
help='set event types ({})'.format(' '.join(ipaaca.iu.IUEventType._choices)))
parser.add_argument(
'-r', '--regex',
action='store_true',
dest='regex',
help='match categories by regular expressions')
parser.add_argument(
'--no-color',
action='store_true',
dest='color',
help='do not colorize output')
parser.add_argument(
'--size-limit',
default=2048,
dest='max_size',
metavar='LIMIT',
type=int,
help='limit payload display chars (default: 2048)')
if __name__ == '__main__':
arguments = parser.parse_args()
buffers = {}
log_file = None if (arguments.output_file[0]=='-') else open(arguments.output_file[0], 'w')
# Create one input buffer for each channel we are listening on
for channel in arguments.channels:
buffers[channel] = ipaaca.InputBuffer(
'IpaacaIUSniffer',
category_interests=arguments.categories if not arguments.regex else [''],
channel=channel,
resend_active=True)
# Check whether the specified event_types are valid
if arguments.event_types is not None:
for et in arguments.event_types:
if et.upper() not in ipaaca.iu.IUEventType._choices:
print('ERROR: "{et}" is not a valid IPAACA event type.'.format(et=et.upper()))
exit(code=1)
buffers[channel].register_handler(
lambda iu,typ,loc: iu_event_recorder_handler(log_file, iu, typ, loc),
for_event_types=[et.upper() for et in arguments.event_types] if arguments.event_types is not None else None)
# Tell user what we are doing
print('ipaaca-session-record listening')
print(' * writing to file: '+('(stdout)' if log_file is None else arguments.output_file[0]))
print(' * on channel(s): ' + ', '.join(arguments.channels))
print(' * for event type(s): ', end='')
if arguments.event_types is None:
print('any')
else:
print(', '.join([highlight_if_color(et.upper(), event_type_color(et.upper())) for et in arguments.event_types]))
print(' * for category/ies', end='')
if arguments.categories == ['']:
print(': any')
else:
if arguments.regex:
print(' that match the regex', end='')
print(': ' + ', '.join(arguments.categories))
# Wait for the user to kill the sniffer
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
pass
except Exception, e:
print(u'Exception: '+unicode(traceback.format_exc()))
if log_file is not None:
log_file.close()
ipaaca.exit(1)
if log_file is not None:
log_file.close()
ipaaca.exit(0)
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# This file is part of IPAACA, the
# "Incremental Processing Architecture
# for Artificial Conversational Agents".
#
# Copyright (c) 2009-2015 Social Cognitive Systems Group
# CITEC, Bielefeld University
#
# http://opensource.cit-ec.de/projects/ipaaca/
# http://purl.org/net/ipaaca
#
# This file may be licensed under the terms of of the
# GNU Lesser General Public License Version 3 (the ``LGPL''),
# or (at your option) any later version.
#
# Software distributed under the License is distributed
# on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
# express or implied. See the LGPL for the specific language
# governing rights and limitations.
#
# You should have received a copy of the LGPL along with this
# program. If not, go to http://www.gnu.org/licenses/lgpl.html
# or write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# The development of this software was supported by the
# Excellence Cluster EXC 277 Cognitive Interaction Technology.
# The Excellence Cluster EXC 277 is a grant of the Deutsche
# Forschungsgemeinschaft (DFG) in the context of the German
# Excellence Initiative.
from __future__ import division, print_function
import itertools
import os
import platform
import sys
import time
import traceback
import ipaaca
def iu_update_handler(iu, event_type, local):
try:
print(event_type + ': ' + unicode(iu))
except:
print(u"An error occurred printing an IU for an event of type "+event_type)
parser = ipaaca.IpaacaArgumentParser(description='Ipaaca Session Replay -- Replay IU event logs from the command line')
parser.add_argument(
'-i', '--input-file',
default=['default.ipaacasession'],
dest='input_file',
metavar='INPUT-FILE',
nargs=1,
help='file from which to read IU data for replay')
parser.add_argument(
'-k', '--keep-alive',
default=1.0,
dest='keep_alive',
metavar='SECONDS',
type=float,
help='set time in seconds to wait for final remote IU updates (default: 1.0)')
parser.add_argument(
'-c', '--categories',
dest='categories',
metavar='CATEGORIES',
required=False,
default=[],
nargs='*',
help='send events for these categories only')
if __name__ == '__main__':
arguments = parser.parse_args()
for_categories = list(arguments.categories)
ob = ipaaca.OutputBuffer('IpaacaSessionReplay')
# CAUTION: special semantics for replay script: do NOT auto-retract at shutdown
# (should only replicate observed retractions form the data file!)
ob._teardown = lambda: True
ob.register_handler(iu_update_handler)
known_ius = {}
log_file = sys.stdin if (arguments.input_file[0]=='-') else open(arguments.input_file[0], 'r')
ref_time = None
last_time = None
for line in log_file:
record = eval(line, {'__builtins__': None}, {})
# event data
uid = record['uid']
category = record['category']
typ = record['type']
payload = record['payload']
# consider only if category filter passes
if len(for_categories)==0 or category in for_categories:
# take ref time from first event
if ref_time is None:
ref_time = record['time']
last_time = ref_time
# recreate delay from previous event
print('Sleep for '+str(record['time'] - last_time)+' s')
time.sleep(record['time'] - last_time)
last_time = record['time']
# do it
print('Synthesize event '+typ+' for IU UID '+uid+', category "'+category+'"')
if typ=='MESSAGE':
msg = ipaaca.Message(category)
msg.payload = payload
ob.add(msg)
elif typ=='ADDED':
if uid in known_ius:
print('ERROR - already added UID '+uid+' before!')
else:
iu = ipaaca.IU(category)
iu.payload = payload
ob.add(iu)
known_ius[uid] = iu
elif typ=='UPDATED':
if uid not in known_ius:
print('ERROR - have not received IU with UID '+uid+' before!')
else:
iu = known_ius[uid]
iu.payload = payload
elif typ=='COMMITTED':
if uid not in known_ius:
print('ERROR - have not received IU with UID '+uid+' before!')
else:
iu = known_ius[uid]
iu.commit()
elif typ=='RETRACTED':
if uid not in known_ius:
print('ERROR - have not received IU with UID '+uid+' before!')
else:
iu = known_ius[uid]
ob.remove(iu)
try:
print('Waiting; specified grace time '+str(arguments.keep_alive)+' s')
time.sleep(arguments.keep_alive)
except KeyboardInterrupt:
pass
except Exception, e:
print(u'Exception: '+unicode(traceback.format_exc()))
if log_file is not sys.stdin:
log_file.close()
ipaaca.exit(1)
if log_file is not sys.stdin:
log_file.close()
ipaaca.exit(0)
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# This file is part of IPAACA, the
# "Incremental Processing Architecture
# for Artificial Conversational Agents".
#
# Copyright (c) 2009-2016 Social Cognitive Systems Group
# CITEC, Bielefeld University
#
# http://opensource.cit-ec.de/projects/ipaaca/
# http://purl.org/net/ipaaca
#
# This file may be licensed under the terms of of the
# GNU Lesser General Public License Version 3 (the ``LGPL''),
# or (at your option) any later version.
#
# Software distributed under the License is distributed
# on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
# express or implied. See the LGPL for the specific language
# governing rights and limitations.
#
# You should have received a copy of the LGPL along with this
# program. If not, go to http://www.gnu.org/licenses/lgpl.html
# or write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# The development of this software was supported by the
# Excellence Cluster EXC 277 Cognitive Interaction Technology.
# The Excellence Cluster EXC 277 is a grant of the Deutsche
# Forschungsgemeinschaft (DFG) in the context of the German
# Excellence Initiative.
from __future__ import division, print_function
import os
import platform
import sys
import time
import traceback
import ipaaca
def exit(code):
ipaaca.exit(code)
#if platform.system() == 'Windows':
# os._exit(code)
#else:
# sys.exit(code)
parser = ipaaca.IpaacaArgumentParser(description='Ipaaca Maintainor')
if __name__ == '__main__':
arguments = parser.parse_args()
# Warn if user tries to configure a transport other than socket or a
# server mode other than server
if (ipaaca.defaults.IPAACA_DEFAULT_RSB_TRANSPORT is not None and
ipaaca.defaults.IPAACA_DEFAULT_RSB_TRANSPORT != 'socket'):
print("ERROR: Works only with RSB transport type 'socket'.")
ipaaca.exit(1)
if (ipaaca.defaults.IPAACA_DEFAULT_RSB_SOCKET_SERVER is not None and
ipaaca.defaults.IPAACA_DEFAULT_RSB_SOCKET_SERVER != '1'):
print("ERROR: Works only in socket server mode '0'.")
ipaaca.exit(1)
# Configure rsb socket transport
ipaaca.defaults.IPAACA_DEFAULT_RSB_TRANSPORT = 'socket'
ipaaca.defaults.IPAACA_DEFAULT_RSB_SOCKET_SERVER = '1'
ob = ipaaca.OutputBuffer("IPAACAMaintainor")
while True:
try:
time.sleep(1)
except KeyboardInterrupt:
decision = raw_input('Shutdown the IPAACA socket transport hub (y/[n])?')
if decision in 'yY':
break
except Exception, e:
print(u'Exception: '+unicode(traceback.format_exc()))
ipaaca.exit(1)
ipaaca.exit(0)
......@@ -5,6 +5,15 @@ if [ -d /vol/soa/opt64/spread ]; then
/vol/soa/opt64/spread/current/sbin/spread -n localhost &
else
echo "Starting local-only spread daemon for ipaaca ..."
spread -n localhost &
spr=`which spread`
[ $? -eq 0 ] || {
echo spread not found in PATH - searching in /usr/sbin and /usr/local/sbin
spr=''
[ -e /usr/local/sbin/spread ] && spr="/usr/local/sbin/spread"
[ -e /usr/sbin/spread ] && spr="/usr/sbin/spread"
[ "$spr" = "" ] && echo "Could not find spread"
echo $spr
}
${spr} -n localhost &
fi
#!/bin/bash
PACKAGES="rsb"
# This file has been auto-generated by the soa script.
eval "`grep '^REQUIRED=\|^OPTIONAL=' DEPS.txt`"
REQ="$REQUIRED"
OPT="$OPTIONAL"
shopt -q nullglob || resetnullglob=1
shopt -s nullglob
shopt -q dotglob || resetdotglob=1
shopt -s dotglob
echo "Performing local resolution... "
mkdir -p deps/bin
mkdir -p deps/lib
mkdir -p deps/include
mkdir -p deps/scripts
mkdir -p deps/python
for P in $PACKAGES; do
for P in $REQ $OPT; do
echo "Importing from $P ..."
files=(../$P/dist/bin/*);
[ "$files" ] && cp -a ../$P/dist/bin/* deps/bin/
files=(../$P/dist/lib/*);
......@@ -25,8 +27,21 @@ for P in $PACKAGES; do
[ "$files" ] && for zipfile in ../$P/dist/python/*.zip; do
unzip -oqq $zipfile -d deps/python
done
files=(../$P/dist/*.cpp.zip);
[ "$files" ] && for zipfile in ../$P/dist/*.cpp.zip; do
unzip -oqq $zipfile -d deps/
done
files=(../$P/dist/*.py.zip);
[ "$files" ] && for zipfile in ../$P/dist/*.py.zip; do
unzip -oqq $zipfile -d deps/python
done
files=(../$P/dist/*.scripts.zip);
[ "$files" ] && for zipfile in ../$P/dist/*.scripts.zip; do
unzip -oqq $zipfile -d deps/scripts
done
chmod -R +x deps/bin
chmod -R +x deps/scripts
done
echo "Done."
[ "$resetdotglob" ] && shopt -u dotglob
[ "$resetnullglob" ] && shopt -u nullglob
[ "$resetnullglob" ] && shopt -u nullglob