repository_name
stringlengths
7
55
func_path_in_repository
stringlengths
4
223
func_name
stringlengths
1
134
whole_func_string
stringlengths
75
104k
language
stringclasses
1 value
func_code_string
stringlengths
75
104k
func_code_tokens
listlengths
19
28.4k
func_documentation_string
stringlengths
1
46.9k
func_documentation_tokens
listlengths
1
1.97k
split_name
stringclasses
1 value
func_code_url
stringlengths
87
315
napalm-automation/napalm-logs
napalm_logs/serializer/__init__.py
get_serializer
def get_serializer(name): ''' Return the serialize function. ''' try: log.debug('Using %s as serializer', name) return SERIALIZER_LOOKUP[name] except KeyError: msg = 'Serializer {} is not available'.format(name) log.error(msg, exc_info=True) raise InvalidSeria...
python
def get_serializer(name): ''' Return the serialize function. ''' try: log.debug('Using %s as serializer', name) return SERIALIZER_LOOKUP[name] except KeyError: msg = 'Serializer {} is not available'.format(name) log.error(msg, exc_info=True) raise InvalidSeria...
[ "def", "get_serializer", "(", "name", ")", ":", "try", ":", "log", ".", "debug", "(", "'Using %s as serializer'", ",", "name", ")", "return", "SERIALIZER_LOOKUP", "[", "name", "]", "except", "KeyError", ":", "msg", "=", "'Serializer {} is not available'", ".", ...
Return the serialize function.
[ "Return", "the", "serialize", "function", "." ]
train
https://github.com/napalm-automation/napalm-logs/blob/4b89100a6e4f994aa004f3ea42a06dc803a7ccb0/napalm_logs/serializer/__init__.py#L34-L44
napalm-automation/napalm-logs
napalm_logs/auth.py
NapalmLogsAuthProc._handshake
def _handshake(self, conn, addr): ''' Ensures that the client receives the AES key. ''' # waiting for the magic request message msg = conn.recv(len(MAGIC_REQ)) log.debug('Received message %s from %s', msg, addr) if msg != MAGIC_REQ: log.warning('%s is ...
python
def _handshake(self, conn, addr): ''' Ensures that the client receives the AES key. ''' # waiting for the magic request message msg = conn.recv(len(MAGIC_REQ)) log.debug('Received message %s from %s', msg, addr) if msg != MAGIC_REQ: log.warning('%s is ...
[ "def", "_handshake", "(", "self", ",", "conn", ",", "addr", ")", ":", "# waiting for the magic request message", "msg", "=", "conn", ".", "recv", "(", "len", "(", "MAGIC_REQ", ")", ")", "log", ".", "debug", "(", "'Received message %s from %s'", ",", "msg", "...
Ensures that the client receives the AES key.
[ "Ensures", "that", "the", "client", "receives", "the", "AES", "key", "." ]
train
https://github.com/napalm-automation/napalm-logs/blob/4b89100a6e4f994aa004f3ea42a06dc803a7ccb0/napalm_logs/auth.py#L79-L104
napalm-automation/napalm-logs
napalm_logs/auth.py
NapalmLogsAuthProc.keep_alive
def keep_alive(self, conn): ''' Maintains auth sessions ''' while self.__up: msg = conn.recv(len(AUTH_KEEP_ALIVE)) if msg != AUTH_KEEP_ALIVE: log.error('Received something other than %s', AUTH_KEEP_ALIVE) conn.close() ...
python
def keep_alive(self, conn): ''' Maintains auth sessions ''' while self.__up: msg = conn.recv(len(AUTH_KEEP_ALIVE)) if msg != AUTH_KEEP_ALIVE: log.error('Received something other than %s', AUTH_KEEP_ALIVE) conn.close() ...
[ "def", "keep_alive", "(", "self", ",", "conn", ")", ":", "while", "self", ".", "__up", ":", "msg", "=", "conn", ".", "recv", "(", "len", "(", "AUTH_KEEP_ALIVE", ")", ")", "if", "msg", "!=", "AUTH_KEEP_ALIVE", ":", "log", ".", "error", "(", "'Received...
Maintains auth sessions
[ "Maintains", "auth", "sessions" ]
train
https://github.com/napalm-automation/napalm-logs/blob/4b89100a6e4f994aa004f3ea42a06dc803a7ccb0/napalm_logs/auth.py#L106-L121
napalm-automation/napalm-logs
napalm_logs/auth.py
NapalmLogsAuthProc.verify_cert
def verify_cert(self): ''' Checks that the provided cert and key are valid and usable ''' log.debug('Verifying the %s certificate, keyfile: %s', self.certificate, self.keyfile) try: ssl.create_default_context().load_cert_chain(self.certificate, keyfi...
python
def verify_cert(self): ''' Checks that the provided cert and key are valid and usable ''' log.debug('Verifying the %s certificate, keyfile: %s', self.certificate, self.keyfile) try: ssl.create_default_context().load_cert_chain(self.certificate, keyfi...
[ "def", "verify_cert", "(", "self", ")", ":", "log", ".", "debug", "(", "'Verifying the %s certificate, keyfile: %s'", ",", "self", ".", "certificate", ",", "self", ".", "keyfile", ")", "try", ":", "ssl", ".", "create_default_context", "(", ")", ".", "load_cert...
Checks that the provided cert and key are valid and usable
[ "Checks", "that", "the", "provided", "cert", "and", "key", "are", "valid", "and", "usable" ]
train
https://github.com/napalm-automation/napalm-logs/blob/4b89100a6e4f994aa004f3ea42a06dc803a7ccb0/napalm_logs/auth.py#L123-L138
napalm-automation/napalm-logs
napalm_logs/auth.py
NapalmLogsAuthProc._create_skt
def _create_skt(self): ''' Create the authentication socket. ''' log.debug('Creating the auth socket') if ':' in self.auth_address: self.socket = socket.socket(socket.AF_INET6, socket.SOCK_STREAM) else: self.socket = socket.socket(socket.AF_INET, s...
python
def _create_skt(self): ''' Create the authentication socket. ''' log.debug('Creating the auth socket') if ':' in self.auth_address: self.socket = socket.socket(socket.AF_INET6, socket.SOCK_STREAM) else: self.socket = socket.socket(socket.AF_INET, s...
[ "def", "_create_skt", "(", "self", ")", ":", "log", ".", "debug", "(", "'Creating the auth socket'", ")", "if", "':'", "in", "self", ".", "auth_address", ":", "self", ".", "socket", "=", "socket", ".", "socket", "(", "socket", ".", "AF_INET6", ",", "sock...
Create the authentication socket.
[ "Create", "the", "authentication", "socket", "." ]
train
https://github.com/napalm-automation/napalm-logs/blob/4b89100a6e4f994aa004f3ea42a06dc803a7ccb0/napalm_logs/auth.py#L140-L154
napalm-automation/napalm-logs
napalm_logs/auth.py
NapalmLogsAuthProc.start
def start(self): ''' Listen to auth requests and send the AES key. Each client connection starts a new thread. ''' # Start suicide polling thread log.debug('Starting the auth process') self.verify_cert() self._create_skt() log.debug('The auth proce...
python
def start(self): ''' Listen to auth requests and send the AES key. Each client connection starts a new thread. ''' # Start suicide polling thread log.debug('Starting the auth process') self.verify_cert() self._create_skt() log.debug('The auth proce...
[ "def", "start", "(", "self", ")", ":", "# Start suicide polling thread", "log", ".", "debug", "(", "'Starting the auth process'", ")", "self", ".", "verify_cert", "(", ")", "self", ".", "_create_skt", "(", ")", "log", ".", "debug", "(", "'The auth process can re...
Listen to auth requests and send the AES key. Each client connection starts a new thread.
[ "Listen", "to", "auth", "requests", "and", "send", "the", "AES", "key", ".", "Each", "client", "connection", "starts", "a", "new", "thread", "." ]
train
https://github.com/napalm-automation/napalm-logs/blob/4b89100a6e4f994aa004f3ea42a06dc803a7ccb0/napalm_logs/auth.py#L156-L192
napalm-automation/napalm-logs
napalm_logs/auth.py
NapalmLogsAuthProc.stop
def stop(self): ''' Stop the auth proc. ''' log.info('Stopping auth process') self.__up = False self.socket.close()
python
def stop(self): ''' Stop the auth proc. ''' log.info('Stopping auth process') self.__up = False self.socket.close()
[ "def", "stop", "(", "self", ")", ":", "log", ".", "info", "(", "'Stopping auth process'", ")", "self", ".", "__up", "=", "False", "self", ".", "socket", ".", "close", "(", ")" ]
Stop the auth proc.
[ "Stop", "the", "auth", "proc", "." ]
train
https://github.com/napalm-automation/napalm-logs/blob/4b89100a6e4f994aa004f3ea42a06dc803a7ccb0/napalm_logs/auth.py#L194-L200
napalm-automation/napalm-logs
napalm_logs/buffer/__init__.py
get_interface
def get_interface(name): ''' Return the serialize function. ''' try: log.debug('Using %s as buffer interface', name) return BUFFER_LOOKUP[name] except KeyError: msg = 'Buffer interface {} is not available'.format(name) log.error(msg, exc_info=True) raise Inval...
python
def get_interface(name): ''' Return the serialize function. ''' try: log.debug('Using %s as buffer interface', name) return BUFFER_LOOKUP[name] except KeyError: msg = 'Buffer interface {} is not available'.format(name) log.error(msg, exc_info=True) raise Inval...
[ "def", "get_interface", "(", "name", ")", ":", "try", ":", "log", ".", "debug", "(", "'Using %s as buffer interface'", ",", "name", ")", "return", "BUFFER_LOOKUP", "[", "name", "]", "except", "KeyError", ":", "msg", "=", "'Buffer interface {} is not available'", ...
Return the serialize function.
[ "Return", "the", "serialize", "function", "." ]
train
https://github.com/napalm-automation/napalm-logs/blob/4b89100a6e4f994aa004f3ea42a06dc803a7ccb0/napalm_logs/buffer/__init__.py#L28-L38
napalm-automation/napalm-logs
napalm_logs/listener/kafka.py
KafkaListener.start
def start(self): ''' Startup the kafka consumer. ''' log.debug('Creating the consumer using the bootstrap servers: %s and the group ID: %s', self.bootstrap_servers, self.group_id) try: self.consumer = kafka.KafkaConsumer(bootstrap_s...
python
def start(self): ''' Startup the kafka consumer. ''' log.debug('Creating the consumer using the bootstrap servers: %s and the group ID: %s', self.bootstrap_servers, self.group_id) try: self.consumer = kafka.KafkaConsumer(bootstrap_s...
[ "def", "start", "(", "self", ")", ":", "log", ".", "debug", "(", "'Creating the consumer using the bootstrap servers: %s and the group ID: %s'", ",", "self", ".", "bootstrap_servers", ",", "self", ".", "group_id", ")", "try", ":", "self", ".", "consumer", "=", "ka...
Startup the kafka consumer.
[ "Startup", "the", "kafka", "consumer", "." ]
train
https://github.com/napalm-automation/napalm-logs/blob/4b89100a6e4f994aa004f3ea42a06dc803a7ccb0/napalm_logs/listener/kafka.py#L41-L55
napalm-automation/napalm-logs
napalm_logs/listener/kafka.py
KafkaListener.receive
def receive(self): ''' Return the message received and the address. ''' try: msg = next(self.consumer) except ValueError as error: log.error('Received kafka error: %s', error, exc_info=True) raise ListenerException(error) log_source = m...
python
def receive(self): ''' Return the message received and the address. ''' try: msg = next(self.consumer) except ValueError as error: log.error('Received kafka error: %s', error, exc_info=True) raise ListenerException(error) log_source = m...
[ "def", "receive", "(", "self", ")", ":", "try", ":", "msg", "=", "next", "(", "self", ".", "consumer", ")", "except", "ValueError", "as", "error", ":", "log", ".", "error", "(", "'Received kafka error: %s'", ",", "error", ",", "exc_info", "=", "True", ...
Return the message received and the address.
[ "Return", "the", "message", "received", "and", "the", "address", "." ]
train
https://github.com/napalm-automation/napalm-logs/blob/4b89100a6e4f994aa004f3ea42a06dc803a7ccb0/napalm_logs/listener/kafka.py#L57-L74
napalm-automation/napalm-logs
napalm_logs/listener/kafka.py
KafkaListener.stop
def stop(self): ''' Shutdown kafka consumer. ''' log.info('Stopping te kafka listener class') self.consumer.unsubscribe() self.consumer.close()
python
def stop(self): ''' Shutdown kafka consumer. ''' log.info('Stopping te kafka listener class') self.consumer.unsubscribe() self.consumer.close()
[ "def", "stop", "(", "self", ")", ":", "log", ".", "info", "(", "'Stopping te kafka listener class'", ")", "self", ".", "consumer", ".", "unsubscribe", "(", ")", "self", ".", "consumer", ".", "close", "(", ")" ]
Shutdown kafka consumer.
[ "Shutdown", "kafka", "consumer", "." ]
train
https://github.com/napalm-automation/napalm-logs/blob/4b89100a6e4f994aa004f3ea42a06dc803a7ccb0/napalm_logs/listener/kafka.py#L76-L82
napalm-automation/napalm-logs
napalm_logs/transport/__init__.py
get_transport
def get_transport(name): ''' Return the transport class. ''' try: log.debug('Using %s as transport', name) return TRANSPORT_LOOKUP[name] except KeyError: msg = 'Transport {} is not available. Are the dependencies installed?'.format(name) log.error(msg, exc_info=True) ...
python
def get_transport(name): ''' Return the transport class. ''' try: log.debug('Using %s as transport', name) return TRANSPORT_LOOKUP[name] except KeyError: msg = 'Transport {} is not available. Are the dependencies installed?'.format(name) log.error(msg, exc_info=True) ...
[ "def", "get_transport", "(", "name", ")", ":", "try", ":", "log", ".", "debug", "(", "'Using %s as transport'", ",", "name", ")", "return", "TRANSPORT_LOOKUP", "[", "name", "]", "except", "KeyError", ":", "msg", "=", "'Transport {} is not available. Are the depend...
Return the transport class.
[ "Return", "the", "transport", "class", "." ]
train
https://github.com/napalm-automation/napalm-logs/blob/4b89100a6e4f994aa004f3ea42a06dc803a7ccb0/napalm_logs/transport/__init__.py#L50-L60
napalm-automation/napalm-logs
napalm_logs/listener/zeromq.py
ZMQListener.start
def start(self): ''' Startup the zmq consumer. ''' zmq_uri = '{protocol}://{address}:{port}'.format( protocol=self.protocol, address=self.address, port=self.port ) if self.port else\ ...
python
def start(self): ''' Startup the zmq consumer. ''' zmq_uri = '{protocol}://{address}:{port}'.format( protocol=self.protocol, address=self.address, port=self.port ) if self.port else\ ...
[ "def", "start", "(", "self", ")", ":", "zmq_uri", "=", "'{protocol}://{address}:{port}'", ".", "format", "(", "protocol", "=", "self", ".", "protocol", ",", "address", "=", "self", ".", "address", ",", "port", "=", "self", ".", "port", ")", "if", "self",...
Startup the zmq consumer.
[ "Startup", "the", "zmq", "consumer", "." ]
train
https://github.com/napalm-automation/napalm-logs/blob/4b89100a6e4f994aa004f3ea42a06dc803a7ccb0/napalm_logs/listener/zeromq.py#L45-L82
napalm-automation/napalm-logs
napalm_logs/listener/zeromq.py
ZMQListener.receive
def receive(self): ''' Return the message received. ..note:: In ZMQ we are unable to get the address where we got the message from. ''' try: msg = self.sub.recv() except zmq.Again as error: log.error('Unable to receive messages: %s', e...
python
def receive(self): ''' Return the message received. ..note:: In ZMQ we are unable to get the address where we got the message from. ''' try: msg = self.sub.recv() except zmq.Again as error: log.error('Unable to receive messages: %s', e...
[ "def", "receive", "(", "self", ")", ":", "try", ":", "msg", "=", "self", ".", "sub", ".", "recv", "(", ")", "except", "zmq", ".", "Again", "as", "error", ":", "log", ".", "error", "(", "'Unable to receive messages: %s'", ",", "error", ",", "exc_info", ...
Return the message received. ..note:: In ZMQ we are unable to get the address where we got the message from.
[ "Return", "the", "message", "received", "." ]
train
https://github.com/napalm-automation/napalm-logs/blob/4b89100a6e4f994aa004f3ea42a06dc803a7ccb0/napalm_logs/listener/zeromq.py#L84-L97
napalm-automation/napalm-logs
napalm_logs/listener/zeromq.py
ZMQListener.stop
def stop(self): ''' Shutdown zmq listener. ''' log.info('Stopping the zmq listener class') self.sub.close() self.ctx.term()
python
def stop(self): ''' Shutdown zmq listener. ''' log.info('Stopping the zmq listener class') self.sub.close() self.ctx.term()
[ "def", "stop", "(", "self", ")", ":", "log", ".", "info", "(", "'Stopping the zmq listener class'", ")", "self", ".", "sub", ".", "close", "(", ")", "self", ".", "ctx", ".", "term", "(", ")" ]
Shutdown zmq listener.
[ "Shutdown", "zmq", "listener", "." ]
train
https://github.com/napalm-automation/napalm-logs/blob/4b89100a6e4f994aa004f3ea42a06dc803a7ccb0/napalm_logs/listener/zeromq.py#L99-L105
napalm-automation/napalm-logs
napalm_logs/listener/udp.py
UDPListener.start
def start(self): ''' Create the UDP listener socket. ''' if ':' in self.address: self.skt = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM) else: self.skt = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) if self.reuse_port: self.skt...
python
def start(self): ''' Create the UDP listener socket. ''' if ':' in self.address: self.skt = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM) else: self.skt = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) if self.reuse_port: self.skt...
[ "def", "start", "(", "self", ")", ":", "if", "':'", "in", "self", ".", "address", ":", "self", ".", "skt", "=", "socket", ".", "socket", "(", "socket", ".", "AF_INET6", ",", "socket", ".", "SOCK_DGRAM", ")", "else", ":", "self", ".", "skt", "=", ...
Create the UDP listener socket.
[ "Create", "the", "UDP", "listener", "socket", "." ]
train
https://github.com/napalm-automation/napalm-logs/blob/4b89100a6e4f994aa004f3ea42a06dc803a7ccb0/napalm_logs/listener/udp.py#L43-L62
napalm-automation/napalm-logs
napalm_logs/listener/udp.py
UDPListener.receive
def receive(self): ''' Return the message received and the address. ''' try: msg, addr = self.skt.recvfrom(self.buffer_size) except socket.error as error: log.error('Received listener socket error: %s', error, exc_info=True) raise ListenerExcep...
python
def receive(self): ''' Return the message received and the address. ''' try: msg, addr = self.skt.recvfrom(self.buffer_size) except socket.error as error: log.error('Received listener socket error: %s', error, exc_info=True) raise ListenerExcep...
[ "def", "receive", "(", "self", ")", ":", "try", ":", "msg", ",", "addr", "=", "self", ".", "skt", ".", "recvfrom", "(", "self", ".", "buffer_size", ")", "except", "socket", ".", "error", "as", "error", ":", "log", ".", "error", "(", "'Received listen...
Return the message received and the address.
[ "Return", "the", "message", "received", "and", "the", "address", "." ]
train
https://github.com/napalm-automation/napalm-logs/blob/4b89100a6e4f994aa004f3ea42a06dc803a7ccb0/napalm_logs/listener/udp.py#L64-L74
napalm-automation/napalm-logs
napalm_logs/proc.py
NapalmLogsProc._suicide_when_without_parent
def _suicide_when_without_parent(self, parent_pid): ''' Kill this process when the parent died. ''' while True: time.sleep(5) try: # Check pid alive os.kill(parent_pid, 0) except OSError: # Forcibly exit ...
python
def _suicide_when_without_parent(self, parent_pid): ''' Kill this process when the parent died. ''' while True: time.sleep(5) try: # Check pid alive os.kill(parent_pid, 0) except OSError: # Forcibly exit ...
[ "def", "_suicide_when_without_parent", "(", "self", ",", "parent_pid", ")", ":", "while", "True", ":", "time", ".", "sleep", "(", "5", ")", "try", ":", "# Check pid alive", "os", ".", "kill", "(", "parent_pid", ",", "0", ")", "except", "OSError", ":", "#...
Kill this process when the parent died.
[ "Kill", "this", "process", "when", "the", "parent", "died", "." ]
train
https://github.com/napalm-automation/napalm-logs/blob/4b89100a6e4f994aa004f3ea42a06dc803a7ccb0/napalm_logs/proc.py#L20-L34
napalm-automation/napalm-logs
napalm_logs/base.py
NapalmLogs._setup_buffer
def _setup_buffer(self): ''' Setup the buffer subsystem. ''' if not self._buffer_cfg or not isinstance(self._buffer_cfg, dict): return buffer_name = list(self._buffer_cfg.keys())[0] buffer_class = napalm_logs.buffer.get_interface(buffer_name) log.debug...
python
def _setup_buffer(self): ''' Setup the buffer subsystem. ''' if not self._buffer_cfg or not isinstance(self._buffer_cfg, dict): return buffer_name = list(self._buffer_cfg.keys())[0] buffer_class = napalm_logs.buffer.get_interface(buffer_name) log.debug...
[ "def", "_setup_buffer", "(", "self", ")", ":", "if", "not", "self", ".", "_buffer_cfg", "or", "not", "isinstance", "(", "self", ".", "_buffer_cfg", ",", "dict", ")", ":", "return", "buffer_name", "=", "list", "(", "self", ".", "_buffer_cfg", ".", "keys",...
Setup the buffer subsystem.
[ "Setup", "the", "buffer", "subsystem", "." ]
train
https://github.com/napalm-automation/napalm-logs/blob/4b89100a6e4f994aa004f3ea42a06dc803a7ccb0/napalm_logs/base.py#L134-L145
napalm-automation/napalm-logs
napalm_logs/base.py
NapalmLogs._setup_metrics
def _setup_metrics(self): """ Start metric exposition """ path = os.environ.get("prometheus_multiproc_dir") if not os.path.exists(self.metrics_dir): try: log.info("Creating metrics directory") os.makedirs(self.metrics_dir) e...
python
def _setup_metrics(self): """ Start metric exposition """ path = os.environ.get("prometheus_multiproc_dir") if not os.path.exists(self.metrics_dir): try: log.info("Creating metrics directory") os.makedirs(self.metrics_dir) e...
[ "def", "_setup_metrics", "(", "self", ")", ":", "path", "=", "os", ".", "environ", ".", "get", "(", "\"prometheus_multiproc_dir\"", ")", "if", "not", "os", ".", "path", ".", "exists", "(", "self", ".", "metrics_dir", ")", ":", "try", ":", "log", ".", ...
Start metric exposition
[ "Start", "metric", "exposition" ]
train
https://github.com/napalm-automation/napalm-logs/blob/4b89100a6e4f994aa004f3ea42a06dc803a7ccb0/napalm_logs/base.py#L147-L177
napalm-automation/napalm-logs
napalm_logs/base.py
NapalmLogs._setup_log
def _setup_log(self): ''' Setup the log object. ''' logging_level = CONFIG.LOGGING_LEVEL.get(self.log_level.lower()) logging.basicConfig(format=self.log_format, level=logging_level)
python
def _setup_log(self): ''' Setup the log object. ''' logging_level = CONFIG.LOGGING_LEVEL.get(self.log_level.lower()) logging.basicConfig(format=self.log_format, level=logging_level)
[ "def", "_setup_log", "(", "self", ")", ":", "logging_level", "=", "CONFIG", ".", "LOGGING_LEVEL", ".", "get", "(", "self", ".", "log_level", ".", "lower", "(", ")", ")", "logging", ".", "basicConfig", "(", "format", "=", "self", ".", "log_format", ",", ...
Setup the log object.
[ "Setup", "the", "log", "object", "." ]
train
https://github.com/napalm-automation/napalm-logs/blob/4b89100a6e4f994aa004f3ea42a06dc803a7ccb0/napalm_logs/base.py#L179-L185
napalm-automation/napalm-logs
napalm_logs/base.py
NapalmLogs._post_preparation
def _post_preparation(self): ''' The steps for post-preparation (when the logs, and everything is already setup). ''' self.opts['hwm'] = CONFIG.ZMQ_INTERNAL_HWM if self.hwm is None else self.hwm self.opts['_server_send_unknown'] = False for pub in self.publisher: ...
python
def _post_preparation(self): ''' The steps for post-preparation (when the logs, and everything is already setup). ''' self.opts['hwm'] = CONFIG.ZMQ_INTERNAL_HWM if self.hwm is None else self.hwm self.opts['_server_send_unknown'] = False for pub in self.publisher: ...
[ "def", "_post_preparation", "(", "self", ")", ":", "self", ".", "opts", "[", "'hwm'", "]", "=", "CONFIG", ".", "ZMQ_INTERNAL_HWM", "if", "self", ".", "hwm", "is", "None", "else", "self", ".", "hwm", "self", ".", "opts", "[", "'_server_send_unknown'", "]"...
The steps for post-preparation (when the logs, and everything is already setup).
[ "The", "steps", "for", "post", "-", "preparation", "(", "when", "the", "logs", "and", "everything", "is", "already", "setup", ")", "." ]
train
https://github.com/napalm-automation/napalm-logs/blob/4b89100a6e4f994aa004f3ea42a06dc803a7ccb0/napalm_logs/base.py#L187-L221
napalm-automation/napalm-logs
napalm_logs/base.py
NapalmLogs._whitelist_blacklist
def _whitelist_blacklist(self, os_name): ''' Determines if the OS should be ignored, depending on the whitelist-blacklist logic configured by the user. ''' return napalm_logs.ext.check_whitelist_blacklist(os_name, w...
python
def _whitelist_blacklist(self, os_name): ''' Determines if the OS should be ignored, depending on the whitelist-blacklist logic configured by the user. ''' return napalm_logs.ext.check_whitelist_blacklist(os_name, w...
[ "def", "_whitelist_blacklist", "(", "self", ",", "os_name", ")", ":", "return", "napalm_logs", ".", "ext", ".", "check_whitelist_blacklist", "(", "os_name", ",", "whitelist", "=", "self", ".", "device_whitelist", ",", "blacklist", "=", "self", ".", "device_black...
Determines if the OS should be ignored, depending on the whitelist-blacklist logic configured by the user.
[ "Determines", "if", "the", "OS", "should", "be", "ignored", "depending", "on", "the", "whitelist", "-", "blacklist", "logic", "configured", "by", "the", "user", "." ]
train
https://github.com/napalm-automation/napalm-logs/blob/4b89100a6e4f994aa004f3ea42a06dc803a7ccb0/napalm_logs/base.py#L223-L231
napalm-automation/napalm-logs
napalm_logs/base.py
NapalmLogs._extract_yaml_docstring
def _extract_yaml_docstring(stream): ''' Extract the comments at the top of the YAML file, from the stream handler. Return the extracted comment as string. ''' comment_lines = [] lines = stream.read().splitlines() for line in lines: line_strip ...
python
def _extract_yaml_docstring(stream): ''' Extract the comments at the top of the YAML file, from the stream handler. Return the extracted comment as string. ''' comment_lines = [] lines = stream.read().splitlines() for line in lines: line_strip ...
[ "def", "_extract_yaml_docstring", "(", "stream", ")", ":", "comment_lines", "=", "[", "]", "lines", "=", "stream", ".", "read", "(", ")", ".", "splitlines", "(", ")", "for", "line", "in", "lines", ":", "line_strip", "=", "line", ".", "strip", "(", ")",...
Extract the comments at the top of the YAML file, from the stream handler. Return the extracted comment as string.
[ "Extract", "the", "comments", "at", "the", "top", "of", "the", "YAML", "file", "from", "the", "stream", "handler", ".", "Return", "the", "extracted", "comment", "as", "string", "." ]
train
https://github.com/napalm-automation/napalm-logs/blob/4b89100a6e4f994aa004f3ea42a06dc803a7ccb0/napalm_logs/base.py#L234-L252
napalm-automation/napalm-logs
napalm_logs/base.py
NapalmLogs._load_config
def _load_config(self, path): ''' Read the configuration under a specific path and return the object. ''' config = {} log.debug('Reading configuration from %s', path) if not os.path.isdir(path): msg = ( 'Unable to read from {path}: ' ...
python
def _load_config(self, path): ''' Read the configuration under a specific path and return the object. ''' config = {} log.debug('Reading configuration from %s', path) if not os.path.isdir(path): msg = ( 'Unable to read from {path}: ' ...
[ "def", "_load_config", "(", "self", ",", "path", ")", ":", "config", "=", "{", "}", "log", ".", "debug", "(", "'Reading configuration from %s'", ",", "path", ")", "if", "not", "os", ".", "path", ".", "isdir", "(", "path", ")", ":", "msg", "=", "(", ...
Read the configuration under a specific path and return the object.
[ "Read", "the", "configuration", "under", "a", "specific", "path", "and", "return", "the", "object", "." ]
train
https://github.com/napalm-automation/napalm-logs/blob/4b89100a6e4f994aa004f3ea42a06dc803a7ccb0/napalm_logs/base.py#L254-L407
napalm-automation/napalm-logs
napalm_logs/base.py
NapalmLogs._verify_config_dict
def _verify_config_dict(self, valid, config, dev_os, key_path=None): ''' Verify if the config dict is valid. ''' if not key_path: key_path = [] for key, value in valid.items(): self._verify_config_key(key, value, valid, config, dev_os, key_path)
python
def _verify_config_dict(self, valid, config, dev_os, key_path=None): ''' Verify if the config dict is valid. ''' if not key_path: key_path = [] for key, value in valid.items(): self._verify_config_key(key, value, valid, config, dev_os, key_path)
[ "def", "_verify_config_dict", "(", "self", ",", "valid", ",", "config", ",", "dev_os", ",", "key_path", "=", "None", ")", ":", "if", "not", "key_path", ":", "key_path", "=", "[", "]", "for", "key", ",", "value", "in", "valid", ".", "items", "(", ")",...
Verify if the config dict is valid.
[ "Verify", "if", "the", "config", "dict", "is", "valid", "." ]
train
https://github.com/napalm-automation/napalm-logs/blob/4b89100a6e4f994aa004f3ea42a06dc803a7ccb0/napalm_logs/base.py#L461-L468
napalm-automation/napalm-logs
napalm_logs/base.py
NapalmLogs._verify_config
def _verify_config(self): ''' Verify that the config is correct ''' if not self.config_dict: self._raise_config_exception('No config found') # Check for device conifg, if there isn't anything then just log, do not raise an exception for dev_os, dev_config in s...
python
def _verify_config(self): ''' Verify that the config is correct ''' if not self.config_dict: self._raise_config_exception('No config found') # Check for device conifg, if there isn't anything then just log, do not raise an exception for dev_os, dev_config in s...
[ "def", "_verify_config", "(", "self", ")", ":", "if", "not", "self", ".", "config_dict", ":", "self", ".", "_raise_config_exception", "(", "'No config found'", ")", "# Check for device conifg, if there isn't anything then just log, do not raise an exception", "for", "dev_os",...
Verify that the config is correct
[ "Verify", "that", "the", "config", "is", "correct" ]
train
https://github.com/napalm-automation/napalm-logs/blob/4b89100a6e4f994aa004f3ea42a06dc803a7ccb0/napalm_logs/base.py#L470-L483
napalm-automation/napalm-logs
napalm_logs/base.py
NapalmLogs._build_config
def _build_config(self): ''' Build the config of the napalm syslog parser. ''' if not self.config_dict: if not self.config_path: # No custom config path requested # Read the native config files self.config_path = os.path.join( ...
python
def _build_config(self): ''' Build the config of the napalm syslog parser. ''' if not self.config_dict: if not self.config_path: # No custom config path requested # Read the native config files self.config_path = os.path.join( ...
[ "def", "_build_config", "(", "self", ")", ":", "if", "not", "self", ".", "config_dict", ":", "if", "not", "self", ".", "config_path", ":", "# No custom config path requested", "# Read the native config files", "self", ".", "config_path", "=", "os", ".", "path", ...
Build the config of the napalm syslog parser.
[ "Build", "the", "config", "of", "the", "napalm", "syslog", "parser", "." ]
train
https://github.com/napalm-automation/napalm-logs/blob/4b89100a6e4f994aa004f3ea42a06dc803a7ccb0/napalm_logs/base.py#L485-L507
napalm-automation/napalm-logs
napalm_logs/base.py
NapalmLogs._start_auth_proc
def _start_auth_proc(self): ''' Start the authenticator process. ''' log.debug('Computing the signing key hex') verify_key = self.__signing_key.verify_key sgn_verify_hex = verify_key.encode(encoder=nacl.encoding.HexEncoder) log.debug('Starting the authenticator su...
python
def _start_auth_proc(self): ''' Start the authenticator process. ''' log.debug('Computing the signing key hex') verify_key = self.__signing_key.verify_key sgn_verify_hex = verify_key.encode(encoder=nacl.encoding.HexEncoder) log.debug('Starting the authenticator su...
[ "def", "_start_auth_proc", "(", "self", ")", ":", "log", ".", "debug", "(", "'Computing the signing key hex'", ")", "verify_key", "=", "self", ".", "__signing_key", ".", "verify_key", "sgn_verify_hex", "=", "verify_key", ".", "encode", "(", "encoder", "=", "nacl...
Start the authenticator process.
[ "Start", "the", "authenticator", "process", "." ]
train
https://github.com/napalm-automation/napalm-logs/blob/4b89100a6e4f994aa004f3ea42a06dc803a7ccb0/napalm_logs/base.py#L509-L527
napalm-automation/napalm-logs
napalm_logs/base.py
NapalmLogs._start_lst_proc
def _start_lst_proc(self, listener_type, listener_opts): ''' Start the listener process. ''' log.debug('Starting the listener process for %s', listener_type) listener = NapalmLogsListenerProc(self.opts, ...
python
def _start_lst_proc(self, listener_type, listener_opts): ''' Start the listener process. ''' log.debug('Starting the listener process for %s', listener_type) listener = NapalmLogsListenerProc(self.opts, ...
[ "def", "_start_lst_proc", "(", "self", ",", "listener_type", ",", "listener_opts", ")", ":", "log", ".", "debug", "(", "'Starting the listener process for %s'", ",", "listener_type", ")", "listener", "=", "NapalmLogsListenerProc", "(", "self", ".", "opts", ",", "s...
Start the listener process.
[ "Start", "the", "listener", "process", "." ]
train
https://github.com/napalm-automation/napalm-logs/blob/4b89100a6e4f994aa004f3ea42a06dc803a7ccb0/napalm_logs/base.py#L529-L545
napalm-automation/napalm-logs
napalm_logs/base.py
NapalmLogs._start_srv_proc
def _start_srv_proc(self, started_os_proc): ''' Start the server process. ''' log.debug('Starting the server process') server = NapalmLogsServerProc(self.opts, self.config_dict, st...
python
def _start_srv_proc(self, started_os_proc): ''' Start the server process. ''' log.debug('Starting the server process') server = NapalmLogsServerProc(self.opts, self.config_dict, st...
[ "def", "_start_srv_proc", "(", "self", ",", "started_os_proc", ")", ":", "log", ".", "debug", "(", "'Starting the server process'", ")", "server", "=", "NapalmLogsServerProc", "(", "self", ".", "opts", ",", "self", ".", "config_dict", ",", "started_os_proc", ","...
Start the server process.
[ "Start", "the", "server", "process", "." ]
train
https://github.com/napalm-automation/napalm-logs/blob/4b89100a6e4f994aa004f3ea42a06dc803a7ccb0/napalm_logs/base.py#L547-L561
napalm-automation/napalm-logs
napalm_logs/base.py
NapalmLogs._start_pub_proc
def _start_pub_proc(self, publisher_type, publisher_opts, pub_id): ''' Start the publisher process. ''' log.debug('Starting the publisher process for %s', publisher_type) publisher = NapalmLogsPublisherProc(s...
python
def _start_pub_proc(self, publisher_type, publisher_opts, pub_id): ''' Start the publisher process. ''' log.debug('Starting the publisher process for %s', publisher_type) publisher = NapalmLogsPublisherProc(s...
[ "def", "_start_pub_proc", "(", "self", ",", "publisher_type", ",", "publisher_opts", ",", "pub_id", ")", ":", "log", ".", "debug", "(", "'Starting the publisher process for %s'", ",", "publisher_type", ")", "publisher", "=", "NapalmLogsPublisherProc", "(", "self", "...
Start the publisher process.
[ "Start", "the", "publisher", "process", "." ]
train
https://github.com/napalm-automation/napalm-logs/blob/4b89100a6e4f994aa004f3ea42a06dc803a7ccb0/napalm_logs/base.py#L573-L595
napalm-automation/napalm-logs
napalm_logs/base.py
NapalmLogs._start_dev_proc
def _start_dev_proc(self, device_os, device_config): ''' Start the device worker process. ''' log.info('Starting the child process for %s', device_os) dos = NapalmLogsDeviceProc(device_os, self.opt...
python
def _start_dev_proc(self, device_os, device_config): ''' Start the device worker process. ''' log.info('Starting the child process for %s', device_os) dos = NapalmLogsDeviceProc(device_os, self.opt...
[ "def", "_start_dev_proc", "(", "self", ",", "device_os", ",", "device_config", ")", ":", "log", ".", "info", "(", "'Starting the child process for %s'", ",", "device_os", ")", "dos", "=", "NapalmLogsDeviceProc", "(", "device_os", ",", "self", ".", "opts", ",", ...
Start the device worker process.
[ "Start", "the", "device", "worker", "process", "." ]
train
https://github.com/napalm-automation/napalm-logs/blob/4b89100a6e4f994aa004f3ea42a06dc803a7ccb0/napalm_logs/base.py#L597-L611
napalm-automation/napalm-logs
napalm_logs/base.py
NapalmLogs.start_engine
def start_engine(self): ''' Start the child processes (one per device OS) ''' if self.disable_security is True: log.warning('***Not starting the authenticator process due to disable_security being set to True***') else: log.debug('Generating the private ke...
python
def start_engine(self): ''' Start the child processes (one per device OS) ''' if self.disable_security is True: log.warning('***Not starting the authenticator process due to disable_security being set to True***') else: log.debug('Generating the private ke...
[ "def", "start_engine", "(", "self", ")", ":", "if", "self", ".", "disable_security", "is", "True", ":", "log", ".", "warning", "(", "'***Not starting the authenticator process due to disable_security being set to True***'", ")", "else", ":", "log", ".", "debug", "(", ...
Start the child processes (one per device OS)
[ "Start", "the", "child", "processes", "(", "one", "per", "device", "OS", ")" ]
train
https://github.com/napalm-automation/napalm-logs/blob/4b89100a6e4f994aa004f3ea42a06dc803a7ccb0/napalm_logs/base.py#L613-L662
napalm-automation/napalm-logs
napalm_logs/base.py
NapalmLogs._check_children
def _check_children(self): ''' Check all of the child processes are still running ''' while self.up: time.sleep(1) for process in self._processes: if process.is_alive() is True: continue log.debug('%s is dead. St...
python
def _check_children(self): ''' Check all of the child processes are still running ''' while self.up: time.sleep(1) for process in self._processes: if process.is_alive() is True: continue log.debug('%s is dead. St...
[ "def", "_check_children", "(", "self", ")", ":", "while", "self", ".", "up", ":", "time", ".", "sleep", "(", "1", ")", "for", "process", "in", "self", ".", "_processes", ":", "if", "process", ".", "is_alive", "(", ")", "is", "True", ":", "continue", ...
Check all of the child processes are still running
[ "Check", "all", "of", "the", "child", "processes", "are", "still", "running" ]
train
https://github.com/napalm-automation/napalm-logs/blob/4b89100a6e4f994aa004f3ea42a06dc803a7ccb0/napalm_logs/base.py#L664-L674
napalm-automation/napalm-logs
napalm_logs/pub_proxy.py
NapalmLogsPublisherProxy._setup_ipc
def _setup_ipc(self): ''' Setup the IPC PUB and SUB sockets for the proxy. ''' log.debug('Setting up the internal IPC proxy') self.ctx = zmq.Context() # Frontend self.sub = self.ctx.socket(zmq.SUB) self.sub.bind(PUB_PX_IPC_URL) self.sub.setsockopt(...
python
def _setup_ipc(self): ''' Setup the IPC PUB and SUB sockets for the proxy. ''' log.debug('Setting up the internal IPC proxy') self.ctx = zmq.Context() # Frontend self.sub = self.ctx.socket(zmq.SUB) self.sub.bind(PUB_PX_IPC_URL) self.sub.setsockopt(...
[ "def", "_setup_ipc", "(", "self", ")", ":", "log", ".", "debug", "(", "'Setting up the internal IPC proxy'", ")", "self", ".", "ctx", "=", "zmq", ".", "Context", "(", ")", "# Frontend", "self", ".", "sub", "=", "self", ".", "ctx", ".", "socket", "(", "...
Setup the IPC PUB and SUB sockets for the proxy.
[ "Setup", "the", "IPC", "PUB", "and", "SUB", "sockets", "for", "the", "proxy", "." ]
train
https://github.com/napalm-automation/napalm-logs/blob/4b89100a6e4f994aa004f3ea42a06dc803a7ccb0/napalm_logs/pub_proxy.py#L38-L64
napalm-automation/napalm-logs
napalm_logs/pub_proxy.py
NapalmLogsPublisherProxy.start
def start(self): ''' Listen to messages and publish them. ''' self._setup_ipc() # Start suicide polling thread thread = threading.Thread(target=self._suicide_when_without_parent, args=(os.getppid(),)) thread.start() signal.signal(signal.SIGTERM, self._exit...
python
def start(self): ''' Listen to messages and publish them. ''' self._setup_ipc() # Start suicide polling thread thread = threading.Thread(target=self._suicide_when_without_parent, args=(os.getppid(),)) thread.start() signal.signal(signal.SIGTERM, self._exit...
[ "def", "start", "(", "self", ")", ":", "self", ".", "_setup_ipc", "(", ")", "# Start suicide polling thread", "thread", "=", "threading", ".", "Thread", "(", "target", "=", "self", ".", "_suicide_when_without_parent", ",", "args", "=", "(", "os", ".", "getpp...
Listen to messages and publish them.
[ "Listen", "to", "messages", "and", "publish", "them", "." ]
train
https://github.com/napalm-automation/napalm-logs/blob/4b89100a6e4f994aa004f3ea42a06dc803a7ccb0/napalm_logs/pub_proxy.py#L66-L83
napalm-automation/napalm-logs
napalm_logs/publisher.py
NapalmLogsPublisherProc._setup_ipc
def _setup_ipc(self): ''' Subscribe to the pub IPC and publish the messages on the right transport. ''' self.ctx = zmq.Context() log.debug('Setting up the %s publisher subscriber #%d', self._transport_type, self.pub_id) self.sub = self.ctx.socket(zmq.SUB) ...
python
def _setup_ipc(self): ''' Subscribe to the pub IPC and publish the messages on the right transport. ''' self.ctx = zmq.Context() log.debug('Setting up the %s publisher subscriber #%d', self._transport_type, self.pub_id) self.sub = self.ctx.socket(zmq.SUB) ...
[ "def", "_setup_ipc", "(", "self", ")", ":", "self", ".", "ctx", "=", "zmq", ".", "Context", "(", ")", "log", ".", "debug", "(", "'Setting up the %s publisher subscriber #%d'", ",", "self", ".", "_transport_type", ",", "self", ".", "pub_id", ")", "self", "....
Subscribe to the pub IPC and publish the messages on the right transport.
[ "Subscribe", "to", "the", "pub", "IPC", "and", "publish", "the", "messages", "on", "the", "right", "transport", "." ]
train
https://github.com/napalm-automation/napalm-logs/blob/4b89100a6e4f994aa004f3ea42a06dc803a7ccb0/napalm_logs/publisher.py#L71-L87
napalm-automation/napalm-logs
napalm_logs/publisher.py
NapalmLogsPublisherProc._setup_transport
def _setup_transport(self): ''' Setup the transport. ''' if 'RAW' in self.error_whitelist: log.info('%s %d will publish partially parsed messages', self._transport_type, self.pub_id) if 'UNKNOWN' in self.error_whitelist: log.info('%s %d will publish unknow...
python
def _setup_transport(self): ''' Setup the transport. ''' if 'RAW' in self.error_whitelist: log.info('%s %d will publish partially parsed messages', self._transport_type, self.pub_id) if 'UNKNOWN' in self.error_whitelist: log.info('%s %d will publish unknow...
[ "def", "_setup_transport", "(", "self", ")", ":", "if", "'RAW'", "in", "self", ".", "error_whitelist", ":", "log", ".", "info", "(", "'%s %d will publish partially parsed messages'", ",", "self", ".", "_transport_type", ",", "self", ".", "pub_id", ")", "if", "...
Setup the transport.
[ "Setup", "the", "transport", "." ]
train
https://github.com/napalm-automation/napalm-logs/blob/4b89100a6e4f994aa004f3ea42a06dc803a7ccb0/napalm_logs/publisher.py#L89-L108
napalm-automation/napalm-logs
napalm_logs/publisher.py
NapalmLogsPublisherProc._prepare
def _prepare(self, serialized_obj): ''' Prepare the object to be sent over the untrusted channel. ''' # generating a nonce nonce = nacl.utils.random(nacl.secret.SecretBox.NONCE_SIZE) # encrypting using the nonce encrypted = self.__safe.encrypt(serialized_obj, nonc...
python
def _prepare(self, serialized_obj): ''' Prepare the object to be sent over the untrusted channel. ''' # generating a nonce nonce = nacl.utils.random(nacl.secret.SecretBox.NONCE_SIZE) # encrypting using the nonce encrypted = self.__safe.encrypt(serialized_obj, nonc...
[ "def", "_prepare", "(", "self", ",", "serialized_obj", ")", ":", "# generating a nonce", "nonce", "=", "nacl", ".", "utils", ".", "random", "(", "nacl", ".", "secret", ".", "SecretBox", ".", "NONCE_SIZE", ")", "# encrypting using the nonce", "encrypted", "=", ...
Prepare the object to be sent over the untrusted channel.
[ "Prepare", "the", "object", "to", "be", "sent", "over", "the", "untrusted", "channel", "." ]
train
https://github.com/napalm-automation/napalm-logs/blob/4b89100a6e4f994aa004f3ea42a06dc803a7ccb0/napalm_logs/publisher.py#L110-L120
napalm-automation/napalm-logs
napalm_logs/publisher.py
NapalmLogsPublisherProc.start
def start(self): ''' Listen to messages and publish them. ''' # metrics napalm_logs_publisher_received_messages = Counter( 'napalm_logs_publisher_received_messages', "Count of messages received by the publisher", ['publisher_type', 'address', '...
python
def start(self): ''' Listen to messages and publish them. ''' # metrics napalm_logs_publisher_received_messages = Counter( 'napalm_logs_publisher_received_messages', "Count of messages received by the publisher", ['publisher_type', 'address', '...
[ "def", "start", "(", "self", ")", ":", "# metrics", "napalm_logs_publisher_received_messages", "=", "Counter", "(", "'napalm_logs_publisher_received_messages'", ",", "\"Count of messages received by the publisher\"", ",", "[", "'publisher_type'", ",", "'address'", ",", "'port...
Listen to messages and publish them.
[ "Listen", "to", "messages", "and", "publish", "them", "." ]
train
https://github.com/napalm-automation/napalm-logs/blob/4b89100a6e4f994aa004f3ea42a06dc803a7ccb0/napalm_logs/publisher.py#L132-L203
napalm-automation/napalm-logs
napalm_logs/listener/__init__.py
get_listener
def get_listener(name): ''' Return the listener class. ''' try: log.debug('Using %s as listener', name) return LISTENER_LOOKUP[name] except KeyError: msg = 'Listener {} is not available. Are the dependencies installed?'.format(name) log.error(msg, exc_info=True) ...
python
def get_listener(name): ''' Return the listener class. ''' try: log.debug('Using %s as listener', name) return LISTENER_LOOKUP[name] except KeyError: msg = 'Listener {} is not available. Are the dependencies installed?'.format(name) log.error(msg, exc_info=True) ...
[ "def", "get_listener", "(", "name", ")", ":", "try", ":", "log", ".", "debug", "(", "'Using %s as listener'", ",", "name", ")", "return", "LISTENER_LOOKUP", "[", "name", "]", "except", "KeyError", ":", "msg", "=", "'Listener {} is not available. Are the dependenci...
Return the listener class.
[ "Return", "the", "listener", "class", "." ]
train
https://github.com/napalm-automation/napalm-logs/blob/4b89100a6e4f994aa004f3ea42a06dc803a7ccb0/napalm_logs/listener/__init__.py#L41-L51
napalm-automation/napalm-logs
napalm_logs/utils/__init__.py
setval
def setval(key, val, dict_=None, delim=defaults.DEFAULT_DELIM): ''' Set a value under the dictionary hierarchy identified under the key. The target 'foo/bar/baz' returns the dictionary hierarchy {'foo': {'bar': {'baz': {}}}}. .. note:: Currently this doesn't work with integers, i.e. ...
python
def setval(key, val, dict_=None, delim=defaults.DEFAULT_DELIM): ''' Set a value under the dictionary hierarchy identified under the key. The target 'foo/bar/baz' returns the dictionary hierarchy {'foo': {'bar': {'baz': {}}}}. .. note:: Currently this doesn't work with integers, i.e. ...
[ "def", "setval", "(", "key", ",", "val", ",", "dict_", "=", "None", ",", "delim", "=", "defaults", ".", "DEFAULT_DELIM", ")", ":", "if", "not", "dict_", ":", "dict_", "=", "{", "}", "prev_hier", "=", "dict_", "dict_hier", "=", "key", ".", "split", ...
Set a value under the dictionary hierarchy identified under the key. The target 'foo/bar/baz' returns the dictionary hierarchy {'foo': {'bar': {'baz': {}}}}. .. note:: Currently this doesn't work with integers, i.e. cannot build lists dynamically. TODO
[ "Set", "a", "value", "under", "the", "dictionary", "hierarchy", "identified", "under", "the", "key", ".", "The", "target", "foo", "/", "bar", "/", "baz", "returns", "the", "dictionary", "hierarchy", "{", "foo", ":", "{", "bar", ":", "{", "baz", ":", "{...
train
https://github.com/napalm-automation/napalm-logs/blob/4b89100a6e4f994aa004f3ea42a06dc803a7ccb0/napalm_logs/utils/__init__.py#L256-L281
napalm-automation/napalm-logs
napalm_logs/utils/__init__.py
traverse
def traverse(data, key, delim=defaults.DEFAULT_DELIM): ''' Traverse a dict or list using a slash delimiter target string. The target 'foo/bar/0' will return data['foo']['bar'][0] if this value exists, otherwise will return empty dict. Return None when not found. This can be used to verify if a c...
python
def traverse(data, key, delim=defaults.DEFAULT_DELIM): ''' Traverse a dict or list using a slash delimiter target string. The target 'foo/bar/0' will return data['foo']['bar'][0] if this value exists, otherwise will return empty dict. Return None when not found. This can be used to verify if a c...
[ "def", "traverse", "(", "data", ",", "key", ",", "delim", "=", "defaults", ".", "DEFAULT_DELIM", ")", ":", "for", "each", "in", "key", ".", "split", "(", "delim", ")", ":", "if", "isinstance", "(", "data", ",", "list", ")", ":", "if", "isinstance", ...
Traverse a dict or list using a slash delimiter target string. The target 'foo/bar/0' will return data['foo']['bar'][0] if this value exists, otherwise will return empty dict. Return None when not found. This can be used to verify if a certain key exists under dictionary hierarchy.
[ "Traverse", "a", "dict", "or", "list", "using", "a", "slash", "delimiter", "target", "string", ".", "The", "target", "foo", "/", "bar", "/", "0", "will", "return", "data", "[", "foo", "]", "[", "bar", "]", "[", "0", "]", "if", "this", "value", "exi...
train
https://github.com/napalm-automation/napalm-logs/blob/4b89100a6e4f994aa004f3ea42a06dc803a7ccb0/napalm_logs/utils/__init__.py#L284-L318
napalm-automation/napalm-logs
napalm_logs/utils/__init__.py
ClientAuth._start_keep_alive
def _start_keep_alive(self): ''' Start the keep alive thread as a daemon ''' keep_alive_thread = threading.Thread(target=self.keep_alive) keep_alive_thread.daemon = True keep_alive_thread.start()
python
def _start_keep_alive(self): ''' Start the keep alive thread as a daemon ''' keep_alive_thread = threading.Thread(target=self.keep_alive) keep_alive_thread.daemon = True keep_alive_thread.start()
[ "def", "_start_keep_alive", "(", "self", ")", ":", "keep_alive_thread", "=", "threading", ".", "Thread", "(", "target", "=", "self", ".", "keep_alive", ")", "keep_alive_thread", ".", "daemon", "=", "True", "keep_alive_thread", ".", "start", "(", ")" ]
Start the keep alive thread as a daemon
[ "Start", "the", "keep", "alive", "thread", "as", "a", "daemon" ]
train
https://github.com/napalm-automation/napalm-logs/blob/4b89100a6e4f994aa004f3ea42a06dc803a7ccb0/napalm_logs/utils/__init__.py#L61-L67
napalm-automation/napalm-logs
napalm_logs/utils/__init__.py
ClientAuth.keep_alive
def keep_alive(self): ''' Send a keep alive request periodically to make sure that the server is still alive. If not then try to reconnect. ''' self.ssl_skt.settimeout(defaults.AUTH_KEEP_ALIVE_INTERVAL) while self.__up: try: log.debug('Sending ...
python
def keep_alive(self): ''' Send a keep alive request periodically to make sure that the server is still alive. If not then try to reconnect. ''' self.ssl_skt.settimeout(defaults.AUTH_KEEP_ALIVE_INTERVAL) while self.__up: try: log.debug('Sending ...
[ "def", "keep_alive", "(", "self", ")", ":", "self", ".", "ssl_skt", ".", "settimeout", "(", "defaults", ".", "AUTH_KEEP_ALIVE_INTERVAL", ")", "while", "self", ".", "__up", ":", "try", ":", "log", ".", "debug", "(", "'Sending keep-alive message to the server'", ...
Send a keep alive request periodically to make sure that the server is still alive. If not then try to reconnect.
[ "Send", "a", "keep", "alive", "request", "periodically", "to", "make", "sure", "that", "the", "server", "is", "still", "alive", ".", "If", "not", "then", "try", "to", "reconnect", "." ]
train
https://github.com/napalm-automation/napalm-logs/blob/4b89100a6e4f994aa004f3ea42a06dc803a7ccb0/napalm_logs/utils/__init__.py#L69-L92
napalm-automation/napalm-logs
napalm_logs/utils/__init__.py
ClientAuth.reconnect
def reconnect(self): ''' Try to reconnect and re-authenticate with the server. ''' log.debug('Closing the SSH socket.') try: self.ssl_skt.close() except socket.error: log.error('The socket seems to be closed already.') log.debug('Re-opening...
python
def reconnect(self): ''' Try to reconnect and re-authenticate with the server. ''' log.debug('Closing the SSH socket.') try: self.ssl_skt.close() except socket.error: log.error('The socket seems to be closed already.') log.debug('Re-opening...
[ "def", "reconnect", "(", "self", ")", ":", "log", ".", "debug", "(", "'Closing the SSH socket.'", ")", "try", ":", "self", ".", "ssl_skt", ".", "close", "(", ")", "except", "socket", ".", "error", ":", "log", ".", "error", "(", "'The socket seems to be clo...
Try to reconnect and re-authenticate with the server.
[ "Try", "to", "reconnect", "and", "re", "-", "authenticate", "with", "the", "server", "." ]
train
https://github.com/napalm-automation/napalm-logs/blob/4b89100a6e4f994aa004f3ea42a06dc803a7ccb0/napalm_logs/utils/__init__.py#L94-L104
napalm-automation/napalm-logs
napalm_logs/utils/__init__.py
ClientAuth.authenticate
def authenticate(self): ''' Authenticate the client and return the private and signature keys. Establish a connection through a secured socket, then do the handshake using the napalm-logs auth algorithm. ''' log.debug('Authenticate to %s:%d, using the cer...
python
def authenticate(self): ''' Authenticate the client and return the private and signature keys. Establish a connection through a secured socket, then do the handshake using the napalm-logs auth algorithm. ''' log.debug('Authenticate to %s:%d, using the cer...
[ "def", "authenticate", "(", "self", ")", ":", "log", ".", "debug", "(", "'Authenticate to %s:%d, using the certificate %s'", ",", "self", ".", "address", ",", "self", ".", "port", ",", "self", ".", "certificate", ")", "if", "':'", "in", "self", ".", "address...
Authenticate the client and return the private and signature keys. Establish a connection through a secured socket, then do the handshake using the napalm-logs auth algorithm.
[ "Authenticate", "the", "client", "and", "return", "the", "private", "and", "signature", "keys", "." ]
train
https://github.com/napalm-automation/napalm-logs/blob/4b89100a6e4f994aa004f3ea42a06dc803a7ccb0/napalm_logs/utils/__init__.py#L106-L150
napalm-automation/napalm-logs
napalm_logs/utils/__init__.py
ClientAuth.decrypt
def decrypt(self, binary): ''' Decrypt and unpack the original OpenConfig object, serialized using MessagePack. Raise BadSignatureException when the signature was forged or corrupted. ''' try: encrypted = self.verify_key.verify(binary) except B...
python
def decrypt(self, binary): ''' Decrypt and unpack the original OpenConfig object, serialized using MessagePack. Raise BadSignatureException when the signature was forged or corrupted. ''' try: encrypted = self.verify_key.verify(binary) except B...
[ "def", "decrypt", "(", "self", ",", "binary", ")", ":", "try", ":", "encrypted", "=", "self", ".", "verify_key", ".", "verify", "(", "binary", ")", "except", "BadSignatureError", ":", "log", ".", "error", "(", "'Signature was forged or corrupt'", ",", "exc_i...
Decrypt and unpack the original OpenConfig object, serialized using MessagePack. Raise BadSignatureException when the signature was forged or corrupted.
[ "Decrypt", "and", "unpack", "the", "original", "OpenConfig", "object", "serialized", "using", "MessagePack", ".", "Raise", "BadSignatureException", "when", "the", "signature", "was", "forged", "or", "corrupted", "." ]
train
https://github.com/napalm-automation/napalm-logs/blob/4b89100a6e4f994aa004f3ea42a06dc803a7ccb0/napalm_logs/utils/__init__.py#L152-L169
napalm-automation/napalm-logs
napalm_logs/listener/tcp.py
TCPListener._client_connection
def _client_connection(self, conn, addr): ''' Handle the connecition with one client. ''' log.debug('Established connection with %s:%d', addr[0], addr[1]) conn.settimeout(self.socket_timeout) try: while self.__up: msg = conn.recv(self.buffer_si...
python
def _client_connection(self, conn, addr): ''' Handle the connecition with one client. ''' log.debug('Established connection with %s:%d', addr[0], addr[1]) conn.settimeout(self.socket_timeout) try: while self.__up: msg = conn.recv(self.buffer_si...
[ "def", "_client_connection", "(", "self", ",", "conn", ",", "addr", ")", ":", "log", ".", "debug", "(", "'Established connection with %s:%d'", ",", "addr", "[", "0", "]", ",", "addr", "[", "1", "]", ")", "conn", ".", "settimeout", "(", "self", ".", "so...
Handle the connecition with one client.
[ "Handle", "the", "connecition", "with", "one", "client", "." ]
train
https://github.com/napalm-automation/napalm-logs/blob/4b89100a6e4f994aa004f3ea42a06dc803a7ccb0/napalm_logs/listener/tcp.py#L53-L75
napalm-automation/napalm-logs
napalm_logs/listener/tcp.py
TCPListener._serve_clients
def _serve_clients(self): ''' Accept cients and serve, one separate thread per client. ''' self.__up = True while self.__up: log.debug('Waiting for a client to connect') try: conn, addr = self.skt.accept() log.debug('Receive...
python
def _serve_clients(self): ''' Accept cients and serve, one separate thread per client. ''' self.__up = True while self.__up: log.debug('Waiting for a client to connect') try: conn, addr = self.skt.accept() log.debug('Receive...
[ "def", "_serve_clients", "(", "self", ")", ":", "self", ".", "__up", "=", "True", "while", "self", ".", "__up", ":", "log", ".", "debug", "(", "'Waiting for a client to connect'", ")", "try", ":", "conn", ",", "addr", "=", "self", ".", "skt", ".", "acc...
Accept cients and serve, one separate thread per client.
[ "Accept", "cients", "and", "serve", "one", "separate", "thread", "per", "client", "." ]
train
https://github.com/napalm-automation/napalm-logs/blob/4b89100a6e4f994aa004f3ea42a06dc803a7ccb0/napalm_logs/listener/tcp.py#L77-L94
napalm-automation/napalm-logs
napalm_logs/listener/tcp.py
TCPListener.start
def start(self): ''' Start listening for messages. ''' log.debug('Creating the TCP server') if ':' in self.address: self.skt = socket.socket(socket.AF_INET6, socket.SOCK_STREAM) else: self.skt = socket.socket(socket.AF_INET, socket.SOCK_STREAM) ...
python
def start(self): ''' Start listening for messages. ''' log.debug('Creating the TCP server') if ':' in self.address: self.skt = socket.socket(socket.AF_INET6, socket.SOCK_STREAM) else: self.skt = socket.socket(socket.AF_INET, socket.SOCK_STREAM) ...
[ "def", "start", "(", "self", ")", ":", "log", ".", "debug", "(", "'Creating the TCP server'", ")", "if", "':'", "in", "self", ".", "address", ":", "self", ".", "skt", "=", "socket", ".", "socket", "(", "socket", ".", "AF_INET6", ",", "socket", ".", "...
Start listening for messages.
[ "Start", "listening", "for", "messages", "." ]
train
https://github.com/napalm-automation/napalm-logs/blob/4b89100a6e4f994aa004f3ea42a06dc803a7ccb0/napalm_logs/listener/tcp.py#L96-L120
napalm-automation/napalm-logs
napalm_logs/listener/tcp.py
TCPListener.receive
def receive(self): ''' Return one message dequeued from the listen buffer. ''' while self.buffer.empty() and self.__up: # This sequence is skipped when the buffer is not empty. sleep_ms = random.randint(0, 1000) # log.debug('The message queue is empty,...
python
def receive(self): ''' Return one message dequeued from the listen buffer. ''' while self.buffer.empty() and self.__up: # This sequence is skipped when the buffer is not empty. sleep_ms = random.randint(0, 1000) # log.debug('The message queue is empty,...
[ "def", "receive", "(", "self", ")", ":", "while", "self", ".", "buffer", ".", "empty", "(", ")", "and", "self", ".", "__up", ":", "# This sequence is skipped when the buffer is not empty.", "sleep_ms", "=", "random", ".", "randint", "(", "0", ",", "1000", ")...
Return one message dequeued from the listen buffer.
[ "Return", "one", "message", "dequeued", "from", "the", "listen", "buffer", "." ]
train
https://github.com/napalm-automation/napalm-logs/blob/4b89100a6e4f994aa004f3ea42a06dc803a7ccb0/napalm_logs/listener/tcp.py#L122-L134
napalm-automation/napalm-logs
napalm_logs/listener/tcp.py
TCPListener.stop
def stop(self): ''' Closing the socket. ''' log.info('Stopping the TCP listener') self.__up = False try: self.skt.shutdown(socket.SHUT_RDWR) except socket.error: log.error('The following error may not be critical:', exc_info=True) s...
python
def stop(self): ''' Closing the socket. ''' log.info('Stopping the TCP listener') self.__up = False try: self.skt.shutdown(socket.SHUT_RDWR) except socket.error: log.error('The following error may not be critical:', exc_info=True) s...
[ "def", "stop", "(", "self", ")", ":", "log", ".", "info", "(", "'Stopping the TCP listener'", ")", "self", ".", "__up", "=", "False", "try", ":", "self", ".", "skt", ".", "shutdown", "(", "socket", ".", "SHUT_RDWR", ")", "except", "socket", ".", "error...
Closing the socket.
[ "Closing", "the", "socket", "." ]
train
https://github.com/napalm-automation/napalm-logs/blob/4b89100a6e4f994aa004f3ea42a06dc803a7ccb0/napalm_logs/listener/tcp.py#L136-L146
napalm-automation/napalm-logs
napalm_logs/listener_proc.py
NapalmLogsListenerProc._setup_listener
def _setup_listener(self): ''' Setup the transport. ''' listener_class = get_listener(self._listener_type) self.address = self.listener_opts.pop('address', self.address) self.port = self.listener_opts.pop('port', self.port) self.listener = listener_class(self.addr...
python
def _setup_listener(self): ''' Setup the transport. ''' listener_class = get_listener(self._listener_type) self.address = self.listener_opts.pop('address', self.address) self.port = self.listener_opts.pop('port', self.port) self.listener = listener_class(self.addr...
[ "def", "_setup_listener", "(", "self", ")", ":", "listener_class", "=", "get_listener", "(", "self", ".", "_listener_type", ")", "self", ".", "address", "=", "self", ".", "listener_opts", ".", "pop", "(", "'address'", ",", "self", ".", "address", ")", "sel...
Setup the transport.
[ "Setup", "the", "transport", "." ]
train
https://github.com/napalm-automation/napalm-logs/blob/4b89100a6e4f994aa004f3ea42a06dc803a7ccb0/napalm_logs/listener_proc.py#L51-L60
napalm-automation/napalm-logs
napalm_logs/listener_proc.py
NapalmLogsListenerProc._setup_ipc
def _setup_ipc(self): ''' Setup the listener ICP pusher. ''' log.debug('Setting up the listener IPC pusher') self.ctx = zmq.Context() self.pub = self.ctx.socket(zmq.PUSH) self.pub.connect(LST_IPC_URL) log.debug('Setting HWM for the listener: %d', self.opts...
python
def _setup_ipc(self): ''' Setup the listener ICP pusher. ''' log.debug('Setting up the listener IPC pusher') self.ctx = zmq.Context() self.pub = self.ctx.socket(zmq.PUSH) self.pub.connect(LST_IPC_URL) log.debug('Setting HWM for the listener: %d', self.opts...
[ "def", "_setup_ipc", "(", "self", ")", ":", "log", ".", "debug", "(", "'Setting up the listener IPC pusher'", ")", "self", ".", "ctx", "=", "zmq", ".", "Context", "(", ")", "self", ".", "pub", "=", "self", ".", "ctx", ".", "socket", "(", "zmq", ".", ...
Setup the listener ICP pusher.
[ "Setup", "the", "listener", "ICP", "pusher", "." ]
train
https://github.com/napalm-automation/napalm-logs/blob/4b89100a6e4f994aa004f3ea42a06dc803a7ccb0/napalm_logs/listener_proc.py#L62-L76
napalm-automation/napalm-logs
napalm_logs/listener_proc.py
NapalmLogsListenerProc.start
def start(self): ''' Listen to messages and publish them. ''' # counter metrics for messages c_logs_ingested = Counter( 'napalm_logs_listener_logs_ingested', 'Count of ingested log messages', ['listener_type', 'address', 'port'], ) ...
python
def start(self): ''' Listen to messages and publish them. ''' # counter metrics for messages c_logs_ingested = Counter( 'napalm_logs_listener_logs_ingested', 'Count of ingested log messages', ['listener_type', 'address', 'port'], ) ...
[ "def", "start", "(", "self", ")", ":", "# counter metrics for messages", "c_logs_ingested", "=", "Counter", "(", "'napalm_logs_listener_logs_ingested'", ",", "'Count of ingested log messages'", ",", "[", "'listener_type'", ",", "'address'", ",", "'port'", "]", ",", ")",...
Listen to messages and publish them.
[ "Listen", "to", "messages", "and", "publish", "them", "." ]
train
https://github.com/napalm-automation/napalm-logs/blob/4b89100a6e4f994aa004f3ea42a06dc803a7ccb0/napalm_logs/listener_proc.py#L78-L118
napalm-automation/napalm-logs
napalm_logs/config/nxos/USER_LOGIN.py
emit
def emit(msg_dict): ''' Extracts the details from the syslog message and returns an object having the following structure: .. code-block:: python { u'users': { u'user': { u'luke': { u'action': { ...
python
def emit(msg_dict): ''' Extracts the details from the syslog message and returns an object having the following structure: .. code-block:: python { u'users': { u'user': { u'luke': { u'action': { ...
[ "def", "emit", "(", "msg_dict", ")", ":", "log", ".", "debug", "(", "'Evaluating the message dict:'", ")", "log", ".", "debug", "(", "msg_dict", ")", "ret", "=", "{", "}", "extracted", "=", "napalm_logs", ".", "utils", ".", "extract", "(", "_RGX", ",", ...
Extracts the details from the syslog message and returns an object having the following structure: .. code-block:: python { u'users': { u'user': { u'luke': { u'action': { u'login': True ...
[ "Extracts", "the", "details", "from", "the", "syslog", "message", "and", "returns", "an", "object", "having", "the", "following", "structure", ":" ]
train
https://github.com/napalm-automation/napalm-logs/blob/4b89100a6e4f994aa004f3ea42a06dc803a7ccb0/napalm_logs/config/nxos/USER_LOGIN.py#L56-L88
napalm-automation/napalm-logs
napalm_logs/ext/__init__.py
expr_match
def expr_match(line, expr): ''' Evaluate a line of text against an expression. First try a full-string match, next try globbing, and then try to match assuming expr is a regular expression. Originally designed to match minion IDs for whitelists/blacklists. ''' if line == expr: return...
python
def expr_match(line, expr): ''' Evaluate a line of text against an expression. First try a full-string match, next try globbing, and then try to match assuming expr is a regular expression. Originally designed to match minion IDs for whitelists/blacklists. ''' if line == expr: return...
[ "def", "expr_match", "(", "line", ",", "expr", ")", ":", "if", "line", "==", "expr", ":", "return", "True", "if", "fnmatch", ".", "fnmatch", "(", "line", ",", "expr", ")", ":", "return", "True", "try", ":", "if", "re", ".", "match", "(", "r'\\A{0}\...
Evaluate a line of text against an expression. First try a full-string match, next try globbing, and then try to match assuming expr is a regular expression. Originally designed to match minion IDs for whitelists/blacklists.
[ "Evaluate", "a", "line", "of", "text", "against", "an", "expression", ".", "First", "try", "a", "full", "-", "string", "match", "next", "try", "globbing", "and", "then", "try", "to", "match", "assuming", "expr", "is", "a", "regular", "expression", ".", "...
train
https://github.com/napalm-automation/napalm-logs/blob/4b89100a6e4f994aa004f3ea42a06dc803a7ccb0/napalm_logs/ext/__init__.py#L14-L30
napalm-automation/napalm-logs
napalm_logs/ext/__init__.py
check_whitelist_blacklist
def check_whitelist_blacklist(value, whitelist=None, blacklist=None): ''' Check a whitelist and/or blacklist to see if the value matches it. value The item to check the whitelist and/or blacklist against. whitelist The list of items that are white-listed. If ``value`` is found ...
python
def check_whitelist_blacklist(value, whitelist=None, blacklist=None): ''' Check a whitelist and/or blacklist to see if the value matches it. value The item to check the whitelist and/or blacklist against. whitelist The list of items that are white-listed. If ``value`` is found ...
[ "def", "check_whitelist_blacklist", "(", "value", ",", "whitelist", "=", "None", ",", "blacklist", "=", "None", ")", ":", "if", "blacklist", "is", "not", "None", ":", "if", "not", "hasattr", "(", "blacklist", ",", "'__iter__'", ")", ":", "blacklist", "=", ...
Check a whitelist and/or blacklist to see if the value matches it. value The item to check the whitelist and/or blacklist against. whitelist The list of items that are white-listed. If ``value`` is found in the whitelist, then the function returns ``True``. Otherwise, it return...
[ "Check", "a", "whitelist", "and", "/", "or", "blacklist", "to", "see", "if", "the", "value", "matches", "it", "." ]
train
https://github.com/napalm-automation/napalm-logs/blob/4b89100a6e4f994aa004f3ea42a06dc803a7ccb0/napalm_logs/ext/__init__.py#L33-L77
poppy-project/pypot
pypot/server/snap.py
set_snap_server_variables
def set_snap_server_variables(host, port, snap_extension='.xml', path=None): """ Change dynamically port and host variable in xml Snap! project file""" localdir = os.getcwd() if path is None: os.chdir(os.path.dirname(os.path.realpath(__file__))) else: os.chdir(path) xml_files = [f f...
python
def set_snap_server_variables(host, port, snap_extension='.xml', path=None): """ Change dynamically port and host variable in xml Snap! project file""" localdir = os.getcwd() if path is None: os.chdir(os.path.dirname(os.path.realpath(__file__))) else: os.chdir(path) xml_files = [f f...
[ "def", "set_snap_server_variables", "(", "host", ",", "port", ",", "snap_extension", "=", "'.xml'", ",", "path", "=", "None", ")", ":", "localdir", "=", "os", ".", "getcwd", "(", ")", "if", "path", "is", "None", ":", "os", ".", "chdir", "(", "os", "....
Change dynamically port and host variable in xml Snap! project file
[ "Change", "dynamically", "port", "and", "host", "variable", "in", "xml", "Snap!", "project", "file" ]
train
https://github.com/poppy-project/pypot/blob/d9c6551bbc87d45d9d1f0bc15e35b616d0002afd/pypot/server/snap.py#L82-L106
poppy-project/pypot
pypot/server/snap.py
SnapRobotServer.run
def run(self, quiet=None, server=''): """ Start the tornado server, run forever. 'quiet' and 'server' arguments are no longer used, they are keep only for backward compatibility """ try: loop = IOLoop() http_server = HTTPServer(WSGIContainer(self.app)) ...
python
def run(self, quiet=None, server=''): """ Start the tornado server, run forever. 'quiet' and 'server' arguments are no longer used, they are keep only for backward compatibility """ try: loop = IOLoop() http_server = HTTPServer(WSGIContainer(self.app)) ...
[ "def", "run", "(", "self", ",", "quiet", "=", "None", ",", "server", "=", "''", ")", ":", "try", ":", "loop", "=", "IOLoop", "(", ")", "http_server", "=", "HTTPServer", "(", "WSGIContainer", "(", "self", ".", "app", ")", ")", "http_server", ".", "l...
Start the tornado server, run forever. 'quiet' and 'server' arguments are no longer used, they are keep only for backward compatibility
[ "Start", "the", "tornado", "server", "run", "forever", ".", "quiet", "and", "server", "arguments", "are", "no", "longer", "used", "they", "are", "keep", "only", "for", "backward", "compatibility" ]
train
https://github.com/poppy-project/pypot/blob/d9c6551bbc87d45d9d1f0bc15e35b616d0002afd/pypot/server/snap.py#L406-L423
poppy-project/pypot
pypot/utils/stoppablethread.py
make_update_loop
def make_update_loop(thread, update_func): """ Makes a run loop which calls an update function at a predefined frequency. """ while not thread.should_stop(): if thread.should_pause(): thread.wait_to_resume() start = time.time() if hasattr(thread, '_updated'): thr...
python
def make_update_loop(thread, update_func): """ Makes a run loop which calls an update function at a predefined frequency. """ while not thread.should_stop(): if thread.should_pause(): thread.wait_to_resume() start = time.time() if hasattr(thread, '_updated'): thr...
[ "def", "make_update_loop", "(", "thread", ",", "update_func", ")", ":", "while", "not", "thread", ".", "should_stop", "(", ")", ":", "if", "thread", ".", "should_pause", "(", ")", ":", "thread", ".", "wait_to_resume", "(", ")", "start", "=", "time", ".",...
Makes a run loop which calls an update function at a predefined frequency.
[ "Makes", "a", "run", "loop", "which", "calls", "an", "update", "function", "at", "a", "predefined", "frequency", "." ]
train
https://github.com/poppy-project/pypot/blob/d9c6551bbc87d45d9d1f0bc15e35b616d0002afd/pypot/utils/stoppablethread.py#L166-L183
poppy-project/pypot
pypot/utils/stoppablethread.py
StoppableThread.start
def start(self): """ Start the run method as a new thread. It will first stop the thread if it is already running. """ if self.running: self.stop() self._thread = threading.Thread(target=self._wrapped_target) self._thread.daemon = True self._thread....
python
def start(self): """ Start the run method as a new thread. It will first stop the thread if it is already running. """ if self.running: self.stop() self._thread = threading.Thread(target=self._wrapped_target) self._thread.daemon = True self._thread....
[ "def", "start", "(", "self", ")", ":", "if", "self", ".", "running", ":", "self", ".", "stop", "(", ")", "self", ".", "_thread", "=", "threading", ".", "Thread", "(", "target", "=", "self", ".", "_wrapped_target", ")", "self", ".", "_thread", ".", ...
Start the run method as a new thread. It will first stop the thread if it is already running.
[ "Start", "the", "run", "method", "as", "a", "new", "thread", "." ]
train
https://github.com/poppy-project/pypot/blob/d9c6551bbc87d45d9d1f0bc15e35b616d0002afd/pypot/utils/stoppablethread.py#L33-L44
poppy-project/pypot
pypot/utils/stoppablethread.py
StoppableThread.stop
def stop(self, wait=True): """ Stop the thread. More precisely, sends the stopping signal to the thread. It is then up to the run method to correctly responds. """ if self.started: self._running.clear() self._resume.set() # We cannot wait for oursel...
python
def stop(self, wait=True): """ Stop the thread. More precisely, sends the stopping signal to the thread. It is then up to the run method to correctly responds. """ if self.started: self._running.clear() self._resume.set() # We cannot wait for oursel...
[ "def", "stop", "(", "self", ",", "wait", "=", "True", ")", ":", "if", "self", ".", "started", ":", "self", ".", "_running", ".", "clear", "(", ")", "self", ".", "_resume", ".", "set", "(", ")", "# We cannot wait for ourself", "if", "wait", "and", "("...
Stop the thread. More precisely, sends the stopping signal to the thread. It is then up to the run method to correctly responds.
[ "Stop", "the", "thread", "." ]
train
https://github.com/poppy-project/pypot/blob/d9c6551bbc87d45d9d1f0bc15e35b616d0002afd/pypot/utils/stoppablethread.py#L46-L64
poppy-project/pypot
pypot/utils/stoppablethread.py
StoppableThread.wait_to_start
def wait_to_start(self, allow_failure=False): """ Wait for the thread to actually starts. """ self._started.wait() if self._crashed and not allow_failure: self._thread.join() raise RuntimeError('Setup failed, see {} Traceback' 'for details....
python
def wait_to_start(self, allow_failure=False): """ Wait for the thread to actually starts. """ self._started.wait() if self._crashed and not allow_failure: self._thread.join() raise RuntimeError('Setup failed, see {} Traceback' 'for details....
[ "def", "wait_to_start", "(", "self", ",", "allow_failure", "=", "False", ")", ":", "self", ".", "_started", ".", "wait", "(", ")", "if", "self", ".", "_crashed", "and", "not", "allow_failure", ":", "self", ".", "_thread", ".", "join", "(", ")", "raise"...
Wait for the thread to actually starts.
[ "Wait", "for", "the", "thread", "to", "actually", "starts", "." ]
train
https://github.com/poppy-project/pypot/blob/d9c6551bbc87d45d9d1f0bc15e35b616d0002afd/pypot/utils/stoppablethread.py#L82-L89
poppy-project/pypot
pypot/vrep/__init__.py
from_vrep
def from_vrep(config, vrep_host='127.0.0.1', vrep_port=19997, scene=None, tracked_objects=[], tracked_collisions=[], id=None, shared_vrep_io=None): """ Create a robot from a V-REP instance. :param config: robot configuration (either the path to the json or directly the dictionary) ...
python
def from_vrep(config, vrep_host='127.0.0.1', vrep_port=19997, scene=None, tracked_objects=[], tracked_collisions=[], id=None, shared_vrep_io=None): """ Create a robot from a V-REP instance. :param config: robot configuration (either the path to the json or directly the dictionary) ...
[ "def", "from_vrep", "(", "config", ",", "vrep_host", "=", "'127.0.0.1'", ",", "vrep_port", "=", "19997", ",", "scene", "=", "None", ",", "tracked_objects", "=", "[", "]", ",", "tracked_collisions", "=", "[", "]", ",", "id", "=", "None", ",", "shared_vrep...
Create a robot from a V-REP instance. :param config: robot configuration (either the path to the json or directly the dictionary) :type config: str or dict :param str vrep_host: host of the V-REP server :param int vrep_port: port of the V-REP server :param str scene: path to the V-REP scene to load...
[ "Create", "a", "robot", "from", "a", "V", "-", "REP", "instance", "." ]
train
https://github.com/poppy-project/pypot/blob/d9c6551bbc87d45d9d1f0bc15e35b616d0002afd/pypot/vrep/__init__.py#L52-L176
poppy-project/pypot
pypot/dynamixel/io/io.py
DxlIO.get_control_mode
def get_control_mode(self, ids): """ Gets the mode ('joint' or 'wheel') for the specified motors. """ to_get_ids = [id for id in ids if id not in self._known_mode] limits = self.get_angle_limit(to_get_ids, convert=False) modes = ['wheel' if limit == (0, 0) else 'joint' for limit in limit...
python
def get_control_mode(self, ids): """ Gets the mode ('joint' or 'wheel') for the specified motors. """ to_get_ids = [id for id in ids if id not in self._known_mode] limits = self.get_angle_limit(to_get_ids, convert=False) modes = ['wheel' if limit == (0, 0) else 'joint' for limit in limit...
[ "def", "get_control_mode", "(", "self", ",", "ids", ")", ":", "to_get_ids", "=", "[", "id", "for", "id", "in", "ids", "if", "id", "not", "in", "self", ".", "_known_mode", "]", "limits", "=", "self", ".", "get_angle_limit", "(", "to_get_ids", ",", "conv...
Gets the mode ('joint' or 'wheel') for the specified motors.
[ "Gets", "the", "mode", "(", "joint", "or", "wheel", ")", "for", "the", "specified", "motors", "." ]
train
https://github.com/poppy-project/pypot/blob/d9c6551bbc87d45d9d1f0bc15e35b616d0002afd/pypot/dynamixel/io/io.py#L20-L28
poppy-project/pypot
pypot/dynamixel/io/io.py
DxlIO.set_wheel_mode
def set_wheel_mode(self, ids): """ Sets the specified motors to wheel mode. """ self.set_control_mode(dict(zip(ids, itertools.repeat('wheel'))))
python
def set_wheel_mode(self, ids): """ Sets the specified motors to wheel mode. """ self.set_control_mode(dict(zip(ids, itertools.repeat('wheel'))))
[ "def", "set_wheel_mode", "(", "self", ",", "ids", ")", ":", "self", ".", "set_control_mode", "(", "dict", "(", "zip", "(", "ids", ",", "itertools", ".", "repeat", "(", "'wheel'", ")", ")", ")", ")" ]
Sets the specified motors to wheel mode.
[ "Sets", "the", "specified", "motors", "to", "wheel", "mode", "." ]
train
https://github.com/poppy-project/pypot/blob/d9c6551bbc87d45d9d1f0bc15e35b616d0002afd/pypot/dynamixel/io/io.py#L30-L32
poppy-project/pypot
pypot/dynamixel/io/io.py
DxlIO.set_joint_mode
def set_joint_mode(self, ids): """ Sets the specified motors to joint mode. """ self.set_control_mode(dict(zip(ids, itertools.repeat('joint'))))
python
def set_joint_mode(self, ids): """ Sets the specified motors to joint mode. """ self.set_control_mode(dict(zip(ids, itertools.repeat('joint'))))
[ "def", "set_joint_mode", "(", "self", ",", "ids", ")", ":", "self", ".", "set_control_mode", "(", "dict", "(", "zip", "(", "ids", ",", "itertools", ".", "repeat", "(", "'joint'", ")", ")", ")", ")" ]
Sets the specified motors to joint mode.
[ "Sets", "the", "specified", "motors", "to", "joint", "mode", "." ]
train
https://github.com/poppy-project/pypot/blob/d9c6551bbc87d45d9d1f0bc15e35b616d0002afd/pypot/dynamixel/io/io.py#L34-L36
poppy-project/pypot
pypot/dynamixel/io/io.py
DxlIO.set_angle_limit
def set_angle_limit(self, limit_for_id, **kwargs): """ Sets the angle limit to the specified motors. """ convert = kwargs['convert'] if 'convert' in kwargs else self._convert if 'wheel' in self.get_control_mode(limit_for_id.keys()): raise ValueError('can not change the angle limit o...
python
def set_angle_limit(self, limit_for_id, **kwargs): """ Sets the angle limit to the specified motors. """ convert = kwargs['convert'] if 'convert' in kwargs else self._convert if 'wheel' in self.get_control_mode(limit_for_id.keys()): raise ValueError('can not change the angle limit o...
[ "def", "set_angle_limit", "(", "self", ",", "limit_for_id", ",", "*", "*", "kwargs", ")", ":", "convert", "=", "kwargs", "[", "'convert'", "]", "if", "'convert'", "in", "kwargs", "else", "self", ".", "_convert", "if", "'wheel'", "in", "self", ".", "get_c...
Sets the angle limit to the specified motors.
[ "Sets", "the", "angle", "limit", "to", "the", "specified", "motors", "." ]
train
https://github.com/poppy-project/pypot/blob/d9c6551bbc87d45d9d1f0bc15e35b616d0002afd/pypot/dynamixel/io/io.py#L55-L65
poppy-project/pypot
pypot/robot/robot.py
Robot.close
def close(self): """ Cleans the robot by stopping synchronization and all controllers.""" self.stop_sync() [c.io.close() for c in self._controllers if c.io is not None]
python
def close(self): """ Cleans the robot by stopping synchronization and all controllers.""" self.stop_sync() [c.io.close() for c in self._controllers if c.io is not None]
[ "def", "close", "(", "self", ")", ":", "self", ".", "stop_sync", "(", ")", "[", "c", ".", "io", ".", "close", "(", ")", "for", "c", "in", "self", ".", "_controllers", "if", "c", ".", "io", "is", "not", "None", "]" ]
Cleans the robot by stopping synchronization and all controllers.
[ "Cleans", "the", "robot", "by", "stopping", "synchronization", "and", "all", "controllers", "." ]
train
https://github.com/poppy-project/pypot/blob/d9c6551bbc87d45d9d1f0bc15e35b616d0002afd/pypot/robot/robot.py#L51-L54
poppy-project/pypot
pypot/robot/robot.py
Robot.start_sync
def start_sync(self): """ Starts all the synchonization loop (sensor/effector controllers). """ if self._syncing: return [c.start() for c in self._controllers] [c.wait_to_start() for c in self._controllers] self._primitive_manager.start() self._primitive_mana...
python
def start_sync(self): """ Starts all the synchonization loop (sensor/effector controllers). """ if self._syncing: return [c.start() for c in self._controllers] [c.wait_to_start() for c in self._controllers] self._primitive_manager.start() self._primitive_mana...
[ "def", "start_sync", "(", "self", ")", ":", "if", "self", ".", "_syncing", ":", "return", "[", "c", ".", "start", "(", ")", "for", "c", "in", "self", ".", "_controllers", "]", "[", "c", ".", "wait_to_start", "(", ")", "for", "c", "in", "self", "....
Starts all the synchonization loop (sensor/effector controllers).
[ "Starts", "all", "the", "synchonization", "loop", "(", "sensor", "/", "effector", "controllers", ")", "." ]
train
https://github.com/poppy-project/pypot/blob/d9c6551bbc87d45d9d1f0bc15e35b616d0002afd/pypot/robot/robot.py#L59-L71
poppy-project/pypot
pypot/robot/robot.py
Robot.stop_sync
def stop_sync(self): """ Stops all the synchonization loop (sensor/effector controllers). """ if not self._syncing: return if self._primitive_manager.running: self._primitive_manager.stop() [c.stop() for c in self._controllers] [s.close() for s in self.s...
python
def stop_sync(self): """ Stops all the synchonization loop (sensor/effector controllers). """ if not self._syncing: return if self._primitive_manager.running: self._primitive_manager.stop() [c.stop() for c in self._controllers] [s.close() for s in self.s...
[ "def", "stop_sync", "(", "self", ")", ":", "if", "not", "self", ".", "_syncing", ":", "return", "if", "self", ".", "_primitive_manager", ".", "running", ":", "self", ".", "_primitive_manager", ".", "stop", "(", ")", "[", "c", ".", "stop", "(", ")", "...
Stops all the synchonization loop (sensor/effector controllers).
[ "Stops", "all", "the", "synchonization", "loop", "(", "sensor", "/", "effector", "controllers", ")", "." ]
train
https://github.com/poppy-project/pypot/blob/d9c6551bbc87d45d9d1f0bc15e35b616d0002afd/pypot/robot/robot.py#L73-L86
poppy-project/pypot
pypot/robot/robot.py
Robot.goto_position
def goto_position(self, position_for_motors, duration, control=None, wait=False): """ Moves a subset of the motors to a position within a specific duration. :param dict position_for_motors: which motors you want to move {motor_name: pos, motor_name: pos,...} :param float duration: durat...
python
def goto_position(self, position_for_motors, duration, control=None, wait=False): """ Moves a subset of the motors to a position within a specific duration. :param dict position_for_motors: which motors you want to move {motor_name: pos, motor_name: pos,...} :param float duration: durat...
[ "def", "goto_position", "(", "self", ",", "position_for_motors", ",", "duration", ",", "control", "=", "None", ",", "wait", "=", "False", ")", ":", "for", "i", ",", "(", "motor_name", ",", "position", ")", "in", "enumerate", "(", "position_for_motors", "."...
Moves a subset of the motors to a position within a specific duration. :param dict position_for_motors: which motors you want to move {motor_name: pos, motor_name: pos,...} :param float duration: duration of the move :param str control: control type ('dummy', 'minjerk') ...
[ "Moves", "a", "subset", "of", "the", "motors", "to", "a", "position", "within", "a", "specific", "duration", "." ]
train
https://github.com/poppy-project/pypot/blob/d9c6551bbc87d45d9d1f0bc15e35b616d0002afd/pypot/robot/robot.py#L126-L141
poppy-project/pypot
pypot/robot/robot.py
Robot.power_up
def power_up(self): """ Changes all settings to guarantee the motors will be used at their maximum power. """ for m in self.motors: m.compliant = False m.moving_speed = 0 m.torque_limit = 100.0
python
def power_up(self): """ Changes all settings to guarantee the motors will be used at their maximum power. """ for m in self.motors: m.compliant = False m.moving_speed = 0 m.torque_limit = 100.0
[ "def", "power_up", "(", "self", ")", ":", "for", "m", "in", "self", ".", "motors", ":", "m", ".", "compliant", "=", "False", "m", ".", "moving_speed", "=", "0", "m", ".", "torque_limit", "=", "100.0" ]
Changes all settings to guarantee the motors will be used at their maximum power.
[ "Changes", "all", "settings", "to", "guarantee", "the", "motors", "will", "be", "used", "at", "their", "maximum", "power", "." ]
train
https://github.com/poppy-project/pypot/blob/d9c6551bbc87d45d9d1f0bc15e35b616d0002afd/pypot/robot/robot.py#L143-L148
poppy-project/pypot
pypot/robot/robot.py
Robot.to_config
def to_config(self): """ Generates the config for the current robot. .. note:: The generated config should be used as a basis and must probably be modified. """ from ..dynamixel.controller import DxlController dxl_controllers = [c for c in self._controllers ...
python
def to_config(self): """ Generates the config for the current robot. .. note:: The generated config should be used as a basis and must probably be modified. """ from ..dynamixel.controller import DxlController dxl_controllers = [c for c in self._controllers ...
[ "def", "to_config", "(", "self", ")", ":", "from", ".", ".", "dynamixel", ".", "controller", "import", "DxlController", "dxl_controllers", "=", "[", "c", "for", "c", "in", "self", ".", "_controllers", "if", "isinstance", "(", "c", ",", "DxlController", ")"...
Generates the config for the current robot. .. note:: The generated config should be used as a basis and must probably be modified.
[ "Generates", "the", "config", "for", "the", "current", "robot", "." ]
train
https://github.com/poppy-project/pypot/blob/d9c6551bbc87d45d9d1f0bc15e35b616d0002afd/pypot/robot/robot.py#L150-L187
poppy-project/pypot
pypot/sensor/imagefeature/blob.py
BlobDetector.detect_blob
def detect_blob(self, img, filters): """ "filters" must be something similar to: filters = { 'R': (150, 255), # (min, max) 'S': (150, 255), } """ acc_mask = ones(img.shape[:2], dtype=uint8) * 255 rgb = img.copy() ...
python
def detect_blob(self, img, filters): """ "filters" must be something similar to: filters = { 'R': (150, 255), # (min, max) 'S': (150, 255), } """ acc_mask = ones(img.shape[:2], dtype=uint8) * 255 rgb = img.copy() ...
[ "def", "detect_blob", "(", "self", ",", "img", ",", "filters", ")", ":", "acc_mask", "=", "ones", "(", "img", ".", "shape", "[", ":", "2", "]", ",", "dtype", "=", "uint8", ")", "*", "255", "rgb", "=", "img", ".", "copy", "(", ")", "hsv", "=", ...
"filters" must be something similar to: filters = { 'R': (150, 255), # (min, max) 'S': (150, 255), }
[ "filters", "must", "be", "something", "similar", "to", ":", "filters", "=", "{", "R", ":", "(", "150", "255", ")", "#", "(", "min", "max", ")", "S", ":", "(", "150", "255", ")", "}" ]
train
https://github.com/poppy-project/pypot/blob/d9c6551bbc87d45d9d1f0bc15e35b616d0002afd/pypot/sensor/imagefeature/blob.py#L40-L67
poppy-project/pypot
pypot/vrep/controller.py
VrepController.setup
def setup(self): """ Setups the controller by reading/setting position for all motors. """ self._init_vrep_streaming() # Init lifo for temperature spoofing for m in self.motors: m.__dict__['_load_fifo'] = deque(200 * [1], maxlen=200) self.update()
python
def setup(self): """ Setups the controller by reading/setting position for all motors. """ self._init_vrep_streaming() # Init lifo for temperature spoofing for m in self.motors: m.__dict__['_load_fifo'] = deque(200 * [1], maxlen=200) self.update()
[ "def", "setup", "(", "self", ")", ":", "self", ".", "_init_vrep_streaming", "(", ")", "# Init lifo for temperature spoofing", "for", "m", "in", "self", ".", "motors", ":", "m", ".", "__dict__", "[", "'_load_fifo'", "]", "=", "deque", "(", "200", "*", "[", ...
Setups the controller by reading/setting position for all motors.
[ "Setups", "the", "controller", "by", "reading", "/", "setting", "position", "for", "all", "motors", "." ]
train
https://github.com/poppy-project/pypot/blob/d9c6551bbc87d45d9d1f0bc15e35b616d0002afd/pypot/vrep/controller.py#L31-L39
poppy-project/pypot
pypot/vrep/controller.py
VrepController.update
def update(self): """ Synchronization update loop. At each update all motor position are read from vrep and set to the motors. The motors target position are also send to v-rep. """ # Read all the angle limits h, _, l, _ = self.io.call_remote_api('simxGetObjectGroupData', ...
python
def update(self): """ Synchronization update loop. At each update all motor position are read from vrep and set to the motors. The motors target position are also send to v-rep. """ # Read all the angle limits h, _, l, _ = self.io.call_remote_api('simxGetObjectGroupData', ...
[ "def", "update", "(", "self", ")", ":", "# Read all the angle limits", "h", ",", "_", ",", "l", ",", "_", "=", "self", ".", "io", ".", "call_remote_api", "(", "'simxGetObjectGroupData'", ",", "remote_api", ".", "sim_object_joint_type", ",", "16", ",", "strea...
Synchronization update loop. At each update all motor position are read from vrep and set to the motors. The motors target position are also send to v-rep.
[ "Synchronization", "update", "loop", "." ]
train
https://github.com/poppy-project/pypot/blob/d9c6551bbc87d45d9d1f0bc15e35b616d0002afd/pypot/vrep/controller.py#L41-L82
poppy-project/pypot
pypot/vrep/controller.py
VrepObjectTracker.update
def update(self): """ Updates the position and orientation of the tracked objects. """ for s in self.sensors: s.position = self.io.get_object_position(object_name=s.name) s.orientation = self.io.get_object_orientation(object_name=s.name)
python
def update(self): """ Updates the position and orientation of the tracked objects. """ for s in self.sensors: s.position = self.io.get_object_position(object_name=s.name) s.orientation = self.io.get_object_orientation(object_name=s.name)
[ "def", "update", "(", "self", ")", ":", "for", "s", "in", "self", ".", "sensors", ":", "s", ".", "position", "=", "self", ".", "io", ".", "get_object_position", "(", "object_name", "=", "s", ".", "name", ")", "s", ".", "orientation", "=", "self", "...
Updates the position and orientation of the tracked objects.
[ "Updates", "the", "position", "and", "orientation", "of", "the", "tracked", "objects", "." ]
train
https://github.com/poppy-project/pypot/blob/d9c6551bbc87d45d9d1f0bc15e35b616d0002afd/pypot/vrep/controller.py#L149-L153
poppy-project/pypot
pypot/vrep/controller.py
VrepCollisionTracker.update
def update(self): """ Update the state of the collision detectors. """ for s in self.sensors: s.colliding = self.io.get_collision_state(collision_name=s.name)
python
def update(self): """ Update the state of the collision detectors. """ for s in self.sensors: s.colliding = self.io.get_collision_state(collision_name=s.name)
[ "def", "update", "(", "self", ")", ":", "for", "s", "in", "self", ".", "sensors", ":", "s", ".", "colliding", "=", "self", ".", "io", ".", "get_collision_state", "(", "collision_name", "=", "s", ".", "name", ")" ]
Update the state of the collision detectors.
[ "Update", "the", "state", "of", "the", "collision", "detectors", "." ]
train
https://github.com/poppy-project/pypot/blob/d9c6551bbc87d45d9d1f0bc15e35b616d0002afd/pypot/vrep/controller.py#L180-L184
poppy-project/pypot
pypot/kinematics.py
Link.get_transformation_matrix
def get_transformation_matrix(self, theta): """ Computes the homogeneous transformation matrix for this link. """ ct = numpy.cos(theta + self.theta) st = numpy.sin(theta + self.theta) ca = numpy.cos(self.alpha) sa = numpy.sin(self.alpha) return numpy.matrix(((ct, -st * c...
python
def get_transformation_matrix(self, theta): """ Computes the homogeneous transformation matrix for this link. """ ct = numpy.cos(theta + self.theta) st = numpy.sin(theta + self.theta) ca = numpy.cos(self.alpha) sa = numpy.sin(self.alpha) return numpy.matrix(((ct, -st * c...
[ "def", "get_transformation_matrix", "(", "self", ",", "theta", ")", ":", "ct", "=", "numpy", ".", "cos", "(", "theta", "+", "self", ".", "theta", ")", "st", "=", "numpy", ".", "sin", "(", "theta", "+", "self", ".", "theta", ")", "ca", "=", "numpy",...
Computes the homogeneous transformation matrix for this link.
[ "Computes", "the", "homogeneous", "transformation", "matrix", "for", "this", "link", "." ]
train
https://github.com/poppy-project/pypot/blob/d9c6551bbc87d45d9d1f0bc15e35b616d0002afd/pypot/kinematics.py#L27-L37
poppy-project/pypot
pypot/kinematics.py
Chain.forward_kinematics
def forward_kinematics(self, q): """ Computes the homogeneous transformation matrix of the end effector of the chain. :param vector q: vector of the joint angles (theta 1, theta 2, ..., theta n) """ q = numpy.array(q).flatten() if len(q) != len(self.links): raise V...
python
def forward_kinematics(self, q): """ Computes the homogeneous transformation matrix of the end effector of the chain. :param vector q: vector of the joint angles (theta 1, theta 2, ..., theta n) """ q = numpy.array(q).flatten() if len(q) != len(self.links): raise V...
[ "def", "forward_kinematics", "(", "self", ",", "q", ")", ":", "q", "=", "numpy", ".", "array", "(", "q", ")", ".", "flatten", "(", ")", "if", "len", "(", "q", ")", "!=", "len", "(", "self", ".", "links", ")", ":", "raise", "ValueError", "(", "'...
Computes the homogeneous transformation matrix of the end effector of the chain. :param vector q: vector of the joint angles (theta 1, theta 2, ..., theta n)
[ "Computes", "the", "homogeneous", "transformation", "matrix", "of", "the", "end", "effector", "of", "the", "chain", "." ]
train
https://github.com/poppy-project/pypot/blob/d9c6551bbc87d45d9d1f0bc15e35b616d0002afd/pypot/kinematics.py#L51-L73
poppy-project/pypot
pypot/kinematics.py
Chain.inverse_kinematics
def inverse_kinematics(self, end_effector_transformation, q=None, max_iter=1000, tolerance=0.05, mask=numpy.ones(6), use_pinv=False): """ Computes the joint angles corresponding to the end effector transf...
python
def inverse_kinematics(self, end_effector_transformation, q=None, max_iter=1000, tolerance=0.05, mask=numpy.ones(6), use_pinv=False): """ Computes the joint angles corresponding to the end effector transf...
[ "def", "inverse_kinematics", "(", "self", ",", "end_effector_transformation", ",", "q", "=", "None", ",", "max_iter", "=", "1000", ",", "tolerance", "=", "0.05", ",", "mask", "=", "numpy", ".", "ones", "(", "6", ")", ",", "use_pinv", "=", "False", ")", ...
Computes the joint angles corresponding to the end effector transformation. :param end_effector_transformation: the end effector homogeneous transformation matrix :param vector q: initial estimate of the joint angles :param int max_iter: maximum number of iteration :param float toleranc...
[ "Computes", "the", "joint", "angles", "corresponding", "to", "the", "end", "effector", "transformation", "." ]
train
https://github.com/poppy-project/pypot/blob/d9c6551bbc87d45d9d1f0bc15e35b616d0002afd/pypot/kinematics.py#L75-L122
poppy-project/pypot
pypot/primitive/utils.py
Sinus.update
def update(self): """ Compute the sin(t) where t is the elapsed time since the primitive has been started. """ pos = self._amp * numpy.sin(self._freq * 2.0 * numpy.pi * self.elapsed_time + self._phase * numpy.pi / 180.0) + self._offset for m in self.motor_lis...
python
def update(self): """ Compute the sin(t) where t is the elapsed time since the primitive has been started. """ pos = self._amp * numpy.sin(self._freq * 2.0 * numpy.pi * self.elapsed_time + self._phase * numpy.pi / 180.0) + self._offset for m in self.motor_lis...
[ "def", "update", "(", "self", ")", ":", "pos", "=", "self", ".", "_amp", "*", "numpy", ".", "sin", "(", "self", ".", "_freq", "*", "2.0", "*", "numpy", ".", "pi", "*", "self", ".", "elapsed_time", "+", "self", ".", "_phase", "*", "numpy", ".", ...
Compute the sin(t) where t is the elapsed time since the primitive has been started.
[ "Compute", "the", "sin", "(", "t", ")", "where", "t", "is", "the", "elapsed", "time", "since", "the", "primitive", "has", "been", "started", "." ]
train
https://github.com/poppy-project/pypot/blob/d9c6551bbc87d45d9d1f0bc15e35b616d0002afd/pypot/primitive/utils.py#L26-L32
poppy-project/pypot
pypot/dynamixel/__init__.py
_get_available_ports
def _get_available_ports(): """ Tries to find the available serial ports on your system. """ if platform.system() == 'Darwin': return glob.glob('/dev/tty.usb*') elif platform.system() == 'Linux': return glob.glob('/dev/ttyACM*') + glob.glob('/dev/ttyUSB*') + glob.glob('/dev/ttyAMA*') e...
python
def _get_available_ports(): """ Tries to find the available serial ports on your system. """ if platform.system() == 'Darwin': return glob.glob('/dev/tty.usb*') elif platform.system() == 'Linux': return glob.glob('/dev/ttyACM*') + glob.glob('/dev/ttyUSB*') + glob.glob('/dev/ttyAMA*') e...
[ "def", "_get_available_ports", "(", ")", ":", "if", "platform", ".", "system", "(", ")", "==", "'Darwin'", ":", "return", "glob", ".", "glob", "(", "'/dev/tty.usb*'", ")", "elif", "platform", ".", "system", "(", ")", "==", "'Linux'", ":", "return", "glob...
Tries to find the available serial ports on your system.
[ "Tries", "to", "find", "the", "available", "serial", "ports", "on", "your", "system", "." ]
train
https://github.com/poppy-project/pypot/blob/d9c6551bbc87d45d9d1f0bc15e35b616d0002afd/pypot/dynamixel/__init__.py#L20-L46
poppy-project/pypot
pypot/dynamixel/__init__.py
get_port_vendor_info
def get_port_vendor_info(port=None): """ Return vendor informations of a usb2serial device. It may depends on the Operating System. :param string port: port of the usb2serial device :Example: Result with a USB2Dynamixel on Linux: In [1]: import pypot.dynamixel In [2...
python
def get_port_vendor_info(port=None): """ Return vendor informations of a usb2serial device. It may depends on the Operating System. :param string port: port of the usb2serial device :Example: Result with a USB2Dynamixel on Linux: In [1]: import pypot.dynamixel In [2...
[ "def", "get_port_vendor_info", "(", "port", "=", "None", ")", ":", "port_info_dict", "=", "dict", "(", "(", "x", "[", "0", "]", ",", "x", "[", "2", "]", ")", "for", "x", "in", "serial", ".", "tools", ".", "list_ports", ".", "comports", "(", ")", ...
Return vendor informations of a usb2serial device. It may depends on the Operating System. :param string port: port of the usb2serial device :Example: Result with a USB2Dynamixel on Linux: In [1]: import pypot.dynamixel In [2]: pypot.dynamixel.get_port_vendor_info('/dev...
[ "Return", "vendor", "informations", "of", "a", "usb2serial", "device", ".", "It", "may", "depends", "on", "the", "Operating", "System", ".", ":", "param", "string", "port", ":", "port", "of", "the", "usb2serial", "device" ]
train
https://github.com/poppy-project/pypot/blob/d9c6551bbc87d45d9d1f0bc15e35b616d0002afd/pypot/dynamixel/__init__.py#L58-L71
poppy-project/pypot
pypot/dynamixel/__init__.py
find_port
def find_port(ids, strict=True): """ Find the port with the specified attached motor ids. :param list ids: list of motor ids to find :param bool strict: specify if all ids should be find (when set to False, only half motor must be found) .. warning:: If two (or more) ports are attached to ...
python
def find_port(ids, strict=True): """ Find the port with the specified attached motor ids. :param list ids: list of motor ids to find :param bool strict: specify if all ids should be find (when set to False, only half motor must be found) .. warning:: If two (or more) ports are attached to ...
[ "def", "find_port", "(", "ids", ",", "strict", "=", "True", ")", ":", "ids_founds", "=", "[", "]", "for", "port", "in", "get_available_ports", "(", ")", ":", "for", "DxlIOCls", "in", "(", "DxlIO", ",", "Dxl320IO", ")", ":", "try", ":", "with", "DxlIO...
Find the port with the specified attached motor ids. :param list ids: list of motor ids to find :param bool strict: specify if all ids should be find (when set to False, only half motor must be found) .. warning:: If two (or more) ports are attached to the same list of motor ids the first matc...
[ "Find", "the", "port", "with", "the", "specified", "attached", "motor", "ids", "." ]
train
https://github.com/poppy-project/pypot/blob/d9c6551bbc87d45d9d1f0bc15e35b616d0002afd/pypot/dynamixel/__init__.py#L74-L106
poppy-project/pypot
pypot/dynamixel/__init__.py
autodetect_robot
def autodetect_robot(): """ Creates a :class:`~pypot.robot.robot.Robot` by detecting dynamixel motors on all available ports. """ motor_controllers = [] for port in get_available_ports(): for DxlIOCls in (DxlIO, Dxl320IO): dxl_io = DxlIOCls(port) ids = dxl_io.scan() ...
python
def autodetect_robot(): """ Creates a :class:`~pypot.robot.robot.Robot` by detecting dynamixel motors on all available ports. """ motor_controllers = [] for port in get_available_ports(): for DxlIOCls in (DxlIO, Dxl320IO): dxl_io = DxlIOCls(port) ids = dxl_io.scan() ...
[ "def", "autodetect_robot", "(", ")", ":", "motor_controllers", "=", "[", "]", "for", "port", "in", "get_available_ports", "(", ")", ":", "for", "DxlIOCls", "in", "(", "DxlIO", ",", "Dxl320IO", ")", ":", "dxl_io", "=", "DxlIOCls", "(", "port", ")", "ids",...
Creates a :class:`~pypot.robot.robot.Robot` by detecting dynamixel motors on all available ports.
[ "Creates", "a", ":", "class", ":", "~pypot", ".", "robot", ".", "robot", ".", "Robot", "by", "detecting", "dynamixel", "motors", "on", "all", "available", "ports", "." ]
train
https://github.com/poppy-project/pypot/blob/d9c6551bbc87d45d9d1f0bc15e35b616d0002afd/pypot/dynamixel/__init__.py#L109-L139
poppy-project/pypot
pypot/dynamixel/controller.py
DxlController.get_register
def get_register(self, motors, disable_sync_read=False): """ Gets the value from the specified register and sets it to the :class:`~pypot.dynamixel.motor.DxlMotor`. """ if not motors: return False ids = [m.id for m in motors] getter = getattr(self.io, 'get_{}'.format(self.re...
python
def get_register(self, motors, disable_sync_read=False): """ Gets the value from the specified register and sets it to the :class:`~pypot.dynamixel.motor.DxlMotor`. """ if not motors: return False ids = [m.id for m in motors] getter = getattr(self.io, 'get_{}'.format(self.re...
[ "def", "get_register", "(", "self", ",", "motors", ",", "disable_sync_read", "=", "False", ")", ":", "if", "not", "motors", ":", "return", "False", "ids", "=", "[", "m", ".", "id", "for", "m", "in", "motors", "]", "getter", "=", "getattr", "(", "self...
Gets the value from the specified register and sets it to the :class:`~pypot.dynamixel.motor.DxlMotor`.
[ "Gets", "the", "value", "from", "the", "specified", "register", "and", "sets", "it", "to", "the", ":", "class", ":", "~pypot", ".", "dynamixel", ".", "motor", ".", "DxlMotor", "." ]
train
https://github.com/poppy-project/pypot/blob/d9c6551bbc87d45d9d1f0bc15e35b616d0002afd/pypot/dynamixel/controller.py#L62-L83
poppy-project/pypot
pypot/dynamixel/controller.py
DxlController.set_register
def set_register(self, motors): """ Gets the value from :class:`~pypot.dynamixel.motor.DxlMotor` and sets it to the specified register. """ if not motors: return ids = [m.id for m in motors] values = (m.__dict__[self.varname] for m in motors) getattr(self.io, 'set_{}...
python
def set_register(self, motors): """ Gets the value from :class:`~pypot.dynamixel.motor.DxlMotor` and sets it to the specified register. """ if not motors: return ids = [m.id for m in motors] values = (m.__dict__[self.varname] for m in motors) getattr(self.io, 'set_{}...
[ "def", "set_register", "(", "self", ",", "motors", ")", ":", "if", "not", "motors", ":", "return", "ids", "=", "[", "m", ".", "id", "for", "m", "in", "motors", "]", "values", "=", "(", "m", ".", "__dict__", "[", "self", ".", "varname", "]", "for"...
Gets the value from :class:`~pypot.dynamixel.motor.DxlMotor` and sets it to the specified register.
[ "Gets", "the", "value", "from", ":", "class", ":", "~pypot", ".", "dynamixel", ".", "motor", ".", "DxlMotor", "and", "sets", "it", "to", "the", "specified", "register", "." ]
train
https://github.com/poppy-project/pypot/blob/d9c6551bbc87d45d9d1f0bc15e35b616d0002afd/pypot/dynamixel/controller.py#L85-L95
poppy-project/pypot
pypot/sensor/depth/sonar.py
Sonar._filter
def _filter(self, data): """ Apply a filter to reduce noisy data. Return the median value of a heap of data. """ filtered_data = [] for queue, data in zip(self._raw_data_queues, data): queue.append(data) filtered_data.append(numpy.median(queue)) ...
python
def _filter(self, data): """ Apply a filter to reduce noisy data. Return the median value of a heap of data. """ filtered_data = [] for queue, data in zip(self._raw_data_queues, data): queue.append(data) filtered_data.append(numpy.median(queue)) ...
[ "def", "_filter", "(", "self", ",", "data", ")", ":", "filtered_data", "=", "[", "]", "for", "queue", ",", "data", "in", "zip", "(", "self", ".", "_raw_data_queues", ",", "data", ")", ":", "queue", ".", "append", "(", "data", ")", "filtered_data", "....
Apply a filter to reduce noisy data. Return the median value of a heap of data.
[ "Apply", "a", "filter", "to", "reduce", "noisy", "data", "." ]
train
https://github.com/poppy-project/pypot/blob/d9c6551bbc87d45d9d1f0bc15e35b616d0002afd/pypot/sensor/depth/sonar.py#L87-L98
poppy-project/pypot
pypot/vrep/remoteApiBindings/vrep.py
simxGetJointPosition
def simxGetJointPosition(clientID, jointHandle, operationMode): ''' Please have a look at the function description/documentation in the V-REP user manual ''' position = ct.c_float() return c_GetJointPosition(clientID, jointHandle, ct.byref(position), operationMode), position.value
python
def simxGetJointPosition(clientID, jointHandle, operationMode): ''' Please have a look at the function description/documentation in the V-REP user manual ''' position = ct.c_float() return c_GetJointPosition(clientID, jointHandle, ct.byref(position), operationMode), position.value
[ "def", "simxGetJointPosition", "(", "clientID", ",", "jointHandle", ",", "operationMode", ")", ":", "position", "=", "ct", ".", "c_float", "(", ")", "return", "c_GetJointPosition", "(", "clientID", ",", "jointHandle", ",", "ct", ".", "byref", "(", "position", ...
Please have a look at the function description/documentation in the V-REP user manual
[ "Please", "have", "a", "look", "at", "the", "function", "description", "/", "documentation", "in", "the", "V", "-", "REP", "user", "manual" ]
train
https://github.com/poppy-project/pypot/blob/d9c6551bbc87d45d9d1f0bc15e35b616d0002afd/pypot/vrep/remoteApiBindings/vrep.py#L162-L167
poppy-project/pypot
pypot/vrep/remoteApiBindings/vrep.py
simxSetJointPosition
def simxSetJointPosition(clientID, jointHandle, position, operationMode): ''' Please have a look at the function description/documentation in the V-REP user manual ''' return c_SetJointPosition(clientID, jointHandle, position, operationMode)
python
def simxSetJointPosition(clientID, jointHandle, position, operationMode): ''' Please have a look at the function description/documentation in the V-REP user manual ''' return c_SetJointPosition(clientID, jointHandle, position, operationMode)
[ "def", "simxSetJointPosition", "(", "clientID", ",", "jointHandle", ",", "position", ",", "operationMode", ")", ":", "return", "c_SetJointPosition", "(", "clientID", ",", "jointHandle", ",", "position", ",", "operationMode", ")" ]
Please have a look at the function description/documentation in the V-REP user manual
[ "Please", "have", "a", "look", "at", "the", "function", "description", "/", "documentation", "in", "the", "V", "-", "REP", "user", "manual" ]
train
https://github.com/poppy-project/pypot/blob/d9c6551bbc87d45d9d1f0bc15e35b616d0002afd/pypot/vrep/remoteApiBindings/vrep.py#L169-L174
poppy-project/pypot
pypot/vrep/remoteApiBindings/vrep.py
simxGetJointMatrix
def simxGetJointMatrix(clientID, jointHandle, operationMode): ''' Please have a look at the function description/documentation in the V-REP user manual ''' matrix = (ct.c_float*12)() ret = c_GetJointMatrix(clientID, jointHandle, matrix, operationMode) arr = [] for i in range(12): arr...
python
def simxGetJointMatrix(clientID, jointHandle, operationMode): ''' Please have a look at the function description/documentation in the V-REP user manual ''' matrix = (ct.c_float*12)() ret = c_GetJointMatrix(clientID, jointHandle, matrix, operationMode) arr = [] for i in range(12): arr...
[ "def", "simxGetJointMatrix", "(", "clientID", ",", "jointHandle", ",", "operationMode", ")", ":", "matrix", "=", "(", "ct", ".", "c_float", "*", "12", ")", "(", ")", "ret", "=", "c_GetJointMatrix", "(", "clientID", ",", "jointHandle", ",", "matrix", ",", ...
Please have a look at the function description/documentation in the V-REP user manual
[ "Please", "have", "a", "look", "at", "the", "function", "description", "/", "documentation", "in", "the", "V", "-", "REP", "user", "manual" ]
train
https://github.com/poppy-project/pypot/blob/d9c6551bbc87d45d9d1f0bc15e35b616d0002afd/pypot/vrep/remoteApiBindings/vrep.py#L176-L185
poppy-project/pypot
pypot/vrep/remoteApiBindings/vrep.py
simxSetSphericalJointMatrix
def simxSetSphericalJointMatrix(clientID, jointHandle, matrix, operationMode): ''' Please have a look at the function description/documentation in the V-REP user manual ''' matrix = (ct.c_float*12)(*matrix) return c_SetSphericalJointMatrix(clientID, jointHandle, matrix, operationMode)
python
def simxSetSphericalJointMatrix(clientID, jointHandle, matrix, operationMode): ''' Please have a look at the function description/documentation in the V-REP user manual ''' matrix = (ct.c_float*12)(*matrix) return c_SetSphericalJointMatrix(clientID, jointHandle, matrix, operationMode)
[ "def", "simxSetSphericalJointMatrix", "(", "clientID", ",", "jointHandle", ",", "matrix", ",", "operationMode", ")", ":", "matrix", "=", "(", "ct", ".", "c_float", "*", "12", ")", "(", "*", "matrix", ")", "return", "c_SetSphericalJointMatrix", "(", "clientID",...
Please have a look at the function description/documentation in the V-REP user manual
[ "Please", "have", "a", "look", "at", "the", "function", "description", "/", "documentation", "in", "the", "V", "-", "REP", "user", "manual" ]
train
https://github.com/poppy-project/pypot/blob/d9c6551bbc87d45d9d1f0bc15e35b616d0002afd/pypot/vrep/remoteApiBindings/vrep.py#L187-L192
poppy-project/pypot
pypot/vrep/remoteApiBindings/vrep.py
simxSetJointTargetVelocity
def simxSetJointTargetVelocity(clientID, jointHandle, targetVelocity, operationMode): ''' Please have a look at the function description/documentation in the V-REP user manual ''' return c_SetJointTargetVelocity(clientID, jointHandle, targetVelocity, operationMode)
python
def simxSetJointTargetVelocity(clientID, jointHandle, targetVelocity, operationMode): ''' Please have a look at the function description/documentation in the V-REP user manual ''' return c_SetJointTargetVelocity(clientID, jointHandle, targetVelocity, operationMode)
[ "def", "simxSetJointTargetVelocity", "(", "clientID", ",", "jointHandle", ",", "targetVelocity", ",", "operationMode", ")", ":", "return", "c_SetJointTargetVelocity", "(", "clientID", ",", "jointHandle", ",", "targetVelocity", ",", "operationMode", ")" ]
Please have a look at the function description/documentation in the V-REP user manual
[ "Please", "have", "a", "look", "at", "the", "function", "description", "/", "documentation", "in", "the", "V", "-", "REP", "user", "manual" ]
train
https://github.com/poppy-project/pypot/blob/d9c6551bbc87d45d9d1f0bc15e35b616d0002afd/pypot/vrep/remoteApiBindings/vrep.py#L194-L199
poppy-project/pypot
pypot/vrep/remoteApiBindings/vrep.py
simxSetJointTargetPosition
def simxSetJointTargetPosition(clientID, jointHandle, targetPosition, operationMode): ''' Please have a look at the function description/documentation in the V-REP user manual ''' return c_SetJointTargetPosition(clientID, jointHandle, targetPosition, operationMode)
python
def simxSetJointTargetPosition(clientID, jointHandle, targetPosition, operationMode): ''' Please have a look at the function description/documentation in the V-REP user manual ''' return c_SetJointTargetPosition(clientID, jointHandle, targetPosition, operationMode)
[ "def", "simxSetJointTargetPosition", "(", "clientID", ",", "jointHandle", ",", "targetPosition", ",", "operationMode", ")", ":", "return", "c_SetJointTargetPosition", "(", "clientID", ",", "jointHandle", ",", "targetPosition", ",", "operationMode", ")" ]
Please have a look at the function description/documentation in the V-REP user manual
[ "Please", "have", "a", "look", "at", "the", "function", "description", "/", "documentation", "in", "the", "V", "-", "REP", "user", "manual" ]
train
https://github.com/poppy-project/pypot/blob/d9c6551bbc87d45d9d1f0bc15e35b616d0002afd/pypot/vrep/remoteApiBindings/vrep.py#L201-L206
poppy-project/pypot
pypot/vrep/remoteApiBindings/vrep.py
simxJointGetForce
def simxJointGetForce(clientID, jointHandle, operationMode): ''' Please have a look at the function description/documentation in the V-REP user manual ''' force = ct.c_float() return c_GetJointForce(clientID, jointHandle, ct.byref(force), operationMode), force.value
python
def simxJointGetForce(clientID, jointHandle, operationMode): ''' Please have a look at the function description/documentation in the V-REP user manual ''' force = ct.c_float() return c_GetJointForce(clientID, jointHandle, ct.byref(force), operationMode), force.value
[ "def", "simxJointGetForce", "(", "clientID", ",", "jointHandle", ",", "operationMode", ")", ":", "force", "=", "ct", ".", "c_float", "(", ")", "return", "c_GetJointForce", "(", "clientID", ",", "jointHandle", ",", "ct", ".", "byref", "(", "force", ")", ","...
Please have a look at the function description/documentation in the V-REP user manual
[ "Please", "have", "a", "look", "at", "the", "function", "description", "/", "documentation", "in", "the", "V", "-", "REP", "user", "manual" ]
train
https://github.com/poppy-project/pypot/blob/d9c6551bbc87d45d9d1f0bc15e35b616d0002afd/pypot/vrep/remoteApiBindings/vrep.py#L208-L213