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
10gen/mongo-orchestration
mongo_orchestration/common.py
BaseModel.key_file
def key_file(self): """Get the path to the key file containig our auth key, or None.""" if self.auth_key: key_file_path = os.path.join(orchestration_mkdtemp(), 'key') with open(key_file_path, 'w') as fd: fd.write(self.auth_key) os.chmod(key_file_path, ...
python
def key_file(self): """Get the path to the key file containig our auth key, or None.""" if self.auth_key: key_file_path = os.path.join(orchestration_mkdtemp(), 'key') with open(key_file_path, 'w') as fd: fd.write(self.auth_key) os.chmod(key_file_path, ...
[ "def", "key_file", "(", "self", ")", ":", "if", "self", ".", "auth_key", ":", "key_file_path", "=", "os", ".", "path", ".", "join", "(", "orchestration_mkdtemp", "(", ")", ",", "'key'", ")", "with", "open", "(", "key_file_path", ",", "'w'", ")", "as", ...
Get the path to the key file containig our auth key, or None.
[ "Get", "the", "path", "to", "the", "key", "file", "containig", "our", "auth", "key", "or", "None", "." ]
train
https://github.com/10gen/mongo-orchestration/blob/81fd2224205922ea2178b08190b53a33aec47261/mongo_orchestration/common.py#L67-L74
10gen/mongo-orchestration
mongo_orchestration/common.py
BaseModel._strip_auth
def _strip_auth(self, proc_params): """Remove options from parameters that cause auth to be enabled.""" params = proc_params.copy() params.pop("auth", None) params.pop("clusterAuthMode", None) return params
python
def _strip_auth(self, proc_params): """Remove options from parameters that cause auth to be enabled.""" params = proc_params.copy() params.pop("auth", None) params.pop("clusterAuthMode", None) return params
[ "def", "_strip_auth", "(", "self", ",", "proc_params", ")", ":", "params", "=", "proc_params", ".", "copy", "(", ")", "params", ".", "pop", "(", "\"auth\"", ",", "None", ")", "params", ".", "pop", "(", "\"clusterAuthMode\"", ",", "None", ")", "return", ...
Remove options from parameters that cause auth to be enabled.
[ "Remove", "options", "from", "parameters", "that", "cause", "auth", "to", "be", "enabled", "." ]
train
https://github.com/10gen/mongo-orchestration/blob/81fd2224205922ea2178b08190b53a33aec47261/mongo_orchestration/common.py#L76-L81
10gen/mongo-orchestration
mongo_orchestration/common.py
BaseModel.mongodb_auth_uri
def mongodb_auth_uri(self, hosts): """Get a connection string with all info necessary to authenticate.""" parts = ['mongodb://'] if self.login: parts.append(self.login) if self.password: parts.append(':' + self.password) parts.append('@') ...
python
def mongodb_auth_uri(self, hosts): """Get a connection string with all info necessary to authenticate.""" parts = ['mongodb://'] if self.login: parts.append(self.login) if self.password: parts.append(':' + self.password) parts.append('@') ...
[ "def", "mongodb_auth_uri", "(", "self", ",", "hosts", ")", ":", "parts", "=", "[", "'mongodb://'", "]", "if", "self", ".", "login", ":", "parts", ".", "append", "(", "self", ".", "login", ")", "if", "self", ".", "password", ":", "parts", ".", "append...
Get a connection string with all info necessary to authenticate.
[ "Get", "a", "connection", "string", "with", "all", "info", "necessary", "to", "authenticate", "." ]
train
https://github.com/10gen/mongo-orchestration/blob/81fd2224205922ea2178b08190b53a33aec47261/mongo_orchestration/common.py#L83-L96
10gen/mongo-orchestration
mongo_orchestration/common.py
BaseModel._add_users
def _add_users(self, db, mongo_version): """Add given user, and extra x509 user if necessary.""" if self.x509_extra_user: # Build dict of kwargs to pass to add_user. auth_dict = { 'name': DEFAULT_SUBJECT, 'roles': self._user_roles(db.client) ...
python
def _add_users(self, db, mongo_version): """Add given user, and extra x509 user if necessary.""" if self.x509_extra_user: # Build dict of kwargs to pass to add_user. auth_dict = { 'name': DEFAULT_SUBJECT, 'roles': self._user_roles(db.client) ...
[ "def", "_add_users", "(", "self", ",", "db", ",", "mongo_version", ")", ":", "if", "self", ".", "x509_extra_user", ":", "# Build dict of kwargs to pass to add_user.", "auth_dict", "=", "{", "'name'", ":", "DEFAULT_SUBJECT", ",", "'roles'", ":", "self", ".", "_us...
Add given user, and extra x509 user if necessary.
[ "Add", "given", "user", "and", "extra", "x509", "user", "if", "necessary", "." ]
train
https://github.com/10gen/mongo-orchestration/blob/81fd2224205922ea2178b08190b53a33aec47261/mongo_orchestration/common.py#L108-L131
10gen/mongo-orchestration
mongo_orchestration/apps/links.py
base_link
def base_link(rel, self_rel=False): """Helper for getting a link document under the API root, given a rel.""" link = _BASE_LINKS[rel].copy() link['rel'] = 'self' if self_rel else rel return link
python
def base_link(rel, self_rel=False): """Helper for getting a link document under the API root, given a rel.""" link = _BASE_LINKS[rel].copy() link['rel'] = 'self' if self_rel else rel return link
[ "def", "base_link", "(", "rel", ",", "self_rel", "=", "False", ")", ":", "link", "=", "_BASE_LINKS", "[", "rel", "]", ".", "copy", "(", ")", "link", "[", "'rel'", "]", "=", "'self'", "if", "self_rel", "else", "rel", "return", "link" ]
Helper for getting a link document under the API root, given a rel.
[ "Helper", "for", "getting", "a", "link", "document", "under", "the", "API", "root", "given", "a", "rel", "." ]
train
https://github.com/10gen/mongo-orchestration/blob/81fd2224205922ea2178b08190b53a33aec47261/mongo_orchestration/apps/links.py#L105-L109
10gen/mongo-orchestration
mongo_orchestration/apps/links.py
all_base_links
def all_base_links(rel_to=None): """Get a list of all links to be included to base (/) API requests.""" links = [ base_link('get-releases'), base_link('service'), server_link('get-servers'), server_link('add-server'), replica_set_link('add-replica-set'), replica_s...
python
def all_base_links(rel_to=None): """Get a list of all links to be included to base (/) API requests.""" links = [ base_link('get-releases'), base_link('service'), server_link('get-servers'), server_link('add-server'), replica_set_link('add-replica-set'), replica_s...
[ "def", "all_base_links", "(", "rel_to", "=", "None", ")", ":", "links", "=", "[", "base_link", "(", "'get-releases'", ")", ",", "base_link", "(", "'service'", ")", ",", "server_link", "(", "'get-servers'", ")", ",", "server_link", "(", "'add-server'", ")", ...
Get a list of all links to be included to base (/) API requests.
[ "Get", "a", "list", "of", "all", "links", "to", "be", "included", "to", "base", "(", "/", ")", "API", "requests", "." ]
train
https://github.com/10gen/mongo-orchestration/blob/81fd2224205922ea2178b08190b53a33aec47261/mongo_orchestration/apps/links.py#L112-L127
10gen/mongo-orchestration
mongo_orchestration/apps/links.py
server_link
def server_link(rel, server_id=None, self_rel=False): """Helper for getting a Server link document, given a rel.""" servers_href = '/v1/servers' link = _SERVER_LINKS[rel].copy() link['href'] = link['href'].format(**locals()) link['rel'] = 'self' if self_rel else rel return link
python
def server_link(rel, server_id=None, self_rel=False): """Helper for getting a Server link document, given a rel.""" servers_href = '/v1/servers' link = _SERVER_LINKS[rel].copy() link['href'] = link['href'].format(**locals()) link['rel'] = 'self' if self_rel else rel return link
[ "def", "server_link", "(", "rel", ",", "server_id", "=", "None", ",", "self_rel", "=", "False", ")", ":", "servers_href", "=", "'/v1/servers'", "link", "=", "_SERVER_LINKS", "[", "rel", "]", ".", "copy", "(", ")", "link", "[", "'href'", "]", "=", "link...
Helper for getting a Server link document, given a rel.
[ "Helper", "for", "getting", "a", "Server", "link", "document", "given", "a", "rel", "." ]
train
https://github.com/10gen/mongo-orchestration/blob/81fd2224205922ea2178b08190b53a33aec47261/mongo_orchestration/apps/links.py#L130-L136
10gen/mongo-orchestration
mongo_orchestration/apps/links.py
all_server_links
def all_server_links(server_id, rel_to=None): """Get a list of all links to be included with Servers.""" return [ server_link(rel, server_id, self_rel=(rel == rel_to)) for rel in ('delete-server', 'get-server-info', 'server-command') ]
python
def all_server_links(server_id, rel_to=None): """Get a list of all links to be included with Servers.""" return [ server_link(rel, server_id, self_rel=(rel == rel_to)) for rel in ('delete-server', 'get-server-info', 'server-command') ]
[ "def", "all_server_links", "(", "server_id", ",", "rel_to", "=", "None", ")", ":", "return", "[", "server_link", "(", "rel", ",", "server_id", ",", "self_rel", "=", "(", "rel", "==", "rel_to", ")", ")", "for", "rel", "in", "(", "'delete-server'", ",", ...
Get a list of all links to be included with Servers.
[ "Get", "a", "list", "of", "all", "links", "to", "be", "included", "with", "Servers", "." ]
train
https://github.com/10gen/mongo-orchestration/blob/81fd2224205922ea2178b08190b53a33aec47261/mongo_orchestration/apps/links.py#L139-L144
10gen/mongo-orchestration
mongo_orchestration/apps/links.py
replica_set_link
def replica_set_link(rel, repl_id=None, member_id=None, self_rel=False): """Helper for getting a ReplicaSet link document, given a rel.""" repls_href = '/v1/replica_sets' link = _REPLICA_SET_LINKS[rel].copy() link['href'] = link['href'].format(**locals()) link['rel'] = 'self' if self_rel else rel ...
python
def replica_set_link(rel, repl_id=None, member_id=None, self_rel=False): """Helper for getting a ReplicaSet link document, given a rel.""" repls_href = '/v1/replica_sets' link = _REPLICA_SET_LINKS[rel].copy() link['href'] = link['href'].format(**locals()) link['rel'] = 'self' if self_rel else rel ...
[ "def", "replica_set_link", "(", "rel", ",", "repl_id", "=", "None", ",", "member_id", "=", "None", ",", "self_rel", "=", "False", ")", ":", "repls_href", "=", "'/v1/replica_sets'", "link", "=", "_REPLICA_SET_LINKS", "[", "rel", "]", ".", "copy", "(", ")", ...
Helper for getting a ReplicaSet link document, given a rel.
[ "Helper", "for", "getting", "a", "ReplicaSet", "link", "document", "given", "a", "rel", "." ]
train
https://github.com/10gen/mongo-orchestration/blob/81fd2224205922ea2178b08190b53a33aec47261/mongo_orchestration/apps/links.py#L147-L153
10gen/mongo-orchestration
mongo_orchestration/apps/links.py
all_replica_set_links
def all_replica_set_links(rs_id, rel_to=None): """Get a list of all links to be included with replica sets.""" return [ replica_set_link(rel, rs_id, self_rel=(rel == rel_to)) for rel in ( 'get-replica-set-info', 'delete-replica-set', 'replica-set-command', 'ge...
python
def all_replica_set_links(rs_id, rel_to=None): """Get a list of all links to be included with replica sets.""" return [ replica_set_link(rel, rs_id, self_rel=(rel == rel_to)) for rel in ( 'get-replica-set-info', 'delete-replica-set', 'replica-set-command', 'ge...
[ "def", "all_replica_set_links", "(", "rs_id", ",", "rel_to", "=", "None", ")", ":", "return", "[", "replica_set_link", "(", "rel", ",", "rs_id", ",", "self_rel", "=", "(", "rel", "==", "rel_to", ")", ")", "for", "rel", "in", "(", "'get-replica-set-info'", ...
Get a list of all links to be included with replica sets.
[ "Get", "a", "list", "of", "all", "links", "to", "be", "included", "with", "replica", "sets", "." ]
train
https://github.com/10gen/mongo-orchestration/blob/81fd2224205922ea2178b08190b53a33aec47261/mongo_orchestration/apps/links.py#L156-L168
10gen/mongo-orchestration
mongo_orchestration/apps/links.py
sharded_cluster_link
def sharded_cluster_link(rel, cluster_id=None, shard_id=None, router_id=None, self_rel=False): """Helper for getting a ShardedCluster link document, given a rel.""" clusters_href = '/v1/sharded_clusters' link = _SHARDED_CLUSTER_LINKS[rel].copy() link['href'] = link['href'].forma...
python
def sharded_cluster_link(rel, cluster_id=None, shard_id=None, router_id=None, self_rel=False): """Helper for getting a ShardedCluster link document, given a rel.""" clusters_href = '/v1/sharded_clusters' link = _SHARDED_CLUSTER_LINKS[rel].copy() link['href'] = link['href'].forma...
[ "def", "sharded_cluster_link", "(", "rel", ",", "cluster_id", "=", "None", ",", "shard_id", "=", "None", ",", "router_id", "=", "None", ",", "self_rel", "=", "False", ")", ":", "clusters_href", "=", "'/v1/sharded_clusters'", "link", "=", "_SHARDED_CLUSTER_LINKS"...
Helper for getting a ShardedCluster link document, given a rel.
[ "Helper", "for", "getting", "a", "ShardedCluster", "link", "document", "given", "a", "rel", "." ]
train
https://github.com/10gen/mongo-orchestration/blob/81fd2224205922ea2178b08190b53a33aec47261/mongo_orchestration/apps/links.py#L171-L178
10gen/mongo-orchestration
mongo_orchestration/apps/links.py
all_sharded_cluster_links
def all_sharded_cluster_links(cluster_id, shard_id=None, router_id=None, rel_to=None): """Get a list of all links to be included with ShardedClusters.""" return [ sharded_cluster_link(rel, cluster_id, shard_id, router_id, self_rel=(rel == rel_to...
python
def all_sharded_cluster_links(cluster_id, shard_id=None, router_id=None, rel_to=None): """Get a list of all links to be included with ShardedClusters.""" return [ sharded_cluster_link(rel, cluster_id, shard_id, router_id, self_rel=(rel == rel_to...
[ "def", "all_sharded_cluster_links", "(", "cluster_id", ",", "shard_id", "=", "None", ",", "router_id", "=", "None", ",", "rel_to", "=", "None", ")", ":", "return", "[", "sharded_cluster_link", "(", "rel", ",", "cluster_id", ",", "shard_id", ",", "router_id", ...
Get a list of all links to be included with ShardedClusters.
[ "Get", "a", "list", "of", "all", "links", "to", "be", "included", "with", "ShardedClusters", "." ]
train
https://github.com/10gen/mongo-orchestration/blob/81fd2224205922ea2178b08190b53a33aec47261/mongo_orchestration/apps/links.py#L181-L193
10gen/mongo-orchestration
mongo_orchestration/__init__.py
cleanup_storage
def cleanup_storage(*args): """Clean up processes after SIGTERM or SIGINT is received.""" ShardedClusters().cleanup() ReplicaSets().cleanup() Servers().cleanup() sys.exit(0)
python
def cleanup_storage(*args): """Clean up processes after SIGTERM or SIGINT is received.""" ShardedClusters().cleanup() ReplicaSets().cleanup() Servers().cleanup() sys.exit(0)
[ "def", "cleanup_storage", "(", "*", "args", ")", ":", "ShardedClusters", "(", ")", ".", "cleanup", "(", ")", "ReplicaSets", "(", ")", ".", "cleanup", "(", ")", "Servers", "(", ")", ".", "cleanup", "(", ")", "sys", ".", "exit", "(", "0", ")" ]
Clean up processes after SIGTERM or SIGINT is received.
[ "Clean", "up", "processes", "after", "SIGTERM", "or", "SIGINT", "is", "received", "." ]
train
https://github.com/10gen/mongo-orchestration/blob/81fd2224205922ea2178b08190b53a33aec47261/mongo_orchestration/__init__.py#L32-L37
10gen/mongo-orchestration
mongo_orchestration/server.py
read_env
def read_env(): """return command-line arguments""" parser = argparse.ArgumentParser(description='mongo-orchestration server') parser.add_argument('-f', '--config', action='store', default=None, type=str, dest='config') parser.add_argument('-e', '--env', a...
python
def read_env(): """return command-line arguments""" parser = argparse.ArgumentParser(description='mongo-orchestration server') parser.add_argument('-f', '--config', action='store', default=None, type=str, dest='config') parser.add_argument('-e', '--env', a...
[ "def", "read_env", "(", ")", ":", "parser", "=", "argparse", ".", "ArgumentParser", "(", "description", "=", "'mongo-orchestration server'", ")", "parser", ".", "add_argument", "(", "'-f'", ",", "'--config'", ",", "action", "=", "'store'", ",", "default", "=",...
return command-line arguments
[ "return", "command", "-", "line", "arguments" ]
train
https://github.com/10gen/mongo-orchestration/blob/81fd2224205922ea2178b08190b53a33aec47261/mongo_orchestration/server.py#L36-L92
10gen/mongo-orchestration
mongo_orchestration/server.py
setup
def setup(releases, default_release): """setup storages""" from mongo_orchestration import set_releases, cleanup_storage set_releases(releases, default_release) signal.signal(signal.SIGTERM, cleanup_storage) signal.signal(signal.SIGINT, cleanup_storage)
python
def setup(releases, default_release): """setup storages""" from mongo_orchestration import set_releases, cleanup_storage set_releases(releases, default_release) signal.signal(signal.SIGTERM, cleanup_storage) signal.signal(signal.SIGINT, cleanup_storage)
[ "def", "setup", "(", "releases", ",", "default_release", ")", ":", "from", "mongo_orchestration", "import", "set_releases", ",", "cleanup_storage", "set_releases", "(", "releases", ",", "default_release", ")", "signal", ".", "signal", "(", "signal", ".", "SIGTERM"...
setup storages
[ "setup", "storages" ]
train
https://github.com/10gen/mongo-orchestration/blob/81fd2224205922ea2178b08190b53a33aec47261/mongo_orchestration/server.py#L95-L100
10gen/mongo-orchestration
mongo_orchestration/server.py
get_app
def get_app(): """return bottle app that includes all sub-apps""" from bottle import default_app default_app.push() for module in ("mongo_orchestration.apps.servers", "mongo_orchestration.apps.replica_sets", "mongo_orchestration.apps.sharded_clusters"): __im...
python
def get_app(): """return bottle app that includes all sub-apps""" from bottle import default_app default_app.push() for module in ("mongo_orchestration.apps.servers", "mongo_orchestration.apps.replica_sets", "mongo_orchestration.apps.sharded_clusters"): __im...
[ "def", "get_app", "(", ")", ":", "from", "bottle", "import", "default_app", "default_app", ".", "push", "(", ")", "for", "module", "in", "(", "\"mongo_orchestration.apps.servers\"", ",", "\"mongo_orchestration.apps.replica_sets\"", ",", "\"mongo_orchestration.apps.sharded...
return bottle app that includes all sub-apps
[ "return", "bottle", "app", "that", "includes", "all", "sub", "-", "apps" ]
train
https://github.com/10gen/mongo-orchestration/blob/81fd2224205922ea2178b08190b53a33aec47261/mongo_orchestration/server.py#L103-L112
10gen/mongo-orchestration
mongo_orchestration/server.py
await_connection
def await_connection(host, port): """Wait for the mongo-orchestration server to accept connections.""" for i in range(CONNECT_ATTEMPTS): try: conn = socket.create_connection((host, port), CONNECT_TIMEOUT) conn.close() return True except (IOError, socket.error)...
python
def await_connection(host, port): """Wait for the mongo-orchestration server to accept connections.""" for i in range(CONNECT_ATTEMPTS): try: conn = socket.create_connection((host, port), CONNECT_TIMEOUT) conn.close() return True except (IOError, socket.error)...
[ "def", "await_connection", "(", "host", ",", "port", ")", ":", "for", "i", "in", "range", "(", "CONNECT_ATTEMPTS", ")", ":", "try", ":", "conn", "=", "socket", ".", "create_connection", "(", "(", "host", ",", "port", ")", ",", "CONNECT_TIMEOUT", ")", "...
Wait for the mongo-orchestration server to accept connections.
[ "Wait", "for", "the", "mongo", "-", "orchestration", "server", "to", "accept", "connections", "." ]
train
https://github.com/10gen/mongo-orchestration/blob/81fd2224205922ea2178b08190b53a33aec47261/mongo_orchestration/server.py#L144-L153
10gen/mongo-orchestration
mongo_orchestration/servers.py
Server.__init_config_params
def __init_config_params(self, config): """Conditionally enable options in the Server's config file.""" if self.version >= (2, 4): params = config.get('setParameter', {}) # Set enableTestCommands by default but allow enableTestCommands:0. params.setdefault('enableTest...
python
def __init_config_params(self, config): """Conditionally enable options in the Server's config file.""" if self.version >= (2, 4): params = config.get('setParameter', {}) # Set enableTestCommands by default but allow enableTestCommands:0. params.setdefault('enableTest...
[ "def", "__init_config_params", "(", "self", ",", "config", ")", ":", "if", "self", ".", "version", ">=", "(", "2", ",", "4", ")", ":", "params", "=", "config", ".", "get", "(", "'setParameter'", ",", "{", "}", ")", "# Set enableTestCommands by default but ...
Conditionally enable options in the Server's config file.
[ "Conditionally", "enable", "options", "in", "the", "Server", "s", "config", "file", "." ]
train
https://github.com/10gen/mongo-orchestration/blob/81fd2224205922ea2178b08190b53a33aec47261/mongo_orchestration/servers.py#L73-L97
10gen/mongo-orchestration
mongo_orchestration/servers.py
Server.connection
def connection(self): """return authenticated connection""" c = pymongo.MongoClient( self.hostname, fsync=True, socketTimeoutMS=self.socket_timeout, **self.kwargs) connected(c) if not self.is_mongos and self.login and not self.restart_required: db = c[...
python
def connection(self): """return authenticated connection""" c = pymongo.MongoClient( self.hostname, fsync=True, socketTimeoutMS=self.socket_timeout, **self.kwargs) connected(c) if not self.is_mongos and self.login and not self.restart_required: db = c[...
[ "def", "connection", "(", "self", ")", ":", "c", "=", "pymongo", ".", "MongoClient", "(", "self", ".", "hostname", ",", "fsync", "=", "True", ",", "socketTimeoutMS", "=", "self", ".", "socket_timeout", ",", "*", "*", "self", ".", "kwargs", ")", "connec...
return authenticated connection
[ "return", "authenticated", "connection" ]
train
https://github.com/10gen/mongo-orchestration/blob/81fd2224205922ea2178b08190b53a33aec47261/mongo_orchestration/servers.py#L201-L220
10gen/mongo-orchestration
mongo_orchestration/servers.py
Server.version
def version(self): """Get the version of MongoDB that this Server runs as a tuple.""" if not self.__version: command = (self.name, '--version') logger.debug(command) stdout, _ = subprocess.Popen( command, stdout=subprocess.PIPE).communicate() ...
python
def version(self): """Get the version of MongoDB that this Server runs as a tuple.""" if not self.__version: command = (self.name, '--version') logger.debug(command) stdout, _ = subprocess.Popen( command, stdout=subprocess.PIPE).communicate() ...
[ "def", "version", "(", "self", ")", ":", "if", "not", "self", ".", "__version", ":", "command", "=", "(", "self", ".", "name", ",", "'--version'", ")", "logger", ".", "debug", "(", "command", ")", "stdout", ",", "_", "=", "subprocess", ".", "Popen", ...
Get the version of MongoDB that this Server runs as a tuple.
[ "Get", "the", "version", "of", "MongoDB", "that", "this", "Server", "runs", "as", "a", "tuple", "." ]
train
https://github.com/10gen/mongo-orchestration/blob/81fd2224205922ea2178b08190b53a33aec47261/mongo_orchestration/servers.py#L223-L238
10gen/mongo-orchestration
mongo_orchestration/servers.py
Server.run_command
def run_command(self, command, arg=None, is_eval=False): """run command on the server Args: command - command string arg - command argument is_eval - if True execute command as eval return command's result """ mode = is_eval and 'eval' or 'co...
python
def run_command(self, command, arg=None, is_eval=False): """run command on the server Args: command - command string arg - command argument is_eval - if True execute command as eval return command's result """ mode = is_eval and 'eval' or 'co...
[ "def", "run_command", "(", "self", ",", "command", ",", "arg", "=", "None", ",", "is_eval", "=", "False", ")", ":", "mode", "=", "is_eval", "and", "'eval'", "or", "'command'", "if", "isinstance", "(", "arg", ",", "tuple", ")", ":", "name", ",", "d", ...
run command on the server Args: command - command string arg - command argument is_eval - if True execute command as eval return command's result
[ "run", "command", "on", "the", "server" ]
train
https://github.com/10gen/mongo-orchestration/blob/81fd2224205922ea2178b08190b53a33aec47261/mongo_orchestration/servers.py#L259-L277
10gen/mongo-orchestration
mongo_orchestration/servers.py
Server.info
def info(self): """return info about server as dict object""" proc_info = {"name": self.name, "params": self.cfg, "alive": self.is_alive, "optfile": self.config_path} if self.is_alive: proc_info['pid'] = self.proc.pid ...
python
def info(self): """return info about server as dict object""" proc_info = {"name": self.name, "params": self.cfg, "alive": self.is_alive, "optfile": self.config_path} if self.is_alive: proc_info['pid'] = self.proc.pid ...
[ "def", "info", "(", "self", ")", ":", "proc_info", "=", "{", "\"name\"", ":", "self", ".", "name", ",", "\"params\"", ":", "self", ".", "cfg", ",", "\"alive\"", ":", "self", ".", "is_alive", ",", "\"optfile\"", ":", "self", ".", "config_path", "}", "...
return info about server as dict object
[ "return", "info", "about", "server", "as", "dict", "object" ]
train
https://github.com/10gen/mongo-orchestration/blob/81fd2224205922ea2178b08190b53a33aec47261/mongo_orchestration/servers.py#L283-L313
10gen/mongo-orchestration
mongo_orchestration/servers.py
Server.start
def start(self, timeout=300): """start server return True of False""" if self.is_alive: return True try: dbpath = self.cfg.get('dbpath') if dbpath and self._is_locked: # repair if needed logger.info("Performing repair on...
python
def start(self, timeout=300): """start server return True of False""" if self.is_alive: return True try: dbpath = self.cfg.get('dbpath') if dbpath and self._is_locked: # repair if needed logger.info("Performing repair on...
[ "def", "start", "(", "self", ",", "timeout", "=", "300", ")", ":", "if", "self", ".", "is_alive", ":", "return", "True", "try", ":", "dbpath", "=", "self", ".", "cfg", ".", "get", "(", "'dbpath'", ")", "if", "dbpath", "and", "self", ".", "_is_locke...
start server return True of False
[ "start", "server", "return", "True", "of", "False" ]
train
https://github.com/10gen/mongo-orchestration/blob/81fd2224205922ea2178b08190b53a33aec47261/mongo_orchestration/servers.py#L330-L397
10gen/mongo-orchestration
mongo_orchestration/servers.py
Server.shutdown
def shutdown(self): """Send shutdown command and wait for the process to exit.""" # Return early if this server has already exited. if not process.proc_alive(self.proc): return logger.info("Attempting to connect to %s", self.hostname) client = self.connection ...
python
def shutdown(self): """Send shutdown command and wait for the process to exit.""" # Return early if this server has already exited. if not process.proc_alive(self.proc): return logger.info("Attempting to connect to %s", self.hostname) client = self.connection ...
[ "def", "shutdown", "(", "self", ")", ":", "# Return early if this server has already exited.", "if", "not", "process", ".", "proc_alive", "(", "self", ".", "proc", ")", ":", "return", "logger", ".", "info", "(", "\"Attempting to connect to %s\"", ",", "self", ".",...
Send shutdown command and wait for the process to exit.
[ "Send", "shutdown", "command", "and", "wait", "for", "the", "process", "to", "exit", "." ]
train
https://github.com/10gen/mongo-orchestration/blob/81fd2224205922ea2178b08190b53a33aec47261/mongo_orchestration/servers.py#L399-L426
10gen/mongo-orchestration
mongo_orchestration/servers.py
Server.stop
def stop(self): """stop server""" try: self.shutdown() except (PyMongoError, ServersError) as exc: logger.info("Killing %s with signal, shutdown command failed: %r", self.name, exc) return process.kill_mprocess(self.proc)
python
def stop(self): """stop server""" try: self.shutdown() except (PyMongoError, ServersError) as exc: logger.info("Killing %s with signal, shutdown command failed: %r", self.name, exc) return process.kill_mprocess(self.proc)
[ "def", "stop", "(", "self", ")", ":", "try", ":", "self", ".", "shutdown", "(", ")", "except", "(", "PyMongoError", ",", "ServersError", ")", "as", "exc", ":", "logger", ".", "info", "(", "\"Killing %s with signal, shutdown command failed: %r\"", ",", "self", ...
stop server
[ "stop", "server" ]
train
https://github.com/10gen/mongo-orchestration/blob/81fd2224205922ea2178b08190b53a33aec47261/mongo_orchestration/servers.py#L428-L435
10gen/mongo-orchestration
mongo_orchestration/servers.py
Server.restart
def restart(self, timeout=300, config_callback=None): """restart server: stop() and start() return status of start command """ self.stop() if config_callback: self.cfg = config_callback(self.cfg.copy()) self.config_path = process.write_config(self.cfg) ...
python
def restart(self, timeout=300, config_callback=None): """restart server: stop() and start() return status of start command """ self.stop() if config_callback: self.cfg = config_callback(self.cfg.copy()) self.config_path = process.write_config(self.cfg) ...
[ "def", "restart", "(", "self", ",", "timeout", "=", "300", ",", "config_callback", "=", "None", ")", ":", "self", ".", "stop", "(", ")", "if", "config_callback", ":", "self", ".", "cfg", "=", "config_callback", "(", "self", ".", "cfg", ".", "copy", "...
restart server: stop() and start() return status of start command
[ "restart", "server", ":", "stop", "()", "and", "start", "()", "return", "status", "of", "start", "command" ]
train
https://github.com/10gen/mongo-orchestration/blob/81fd2224205922ea2178b08190b53a33aec47261/mongo_orchestration/servers.py#L437-L445
10gen/mongo-orchestration
mongo_orchestration/servers.py
Servers.create
def create(self, name, procParams, sslParams={}, auth_key=None, login=None, password=None, auth_source='admin', timeout=300, autostart=True, server_id=None, version=None): """create new server Args: name - process name or path procParams...
python
def create(self, name, procParams, sslParams={}, auth_key=None, login=None, password=None, auth_source='admin', timeout=300, autostart=True, server_id=None, version=None): """create new server Args: name - process name or path procParams...
[ "def", "create", "(", "self", ",", "name", ",", "procParams", ",", "sslParams", "=", "{", "}", ",", "auth_key", "=", "None", ",", "login", "=", "None", ",", "password", "=", "None", ",", "auth_source", "=", "'admin'", ",", "timeout", "=", "300", ",",...
create new server Args: name - process name or path procParams - dictionary with specific params for instance auth_key - authorization key login - username for the admin collection password - password timeout - specify how long, in seconds, a c...
[ "create", "new", "server", "Args", ":", "name", "-", "process", "name", "or", "path", "procParams", "-", "dictionary", "with", "specific", "params", "for", "instance", "auth_key", "-", "authorization", "key", "login", "-", "username", "for", "the", "admin", ...
train
https://github.com/10gen/mongo-orchestration/blob/81fd2224205922ea2178b08190b53a33aec47261/mongo_orchestration/servers.py#L492-L520
10gen/mongo-orchestration
mongo_orchestration/servers.py
Servers.remove
def remove(self, server_id): """remove server and data stuff Args: server_id - server identity """ server = self._storage.pop(server_id) server.stop() server.cleanup()
python
def remove(self, server_id): """remove server and data stuff Args: server_id - server identity """ server = self._storage.pop(server_id) server.stop() server.cleanup()
[ "def", "remove", "(", "self", ",", "server_id", ")", ":", "server", "=", "self", ".", "_storage", ".", "pop", "(", "server_id", ")", "server", ".", "stop", "(", ")", "server", ".", "cleanup", "(", ")" ]
remove server and data stuff Args: server_id - server identity
[ "remove", "server", "and", "data", "stuff", "Args", ":", "server_id", "-", "server", "identity" ]
train
https://github.com/10gen/mongo-orchestration/blob/81fd2224205922ea2178b08190b53a33aec47261/mongo_orchestration/servers.py#L525-L532
10gen/mongo-orchestration
mongo_orchestration/servers.py
Servers.command
def command(self, server_id, command, *args): """run command Args: server_id - server identity command - command which apply to server """ server = self._storage[server_id] try: if args: result = getattr(server, command)(*args) ...
python
def command(self, server_id, command, *args): """run command Args: server_id - server identity command - command which apply to server """ server = self._storage[server_id] try: if args: result = getattr(server, command)(*args) ...
[ "def", "command", "(", "self", ",", "server_id", ",", "command", ",", "*", "args", ")", ":", "server", "=", "self", ".", "_storage", "[", "server_id", "]", "try", ":", "if", "args", ":", "result", "=", "getattr", "(", "server", ",", "command", ")", ...
run command Args: server_id - server identity command - command which apply to server
[ "run", "command", "Args", ":", "server_id", "-", "server", "identity", "command", "-", "command", "which", "apply", "to", "server" ]
train
https://github.com/10gen/mongo-orchestration/blob/81fd2224205922ea2178b08190b53a33aec47261/mongo_orchestration/servers.py#L540-L556
10gen/mongo-orchestration
mongo_orchestration/servers.py
Servers.info
def info(self, server_id): """return dicionary object with info about server Args: server_id - server identity """ result = self._storage[server_id].info() result['id'] = server_id return result
python
def info(self, server_id): """return dicionary object with info about server Args: server_id - server identity """ result = self._storage[server_id].info() result['id'] = server_id return result
[ "def", "info", "(", "self", ",", "server_id", ")", ":", "result", "=", "self", ".", "_storage", "[", "server_id", "]", ".", "info", "(", ")", "result", "[", "'id'", "]", "=", "server_id", "return", "result" ]
return dicionary object with info about server Args: server_id - server identity
[ "return", "dicionary", "object", "with", "info", "about", "server", "Args", ":", "server_id", "-", "server", "identity" ]
train
https://github.com/10gen/mongo-orchestration/blob/81fd2224205922ea2178b08190b53a33aec47261/mongo_orchestration/servers.py#L558-L565
10gen/mongo-orchestration
mongo_orchestration/container.py
Container.set_settings
def set_settings(self, releases=None, default_release=None): """set path to storage""" if (self._storage is None or getattr(self, 'releases', {}) != releases or getattr(self, 'default_release', '') != default_release): self._storage = {} self.relea...
python
def set_settings(self, releases=None, default_release=None): """set path to storage""" if (self._storage is None or getattr(self, 'releases', {}) != releases or getattr(self, 'default_release', '') != default_release): self._storage = {} self.relea...
[ "def", "set_settings", "(", "self", ",", "releases", "=", "None", ",", "default_release", "=", "None", ")", ":", "if", "(", "self", ".", "_storage", "is", "None", "or", "getattr", "(", "self", ",", "'releases'", ",", "{", "}", ")", "!=", "releases", ...
set path to storage
[ "set", "path", "to", "storage" ]
train
https://github.com/10gen/mongo-orchestration/blob/81fd2224205922ea2178b08190b53a33aec47261/mongo_orchestration/container.py#L30-L37
10gen/mongo-orchestration
mongo_orchestration/container.py
Container.bin_path
def bin_path(self, release=None): """Get the bin path for a particular release.""" if release: for r in self.releases: if release in r: return self.releases[r] raise MongoOrchestrationError("No such release '%s' in %r" ...
python
def bin_path(self, release=None): """Get the bin path for a particular release.""" if release: for r in self.releases: if release in r: return self.releases[r] raise MongoOrchestrationError("No such release '%s' in %r" ...
[ "def", "bin_path", "(", "self", ",", "release", "=", "None", ")", ":", "if", "release", ":", "for", "r", "in", "self", ".", "releases", ":", "if", "release", "in", "r", ":", "return", "self", ".", "releases", "[", "r", "]", "raise", "MongoOrchestrati...
Get the bin path for a particular release.
[ "Get", "the", "bin", "path", "for", "a", "particular", "release", "." ]
train
https://github.com/10gen/mongo-orchestration/blob/81fd2224205922ea2178b08190b53a33aec47261/mongo_orchestration/container.py#L39-L51
10gen/mongo-orchestration
mongo_orchestration/sharded_clusters.py
ShardedCluster.__init_configrs
def __init_configrs(self, rs_cfg): """Create and start a config replica set.""" # Use 'rs_id' to set the id for consistency, but need to rename # to 'id' to use with ReplicaSets.create() rs_cfg['id'] = rs_cfg.pop('rs_id', None) for member in rs_cfg.setdefault('members', [{}]): ...
python
def __init_configrs(self, rs_cfg): """Create and start a config replica set.""" # Use 'rs_id' to set the id for consistency, but need to rename # to 'id' to use with ReplicaSets.create() rs_cfg['id'] = rs_cfg.pop('rs_id', None) for member in rs_cfg.setdefault('members', [{}]): ...
[ "def", "__init_configrs", "(", "self", ",", "rs_cfg", ")", ":", "# Use 'rs_id' to set the id for consistency, but need to rename", "# to 'id' to use with ReplicaSets.create()", "rs_cfg", "[", "'id'", "]", "=", "rs_cfg", ".", "pop", "(", "'rs_id'", ",", "None", ")", "for...
Create and start a config replica set.
[ "Create", "and", "start", "a", "config", "replica", "set", "." ]
train
https://github.com/10gen/mongo-orchestration/blob/81fd2224205922ea2178b08190b53a33aec47261/mongo_orchestration/sharded_clusters.py#L214-L226
10gen/mongo-orchestration
mongo_orchestration/sharded_clusters.py
ShardedCluster.__init_configsvrs
def __init_configsvrs(self, params): """create and start config servers""" self._configsvrs = [] for cfg in params: # Remove flags that turn on auth. cfg = self._strip_auth(cfg) server_id = cfg.pop('server_id', None) version = cfg.pop('version', se...
python
def __init_configsvrs(self, params): """create and start config servers""" self._configsvrs = [] for cfg in params: # Remove flags that turn on auth. cfg = self._strip_auth(cfg) server_id = cfg.pop('server_id', None) version = cfg.pop('version', se...
[ "def", "__init_configsvrs", "(", "self", ",", "params", ")", ":", "self", ".", "_configsvrs", "=", "[", "]", "for", "cfg", "in", "params", ":", "# Remove flags that turn on auth.", "cfg", "=", "self", ".", "_strip_auth", "(", "cfg", ")", "server_id", "=", ...
create and start config servers
[ "create", "and", "start", "config", "servers" ]
train
https://github.com/10gen/mongo-orchestration/blob/81fd2224205922ea2178b08190b53a33aec47261/mongo_orchestration/sharded_clusters.py#L228-L241
10gen/mongo-orchestration
mongo_orchestration/sharded_clusters.py
ShardedCluster.configsvrs
def configsvrs(self): """return list of config servers""" if self.uses_rs_configdb: rs_id = self._configsvrs[0] mongodb_uri = ReplicaSets().info(rs_id)['mongodb_uri'] return [{'id': rs_id, 'mongodb_uri': mongodb_uri}] return [{'id': h_id, 'hostname': Servers()...
python
def configsvrs(self): """return list of config servers""" if self.uses_rs_configdb: rs_id = self._configsvrs[0] mongodb_uri = ReplicaSets().info(rs_id)['mongodb_uri'] return [{'id': rs_id, 'mongodb_uri': mongodb_uri}] return [{'id': h_id, 'hostname': Servers()...
[ "def", "configsvrs", "(", "self", ")", ":", "if", "self", ".", "uses_rs_configdb", ":", "rs_id", "=", "self", ".", "_configsvrs", "[", "0", "]", "mongodb_uri", "=", "ReplicaSets", "(", ")", ".", "info", "(", "rs_id", ")", "[", "'mongodb_uri'", "]", "re...
return list of config servers
[ "return", "list", "of", "config", "servers" ]
train
https://github.com/10gen/mongo-orchestration/blob/81fd2224205922ea2178b08190b53a33aec47261/mongo_orchestration/sharded_clusters.py#L247-L254
10gen/mongo-orchestration
mongo_orchestration/sharded_clusters.py
ShardedCluster.router
def router(self): """return first available router""" for server in self._routers: info = Servers().info(server) if info['procInfo'].get('alive', False): return {'id': server, 'hostname': Servers().hostname(server)}
python
def router(self): """return first available router""" for server in self._routers: info = Servers().info(server) if info['procInfo'].get('alive', False): return {'id': server, 'hostname': Servers().hostname(server)}
[ "def", "router", "(", "self", ")", ":", "for", "server", "in", "self", ".", "_routers", ":", "info", "=", "Servers", "(", ")", ".", "info", "(", "server", ")", "if", "info", "[", "'procInfo'", "]", ".", "get", "(", "'alive'", ",", "False", ")", "...
return first available router
[ "return", "first", "available", "router" ]
train
https://github.com/10gen/mongo-orchestration/blob/81fd2224205922ea2178b08190b53a33aec47261/mongo_orchestration/sharded_clusters.py#L268-L273
10gen/mongo-orchestration
mongo_orchestration/sharded_clusters.py
ShardedCluster.router_add
def router_add(self, params): """add new router (mongos) into existing configuration""" if self.uses_rs_configdb: # Replica set configdb. rs_id = self._configsvrs[0] config_members = ReplicaSets().members(rs_id) configdb = '%s/%s' % ( rs_id...
python
def router_add(self, params): """add new router (mongos) into existing configuration""" if self.uses_rs_configdb: # Replica set configdb. rs_id = self._configsvrs[0] config_members = ReplicaSets().members(rs_id) configdb = '%s/%s' % ( rs_id...
[ "def", "router_add", "(", "self", ",", "params", ")", ":", "if", "self", ".", "uses_rs_configdb", ":", "# Replica set configdb.", "rs_id", "=", "self", ".", "_configsvrs", "[", "0", "]", "config_members", "=", "ReplicaSets", "(", ")", ".", "members", "(", ...
add new router (mongos) into existing configuration
[ "add", "new", "router", "(", "mongos", ")", "into", "existing", "configuration" ]
train
https://github.com/10gen/mongo-orchestration/blob/81fd2224205922ea2178b08190b53a33aec47261/mongo_orchestration/sharded_clusters.py#L275-L298
10gen/mongo-orchestration
mongo_orchestration/sharded_clusters.py
ShardedCluster.router_connections
def router_connections(self): """Return a list of MongoClients, one for each mongos.""" clients = [] for server in self._routers: if Servers().is_alive(server): client = self.create_connection(Servers().hostname(server)) clients.append(client) ...
python
def router_connections(self): """Return a list of MongoClients, one for each mongos.""" clients = [] for server in self._routers: if Servers().is_alive(server): client = self.create_connection(Servers().hostname(server)) clients.append(client) ...
[ "def", "router_connections", "(", "self", ")", ":", "clients", "=", "[", "]", "for", "server", "in", "self", ".", "_routers", ":", "if", "Servers", "(", ")", ".", "is_alive", "(", "server", ")", ":", "client", "=", "self", ".", "create_connection", "("...
Return a list of MongoClients, one for each mongos.
[ "Return", "a", "list", "of", "MongoClients", "one", "for", "each", "mongos", "." ]
train
https://github.com/10gen/mongo-orchestration/blob/81fd2224205922ea2178b08190b53a33aec47261/mongo_orchestration/sharded_clusters.py#L321-L328
10gen/mongo-orchestration
mongo_orchestration/sharded_clusters.py
ShardedCluster.router_remove
def router_remove(self, router_id): """remove """ result = Servers().remove(router_id) del self._routers[ self._routers.index(router_id) ] return { "ok": 1, "routers": self._routers }
python
def router_remove(self, router_id): """remove """ result = Servers().remove(router_id) del self._routers[ self._routers.index(router_id) ] return { "ok": 1, "routers": self._routers }
[ "def", "router_remove", "(", "self", ",", "router_id", ")", ":", "result", "=", "Servers", "(", ")", ".", "remove", "(", "router_id", ")", "del", "self", ".", "_routers", "[", "self", ".", "_routers", ".", "index", "(", "router_id", ")", "]", "return",...
remove
[ "remove" ]
train
https://github.com/10gen/mongo-orchestration/blob/81fd2224205922ea2178b08190b53a33aec47261/mongo_orchestration/sharded_clusters.py#L350-L354
10gen/mongo-orchestration
mongo_orchestration/sharded_clusters.py
ShardedCluster._add
def _add(self, shard_uri, name): """execute addShard command""" return self.router_command("addShard", (shard_uri, {"name": name}), is_eval=False)
python
def _add(self, shard_uri, name): """execute addShard command""" return self.router_command("addShard", (shard_uri, {"name": name}), is_eval=False)
[ "def", "_add", "(", "self", ",", "shard_uri", ",", "name", ")", ":", "return", "self", ".", "router_command", "(", "\"addShard\"", ",", "(", "shard_uri", ",", "{", "\"name\"", ":", "name", "}", ")", ",", "is_eval", "=", "False", ")" ]
execute addShard command
[ "execute", "addShard", "command" ]
train
https://github.com/10gen/mongo-orchestration/blob/81fd2224205922ea2178b08190b53a33aec47261/mongo_orchestration/sharded_clusters.py#L356-L358
10gen/mongo-orchestration
mongo_orchestration/sharded_clusters.py
ShardedCluster.member_add
def member_add(self, member_id=None, params=None): """add new member into existing configuration""" member_id = member_id or str(uuid4()) if self.enable_ipv6: common.enable_ipv6_repl(params) if 'members' in params: # is replica set for member in params...
python
def member_add(self, member_id=None, params=None): """add new member into existing configuration""" member_id = member_id or str(uuid4()) if self.enable_ipv6: common.enable_ipv6_repl(params) if 'members' in params: # is replica set for member in params...
[ "def", "member_add", "(", "self", ",", "member_id", "=", "None", ",", "params", "=", "None", ")", ":", "member_id", "=", "member_id", "or", "str", "(", "uuid4", "(", ")", ")", "if", "self", ".", "enable_ipv6", ":", "common", ".", "enable_ipv6_repl", "(...
add new member into existing configuration
[ "add", "new", "member", "into", "existing", "configuration" ]
train
https://github.com/10gen/mongo-orchestration/blob/81fd2224205922ea2178b08190b53a33aec47261/mongo_orchestration/sharded_clusters.py#L360-L400
10gen/mongo-orchestration
mongo_orchestration/sharded_clusters.py
ShardedCluster.member_info
def member_info(self, member_id): """return info about member""" info = self._shards[member_id].copy() info['id'] = member_id info['tags'] = self.tags.get(member_id, list()) return info
python
def member_info(self, member_id): """return info about member""" info = self._shards[member_id].copy() info['id'] = member_id info['tags'] = self.tags.get(member_id, list()) return info
[ "def", "member_info", "(", "self", ",", "member_id", ")", ":", "info", "=", "self", ".", "_shards", "[", "member_id", "]", ".", "copy", "(", ")", "info", "[", "'id'", "]", "=", "member_id", "info", "[", "'tags'", "]", "=", "self", ".", "tags", ".",...
return info about member
[ "return", "info", "about", "member" ]
train
https://github.com/10gen/mongo-orchestration/blob/81fd2224205922ea2178b08190b53a33aec47261/mongo_orchestration/sharded_clusters.py#L402-L407
10gen/mongo-orchestration
mongo_orchestration/sharded_clusters.py
ShardedCluster._remove
def _remove(self, shard_name): """remove member from configuration""" result = self.router_command("removeShard", shard_name, is_eval=False) if result['ok'] == 1 and result['state'] == 'completed': shard = self._shards.pop(shard_name) if shard.get('isServer', False): ...
python
def _remove(self, shard_name): """remove member from configuration""" result = self.router_command("removeShard", shard_name, is_eval=False) if result['ok'] == 1 and result['state'] == 'completed': shard = self._shards.pop(shard_name) if shard.get('isServer', False): ...
[ "def", "_remove", "(", "self", ",", "shard_name", ")", ":", "result", "=", "self", ".", "router_command", "(", "\"removeShard\"", ",", "shard_name", ",", "is_eval", "=", "False", ")", "if", "result", "[", "'ok'", "]", "==", "1", "and", "result", "[", "...
remove member from configuration
[ "remove", "member", "from", "configuration" ]
train
https://github.com/10gen/mongo-orchestration/blob/81fd2224205922ea2178b08190b53a33aec47261/mongo_orchestration/sharded_clusters.py#L409-L418
10gen/mongo-orchestration
mongo_orchestration/sharded_clusters.py
ShardedCluster.reset
def reset(self): """Ensure all shards, configs, and routers are running and available.""" # Ensure all shards by calling "reset" on each. for shard_id in self._shards: if self._shards[shard_id].get('isReplicaSet'): singleton = ReplicaSets() elif self._shar...
python
def reset(self): """Ensure all shards, configs, and routers are running and available.""" # Ensure all shards by calling "reset" on each. for shard_id in self._shards: if self._shards[shard_id].get('isReplicaSet'): singleton = ReplicaSets() elif self._shar...
[ "def", "reset", "(", "self", ")", ":", "# Ensure all shards by calling \"reset\" on each.", "for", "shard_id", "in", "self", ".", "_shards", ":", "if", "self", ".", "_shards", "[", "shard_id", "]", ".", "get", "(", "'isReplicaSet'", ")", ":", "singleton", "=",...
Ensure all shards, configs, and routers are running and available.
[ "Ensure", "all", "shards", "configs", "and", "routers", "are", "running", "and", "available", "." ]
train
https://github.com/10gen/mongo-orchestration/blob/81fd2224205922ea2178b08190b53a33aec47261/mongo_orchestration/sharded_clusters.py#L424-L439
10gen/mongo-orchestration
mongo_orchestration/sharded_clusters.py
ShardedCluster.info
def info(self): """return info about configuration""" uri = ','.join(x['hostname'] for x in self.routers) mongodb_uri = 'mongodb://' + uri result = {'id': self.id, 'shards': self.members, 'configsvrs': self.configsvrs, 'routers': self...
python
def info(self): """return info about configuration""" uri = ','.join(x['hostname'] for x in self.routers) mongodb_uri = 'mongodb://' + uri result = {'id': self.id, 'shards': self.members, 'configsvrs': self.configsvrs, 'routers': self...
[ "def", "info", "(", "self", ")", ":", "uri", "=", "','", ".", "join", "(", "x", "[", "'hostname'", "]", "for", "x", "in", "self", ".", "routers", ")", "mongodb_uri", "=", "'mongodb://'", "+", "uri", "result", "=", "{", "'id'", ":", "self", ".", "...
return info about configuration
[ "return", "info", "about", "configuration" ]
train
https://github.com/10gen/mongo-orchestration/blob/81fd2224205922ea2178b08190b53a33aec47261/mongo_orchestration/sharded_clusters.py#L441-L453
10gen/mongo-orchestration
mongo_orchestration/sharded_clusters.py
ShardedCluster.cleanup
def cleanup(self): """cleanup configuration: stop and remove all servers""" for _id, shard in self._shards.items(): if shard.get('isServer', False): Servers().remove(shard['_id']) if shard.get('isReplicaSet', False): ReplicaSets().remove(shard['_id...
python
def cleanup(self): """cleanup configuration: stop and remove all servers""" for _id, shard in self._shards.items(): if shard.get('isServer', False): Servers().remove(shard['_id']) if shard.get('isReplicaSet', False): ReplicaSets().remove(shard['_id...
[ "def", "cleanup", "(", "self", ")", ":", "for", "_id", ",", "shard", "in", "self", ".", "_shards", ".", "items", "(", ")", ":", "if", "shard", ".", "get", "(", "'isServer'", ",", "False", ")", ":", "Servers", "(", ")", ".", "remove", "(", "shard"...
cleanup configuration: stop and remove all servers
[ "cleanup", "configuration", ":", "stop", "and", "remove", "all", "servers" ]
train
https://github.com/10gen/mongo-orchestration/blob/81fd2224205922ea2178b08190b53a33aec47261/mongo_orchestration/sharded_clusters.py#L455-L471
10gen/mongo-orchestration
mongo_orchestration/sharded_clusters.py
ShardedClusters.set_settings
def set_settings(self, releases=None, default_release=None): """set path to storage""" super(ShardedClusters, self).set_settings(releases, default_release) ReplicaSets().set_settings(releases, default_release)
python
def set_settings(self, releases=None, default_release=None): """set path to storage""" super(ShardedClusters, self).set_settings(releases, default_release) ReplicaSets().set_settings(releases, default_release)
[ "def", "set_settings", "(", "self", ",", "releases", "=", "None", ",", "default_release", "=", "None", ")", ":", "super", "(", "ShardedClusters", ",", "self", ")", ".", "set_settings", "(", "releases", ",", "default_release", ")", "ReplicaSets", "(", ")", ...
set path to storage
[ "set", "path", "to", "storage" ]
train
https://github.com/10gen/mongo-orchestration/blob/81fd2224205922ea2178b08190b53a33aec47261/mongo_orchestration/sharded_clusters.py#L481-L484
10gen/mongo-orchestration
mongo_orchestration/sharded_clusters.py
ShardedClusters.create
def create(self, params): """create new ShardedCluster Args: params - dictionary with specific params for instance Return cluster_id where cluster_id - id which can use to take the cluster from servers collection """ sh_id = params.get('id', str(uuid4())) ...
python
def create(self, params): """create new ShardedCluster Args: params - dictionary with specific params for instance Return cluster_id where cluster_id - id which can use to take the cluster from servers collection """ sh_id = params.get('id', str(uuid4())) ...
[ "def", "create", "(", "self", ",", "params", ")", ":", "sh_id", "=", "params", ".", "get", "(", "'id'", ",", "str", "(", "uuid4", "(", ")", ")", ")", "if", "sh_id", "in", "self", ":", "raise", "ShardedClusterError", "(", "\"Sharded cluster with id %s alr...
create new ShardedCluster Args: params - dictionary with specific params for instance Return cluster_id where cluster_id - id which can use to take the cluster from servers collection
[ "create", "new", "ShardedCluster", "Args", ":", "params", "-", "dictionary", "with", "specific", "params", "for", "instance", "Return", "cluster_id", "where", "cluster_id", "-", "id", "which", "can", "use", "to", "take", "the", "cluster", "from", "servers", "c...
train
https://github.com/10gen/mongo-orchestration/blob/81fd2224205922ea2178b08190b53a33aec47261/mongo_orchestration/sharded_clusters.py#L494-L508
10gen/mongo-orchestration
mongo_orchestration/sharded_clusters.py
ShardedClusters.remove
def remove(self, cluster_id): """remove cluster and data stuff Args: cluster_id - cluster identity """ cluster = self._storage.pop(cluster_id) cluster.cleanup()
python
def remove(self, cluster_id): """remove cluster and data stuff Args: cluster_id - cluster identity """ cluster = self._storage.pop(cluster_id) cluster.cleanup()
[ "def", "remove", "(", "self", ",", "cluster_id", ")", ":", "cluster", "=", "self", ".", "_storage", ".", "pop", "(", "cluster_id", ")", "cluster", ".", "cleanup", "(", ")" ]
remove cluster and data stuff Args: cluster_id - cluster identity
[ "remove", "cluster", "and", "data", "stuff", "Args", ":", "cluster_id", "-", "cluster", "identity" ]
train
https://github.com/10gen/mongo-orchestration/blob/81fd2224205922ea2178b08190b53a33aec47261/mongo_orchestration/sharded_clusters.py#L510-L516
10gen/mongo-orchestration
mongo_orchestration/sharded_clusters.py
ShardedClusters.router_add
def router_add(self, cluster_id, params): """add new router""" cluster = self._storage[cluster_id] result = cluster.router_add(params) self._storage[cluster_id] = cluster return result
python
def router_add(self, cluster_id, params): """add new router""" cluster = self._storage[cluster_id] result = cluster.router_add(params) self._storage[cluster_id] = cluster return result
[ "def", "router_add", "(", "self", ",", "cluster_id", ",", "params", ")", ":", "cluster", "=", "self", ".", "_storage", "[", "cluster_id", "]", "result", "=", "cluster", ".", "router_add", "(", "params", ")", "self", ".", "_storage", "[", "cluster_id", "]...
add new router
[ "add", "new", "router" ]
train
https://github.com/10gen/mongo-orchestration/blob/81fd2224205922ea2178b08190b53a33aec47261/mongo_orchestration/sharded_clusters.py#L533-L538
10gen/mongo-orchestration
mongo_orchestration/sharded_clusters.py
ShardedClusters.router_del
def router_del(self, cluster_id, router_id): """remove router from the ShardedCluster""" cluster = self._storage[cluster_id] result = cluster.router_remove(router_id) self._storage[cluster_id] = cluster return result
python
def router_del(self, cluster_id, router_id): """remove router from the ShardedCluster""" cluster = self._storage[cluster_id] result = cluster.router_remove(router_id) self._storage[cluster_id] = cluster return result
[ "def", "router_del", "(", "self", ",", "cluster_id", ",", "router_id", ")", ":", "cluster", "=", "self", ".", "_storage", "[", "cluster_id", "]", "result", "=", "cluster", ".", "router_remove", "(", "router_id", ")", "self", ".", "_storage", "[", "cluster_...
remove router from the ShardedCluster
[ "remove", "router", "from", "the", "ShardedCluster" ]
train
https://github.com/10gen/mongo-orchestration/blob/81fd2224205922ea2178b08190b53a33aec47261/mongo_orchestration/sharded_clusters.py#L540-L545
10gen/mongo-orchestration
mongo_orchestration/sharded_clusters.py
ShardedClusters.member_info
def member_info(self, cluster_id, member_id): """return info about member""" cluster = self._storage[cluster_id] return cluster.member_info(member_id)
python
def member_info(self, cluster_id, member_id): """return info about member""" cluster = self._storage[cluster_id] return cluster.member_info(member_id)
[ "def", "member_info", "(", "self", ",", "cluster_id", ",", "member_id", ")", ":", "cluster", "=", "self", ".", "_storage", "[", "cluster_id", "]", "return", "cluster", ".", "member_info", "(", "member_id", ")" ]
return info about member
[ "return", "info", "about", "member" ]
train
https://github.com/10gen/mongo-orchestration/blob/81fd2224205922ea2178b08190b53a33aec47261/mongo_orchestration/sharded_clusters.py#L551-L554
10gen/mongo-orchestration
mongo_orchestration/sharded_clusters.py
ShardedClusters.command
def command(self, cluster_id, command, *args): """Call a ShardedCluster method.""" cluster = self._storage[cluster_id] try: return getattr(cluster, command)(*args) except AttributeError: raise ValueError("Cannot issue the command %r to ShardedCluster %s" ...
python
def command(self, cluster_id, command, *args): """Call a ShardedCluster method.""" cluster = self._storage[cluster_id] try: return getattr(cluster, command)(*args) except AttributeError: raise ValueError("Cannot issue the command %r to ShardedCluster %s" ...
[ "def", "command", "(", "self", ",", "cluster_id", ",", "command", ",", "*", "args", ")", ":", "cluster", "=", "self", ".", "_storage", "[", "cluster_id", "]", "try", ":", "return", "getattr", "(", "cluster", ",", "command", ")", "(", "*", "args", ")"...
Call a ShardedCluster method.
[ "Call", "a", "ShardedCluster", "method", "." ]
train
https://github.com/10gen/mongo-orchestration/blob/81fd2224205922ea2178b08190b53a33aec47261/mongo_orchestration/sharded_clusters.py#L556-L563
10gen/mongo-orchestration
mongo_orchestration/sharded_clusters.py
ShardedClusters.member_del
def member_del(self, cluster_id, member_id): """remove member from cluster cluster""" cluster = self._storage[cluster_id] result = cluster.member_remove(member_id) self._storage[cluster_id] = cluster return result
python
def member_del(self, cluster_id, member_id): """remove member from cluster cluster""" cluster = self._storage[cluster_id] result = cluster.member_remove(member_id) self._storage[cluster_id] = cluster return result
[ "def", "member_del", "(", "self", ",", "cluster_id", ",", "member_id", ")", ":", "cluster", "=", "self", ".", "_storage", "[", "cluster_id", "]", "result", "=", "cluster", ".", "member_remove", "(", "member_id", ")", "self", ".", "_storage", "[", "cluster_...
remove member from cluster cluster
[ "remove", "member", "from", "cluster", "cluster" ]
train
https://github.com/10gen/mongo-orchestration/blob/81fd2224205922ea2178b08190b53a33aec47261/mongo_orchestration/sharded_clusters.py#L565-L570
10gen/mongo-orchestration
mongo_orchestration/sharded_clusters.py
ShardedClusters.member_add
def member_add(self, cluster_id, params): """add new member into configuration""" cluster = self._storage[cluster_id] result = cluster.member_add(params.get('id', None), params.get('shardParams', {})) self._storage[cluster_id] = cluster return result
python
def member_add(self, cluster_id, params): """add new member into configuration""" cluster = self._storage[cluster_id] result = cluster.member_add(params.get('id', None), params.get('shardParams', {})) self._storage[cluster_id] = cluster return result
[ "def", "member_add", "(", "self", ",", "cluster_id", ",", "params", ")", ":", "cluster", "=", "self", ".", "_storage", "[", "cluster_id", "]", "result", "=", "cluster", ".", "member_add", "(", "params", ".", "get", "(", "'id'", ",", "None", ")", ",", ...
add new member into configuration
[ "add", "new", "member", "into", "configuration" ]
train
https://github.com/10gen/mongo-orchestration/blob/81fd2224205922ea2178b08190b53a33aec47261/mongo_orchestration/sharded_clusters.py#L572-L577
vcs-python/vcspull
vcspull/config.py
expand_dir
def expand_dir(_dir, cwd=os.getcwd()): """Return path with environmental variables and tilde ~ expanded. :param _dir: :type _dir: str :param cwd: current working dir (for deciphering relative _dir paths) :type cwd: str :rtype; str """ _dir = os.path.expanduser(os.path.expandvars(_dir)) ...
python
def expand_dir(_dir, cwd=os.getcwd()): """Return path with environmental variables and tilde ~ expanded. :param _dir: :type _dir: str :param cwd: current working dir (for deciphering relative _dir paths) :type cwd: str :rtype; str """ _dir = os.path.expanduser(os.path.expandvars(_dir)) ...
[ "def", "expand_dir", "(", "_dir", ",", "cwd", "=", "os", ".", "getcwd", "(", ")", ")", ":", "_dir", "=", "os", ".", "path", ".", "expanduser", "(", "os", ".", "path", ".", "expandvars", "(", "_dir", ")", ")", "if", "not", "os", ".", "path", "."...
Return path with environmental variables and tilde ~ expanded. :param _dir: :type _dir: str :param cwd: current working dir (for deciphering relative _dir paths) :type cwd: str :rtype; str
[ "Return", "path", "with", "environmental", "variables", "and", "tilde", "~", "expanded", "." ]
train
https://github.com/vcs-python/vcspull/blob/c1827bf78d2cdebc61d82111c9aa35afd6ea6a25/vcspull/config.py#L26-L38
vcs-python/vcspull
vcspull/config.py
extract_repos
def extract_repos(config, cwd=os.getcwd()): """Return expanded configuration. end-user configuration permit inline configuration shortcuts, expand to identical format for parsing. :param config: the repo config in :py:class:`dict` format. :type config: dict :param cwd: current working dir (for...
python
def extract_repos(config, cwd=os.getcwd()): """Return expanded configuration. end-user configuration permit inline configuration shortcuts, expand to identical format for parsing. :param config: the repo config in :py:class:`dict` format. :type config: dict :param cwd: current working dir (for...
[ "def", "extract_repos", "(", "config", ",", "cwd", "=", "os", ".", "getcwd", "(", ")", ")", ":", "configs", "=", "[", "]", "for", "directory", ",", "repos", "in", "config", ".", "items", "(", ")", ":", "for", "repo", ",", "repo_data", "in", "repos"...
Return expanded configuration. end-user configuration permit inline configuration shortcuts, expand to identical format for parsing. :param config: the repo config in :py:class:`dict` format. :type config: dict :param cwd: current working dir (for deciphering relative paths) :type cwd: str ...
[ "Return", "expanded", "configuration", "." ]
train
https://github.com/vcs-python/vcspull/blob/c1827bf78d2cdebc61d82111c9aa35afd6ea6a25/vcspull/config.py#L41-L106
vcs-python/vcspull
vcspull/config.py
find_home_config_files
def find_home_config_files(filetype=['json', 'yaml']): """Return configs of ``.vcspull.{yaml,json}`` in user's home directory.""" configs = [] yaml_config = os.path.expanduser('~/.vcspull.yaml') has_yaml_config = os.path.exists(yaml_config) json_config = os.path.expanduser('~/.vcspull.json') ha...
python
def find_home_config_files(filetype=['json', 'yaml']): """Return configs of ``.vcspull.{yaml,json}`` in user's home directory.""" configs = [] yaml_config = os.path.expanduser('~/.vcspull.yaml') has_yaml_config = os.path.exists(yaml_config) json_config = os.path.expanduser('~/.vcspull.json') ha...
[ "def", "find_home_config_files", "(", "filetype", "=", "[", "'json'", ",", "'yaml'", "]", ")", ":", "configs", "=", "[", "]", "yaml_config", "=", "os", ".", "path", ".", "expanduser", "(", "'~/.vcspull.yaml'", ")", "has_yaml_config", "=", "os", ".", "path"...
Return configs of ``.vcspull.{yaml,json}`` in user's home directory.
[ "Return", "configs", "of", ".", "vcspull", ".", "{", "yaml", "json", "}", "in", "user", "s", "home", "directory", "." ]
train
https://github.com/vcs-python/vcspull/blob/c1827bf78d2cdebc61d82111c9aa35afd6ea6a25/vcspull/config.py#L109-L132
vcs-python/vcspull
vcspull/config.py
find_config_files
def find_config_files( path=['~/.vcspull'], match=['*'], filetype=['json', 'yaml'], include_home=False ): """Return repos from a directory and match. Not recursive. :param path: list of paths to search :type path: list :param match: list of globs to search against :type match: list :param f...
python
def find_config_files( path=['~/.vcspull'], match=['*'], filetype=['json', 'yaml'], include_home=False ): """Return repos from a directory and match. Not recursive. :param path: list of paths to search :type path: list :param match: list of globs to search against :type match: list :param f...
[ "def", "find_config_files", "(", "path", "=", "[", "'~/.vcspull'", "]", ",", "match", "=", "[", "'*'", "]", ",", "filetype", "=", "[", "'json'", ",", "'yaml'", "]", ",", "include_home", "=", "False", ")", ":", "configs", "=", "[", "]", "if", "include...
Return repos from a directory and match. Not recursive. :param path: list of paths to search :type path: list :param match: list of globs to search against :type match: list :param filetype: list of filetypes to search against :type filetype: list :param include_home: Include home configura...
[ "Return", "repos", "from", "a", "directory", "and", "match", ".", "Not", "recursive", "." ]
train
https://github.com/vcs-python/vcspull/blob/c1827bf78d2cdebc61d82111c9aa35afd6ea6a25/vcspull/config.py#L135-L179
vcs-python/vcspull
vcspull/config.py
load_configs
def load_configs(files, cwd=os.getcwd()): """Return repos from a list of files. :todo: Validate scheme, check for duplciate destinations, VCS urls :param files: paths to config file :type files: list :param cwd: current path (pass down for :func:`extract_repos` :type cwd: str :returns: exp...
python
def load_configs(files, cwd=os.getcwd()): """Return repos from a list of files. :todo: Validate scheme, check for duplciate destinations, VCS urls :param files: paths to config file :type files: list :param cwd: current path (pass down for :func:`extract_repos` :type cwd: str :returns: exp...
[ "def", "load_configs", "(", "files", ",", "cwd", "=", "os", ".", "getcwd", "(", ")", ")", ":", "repos", "=", "[", "]", "for", "f", "in", "files", ":", "_", ",", "ext", "=", "os", ".", "path", ".", "splitext", "(", "f", ")", "conf", "=", "kapt...
Return repos from a list of files. :todo: Validate scheme, check for duplciate destinations, VCS urls :param files: paths to config file :type files: list :param cwd: current path (pass down for :func:`extract_repos` :type cwd: str :returns: expanded config dict item :rtype: list of dict
[ "Return", "repos", "from", "a", "list", "of", "files", "." ]
train
https://github.com/vcs-python/vcspull/blob/c1827bf78d2cdebc61d82111c9aa35afd6ea6a25/vcspull/config.py#L182-L212
vcs-python/vcspull
vcspull/config.py
detect_duplicate_repos
def detect_duplicate_repos(repos1, repos2): """Return duplicate repos dict if repo_dir same and vcs different. :param repos1: list of repo expanded dicts :type repos1: list of :py:dict :param repos2: list of repo expanded dicts :type repos2: list of :py:dict :rtype: list of dicts or None :r...
python
def detect_duplicate_repos(repos1, repos2): """Return duplicate repos dict if repo_dir same and vcs different. :param repos1: list of repo expanded dicts :type repos1: list of :py:dict :param repos2: list of repo expanded dicts :type repos2: list of :py:dict :rtype: list of dicts or None :r...
[ "def", "detect_duplicate_repos", "(", "repos1", ",", "repos2", ")", ":", "dupes", "=", "[", "]", "path_dupe_repos", "=", "[", "]", "curpaths", "=", "[", "r", "[", "'repo_dir'", "]", "for", "r", "in", "repos1", "]", "newpaths", "=", "[", "r", "[", "'r...
Return duplicate repos dict if repo_dir same and vcs different. :param repos1: list of repo expanded dicts :type repos1: list of :py:dict :param repos2: list of repo expanded dicts :type repos2: list of :py:dict :rtype: list of dicts or None :returns: Duplicate lists
[ "Return", "duplicate", "repos", "dict", "if", "repo_dir", "same", "and", "vcs", "different", "." ]
train
https://github.com/vcs-python/vcspull/blob/c1827bf78d2cdebc61d82111c9aa35afd6ea6a25/vcspull/config.py#L215-L246
vcs-python/vcspull
vcspull/config.py
in_dir
def in_dir(config_dir=CONFIG_DIR, extensions=['.yml', '.yaml', '.json']): """Return a list of configs in ``config_dir``. :param config_dir: directory to search :type config_dir: str :param extensions: filetypes to check (e.g. ``['.yaml', '.json']``). :type extensions: list :rtype: list """...
python
def in_dir(config_dir=CONFIG_DIR, extensions=['.yml', '.yaml', '.json']): """Return a list of configs in ``config_dir``. :param config_dir: directory to search :type config_dir: str :param extensions: filetypes to check (e.g. ``['.yaml', '.json']``). :type extensions: list :rtype: list """...
[ "def", "in_dir", "(", "config_dir", "=", "CONFIG_DIR", ",", "extensions", "=", "[", "'.yml'", ",", "'.yaml'", ",", "'.json'", "]", ")", ":", "configs", "=", "[", "]", "for", "filename", "in", "os", ".", "listdir", "(", "config_dir", ")", ":", "if", "...
Return a list of configs in ``config_dir``. :param config_dir: directory to search :type config_dir: str :param extensions: filetypes to check (e.g. ``['.yaml', '.json']``). :type extensions: list :rtype: list
[ "Return", "a", "list", "of", "configs", "in", "config_dir", "." ]
train
https://github.com/vcs-python/vcspull/blob/c1827bf78d2cdebc61d82111c9aa35afd6ea6a25/vcspull/config.py#L249-L265
vcs-python/vcspull
vcspull/config.py
filter_repos
def filter_repos(config, repo_dir=None, vcs_url=None, name=None): """Return a :py:obj:`list` list of repos from (expanded) config file. repo_dir, vcs_url and name all support fnmatch. :param config: the expanded repo config in :py:class:`dict` format. :type config: dict :param repo_dir: directory ...
python
def filter_repos(config, repo_dir=None, vcs_url=None, name=None): """Return a :py:obj:`list` list of repos from (expanded) config file. repo_dir, vcs_url and name all support fnmatch. :param config: the expanded repo config in :py:class:`dict` format. :type config: dict :param repo_dir: directory ...
[ "def", "filter_repos", "(", "config", ",", "repo_dir", "=", "None", ",", "vcs_url", "=", "None", ",", "name", "=", "None", ")", ":", "repo_list", "=", "[", "]", "if", "repo_dir", ":", "repo_list", ".", "extend", "(", "[", "r", "for", "r", "in", "co...
Return a :py:obj:`list` list of repos from (expanded) config file. repo_dir, vcs_url and name all support fnmatch. :param config: the expanded repo config in :py:class:`dict` format. :type config: dict :param repo_dir: directory of checkout location, fnmatch pattern supported :type repo_dir: str o...
[ "Return", "a", ":", "py", ":", "obj", ":", "list", "list", "of", "repos", "from", "(", "expanded", ")", "config", "file", "." ]
train
https://github.com/vcs-python/vcspull/blob/c1827bf78d2cdebc61d82111c9aa35afd6ea6a25/vcspull/config.py#L268-L299
vcs-python/vcspull
vcspull/cli.py
setup_logger
def setup_logger(log=None, level='INFO'): """Setup logging for CLI use. :param log: instance of logger :type log: :py:class:`Logger` """ if not log: log = logging.getLogger() if not log.handlers: channel = logging.StreamHandler() channel.setFormatter(DebugLogFormatter()...
python
def setup_logger(log=None, level='INFO'): """Setup logging for CLI use. :param log: instance of logger :type log: :py:class:`Logger` """ if not log: log = logging.getLogger() if not log.handlers: channel = logging.StreamHandler() channel.setFormatter(DebugLogFormatter()...
[ "def", "setup_logger", "(", "log", "=", "None", ",", "level", "=", "'INFO'", ")", ":", "if", "not", "log", ":", "log", "=", "logging", ".", "getLogger", "(", ")", "if", "not", "log", ".", "handlers", ":", "channel", "=", "logging", ".", "StreamHandle...
Setup logging for CLI use. :param log: instance of logger :type log: :py:class:`Logger`
[ "Setup", "logging", "for", "CLI", "use", "." ]
train
https://github.com/vcs-python/vcspull/blob/c1827bf78d2cdebc61d82111c9aa35afd6ea6a25/vcspull/cli.py#L28-L50
jschaf/pylint-flask
pylint_flask/__init__.py
copy_node_info
def copy_node_info(src, dest): """Copy information from src to dest Every node in the AST has to have line number information. Get the information from the old stmt.""" for attr in ['lineno', 'fromlineno', 'tolineno', 'col_offset', 'parent']: if hasattr(src, attr): ...
python
def copy_node_info(src, dest): """Copy information from src to dest Every node in the AST has to have line number information. Get the information from the old stmt.""" for attr in ['lineno', 'fromlineno', 'tolineno', 'col_offset', 'parent']: if hasattr(src, attr): ...
[ "def", "copy_node_info", "(", "src", ",", "dest", ")", ":", "for", "attr", "in", "[", "'lineno'", ",", "'fromlineno'", ",", "'tolineno'", ",", "'col_offset'", ",", "'parent'", "]", ":", "if", "hasattr", "(", "src", ",", "attr", ")", ":", "setattr", "("...
Copy information from src to dest Every node in the AST has to have line number information. Get the information from the old stmt.
[ "Copy", "information", "from", "src", "to", "dest" ]
train
https://github.com/jschaf/pylint-flask/blob/3851d142679facbc60b4755dc7fb5428aafdebe7/pylint_flask/__init__.py#L15-L23
jschaf/pylint-flask
pylint_flask/__init__.py
make_non_magical_flask_import
def make_non_magical_flask_import(flask_ext_name): '''Convert a flask.ext.admin into flask_admin.''' match = re.match(r'flask\.ext\.(.*)', flask_ext_name) if match is None: raise LookupError("Module name `{}` doesn't match" "`flask.ext` style import.") from_name = match...
python
def make_non_magical_flask_import(flask_ext_name): '''Convert a flask.ext.admin into flask_admin.''' match = re.match(r'flask\.ext\.(.*)', flask_ext_name) if match is None: raise LookupError("Module name `{}` doesn't match" "`flask.ext` style import.") from_name = match...
[ "def", "make_non_magical_flask_import", "(", "flask_ext_name", ")", ":", "match", "=", "re", ".", "match", "(", "r'flask\\.ext\\.(.*)'", ",", "flask_ext_name", ")", "if", "match", "is", "None", ":", "raise", "LookupError", "(", "\"Module name `{}` doesn't match\"", ...
Convert a flask.ext.admin into flask_admin.
[ "Convert", "a", "flask", ".", "ext", ".", "admin", "into", "flask_admin", "." ]
train
https://github.com/jschaf/pylint-flask/blob/3851d142679facbc60b4755dc7fb5428aafdebe7/pylint_flask/__init__.py#L36-L44
jschaf/pylint-flask
pylint_flask/__init__.py
transform_flask_from_import
def transform_flask_from_import(node): '''Translates a flask.ext from-style import into a non-magical import. Translates: from flask.ext import wtf, bcrypt as fcrypt Into: import flask_wtf as wtf, flask_bcrypt as fcrypt ''' new_names = [] # node.names is a list of 2-tuples. Eac...
python
def transform_flask_from_import(node): '''Translates a flask.ext from-style import into a non-magical import. Translates: from flask.ext import wtf, bcrypt as fcrypt Into: import flask_wtf as wtf, flask_bcrypt as fcrypt ''' new_names = [] # node.names is a list of 2-tuples. Eac...
[ "def", "transform_flask_from_import", "(", "node", ")", ":", "new_names", "=", "[", "]", "# node.names is a list of 2-tuples. Each tuple consists of (name, as_name).", "# So, the import would be represented as:", "#", "# from flask.ext import wtf as ftw, admin", "#", "# node.names =...
Translates a flask.ext from-style import into a non-magical import. Translates: from flask.ext import wtf, bcrypt as fcrypt Into: import flask_wtf as wtf, flask_bcrypt as fcrypt
[ "Translates", "a", "flask", ".", "ext", "from", "-", "style", "import", "into", "a", "non", "-", "magical", "import", "." ]
train
https://github.com/jschaf/pylint-flask/blob/3851d142679facbc60b4755dc7fb5428aafdebe7/pylint_flask/__init__.py#L47-L71
jschaf/pylint-flask
pylint_flask/__init__.py
transform_flask_from_long
def transform_flask_from_long(node): '''Translates a flask.ext.wtf from-style import into a non-magical import. Translates: from flask.ext.wtf import Form from flask.ext.admin.model import InlineFormAdmin Into: from flask_wtf import Form from flask_admin.model import InlineF...
python
def transform_flask_from_long(node): '''Translates a flask.ext.wtf from-style import into a non-magical import. Translates: from flask.ext.wtf import Form from flask.ext.admin.model import InlineFormAdmin Into: from flask_wtf import Form from flask_admin.model import InlineF...
[ "def", "transform_flask_from_long", "(", "node", ")", ":", "actual_module_name", "=", "make_non_magical_flask_import", "(", "node", ".", "modname", ")", "new_node", "=", "nodes", ".", "ImportFrom", "(", "actual_module_name", ",", "node", ".", "names", ",", "node",...
Translates a flask.ext.wtf from-style import into a non-magical import. Translates: from flask.ext.wtf import Form from flask.ext.admin.model import InlineFormAdmin Into: from flask_wtf import Form from flask_admin.model import InlineFormAdmin
[ "Translates", "a", "flask", ".", "ext", ".", "wtf", "from", "-", "style", "import", "into", "a", "non", "-", "magical", "import", "." ]
train
https://github.com/jschaf/pylint-flask/blob/3851d142679facbc60b4755dc7fb5428aafdebe7/pylint_flask/__init__.py#L84-L99
jschaf/pylint-flask
pylint_flask/__init__.py
transform_flask_bare_import
def transform_flask_bare_import(node): '''Translates a flask.ext.wtf bare import into a non-magical import. Translates: import flask.ext.admin as admin Into: import flask_admin as admin ''' new_names = [] for (name, as_name) in node.names: match = re.match(r'flask\.ext\...
python
def transform_flask_bare_import(node): '''Translates a flask.ext.wtf bare import into a non-magical import. Translates: import flask.ext.admin as admin Into: import flask_admin as admin ''' new_names = [] for (name, as_name) in node.names: match = re.match(r'flask\.ext\...
[ "def", "transform_flask_bare_import", "(", "node", ")", ":", "new_names", "=", "[", "]", "for", "(", "name", ",", "as_name", ")", "in", "node", ".", "names", ":", "match", "=", "re", ".", "match", "(", "r'flask\\.ext\\.(.*)'", ",", "name", ")", "from_nam...
Translates a flask.ext.wtf bare import into a non-magical import. Translates: import flask.ext.admin as admin Into: import flask_admin as admin
[ "Translates", "a", "flask", ".", "ext", ".", "wtf", "bare", "import", "into", "a", "non", "-", "magical", "import", "." ]
train
https://github.com/jschaf/pylint-flask/blob/3851d142679facbc60b4755dc7fb5428aafdebe7/pylint_flask/__init__.py#L112-L132
niolabs/python-xbee
xbee/backend/base.py
XBeeBase._write
def _write(self, data): """ _write: binary data -> None Packages the given binary data in an API frame and writes the result to the serial port """ frame = APIFrame(data, self._escaped).output() self.serial.write(frame)
python
def _write(self, data): """ _write: binary data -> None Packages the given binary data in an API frame and writes the result to the serial port """ frame = APIFrame(data, self._escaped).output() self.serial.write(frame)
[ "def", "_write", "(", "self", ",", "data", ")", ":", "frame", "=", "APIFrame", "(", "data", ",", "self", ".", "_escaped", ")", ".", "output", "(", ")", "self", ".", "serial", ".", "write", "(", "frame", ")" ]
_write: binary data -> None Packages the given binary data in an API frame and writes the result to the serial port
[ "_write", ":", "binary", "data", "-", ">", "None" ]
train
https://github.com/niolabs/python-xbee/blob/b91be3d0ee7ccaa1990120b5b5490999d8e6cbc7/xbee/backend/base.py#L74-L82
niolabs/python-xbee
xbee/backend/base.py
XBeeBase._build_command
def _build_command(self, cmd, **kwargs): """ _build_command: string (binary data) ... -> binary data _build_command will construct a command packet according to the specified command's specification in api_commands. It will expect named arguments for all fields other than those ...
python
def _build_command(self, cmd, **kwargs): """ _build_command: string (binary data) ... -> binary data _build_command will construct a command packet according to the specified command's specification in api_commands. It will expect named arguments for all fields other than those ...
[ "def", "_build_command", "(", "self", ",", "cmd", ",", "*", "*", "kwargs", ")", ":", "try", ":", "cmd_spec", "=", "self", ".", "api_commands", "[", "cmd", "]", "except", "AttributeError", ":", "raise", "NotImplementedError", "(", "\"API command specifications ...
_build_command: string (binary data) ... -> binary data _build_command will construct a command packet according to the specified command's specification in api_commands. It will expect named arguments for all fields other than those with a default value or a length of 'None'. ...
[ "_build_command", ":", "string", "(", "binary", "data", ")", "...", "-", ">", "binary", "data" ]
train
https://github.com/niolabs/python-xbee/blob/b91be3d0ee7ccaa1990120b5b5490999d8e6cbc7/xbee/backend/base.py#L84-L145
niolabs/python-xbee
xbee/backend/base.py
XBeeBase._split_response
def _split_response(self, data): """ _split_response: binary data -> {'id':str, 'param':binary data, ...} _split_response takes a data packet received from an XBee device and converts it into a dictionary....
python
def _split_response(self, data): """ _split_response: binary data -> {'id':str, 'param':binary data, ...} _split_response takes a data packet received from an XBee device and converts it into a dictionary....
[ "def", "_split_response", "(", "self", ",", "data", ")", ":", "# Fetch the first byte, identify the packet", "# If the spec doesn't exist, raise exception", "packet_id", "=", "data", "[", "0", ":", "1", "]", "try", ":", "packet", "=", "self", ".", "api_responses", "...
_split_response: binary data -> {'id':str, 'param':binary data, ...} _split_response takes a data packet received from an XBee device and converts it into a dictionary. This dictionary provides names for each segm...
[ "_split_response", ":", "binary", "data", "-", ">", "{", "id", ":", "str", "param", ":", "binary", "data", "...", "}" ]
train
https://github.com/niolabs/python-xbee/blob/b91be3d0ee7ccaa1990120b5b5490999d8e6cbc7/xbee/backend/base.py#L147-L244
niolabs/python-xbee
xbee/backend/base.py
XBeeBase._parse_samples_header
def _parse_samples_header(self, io_bytes): """ _parse_samples_header: binary data in XBee IO data format -> (int, [int ...], [int ...], int, int) _parse_samples_header will read the first three bytes of the binary data given and will return the number of samples ...
python
def _parse_samples_header(self, io_bytes): """ _parse_samples_header: binary data in XBee IO data format -> (int, [int ...], [int ...], int, int) _parse_samples_header will read the first three bytes of the binary data given and will return the number of samples ...
[ "def", "_parse_samples_header", "(", "self", ",", "io_bytes", ")", ":", "header_size", "=", "3", "# number of samples (always 1?) is the first byte", "sample_count", "=", "byteToInt", "(", "io_bytes", "[", "0", "]", ")", "# part of byte 1 and byte 2 are the DIO mask ( 9 bit...
_parse_samples_header: binary data in XBee IO data format -> (int, [int ...], [int ...], int, int) _parse_samples_header will read the first three bytes of the binary data given and will return the number of samples which follow, a list of enabled digital inputs, a list ...
[ "_parse_samples_header", ":", "binary", "data", "in", "XBee", "IO", "data", "format", "-", ">", "(", "int", "[", "int", "...", "]", "[", "int", "...", "]", "int", "int", ")" ]
train
https://github.com/niolabs/python-xbee/blob/b91be3d0ee7ccaa1990120b5b5490999d8e6cbc7/xbee/backend/base.py#L246-L284
niolabs/python-xbee
xbee/backend/base.py
XBeeBase._parse_samples
def _parse_samples(self, io_bytes): """ _parse_samples: binary data in XBee IO data format -> [ {"dio-0":True, "dio-1":False, "adc-0":100"}, ...] _parse_samples reads binary data from an XBee device in the IO ...
python
def _parse_samples(self, io_bytes): """ _parse_samples: binary data in XBee IO data format -> [ {"dio-0":True, "dio-1":False, "adc-0":100"}, ...] _parse_samples reads binary data from an XBee device in the IO ...
[ "def", "_parse_samples", "(", "self", ",", "io_bytes", ")", ":", "sample_count", ",", "dio_chans", ",", "aio_chans", ",", "dio_mask", ",", "header_size", "=", "self", ".", "_parse_samples_header", "(", "io_bytes", ")", "samples", "=", "[", "]", "# split the sa...
_parse_samples: binary data in XBee IO data format -> [ {"dio-0":True, "dio-1":False, "adc-0":100"}, ...] _parse_samples reads binary data from an XBee device in the IO data format specified by the API. It will then return a ...
[ "_parse_samples", ":", "binary", "data", "in", "XBee", "IO", "data", "format", "-", ">", "[", "{", "dio", "-", "0", ":", "True", "dio", "-", "1", ":", "False", "adc", "-", "0", ":", "100", "}", "...", "]" ]
train
https://github.com/niolabs/python-xbee/blob/b91be3d0ee7ccaa1990120b5b5490999d8e6cbc7/xbee/backend/base.py#L286-L326
niolabs/python-xbee
xbee/backend/base.py
XBeeBase.send
def send(self, cmd, **kwargs): """ send: string param=binary data ... -> None When send is called with the proper arguments, an API command will be written to the serial port for this XBee device containing the proper instructions and data. This method must be called wi...
python
def send(self, cmd, **kwargs): """ send: string param=binary data ... -> None When send is called with the proper arguments, an API command will be written to the serial port for this XBee device containing the proper instructions and data. This method must be called wi...
[ "def", "send", "(", "self", ",", "cmd", ",", "*", "*", "kwargs", ")", ":", "# Pass through the keyword arguments", "self", ".", "_write", "(", "self", ".", "_build_command", "(", "cmd", ",", "*", "*", "kwargs", ")", ")" ]
send: string param=binary data ... -> None When send is called with the proper arguments, an API command will be written to the serial port for this XBee device containing the proper instructions and data. This method must be called with named arguments in accordance with the a...
[ "send", ":", "string", "param", "=", "binary", "data", "...", "-", ">", "None" ]
train
https://github.com/niolabs/python-xbee/blob/b91be3d0ee7ccaa1990120b5b5490999d8e6cbc7/xbee/backend/base.py#L328-L343
niolabs/python-xbee
examples/alarm.py
main
def main(): """ Run through simple demonstration of alarm concept """ alarm = XBeeAlarm('/dev/ttyUSB0', '\x56\x78') routine = SimpleWakeupRoutine(alarm) from time import sleep while True: """ Run the routine with 10 second delays """ try: print "W...
python
def main(): """ Run through simple demonstration of alarm concept """ alarm = XBeeAlarm('/dev/ttyUSB0', '\x56\x78') routine = SimpleWakeupRoutine(alarm) from time import sleep while True: """ Run the routine with 10 second delays """ try: print "W...
[ "def", "main", "(", ")", ":", "alarm", "=", "XBeeAlarm", "(", "'/dev/ttyUSB0'", ",", "'\\x56\\x78'", ")", "routine", "=", "SimpleWakeupRoutine", "(", "alarm", ")", "from", "time", "import", "sleep", "while", "True", ":", "\"\"\"\n Run the routine with 10 se...
Run through simple demonstration of alarm concept
[ "Run", "through", "simple", "demonstration", "of", "alarm", "concept" ]
train
https://github.com/niolabs/python-xbee/blob/b91be3d0ee7ccaa1990120b5b5490999d8e6cbc7/examples/alarm.py#L232-L250
niolabs/python-xbee
examples/alarm.py
XBeeAlarm._reset
def _reset(self): """ reset: None -> None Resets the remote XBee device to a standard configuration """ # Analog pin 0 self.hw.remote_at( dest_addr=self.remote_addr, command='D0', parameter='\x02') # Disengage remote LED, buzz...
python
def _reset(self): """ reset: None -> None Resets the remote XBee device to a standard configuration """ # Analog pin 0 self.hw.remote_at( dest_addr=self.remote_addr, command='D0', parameter='\x02') # Disengage remote LED, buzz...
[ "def", "_reset", "(", "self", ")", ":", "# Analog pin 0", "self", ".", "hw", ".", "remote_at", "(", "dest_addr", "=", "self", ".", "remote_addr", ",", "command", "=", "'D0'", ",", "parameter", "=", "'\\x02'", ")", "# Disengage remote LED, buzzer", "self", "....
reset: None -> None Resets the remote XBee device to a standard configuration
[ "reset", ":", "None", "-", ">", "None" ]
train
https://github.com/niolabs/python-xbee/blob/b91be3d0ee7ccaa1990120b5b5490999d8e6cbc7/examples/alarm.py#L106-L120
niolabs/python-xbee
examples/alarm.py
XBeeAlarm._set_LED
def _set_LED(self, status): """ _set_LED: boolean -> None Sets the status of the remote LED """ # DIO pin 1 (LED), active low self.hw.remote_at( dest_addr=self.remote_addr, command='D1', parameter='\x04' if status else '\x05')
python
def _set_LED(self, status): """ _set_LED: boolean -> None Sets the status of the remote LED """ # DIO pin 1 (LED), active low self.hw.remote_at( dest_addr=self.remote_addr, command='D1', parameter='\x04' if status else '\x05')
[ "def", "_set_LED", "(", "self", ",", "status", ")", ":", "# DIO pin 1 (LED), active low", "self", ".", "hw", ".", "remote_at", "(", "dest_addr", "=", "self", ".", "remote_addr", ",", "command", "=", "'D1'", ",", "parameter", "=", "'\\x04'", "if", "status", ...
_set_LED: boolean -> None Sets the status of the remote LED
[ "_set_LED", ":", "boolean", "-", ">", "None" ]
train
https://github.com/niolabs/python-xbee/blob/b91be3d0ee7ccaa1990120b5b5490999d8e6cbc7/examples/alarm.py#L122-L132
niolabs/python-xbee
examples/alarm.py
XBeeAlarm.bed_occupied
def bed_occupied(self): """ bed_occupied: None -> boolean Determines whether the bed is currently occupied by requesting data from the remote XBee and comparing the analog value with a threshold. """ # Receive samples from the remote device self._set_sen...
python
def bed_occupied(self): """ bed_occupied: None -> boolean Determines whether the bed is currently occupied by requesting data from the remote XBee and comparing the analog value with a threshold. """ # Receive samples from the remote device self._set_sen...
[ "def", "bed_occupied", "(", "self", ")", ":", "# Receive samples from the remote device", "self", ".", "_set_send_samples", "(", "True", ")", "while", "True", ":", "packet", "=", "self", ".", "hw", ".", "wait_read_frame", "(", ")", "if", "'adc-0'", "in", "pack...
bed_occupied: None -> boolean Determines whether the bed is currently occupied by requesting data from the remote XBee and comparing the analog value with a threshold.
[ "bed_occupied", ":", "None", "-", ">", "boolean" ]
train
https://github.com/niolabs/python-xbee/blob/b91be3d0ee7ccaa1990120b5b5490999d8e6cbc7/examples/alarm.py#L177-L195
niolabs/python-xbee
xbee/frame.py
APIFrame.checksum
def checksum(self): """ checksum: None -> single checksum byte checksum adds all bytes of the binary, unescaped data in the frame, saves the last byte of the result, and subtracts it from 0xFF. The final result is the checksum """ total = 0 # Add togethe...
python
def checksum(self): """ checksum: None -> single checksum byte checksum adds all bytes of the binary, unescaped data in the frame, saves the last byte of the result, and subtracts it from 0xFF. The final result is the checksum """ total = 0 # Add togethe...
[ "def", "checksum", "(", "self", ")", ":", "total", "=", "0", "# Add together all bytes", "for", "byte", "in", "self", ".", "data", ":", "total", "+=", "byteToInt", "(", "byte", ")", "# Only keep the last byte", "total", "=", "total", "&", "0xFF", "return", ...
checksum: None -> single checksum byte checksum adds all bytes of the binary, unescaped data in the frame, saves the last byte of the result, and subtracts it from 0xFF. The final result is the checksum
[ "checksum", ":", "None", "-", ">", "single", "checksum", "byte" ]
train
https://github.com/niolabs/python-xbee/blob/b91be3d0ee7ccaa1990120b5b5490999d8e6cbc7/xbee/frame.py#L31-L48
niolabs/python-xbee
xbee/frame.py
APIFrame.verify
def verify(self, chksum): """ verify: 1 byte -> boolean verify checksums the frame, adds the expected checksum, and determines whether the result is correct. The result should be 0xFF. """ total = 0 # Add together all bytes for byte in self.data:...
python
def verify(self, chksum): """ verify: 1 byte -> boolean verify checksums the frame, adds the expected checksum, and determines whether the result is correct. The result should be 0xFF. """ total = 0 # Add together all bytes for byte in self.data:...
[ "def", "verify", "(", "self", ",", "chksum", ")", ":", "total", "=", "0", "# Add together all bytes", "for", "byte", "in", "self", ".", "data", ":", "total", "+=", "byteToInt", "(", "byte", ")", "# Add checksum too", "total", "+=", "byteToInt", "(", "chksu...
verify: 1 byte -> boolean verify checksums the frame, adds the expected checksum, and determines whether the result is correct. The result should be 0xFF.
[ "verify", ":", "1", "byte", "-", ">", "boolean" ]
train
https://github.com/niolabs/python-xbee/blob/b91be3d0ee7ccaa1990120b5b5490999d8e6cbc7/xbee/frame.py#L50-L71
niolabs/python-xbee
xbee/frame.py
APIFrame.output
def output(self): """ output: None -> valid API frame (binary data) output will produce a valid API frame for transmission to an XBee module. """ # start is one byte long, length is two bytes # data is n bytes long (indicated by length) # chksum is one by...
python
def output(self): """ output: None -> valid API frame (binary data) output will produce a valid API frame for transmission to an XBee module. """ # start is one byte long, length is two bytes # data is n bytes long (indicated by length) # chksum is one by...
[ "def", "output", "(", "self", ")", ":", "# start is one byte long, length is two bytes", "# data is n bytes long (indicated by length)", "# chksum is one byte long", "data", "=", "self", ".", "len_bytes", "(", ")", "+", "self", ".", "data", "+", "self", ".", "checksum",...
output: None -> valid API frame (binary data) output will produce a valid API frame for transmission to an XBee module.
[ "output", ":", "None", "-", ">", "valid", "API", "frame", "(", "binary", "data", ")" ]
train
https://github.com/niolabs/python-xbee/blob/b91be3d0ee7ccaa1990120b5b5490999d8e6cbc7/xbee/frame.py#L83-L103
niolabs/python-xbee
xbee/frame.py
APIFrame.escape
def escape(data): """ escape: byte string -> byte string When a 'special' byte is encountered in the given data string, it is preceded by an escape byte and XORed with 0x20. """ escaped_data = b"" for byte in data: if intToByte(byteToInt(byte)) in AP...
python
def escape(data): """ escape: byte string -> byte string When a 'special' byte is encountered in the given data string, it is preceded by an escape byte and XORed with 0x20. """ escaped_data = b"" for byte in data: if intToByte(byteToInt(byte)) in AP...
[ "def", "escape", "(", "data", ")", ":", "escaped_data", "=", "b\"\"", "for", "byte", "in", "data", ":", "if", "intToByte", "(", "byteToInt", "(", "byte", ")", ")", "in", "APIFrame", ".", "ESCAPE_BYTES", ":", "escaped_data", "+=", "APIFrame", ".", "ESCAPE...
escape: byte string -> byte string When a 'special' byte is encountered in the given data string, it is preceded by an escape byte and XORed with 0x20.
[ "escape", ":", "byte", "string", "-", ">", "byte", "string" ]
train
https://github.com/niolabs/python-xbee/blob/b91be3d0ee7ccaa1990120b5b5490999d8e6cbc7/xbee/frame.py#L106-L122
niolabs/python-xbee
xbee/frame.py
APIFrame.fill
def fill(self, byte): """ fill: byte -> None Adds the given raw byte to this APIFrame. If this APIFrame is marked as escaped and this byte is an escape byte, the next byte in a call to fill() will be unescaped. """ if self._unescape_next_byte: byte =...
python
def fill(self, byte): """ fill: byte -> None Adds the given raw byte to this APIFrame. If this APIFrame is marked as escaped and this byte is an escape byte, the next byte in a call to fill() will be unescaped. """ if self._unescape_next_byte: byte =...
[ "def", "fill", "(", "self", ",", "byte", ")", ":", "if", "self", ".", "_unescape_next_byte", ":", "byte", "=", "intToByte", "(", "byteToInt", "(", "byte", ")", "^", "0x20", ")", "self", ".", "_unescape_next_byte", "=", "False", "elif", "self", ".", "es...
fill: byte -> None Adds the given raw byte to this APIFrame. If this APIFrame is marked as escaped and this byte is an escape byte, the next byte in a call to fill() will be unescaped.
[ "fill", ":", "byte", "-", ">", "None" ]
train
https://github.com/niolabs/python-xbee/blob/b91be3d0ee7ccaa1990120b5b5490999d8e6cbc7/xbee/frame.py#L124-L140
niolabs/python-xbee
xbee/frame.py
APIFrame.parse
def parse(self): """ parse: None -> None Given a valid API frame, parse extracts the data contained inside it and verifies it against its checksum """ if len(self.raw_data) < 3: ValueError("parse() may only be called on a frame containing at " ...
python
def parse(self): """ parse: None -> None Given a valid API frame, parse extracts the data contained inside it and verifies it against its checksum """ if len(self.raw_data) < 3: ValueError("parse() may only be called on a frame containing at " ...
[ "def", "parse", "(", "self", ")", ":", "if", "len", "(", "self", ".", "raw_data", ")", "<", "3", ":", "ValueError", "(", "\"parse() may only be called on a frame containing at \"", "\"least 3 bytes of raw data (see fill())\"", ")", "# First two bytes are the length of the d...
parse: None -> None Given a valid API frame, parse extracts the data contained inside it and verifies it against its checksum
[ "parse", ":", "None", "-", ">", "None" ]
train
https://github.com/niolabs/python-xbee/blob/b91be3d0ee7ccaa1990120b5b5490999d8e6cbc7/xbee/frame.py#L157-L181
niolabs/python-xbee
xbee/backend/zigbee.py
ZigBee._parse_IS_at_response
def _parse_IS_at_response(self, packet_info): """ If the given packet is a successful remote AT response for an IS command, parse the parameter field as IO data. """ if packet_info['id'] in ('at_response', 'remote_at_response') and \ packet_info['command'].lower()...
python
def _parse_IS_at_response(self, packet_info): """ If the given packet is a successful remote AT response for an IS command, parse the parameter field as IO data. """ if packet_info['id'] in ('at_response', 'remote_at_response') and \ packet_info['command'].lower()...
[ "def", "_parse_IS_at_response", "(", "self", ",", "packet_info", ")", ":", "if", "packet_info", "[", "'id'", "]", "in", "(", "'at_response'", ",", "'remote_at_response'", ")", "and", "packet_info", "[", "'command'", "]", ".", "lower", "(", ")", "==", "b'is'"...
If the given packet is a successful remote AT response for an IS command, parse the parameter field as IO data.
[ "If", "the", "given", "packet", "is", "a", "successful", "remote", "AT", "response", "for", "an", "IS", "command", "parse", "the", "parameter", "field", "as", "IO", "data", "." ]
train
https://github.com/niolabs/python-xbee/blob/b91be3d0ee7ccaa1990120b5b5490999d8e6cbc7/xbee/backend/zigbee.py#L254-L264
niolabs/python-xbee
xbee/backend/zigbee.py
ZigBee._parse_ND_at_response
def _parse_ND_at_response(self, packet_info): """ If the given packet is a successful AT response for an ND command, parse the parameter field. """ if packet_info['id'] == 'at_response' and \ packet_info['command'].lower() == b'nd' and \ packet_inf...
python
def _parse_ND_at_response(self, packet_info): """ If the given packet is a successful AT response for an ND command, parse the parameter field. """ if packet_info['id'] == 'at_response' and \ packet_info['command'].lower() == b'nd' and \ packet_inf...
[ "def", "_parse_ND_at_response", "(", "self", ",", "packet_info", ")", ":", "if", "packet_info", "[", "'id'", "]", "==", "'at_response'", "and", "packet_info", "[", "'command'", "]", ".", "lower", "(", ")", "==", "b'nd'", "and", "packet_info", "[", "'status'"...
If the given packet is a successful AT response for an ND command, parse the parameter field.
[ "If", "the", "given", "packet", "is", "a", "successful", "AT", "response", "for", "an", "ND", "command", "parse", "the", "parameter", "field", "." ]
train
https://github.com/niolabs/python-xbee/blob/b91be3d0ee7ccaa1990120b5b5490999d8e6cbc7/xbee/backend/zigbee.py#L266-L315
niolabs/python-xbee
xbee/thread/base.py
XBeeBase.halt
def halt(self): """ halt: None -> None If this instance has a separate thread running, it will be halted. This method will wait until the thread has cleaned up before returning. """ if self._callback: self._thread_continue = False self._th...
python
def halt(self): """ halt: None -> None If this instance has a separate thread running, it will be halted. This method will wait until the thread has cleaned up before returning. """ if self._callback: self._thread_continue = False self._th...
[ "def", "halt", "(", "self", ")", ":", "if", "self", ".", "_callback", ":", "self", ".", "_thread_continue", "=", "False", "self", ".", "_thread", ".", "join", "(", ")" ]
halt: None -> None If this instance has a separate thread running, it will be halted. This method will wait until the thread has cleaned up before returning.
[ "halt", ":", "None", "-", ">", "None" ]
train
https://github.com/niolabs/python-xbee/blob/b91be3d0ee7ccaa1990120b5b5490999d8e6cbc7/xbee/thread/base.py#L67-L77
niolabs/python-xbee
xbee/thread/base.py
XBeeBase.run
def run(self): """ run: None -> None This method overrides threading.Thread.run() and is automatically called when an instance is created with threading enabled. """ while True: try: self._callback(self.wait_read_frame()) except Th...
python
def run(self): """ run: None -> None This method overrides threading.Thread.run() and is automatically called when an instance is created with threading enabled. """ while True: try: self._callback(self.wait_read_frame()) except Th...
[ "def", "run", "(", "self", ")", ":", "while", "True", ":", "try", ":", "self", ".", "_callback", "(", "self", ".", "wait_read_frame", "(", ")", ")", "except", "ThreadQuitException", ":", "# Expected termintation of thread due to self.halt()", "break", "except", ...
run: None -> None This method overrides threading.Thread.run() and is automatically called when an instance is created with threading enabled.
[ "run", ":", "None", "-", ">", "None" ]
train
https://github.com/niolabs/python-xbee/blob/b91be3d0ee7ccaa1990120b5b5490999d8e6cbc7/xbee/thread/base.py#L79-L95
niolabs/python-xbee
xbee/thread/base.py
XBeeBase.wait_read_frame
def wait_read_frame(self, timeout=None): """ wait_read_frame: None -> frame info dictionary wait_read_frame calls XBee._wait_for_frame() and waits until a valid frame appears on the serial port. Once it receives a frame, wait_read_frame attempts to parse the data contained withi...
python
def wait_read_frame(self, timeout=None): """ wait_read_frame: None -> frame info dictionary wait_read_frame calls XBee._wait_for_frame() and waits until a valid frame appears on the serial port. Once it receives a frame, wait_read_frame attempts to parse the data contained withi...
[ "def", "wait_read_frame", "(", "self", ",", "timeout", "=", "None", ")", ":", "frame", "=", "self", ".", "_wait_for_frame", "(", "timeout", ")", "return", "self", ".", "_split_response", "(", "frame", ".", "data", ")" ]
wait_read_frame: None -> frame info dictionary wait_read_frame calls XBee._wait_for_frame() and waits until a valid frame appears on the serial port. Once it receives a frame, wait_read_frame attempts to parse the data contained within it and returns the resulting dictionary
[ "wait_read_frame", ":", "None", "-", ">", "frame", "info", "dictionary" ]
train
https://github.com/niolabs/python-xbee/blob/b91be3d0ee7ccaa1990120b5b5490999d8e6cbc7/xbee/thread/base.py#L97-L107
niolabs/python-xbee
xbee/thread/base.py
XBeeBase._wait_for_frame
def _wait_for_frame(self, timeout=None): """ _wait_for_frame: None -> binary data _wait_for_frame will read from the serial port until a valid API frame arrives. It will then return the binary data contained within the frame. If this method is called as a separate threa...
python
def _wait_for_frame(self, timeout=None): """ _wait_for_frame: None -> binary data _wait_for_frame will read from the serial port until a valid API frame arrives. It will then return the binary data contained within the frame. If this method is called as a separate threa...
[ "def", "_wait_for_frame", "(", "self", ",", "timeout", "=", "None", ")", ":", "frame", "=", "APIFrame", "(", "escaped", "=", "self", ".", "_escaped", ")", "deadline", "=", "0", "if", "timeout", "is", "not", "None", "and", "timeout", ">", "0", ":", "d...
_wait_for_frame: None -> binary data _wait_for_frame will read from the serial port until a valid API frame arrives. It will then return the binary data contained within the frame. If this method is called as a separate thread and self.thread_continue is set to False, the threa...
[ "_wait_for_frame", ":", "None", "-", ">", "binary", "data" ]
train
https://github.com/niolabs/python-xbee/blob/b91be3d0ee7ccaa1990120b5b5490999d8e6cbc7/xbee/thread/base.py#L109-L164
niolabs/python-xbee
examples/serial_example_series_1.py
main
def main(): """ Sends an API AT command to read the lower-order address bits from an XBee Series 1 and looks for a response """ try: # Open serial port ser = serial.Serial('/dev/ttyUSB0', 9600) # Create XBee Series 1 object xbee = XBee(ser) # Send AT packe...
python
def main(): """ Sends an API AT command to read the lower-order address bits from an XBee Series 1 and looks for a response """ try: # Open serial port ser = serial.Serial('/dev/ttyUSB0', 9600) # Create XBee Series 1 object xbee = XBee(ser) # Send AT packe...
[ "def", "main", "(", ")", ":", "try", ":", "# Open serial port", "ser", "=", "serial", ".", "Serial", "(", "'/dev/ttyUSB0'", ",", "9600", ")", "# Create XBee Series 1 object", "xbee", "=", "XBee", "(", "ser", ")", "# Send AT packet", "xbee", ".", "send", "(",...
Sends an API AT command to read the lower-order address bits from an XBee Series 1 and looks for a response
[ "Sends", "an", "API", "AT", "command", "to", "read", "the", "lower", "-", "order", "address", "bits", "from", "an", "XBee", "Series", "1", "and", "looks", "for", "a", "response" ]
train
https://github.com/niolabs/python-xbee/blob/b91be3d0ee7ccaa1990120b5b5490999d8e6cbc7/examples/serial_example_series_1.py#L14-L58
niolabs/python-xbee
xbee/tornado/base.py
XBeeBase.halt
def halt(self): """ halt: None -> None Stop the event, and remove the FD from the loop handler """ if self._callback: self._running.clear() self._ioloop.remove_handler(self.serial.fd) if self._frame_future is not None: self._f...
python
def halt(self): """ halt: None -> None Stop the event, and remove the FD from the loop handler """ if self._callback: self._running.clear() self._ioloop.remove_handler(self.serial.fd) if self._frame_future is not None: self._f...
[ "def", "halt", "(", "self", ")", ":", "if", "self", ".", "_callback", ":", "self", ".", "_running", ".", "clear", "(", ")", "self", ".", "_ioloop", ".", "remove_handler", "(", "self", ".", "serial", ".", "fd", ")", "if", "self", ".", "_frame_future",...
halt: None -> None Stop the event, and remove the FD from the loop handler
[ "halt", ":", "None", "-", ">", "None" ]
train
https://github.com/niolabs/python-xbee/blob/b91be3d0ee7ccaa1990120b5b5490999d8e6cbc7/xbee/tornado/base.py#L71-L83
niolabs/python-xbee
xbee/tornado/base.py
XBeeBase.process_frames
def process_frames(self): """ process_frames: None -> None Wait for a frame to become available, when resolved call the callback """ while self._running.is_set(): try: frame = yield self._get_frame() info = self._split_response(frame.d...
python
def process_frames(self): """ process_frames: None -> None Wait for a frame to become available, when resolved call the callback """ while self._running.is_set(): try: frame = yield self._get_frame() info = self._split_response(frame.d...
[ "def", "process_frames", "(", "self", ")", ":", "while", "self", ".", "_running", ".", "is_set", "(", ")", ":", "try", ":", "frame", "=", "yield", "self", ".", "_get_frame", "(", ")", "info", "=", "self", ".", "_split_response", "(", "frame", ".", "d...
process_frames: None -> None Wait for a frame to become available, when resolved call the callback
[ "process_frames", ":", "None", "-", ">", "None" ]
train
https://github.com/niolabs/python-xbee/blob/b91be3d0ee7ccaa1990120b5b5490999d8e6cbc7/xbee/tornado/base.py#L86-L101
niolabs/python-xbee
xbee/tornado/base.py
XBeeBase._process_input
def _process_input(self, data, events): """ _process_input: _process_input will be notified when there is data ready on the serial connection to be read. It will read and process the data into an API Frame and then either resolve a frame future, or push the frame into t...
python
def _process_input(self, data, events): """ _process_input: _process_input will be notified when there is data ready on the serial connection to be read. It will read and process the data into an API Frame and then either resolve a frame future, or push the frame into t...
[ "def", "_process_input", "(", "self", ",", "data", ",", "events", ")", ":", "frame", "=", "APIFrame", "(", "escaped", "=", "self", ".", "_escaped", ")", "byte", "=", "self", ".", "serial", ".", "read", "(", ")", "if", "byte", "!=", "APIFrame", ".", ...
_process_input: _process_input will be notified when there is data ready on the serial connection to be read. It will read and process the data into an API Frame and then either resolve a frame future, or push the frame into the queue of frames needing to be processed
[ "_process_input", ":" ]
train
https://github.com/niolabs/python-xbee/blob/b91be3d0ee7ccaa1990120b5b5490999d8e6cbc7/xbee/tornado/base.py#L127-L167
niolabs/python-xbee
scripts/shell.py
XBeeShell.do_serial
def do_serial(self, p): """Set the serial port, e.g.: /dev/tty.usbserial-A4001ib8""" try: self.serial.port = p self.serial.open() print 'Opening serial port: %s' % p except Exception, e: print 'Unable to open serial port: %s' % p
python
def do_serial(self, p): """Set the serial port, e.g.: /dev/tty.usbserial-A4001ib8""" try: self.serial.port = p self.serial.open() print 'Opening serial port: %s' % p except Exception, e: print 'Unable to open serial port: %s' % p
[ "def", "do_serial", "(", "self", ",", "p", ")", ":", "try", ":", "self", ".", "serial", ".", "port", "=", "p", "self", ".", "serial", ".", "open", "(", ")", "print", "'Opening serial port: %s'", "%", "p", "except", "Exception", ",", "e", ":", "print"...
Set the serial port, e.g.: /dev/tty.usbserial-A4001ib8
[ "Set", "the", "serial", "port", "e", ".", "g", ".", ":", "/", "dev", "/", "tty", ".", "usbserial", "-", "A4001ib8" ]
train
https://github.com/niolabs/python-xbee/blob/b91be3d0ee7ccaa1990120b5b5490999d8e6cbc7/scripts/shell.py#L42-L49
niolabs/python-xbee
xbee/helpers/dispatch/dispatch.py
Dispatch.register
def register(self, name, callback, filter): """ register: string, function: string, data -> None, function: data -> boolean -> None Register will save the given name, callback, and filter function for use when a packet arrives. When one arrives, the filter function will ...
python
def register(self, name, callback, filter): """ register: string, function: string, data -> None, function: data -> boolean -> None Register will save the given name, callback, and filter function for use when a packet arrives. When one arrives, the filter function will ...
[ "def", "register", "(", "self", ",", "name", ",", "callback", ",", "filter", ")", ":", "if", "name", "in", "self", ".", "names", ":", "raise", "ValueError", "(", "\"A callback has already been registered with \\\n the name '%s'\"", "%", "na...
register: string, function: string, data -> None, function: data -> boolean -> None Register will save the given name, callback, and filter function for use when a packet arrives. When one arrives, the filter function will be called to determine whether to call its associated ca...
[ "register", ":", "string", "function", ":", "string", "data", "-", ">", "None", "function", ":", "data", "-", ">", "boolean", "-", ">", "None" ]
train
https://github.com/niolabs/python-xbee/blob/b91be3d0ee7ccaa1990120b5b5490999d8e6cbc7/xbee/helpers/dispatch/dispatch.py#L26-L48
niolabs/python-xbee
xbee/helpers/dispatch/dispatch.py
Dispatch.run
def run(self, oneshot=False): """ run: boolean -> None run will read and dispatch any packet which arrives from the XBee device """ if not self.xbee: raise ValueError("Either a serial port or an XBee must be provided \ to __init__...
python
def run(self, oneshot=False): """ run: boolean -> None run will read and dispatch any packet which arrives from the XBee device """ if not self.xbee: raise ValueError("Either a serial port or an XBee must be provided \ to __init__...
[ "def", "run", "(", "self", ",", "oneshot", "=", "False", ")", ":", "if", "not", "self", ".", "xbee", ":", "raise", "ValueError", "(", "\"Either a serial port or an XBee must be provided \\\n to __init__ to execute run()\"", ")", "while", "True"...
run: boolean -> None run will read and dispatch any packet which arrives from the XBee device
[ "run", ":", "boolean", "-", ">", "None" ]
train
https://github.com/niolabs/python-xbee/blob/b91be3d0ee7ccaa1990120b5b5490999d8e6cbc7/xbee/helpers/dispatch/dispatch.py#L50-L65
niolabs/python-xbee
xbee/helpers/dispatch/dispatch.py
Dispatch.dispatch
def dispatch(self, packet): """ dispatch: XBee data dict -> None When called, dispatch checks the given packet against each registered callback method and calls each callback whose filter function returns true. """ for handler in self.handlers: if han...
python
def dispatch(self, packet): """ dispatch: XBee data dict -> None When called, dispatch checks the given packet against each registered callback method and calls each callback whose filter function returns true. """ for handler in self.handlers: if han...
[ "def", "dispatch", "(", "self", ",", "packet", ")", ":", "for", "handler", "in", "self", ".", "handlers", ":", "if", "handler", "[", "'filter'", "]", "(", "packet", ")", ":", "# Call the handler method with its associated", "# name and the packet which passed its fi...
dispatch: XBee data dict -> None When called, dispatch checks the given packet against each registered callback method and calls each callback whose filter function returns true.
[ "dispatch", ":", "XBee", "data", "dict", "-", ">", "None" ]
train
https://github.com/niolabs/python-xbee/blob/b91be3d0ee7ccaa1990120b5b5490999d8e6cbc7/xbee/helpers/dispatch/dispatch.py#L67-L79
niolabs/python-xbee
xbee/python2to3.py
byteToInt
def byteToInt(byte): """ byte -> int Determines whether to use ord() or not to get a byte's value. """ if hasattr(byte, 'bit_length'): # This is already an int return byte return ord(byte) if hasattr(byte, 'encode') else byte[0]
python
def byteToInt(byte): """ byte -> int Determines whether to use ord() or not to get a byte's value. """ if hasattr(byte, 'bit_length'): # This is already an int return byte return ord(byte) if hasattr(byte, 'encode') else byte[0]
[ "def", "byteToInt", "(", "byte", ")", ":", "if", "hasattr", "(", "byte", ",", "'bit_length'", ")", ":", "# This is already an int", "return", "byte", "return", "ord", "(", "byte", ")", "if", "hasattr", "(", "byte", ",", "'encode'", ")", "else", "byte", "...
byte -> int Determines whether to use ord() or not to get a byte's value.
[ "byte", "-", ">", "int" ]
train
https://github.com/niolabs/python-xbee/blob/b91be3d0ee7ccaa1990120b5b5490999d8e6cbc7/xbee/python2to3.py#L10-L19