repo stringlengths 7 55 | path stringlengths 4 127 | func_name stringlengths 1 88 | original_string stringlengths 75 19.8k | language stringclasses 1
value | code stringlengths 75 19.8k | code_tokens list | docstring stringlengths 3 17.3k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 87 242 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
theelous3/multio | multio/__init__.py | SocketWrapper.wrap | def wrap(cls, meth):
'''
Wraps a connection opening method in this class.
'''
async def inner(*args, **kwargs):
sock = await meth(*args, **kwargs)
return cls(sock)
return inner | python | def wrap(cls, meth):
'''
Wraps a connection opening method in this class.
'''
async def inner(*args, **kwargs):
sock = await meth(*args, **kwargs)
return cls(sock)
return inner | [
"def",
"wrap",
"(",
"cls",
",",
"meth",
")",
":",
"async",
"def",
"inner",
"(",
"*",
"args",
",",
"**",
"kwargs",
")",
":",
"sock",
"=",
"await",
"meth",
"(",
"*",
"args",
",",
"**",
"kwargs",
")",
"return",
"cls",
"(",
"sock",
")",
"return",
"... | Wraps a connection opening method in this class. | [
"Wraps",
"a",
"connection",
"opening",
"method",
"in",
"this",
"class",
"."
] | 018e4a9f78d5f4e78608a1a1537000b5fd778bbe | https://github.com/theelous3/multio/blob/018e4a9f78d5f4e78608a1a1537000b5fd778bbe/multio/__init__.py#L112-L121 | train |
theelous3/multio | multio/__init__.py | Event.set | async def set(self, *args, **kwargs):
'''
Sets the value of the event.
'''
return await _maybe_await(self.event.set(*args, **kwargs)) | python | async def set(self, *args, **kwargs):
'''
Sets the value of the event.
'''
return await _maybe_await(self.event.set(*args, **kwargs)) | [
"async",
"def",
"set",
"(",
"self",
",",
"*",
"args",
",",
"**",
"kwargs",
")",
":",
"return",
"await",
"_maybe_await",
"(",
"self",
".",
"event",
".",
"set",
"(",
"*",
"args",
",",
"**",
"kwargs",
")",
")"
] | Sets the value of the event. | [
"Sets",
"the",
"value",
"of",
"the",
"event",
"."
] | 018e4a9f78d5f4e78608a1a1537000b5fd778bbe | https://github.com/theelous3/multio/blob/018e4a9f78d5f4e78608a1a1537000b5fd778bbe/multio/__init__.py#L168-L172 | train |
theelous3/multio | multio/__init__.py | _AsyncLibManager.register | def register(self, library: str, cbl: Callable[['_AsyncLib'], None]):
'''
Registers a callable to set up a library.
'''
self._handlers[library] = cbl | python | def register(self, library: str, cbl: Callable[['_AsyncLib'], None]):
'''
Registers a callable to set up a library.
'''
self._handlers[library] = cbl | [
"def",
"register",
"(",
"self",
",",
"library",
":",
"str",
",",
"cbl",
":",
"Callable",
"[",
"[",
"'_AsyncLib'",
"]",
",",
"None",
"]",
")",
":",
"self",
".",
"_handlers",
"[",
"library",
"]",
"=",
"cbl"
] | Registers a callable to set up a library. | [
"Registers",
"a",
"callable",
"to",
"set",
"up",
"a",
"library",
"."
] | 018e4a9f78d5f4e78608a1a1537000b5fd778bbe | https://github.com/theelous3/multio/blob/018e4a9f78d5f4e78608a1a1537000b5fd778bbe/multio/__init__.py#L253-L257 | train |
theelous3/multio | multio/_event_loop_wrappers.py | trio_open_connection | async def trio_open_connection(host, port, *, ssl=False, **kwargs):
'''
Allows connections to be made that may or may not require ssl.
Somewhat surprisingly trio doesn't have an abstraction for this like
curio even though it's fairly trivial to write. Down the line hopefully.
Args:
host (st... | python | async def trio_open_connection(host, port, *, ssl=False, **kwargs):
'''
Allows connections to be made that may or may not require ssl.
Somewhat surprisingly trio doesn't have an abstraction for this like
curio even though it's fairly trivial to write. Down the line hopefully.
Args:
host (st... | [
"async",
"def",
"trio_open_connection",
"(",
"host",
",",
"port",
",",
"*",
",",
"ssl",
"=",
"False",
",",
"**",
"kwargs",
")",
":",
"import",
"trio",
"if",
"not",
"ssl",
":",
"sock",
"=",
"await",
"trio",
".",
"open_tcp_stream",
"(",
"host",
",",
"p... | Allows connections to be made that may or may not require ssl.
Somewhat surprisingly trio doesn't have an abstraction for this like
curio even though it's fairly trivial to write. Down the line hopefully.
Args:
host (str): Network location, either by domain or IP.
port (int): The requested ... | [
"Allows",
"connections",
"to",
"be",
"made",
"that",
"may",
"or",
"may",
"not",
"require",
"ssl",
".",
"Somewhat",
"surprisingly",
"trio",
"doesn",
"t",
"have",
"an",
"abstraction",
"for",
"this",
"like",
"curio",
"even",
"though",
"it",
"s",
"fairly",
"tr... | 018e4a9f78d5f4e78608a1a1537000b5fd778bbe | https://github.com/theelous3/multio/blob/018e4a9f78d5f4e78608a1a1537000b5fd778bbe/multio/_event_loop_wrappers.py#L12-L39 | train |
Fizzadar/pyinfra | pyinfra/modules/puppet.py | agent | def agent(state, host, server=None, port=None):
"""
Run puppet agent
+ server: master server URL
+ port: puppet master port
"""
args = []
if server:
args.append('--server=%s' % server)
if port:
args.append('--masterport=%s' % port)
yield 'puppet agent -t %s' % ' '... | python | def agent(state, host, server=None, port=None):
"""
Run puppet agent
+ server: master server URL
+ port: puppet master port
"""
args = []
if server:
args.append('--server=%s' % server)
if port:
args.append('--masterport=%s' % port)
yield 'puppet agent -t %s' % ' '... | [
"def",
"agent",
"(",
"state",
",",
"host",
",",
"server",
"=",
"None",
",",
"port",
"=",
"None",
")",
":",
"args",
"=",
"[",
"]",
"if",
"server",
":",
"args",
".",
"append",
"(",
"'--server=%s'",
"%",
"server",
")",
"if",
"port",
":",
"args",
"."... | Run puppet agent
+ server: master server URL
+ port: puppet master port | [
"Run",
"puppet",
"agent"
] | 006f751f7db2e07d32522c0285160783de2feb79 | https://github.com/Fizzadar/pyinfra/blob/006f751f7db2e07d32522c0285160783de2feb79/pyinfra/modules/puppet.py#L5-L20 | train |
Fizzadar/pyinfra | pyinfra_cli/config.py | load_config | def load_config(deploy_dir):
'''
Loads any local config.py file.
'''
config = Config()
config_filename = path.join(deploy_dir, 'config.py')
if path.exists(config_filename):
extract_file_config(config_filename, config)
# Now execute the file to trigger loading of any hooks
... | python | def load_config(deploy_dir):
'''
Loads any local config.py file.
'''
config = Config()
config_filename = path.join(deploy_dir, 'config.py')
if path.exists(config_filename):
extract_file_config(config_filename, config)
# Now execute the file to trigger loading of any hooks
... | [
"def",
"load_config",
"(",
"deploy_dir",
")",
":",
"config",
"=",
"Config",
"(",
")",
"config_filename",
"=",
"path",
".",
"join",
"(",
"deploy_dir",
",",
"'config.py'",
")",
"if",
"path",
".",
"exists",
"(",
"config_filename",
")",
":",
"extract_file_config... | Loads any local config.py file. | [
"Loads",
"any",
"local",
"config",
".",
"py",
"file",
"."
] | 006f751f7db2e07d32522c0285160783de2feb79 | https://github.com/Fizzadar/pyinfra/blob/006f751f7db2e07d32522c0285160783de2feb79/pyinfra_cli/config.py#L67-L81 | train |
Fizzadar/pyinfra | pyinfra_cli/config.py | load_deploy_config | def load_deploy_config(deploy_filename, config=None):
'''
Loads any local config overrides in the deploy file.
'''
if not config:
config = Config()
if not deploy_filename:
return
if path.exists(deploy_filename):
extract_file_config(deploy_filename, config)
return ... | python | def load_deploy_config(deploy_filename, config=None):
'''
Loads any local config overrides in the deploy file.
'''
if not config:
config = Config()
if not deploy_filename:
return
if path.exists(deploy_filename):
extract_file_config(deploy_filename, config)
return ... | [
"def",
"load_deploy_config",
"(",
"deploy_filename",
",",
"config",
"=",
"None",
")",
":",
"if",
"not",
"config",
":",
"config",
"=",
"Config",
"(",
")",
"if",
"not",
"deploy_filename",
":",
"return",
"if",
"path",
".",
"exists",
"(",
"deploy_filename",
")... | Loads any local config overrides in the deploy file. | [
"Loads",
"any",
"local",
"config",
"overrides",
"in",
"the",
"deploy",
"file",
"."
] | 006f751f7db2e07d32522c0285160783de2feb79 | https://github.com/Fizzadar/pyinfra/blob/006f751f7db2e07d32522c0285160783de2feb79/pyinfra_cli/config.py#L84-L98 | train |
Fizzadar/pyinfra | pyinfra/facts/iptables.py | parse_iptables_rule | def parse_iptables_rule(line):
'''
Parse one iptables rule. Returns a dict where each iptables code argument
is mapped to a name using IPTABLES_ARGS.
'''
bits = line.split()
definition = {}
key = None
args = []
not_arg = False
def add_args():
arg_string = ' '.join(arg... | python | def parse_iptables_rule(line):
'''
Parse one iptables rule. Returns a dict where each iptables code argument
is mapped to a name using IPTABLES_ARGS.
'''
bits = line.split()
definition = {}
key = None
args = []
not_arg = False
def add_args():
arg_string = ' '.join(arg... | [
"def",
"parse_iptables_rule",
"(",
"line",
")",
":",
"bits",
"=",
"line",
".",
"split",
"(",
")",
"definition",
"=",
"{",
"}",
"key",
"=",
"None",
"args",
"=",
"[",
"]",
"not_arg",
"=",
"False",
"def",
"add_args",
"(",
")",
":",
"arg_string",
"=",
... | Parse one iptables rule. Returns a dict where each iptables code argument
is mapped to a name using IPTABLES_ARGS. | [
"Parse",
"one",
"iptables",
"rule",
".",
"Returns",
"a",
"dict",
"where",
"each",
"iptables",
"code",
"argument",
"is",
"mapped",
"to",
"a",
"name",
"using",
"IPTABLES_ARGS",
"."
] | 006f751f7db2e07d32522c0285160783de2feb79 | https://github.com/Fizzadar/pyinfra/blob/006f751f7db2e07d32522c0285160783de2feb79/pyinfra/facts/iptables.py#L31-L84 | train |
Fizzadar/pyinfra | pyinfra/api/operation.py | add_op | def add_op(state, op_func, *args, **kwargs):
'''
Prepare & add an operation to ``pyinfra.state`` by executing it on all hosts.
Args:
state (``pyinfra.api.State`` obj): the deploy state to add the operation
to op_func (function): the operation function from one of the modules,
ie ``s... | python | def add_op(state, op_func, *args, **kwargs):
'''
Prepare & add an operation to ``pyinfra.state`` by executing it on all hosts.
Args:
state (``pyinfra.api.State`` obj): the deploy state to add the operation
to op_func (function): the operation function from one of the modules,
ie ``s... | [
"def",
"add_op",
"(",
"state",
",",
"op_func",
",",
"*",
"args",
",",
"**",
"kwargs",
")",
":",
"frameinfo",
"=",
"get_caller_frameinfo",
"(",
")",
"kwargs",
"[",
"'frameinfo'",
"]",
"=",
"frameinfo",
"for",
"host",
"in",
"state",
".",
"inventory",
":",
... | Prepare & add an operation to ``pyinfra.state`` by executing it on all hosts.
Args:
state (``pyinfra.api.State`` obj): the deploy state to add the operation
to op_func (function): the operation function from one of the modules,
ie ``server.user``
args/kwargs: passed to the operation... | [
"Prepare",
"&",
"add",
"an",
"operation",
"to",
"pyinfra",
".",
"state",
"by",
"executing",
"it",
"on",
"all",
"hosts",
"."
] | 006f751f7db2e07d32522c0285160783de2feb79 | https://github.com/Fizzadar/pyinfra/blob/006f751f7db2e07d32522c0285160783de2feb79/pyinfra/api/operation.py#L59-L74 | train |
Fizzadar/pyinfra | pyinfra/api/deploy.py | add_deploy | def add_deploy(state, deploy_func, *args, **kwargs):
'''
Prepare & add an deploy to pyinfra.state by executing it on all hosts.
Args:
state (``pyinfra.api.State`` obj): the deploy state to add the operation
deploy_func (function): the operation function from one of the modules,
ie `... | python | def add_deploy(state, deploy_func, *args, **kwargs):
'''
Prepare & add an deploy to pyinfra.state by executing it on all hosts.
Args:
state (``pyinfra.api.State`` obj): the deploy state to add the operation
deploy_func (function): the operation function from one of the modules,
ie `... | [
"def",
"add_deploy",
"(",
"state",
",",
"deploy_func",
",",
"*",
"args",
",",
"**",
"kwargs",
")",
":",
"frameinfo",
"=",
"get_caller_frameinfo",
"(",
")",
"kwargs",
"[",
"'frameinfo'",
"]",
"=",
"frameinfo",
"for",
"host",
"in",
"state",
".",
"inventory",... | Prepare & add an deploy to pyinfra.state by executing it on all hosts.
Args:
state (``pyinfra.api.State`` obj): the deploy state to add the operation
deploy_func (function): the operation function from one of the modules,
ie ``server.user``
args/kwargs: passed to the operation funct... | [
"Prepare",
"&",
"add",
"an",
"deploy",
"to",
"pyinfra",
".",
"state",
"by",
"executing",
"it",
"on",
"all",
"hosts",
"."
] | 006f751f7db2e07d32522c0285160783de2feb79 | https://github.com/Fizzadar/pyinfra/blob/006f751f7db2e07d32522c0285160783de2feb79/pyinfra/api/deploy.py#L24-L39 | train |
Fizzadar/pyinfra | pyinfra_cli/legacy.py | setup_arguments | def setup_arguments(arguments):
'''
Prepares argumnents output by docopt.
'''
# Ensure parallel/port are numbers
for key in ('--parallel', '--port', '--fail-percent'):
if arguments[key]:
try:
arguments[key] = int(arguments[key])
except ValueError:
... | python | def setup_arguments(arguments):
'''
Prepares argumnents output by docopt.
'''
# Ensure parallel/port are numbers
for key in ('--parallel', '--port', '--fail-percent'):
if arguments[key]:
try:
arguments[key] = int(arguments[key])
except ValueError:
... | [
"def",
"setup_arguments",
"(",
"arguments",
")",
":",
"for",
"key",
"in",
"(",
"'--parallel'",
",",
"'--port'",
",",
"'--fail-percent'",
")",
":",
"if",
"arguments",
"[",
"key",
"]",
":",
"try",
":",
"arguments",
"[",
"key",
"]",
"=",
"int",
"(",
"argu... | Prepares argumnents output by docopt. | [
"Prepares",
"argumnents",
"output",
"by",
"docopt",
"."
] | 006f751f7db2e07d32522c0285160783de2feb79 | https://github.com/Fizzadar/pyinfra/blob/006f751f7db2e07d32522c0285160783de2feb79/pyinfra_cli/legacy.py#L210-L272 | train |
Fizzadar/pyinfra | pyinfra/modules/mysql.py | sql | def sql(
state, host, sql,
database=None,
# Details for speaking to MySQL via `mysql` CLI
mysql_user=None, mysql_password=None,
mysql_host=None, mysql_port=None,
):
'''
Execute arbitrary SQL against MySQL.
+ sql: SQL command(s) to execute
+ database: optional database to open the co... | python | def sql(
state, host, sql,
database=None,
# Details for speaking to MySQL via `mysql` CLI
mysql_user=None, mysql_password=None,
mysql_host=None, mysql_port=None,
):
'''
Execute arbitrary SQL against MySQL.
+ sql: SQL command(s) to execute
+ database: optional database to open the co... | [
"def",
"sql",
"(",
"state",
",",
"host",
",",
"sql",
",",
"database",
"=",
"None",
",",
"mysql_user",
"=",
"None",
",",
"mysql_password",
"=",
"None",
",",
"mysql_host",
"=",
"None",
",",
"mysql_port",
"=",
"None",
",",
")",
":",
"yield",
"make_execute... | Execute arbitrary SQL against MySQL.
+ sql: SQL command(s) to execute
+ database: optional database to open the connection with
+ mysql_*: global module arguments, see above | [
"Execute",
"arbitrary",
"SQL",
"against",
"MySQL",
"."
] | 006f751f7db2e07d32522c0285160783de2feb79 | https://github.com/Fizzadar/pyinfra/blob/006f751f7db2e07d32522c0285160783de2feb79/pyinfra/modules/mysql.py#L24-L46 | train |
Fizzadar/pyinfra | pyinfra/modules/mysql.py | dump | def dump(
state, host,
remote_filename, database=None,
# Details for speaking to MySQL via `mysql` CLI
mysql_user=None, mysql_password=None,
mysql_host=None, mysql_port=None,
):
'''
Dump a MySQL database into a ``.sql`` file. Requires ``mysqldump``.
+ database: name of the database to d... | python | def dump(
state, host,
remote_filename, database=None,
# Details for speaking to MySQL via `mysql` CLI
mysql_user=None, mysql_password=None,
mysql_host=None, mysql_port=None,
):
'''
Dump a MySQL database into a ``.sql`` file. Requires ``mysqldump``.
+ database: name of the database to d... | [
"def",
"dump",
"(",
"state",
",",
"host",
",",
"remote_filename",
",",
"database",
"=",
"None",
",",
"mysql_user",
"=",
"None",
",",
"mysql_password",
"=",
"None",
",",
"mysql_host",
"=",
"None",
",",
"mysql_port",
"=",
"None",
",",
")",
":",
"yield",
... | Dump a MySQL database into a ``.sql`` file. Requires ``mysqldump``.
+ database: name of the database to dump
+ remote_filename: name of the file to dump the SQL to
+ mysql_*: global module arguments, see above | [
"Dump",
"a",
"MySQL",
"database",
"into",
"a",
".",
"sql",
"file",
".",
"Requires",
"mysqldump",
"."
] | 006f751f7db2e07d32522c0285160783de2feb79 | https://github.com/Fizzadar/pyinfra/blob/006f751f7db2e07d32522c0285160783de2feb79/pyinfra/modules/mysql.py#L306-L328 | train |
Fizzadar/pyinfra | pyinfra/api/inventory.py | Inventory.get_host | def get_host(self, name, default=NoHostError):
'''
Get a single host by name.
'''
if name in self.hosts:
return self.hosts[name]
if default is NoHostError:
raise NoHostError('No such host: {0}'.format(name))
return default | python | def get_host(self, name, default=NoHostError):
'''
Get a single host by name.
'''
if name in self.hosts:
return self.hosts[name]
if default is NoHostError:
raise NoHostError('No such host: {0}'.format(name))
return default | [
"def",
"get_host",
"(",
"self",
",",
"name",
",",
"default",
"=",
"NoHostError",
")",
":",
"if",
"name",
"in",
"self",
".",
"hosts",
":",
"return",
"self",
".",
"hosts",
"[",
"name",
"]",
"if",
"default",
"is",
"NoHostError",
":",
"raise",
"NoHostError... | Get a single host by name. | [
"Get",
"a",
"single",
"host",
"by",
"name",
"."
] | 006f751f7db2e07d32522c0285160783de2feb79 | https://github.com/Fizzadar/pyinfra/blob/006f751f7db2e07d32522c0285160783de2feb79/pyinfra/api/inventory.py#L258-L269 | train |
Fizzadar/pyinfra | pyinfra/api/inventory.py | Inventory.get_group | def get_group(self, name, default=NoGroupError):
'''
Get a list of hosts belonging to a group.
'''
if name in self.groups:
return self.groups[name]
if default is NoGroupError:
raise NoGroupError('No such group: {0}'.format(name))
return default | python | def get_group(self, name, default=NoGroupError):
'''
Get a list of hosts belonging to a group.
'''
if name in self.groups:
return self.groups[name]
if default is NoGroupError:
raise NoGroupError('No such group: {0}'.format(name))
return default | [
"def",
"get_group",
"(",
"self",
",",
"name",
",",
"default",
"=",
"NoGroupError",
")",
":",
"if",
"name",
"in",
"self",
".",
"groups",
":",
"return",
"self",
".",
"groups",
"[",
"name",
"]",
"if",
"default",
"is",
"NoGroupError",
":",
"raise",
"NoGrou... | Get a list of hosts belonging to a group. | [
"Get",
"a",
"list",
"of",
"hosts",
"belonging",
"to",
"a",
"group",
"."
] | 006f751f7db2e07d32522c0285160783de2feb79 | https://github.com/Fizzadar/pyinfra/blob/006f751f7db2e07d32522c0285160783de2feb79/pyinfra/api/inventory.py#L271-L282 | train |
Fizzadar/pyinfra | pyinfra/api/inventory.py | Inventory.get_groups_data | def get_groups_data(self, groups):
'''
Gets aggregated data from a list of groups. Vars are collected in order so, for
any groups which define the same var twice, the last group's value will hold.
'''
data = {}
for group in groups:
data.update(self.get_group... | python | def get_groups_data(self, groups):
'''
Gets aggregated data from a list of groups. Vars are collected in order so, for
any groups which define the same var twice, the last group's value will hold.
'''
data = {}
for group in groups:
data.update(self.get_group... | [
"def",
"get_groups_data",
"(",
"self",
",",
"groups",
")",
":",
"data",
"=",
"{",
"}",
"for",
"group",
"in",
"groups",
":",
"data",
".",
"update",
"(",
"self",
".",
"get_group_data",
"(",
"group",
")",
")",
"return",
"data"
] | Gets aggregated data from a list of groups. Vars are collected in order so, for
any groups which define the same var twice, the last group's value will hold. | [
"Gets",
"aggregated",
"data",
"from",
"a",
"list",
"of",
"groups",
".",
"Vars",
"are",
"collected",
"in",
"order",
"so",
"for",
"any",
"groups",
"which",
"define",
"the",
"same",
"var",
"twice",
"the",
"last",
"group",
"s",
"value",
"will",
"hold",
"."
] | 006f751f7db2e07d32522c0285160783de2feb79 | https://github.com/Fizzadar/pyinfra/blob/006f751f7db2e07d32522c0285160783de2feb79/pyinfra/api/inventory.py#L312-L323 | train |
Fizzadar/pyinfra | pyinfra/api/inventory.py | Inventory.get_deploy_data | def get_deploy_data(self):
'''
Gets any default data attached to the current deploy, if any.
'''
if self.state and self.state.deploy_data:
return self.state.deploy_data
return {} | python | def get_deploy_data(self):
'''
Gets any default data attached to the current deploy, if any.
'''
if self.state and self.state.deploy_data:
return self.state.deploy_data
return {} | [
"def",
"get_deploy_data",
"(",
"self",
")",
":",
"if",
"self",
".",
"state",
"and",
"self",
".",
"state",
".",
"deploy_data",
":",
"return",
"self",
".",
"state",
".",
"deploy_data",
"return",
"{",
"}"
] | Gets any default data attached to the current deploy, if any. | [
"Gets",
"any",
"default",
"data",
"attached",
"to",
"the",
"current",
"deploy",
"if",
"any",
"."
] | 006f751f7db2e07d32522c0285160783de2feb79 | https://github.com/Fizzadar/pyinfra/blob/006f751f7db2e07d32522c0285160783de2feb79/pyinfra/api/inventory.py#L325-L333 | train |
Fizzadar/pyinfra | pyinfra/modules/git.py | config | def config(
state, host, key, value,
repo=None,
):
'''
Manage git config for a repository or globally.
+ key: the key of the config to ensure
+ value: the value this key should have
+ repo: specify the git repo path to edit local config (defaults to global)
'''
existing_config = ho... | python | def config(
state, host, key, value,
repo=None,
):
'''
Manage git config for a repository or globally.
+ key: the key of the config to ensure
+ value: the value this key should have
+ repo: specify the git repo path to edit local config (defaults to global)
'''
existing_config = ho... | [
"def",
"config",
"(",
"state",
",",
"host",
",",
"key",
",",
"value",
",",
"repo",
"=",
"None",
",",
")",
":",
"existing_config",
"=",
"host",
".",
"fact",
".",
"git_config",
"(",
"repo",
")",
"if",
"key",
"not",
"in",
"existing_config",
"or",
"exist... | Manage git config for a repository or globally.
+ key: the key of the config to ensure
+ value: the value this key should have
+ repo: specify the git repo path to edit local config (defaults to global) | [
"Manage",
"git",
"config",
"for",
"a",
"repository",
"or",
"globally",
"."
] | 006f751f7db2e07d32522c0285160783de2feb79 | https://github.com/Fizzadar/pyinfra/blob/006f751f7db2e07d32522c0285160783de2feb79/pyinfra/modules/git.py#L23-L41 | train |
Fizzadar/pyinfra | pyinfra/local.py | include | def include(filename, hosts=False, when=True):
'''
Executes a local python file within the ``pyinfra.pseudo_state.deploy_dir``
directory.
Args:
hosts (string, list): group name or list of hosts to limit this include to
when (bool): indicate whether to trigger operations in this include
... | python | def include(filename, hosts=False, when=True):
'''
Executes a local python file within the ``pyinfra.pseudo_state.deploy_dir``
directory.
Args:
hosts (string, list): group name or list of hosts to limit this include to
when (bool): indicate whether to trigger operations in this include
... | [
"def",
"include",
"(",
"filename",
",",
"hosts",
"=",
"False",
",",
"when",
"=",
"True",
")",
":",
"if",
"not",
"pyinfra",
".",
"is_cli",
":",
"raise",
"PyinfraError",
"(",
"'local.include is only available in CLI mode.'",
")",
"if",
"not",
"when",
":",
"ret... | Executes a local python file within the ``pyinfra.pseudo_state.deploy_dir``
directory.
Args:
hosts (string, list): group name or list of hosts to limit this include to
when (bool): indicate whether to trigger operations in this include | [
"Executes",
"a",
"local",
"python",
"file",
"within",
"the",
"pyinfra",
".",
"pseudo_state",
".",
"deploy_dir",
"directory",
"."
] | 006f751f7db2e07d32522c0285160783de2feb79 | https://github.com/Fizzadar/pyinfra/blob/006f751f7db2e07d32522c0285160783de2feb79/pyinfra/local.py#L19-L78 | train |
jdowner/gist | gist/gist.py | GistAPI.send | def send(self, request, stem=None):
"""Prepare and send a request
Arguments:
request: a Request object that is not yet prepared
stem: a path to append to the root URL
Returns:
The response to the request
"""
if stem is not None:
... | python | def send(self, request, stem=None):
"""Prepare and send a request
Arguments:
request: a Request object that is not yet prepared
stem: a path to append to the root URL
Returns:
The response to the request
"""
if stem is not None:
... | [
"def",
"send",
"(",
"self",
",",
"request",
",",
"stem",
"=",
"None",
")",
":",
"if",
"stem",
"is",
"not",
"None",
":",
"request",
".",
"url",
"=",
"request",
".",
"url",
"+",
"\"/\"",
"+",
"stem",
".",
"lstrip",
"(",
"\"/\"",
")",
"prepped",
"="... | Prepare and send a request
Arguments:
request: a Request object that is not yet prepared
stem: a path to append to the root URL
Returns:
The response to the request | [
"Prepare",
"and",
"send",
"a",
"request"
] | 0f2941434f63c5aed69218edad454de8c73819a0 | https://github.com/jdowner/gist/blob/0f2941434f63c5aed69218edad454de8c73819a0/gist/gist.py#L143-L164 | train |
jdowner/gist | gist/gist.py | GistAPI.list | def list(self):
"""Returns a list of the users gists as GistInfo objects
Returns:
a list of GistInfo objects
"""
# Define the basic request. The per_page parameter is set to 100, which
# is the maximum github allows. If the user has more than one page of
# g... | python | def list(self):
"""Returns a list of the users gists as GistInfo objects
Returns:
a list of GistInfo objects
"""
# Define the basic request. The per_page parameter is set to 100, which
# is the maximum github allows. If the user has more than one page of
# g... | [
"def",
"list",
"(",
"self",
")",
":",
"request",
"=",
"requests",
".",
"Request",
"(",
"'GET'",
",",
"'https://api.github.com/gists'",
",",
"headers",
"=",
"{",
"'Accept-Encoding'",
":",
"'identity, deflate, compress, gzip'",
",",
"'User-Agent'",
":",
"'python-reque... | Returns a list of the users gists as GistInfo objects
Returns:
a list of GistInfo objects | [
"Returns",
"a",
"list",
"of",
"the",
"users",
"gists",
"as",
"GistInfo",
"objects"
] | 0f2941434f63c5aed69218edad454de8c73819a0 | https://github.com/jdowner/gist/blob/0f2941434f63c5aed69218edad454de8c73819a0/gist/gist.py#L166-L239 | train |
jdowner/gist | gist/gist.py | GistAPI.create | def create(self, request, desc, files, public=False):
"""Creates a gist
Arguments:
request: an initial request object
desc: the gist description
files: a list of files to add to the gist
public: a flag to indicate whether the gist is public or not
... | python | def create(self, request, desc, files, public=False):
"""Creates a gist
Arguments:
request: an initial request object
desc: the gist description
files: a list of files to add to the gist
public: a flag to indicate whether the gist is public or not
... | [
"def",
"create",
"(",
"self",
",",
"request",
",",
"desc",
",",
"files",
",",
"public",
"=",
"False",
")",
":",
"request",
".",
"data",
"=",
"json",
".",
"dumps",
"(",
"{",
"\"description\"",
":",
"desc",
",",
"\"public\"",
":",
"public",
",",
"\"fil... | Creates a gist
Arguments:
request: an initial request object
desc: the gist description
files: a list of files to add to the gist
public: a flag to indicate whether the gist is public or not
Returns:
The URL to the newly created gist. | [
"Creates",
"a",
"gist"
] | 0f2941434f63c5aed69218edad454de8c73819a0 | https://github.com/jdowner/gist/blob/0f2941434f63c5aed69218edad454de8c73819a0/gist/gist.py#L242-L260 | train |
jdowner/gist | gist/gist.py | GistAPI.files | def files(self, request, id):
"""Returns a list of files in the gist
Arguments:
request: an initial request object
id: the gist identifier
Returns:
A list of the files
"""
gist = self.send(request, id).json()
return gist['files'... | python | def files(self, request, id):
"""Returns a list of files in the gist
Arguments:
request: an initial request object
id: the gist identifier
Returns:
A list of the files
"""
gist = self.send(request, id).json()
return gist['files'... | [
"def",
"files",
"(",
"self",
",",
"request",
",",
"id",
")",
":",
"gist",
"=",
"self",
".",
"send",
"(",
"request",
",",
"id",
")",
".",
"json",
"(",
")",
"return",
"gist",
"[",
"'files'",
"]"
] | Returns a list of files in the gist
Arguments:
request: an initial request object
id: the gist identifier
Returns:
A list of the files | [
"Returns",
"a",
"list",
"of",
"files",
"in",
"the",
"gist"
] | 0f2941434f63c5aed69218edad454de8c73819a0 | https://github.com/jdowner/gist/blob/0f2941434f63c5aed69218edad454de8c73819a0/gist/gist.py#L288-L300 | train |
jdowner/gist | gist/gist.py | GistAPI.content | def content(self, request, id):
"""Returns the content of the gist
Arguments:
request: an initial request object
id: the gist identifier
Returns:
A dict containing the contents of each file in the gist
"""
gist = self.send(request, id).... | python | def content(self, request, id):
"""Returns the content of the gist
Arguments:
request: an initial request object
id: the gist identifier
Returns:
A dict containing the contents of each file in the gist
"""
gist = self.send(request, id).... | [
"def",
"content",
"(",
"self",
",",
"request",
",",
"id",
")",
":",
"gist",
"=",
"self",
".",
"send",
"(",
"request",
",",
"id",
")",
".",
"json",
"(",
")",
"def",
"convert",
"(",
"data",
")",
":",
"return",
"base64",
".",
"b64decode",
"(",
"data... | Returns the content of the gist
Arguments:
request: an initial request object
id: the gist identifier
Returns:
A dict containing the contents of each file in the gist | [
"Returns",
"the",
"content",
"of",
"the",
"gist"
] | 0f2941434f63c5aed69218edad454de8c73819a0 | https://github.com/jdowner/gist/blob/0f2941434f63c5aed69218edad454de8c73819a0/gist/gist.py#L303-L323 | train |
jdowner/gist | gist/gist.py | GistAPI.archive | def archive(self, request, id):
"""Create an archive of a gist
The files in the gist are downloaded and added to a compressed archive
(tarball). If the ID of the gist was c78d925546e964b4b1df, the
resulting archive would be,
c78d925546e964b4b1df.tar.gz
The archive ... | python | def archive(self, request, id):
"""Create an archive of a gist
The files in the gist are downloaded and added to a compressed archive
(tarball). If the ID of the gist was c78d925546e964b4b1df, the
resulting archive would be,
c78d925546e964b4b1df.tar.gz
The archive ... | [
"def",
"archive",
"(",
"self",
",",
"request",
",",
"id",
")",
":",
"gist",
"=",
"self",
".",
"send",
"(",
"request",
",",
"id",
")",
".",
"json",
"(",
")",
"with",
"tarfile",
".",
"open",
"(",
"'{}.tar.gz'",
".",
"format",
"(",
"id",
")",
",",
... | Create an archive of a gist
The files in the gist are downloaded and added to a compressed archive
(tarball). If the ID of the gist was c78d925546e964b4b1df, the
resulting archive would be,
c78d925546e964b4b1df.tar.gz
The archive is created in the directory where the comma... | [
"Create",
"an",
"archive",
"of",
"a",
"gist"
] | 0f2941434f63c5aed69218edad454de8c73819a0 | https://github.com/jdowner/gist/blob/0f2941434f63c5aed69218edad454de8c73819a0/gist/gist.py#L326-L349 | train |
jdowner/gist | gist/gist.py | GistAPI.edit | def edit(self, request, id):
"""Edit a gist
The files in the gist a cloned to a temporary directory and passed to
the default editor (defined by the EDITOR environmental variable). When
the user exits the editor, they will be provided with a prompt to
commit the changes, which w... | python | def edit(self, request, id):
"""Edit a gist
The files in the gist a cloned to a temporary directory and passed to
the default editor (defined by the EDITOR environmental variable). When
the user exits the editor, they will be provided with a prompt to
commit the changes, which w... | [
"def",
"edit",
"(",
"self",
",",
"request",
",",
"id",
")",
":",
"with",
"pushd",
"(",
"tempfile",
".",
"gettempdir",
"(",
")",
")",
":",
"try",
":",
"self",
".",
"clone",
"(",
"id",
")",
"with",
"pushd",
"(",
"id",
")",
":",
"files",
"=",
"[",... | Edit a gist
The files in the gist a cloned to a temporary directory and passed to
the default editor (defined by the EDITOR environmental variable). When
the user exits the editor, they will be provided with a prompt to
commit the changes, which will then be pushed to the remote.
... | [
"Edit",
"a",
"gist"
] | 0f2941434f63c5aed69218edad454de8c73819a0 | https://github.com/jdowner/gist/blob/0f2941434f63c5aed69218edad454de8c73819a0/gist/gist.py#L352-L375 | train |
jdowner/gist | gist/gist.py | GistAPI.description | def description(self, request, id, description):
"""Updates the description of a gist
Arguments:
request: an initial request object
id: the id of the gist we want to edit the description for
description: the new description
"""
request.d... | python | def description(self, request, id, description):
"""Updates the description of a gist
Arguments:
request: an initial request object
id: the id of the gist we want to edit the description for
description: the new description
"""
request.d... | [
"def",
"description",
"(",
"self",
",",
"request",
",",
"id",
",",
"description",
")",
":",
"request",
".",
"data",
"=",
"json",
".",
"dumps",
"(",
"{",
"\"description\"",
":",
"description",
"}",
")",
"return",
"self",
".",
"send",
"(",
"request",
","... | Updates the description of a gist
Arguments:
request: an initial request object
id: the id of the gist we want to edit the description for
description: the new description | [
"Updates",
"the",
"description",
"of",
"a",
"gist"
] | 0f2941434f63c5aed69218edad454de8c73819a0 | https://github.com/jdowner/gist/blob/0f2941434f63c5aed69218edad454de8c73819a0/gist/gist.py#L391-L403 | train |
jdowner/gist | gist/gist.py | GistAPI.clone | def clone(self, id, name=None):
"""Clone a gist
Arguments:
id: the gist identifier
name: the name to give the cloned repo
"""
url = 'git@gist.github.com:/{}'.format(id)
if name is None:
os.system('git clone {}'.format(url))
else:
... | python | def clone(self, id, name=None):
"""Clone a gist
Arguments:
id: the gist identifier
name: the name to give the cloned repo
"""
url = 'git@gist.github.com:/{}'.format(id)
if name is None:
os.system('git clone {}'.format(url))
else:
... | [
"def",
"clone",
"(",
"self",
",",
"id",
",",
"name",
"=",
"None",
")",
":",
"url",
"=",
"'git@gist.github.com:/{}'",
".",
"format",
"(",
"id",
")",
"if",
"name",
"is",
"None",
":",
"os",
".",
"system",
"(",
"'git clone {}'",
".",
"format",
"(",
"url"... | Clone a gist
Arguments:
id: the gist identifier
name: the name to give the cloned repo | [
"Clone",
"a",
"gist"
] | 0f2941434f63c5aed69218edad454de8c73819a0 | https://github.com/jdowner/gist/blob/0f2941434f63c5aed69218edad454de8c73819a0/gist/gist.py#L405-L418 | train |
Fizzadar/pyinfra | pyinfra/modules/ssh.py | command | def command(state, host, hostname, command, ssh_user=None):
'''
Execute commands on other servers over SSH.
+ hostname: the hostname to connect to
+ command: the command to execute
+ ssh_user: connect with this user
'''
connection_target = hostname
if ssh_user:
connection_targe... | python | def command(state, host, hostname, command, ssh_user=None):
'''
Execute commands on other servers over SSH.
+ hostname: the hostname to connect to
+ command: the command to execute
+ ssh_user: connect with this user
'''
connection_target = hostname
if ssh_user:
connection_targe... | [
"def",
"command",
"(",
"state",
",",
"host",
",",
"hostname",
",",
"command",
",",
"ssh_user",
"=",
"None",
")",
":",
"connection_target",
"=",
"hostname",
"if",
"ssh_user",
":",
"connection_target",
"=",
"'@'",
".",
"join",
"(",
"(",
"ssh_user",
",",
"h... | Execute commands on other servers over SSH.
+ hostname: the hostname to connect to
+ command: the command to execute
+ ssh_user: connect with this user | [
"Execute",
"commands",
"on",
"other",
"servers",
"over",
"SSH",
"."
] | 006f751f7db2e07d32522c0285160783de2feb79 | https://github.com/Fizzadar/pyinfra/blob/006f751f7db2e07d32522c0285160783de2feb79/pyinfra/modules/ssh.py#L47-L60 | train |
Fizzadar/pyinfra | pyinfra/modules/ssh.py | upload | def upload(
state, host, hostname, filename,
remote_filename=None, use_remote_sudo=False,
ssh_keyscan=False, ssh_user=None,
):
'''
Upload files to other servers using ``scp``.
+ hostname: hostname to upload to
+ filename: file to upload
+ remote_filename: where to upload the file to (de... | python | def upload(
state, host, hostname, filename,
remote_filename=None, use_remote_sudo=False,
ssh_keyscan=False, ssh_user=None,
):
'''
Upload files to other servers using ``scp``.
+ hostname: hostname to upload to
+ filename: file to upload
+ remote_filename: where to upload the file to (de... | [
"def",
"upload",
"(",
"state",
",",
"host",
",",
"hostname",
",",
"filename",
",",
"remote_filename",
"=",
"None",
",",
"use_remote_sudo",
"=",
"False",
",",
"ssh_keyscan",
"=",
"False",
",",
"ssh_user",
"=",
"None",
",",
")",
":",
"remote_filename",
"=",
... | Upload files to other servers using ``scp``.
+ hostname: hostname to upload to
+ filename: file to upload
+ remote_filename: where to upload the file to (defaults to ``filename``)
+ use_remote_sudo: upload to a temporary location and move using sudo
+ ssh_keyscan: execute ``ssh.keyscan`` before upl... | [
"Upload",
"files",
"to",
"other",
"servers",
"using",
"scp",
"."
] | 006f751f7db2e07d32522c0285160783de2feb79 | https://github.com/Fizzadar/pyinfra/blob/006f751f7db2e07d32522c0285160783de2feb79/pyinfra/modules/ssh.py#L64-L108 | train |
Fizzadar/pyinfra | pyinfra/modules/ssh.py | download | def download(
state, host, hostname, filename,
local_filename=None, force=False,
ssh_keyscan=False, ssh_user=None,
):
'''
Download files from other servers using ``scp``.
+ hostname: hostname to upload to
+ filename: file to download
+ local_filename: where to download the file to (defa... | python | def download(
state, host, hostname, filename,
local_filename=None, force=False,
ssh_keyscan=False, ssh_user=None,
):
'''
Download files from other servers using ``scp``.
+ hostname: hostname to upload to
+ filename: file to download
+ local_filename: where to download the file to (defa... | [
"def",
"download",
"(",
"state",
",",
"host",
",",
"hostname",
",",
"filename",
",",
"local_filename",
"=",
"None",
",",
"force",
"=",
"False",
",",
"ssh_keyscan",
"=",
"False",
",",
"ssh_user",
"=",
"None",
",",
")",
":",
"local_filename",
"=",
"local_f... | Download files from other servers using ``scp``.
+ hostname: hostname to upload to
+ filename: file to download
+ local_filename: where to download the file to (defaults to ``filename``)
+ force: always download the file, even if present locally
+ ssh_keyscan: execute ``ssh.keyscan`` before uploadi... | [
"Download",
"files",
"from",
"other",
"servers",
"using",
"scp",
"."
] | 006f751f7db2e07d32522c0285160783de2feb79 | https://github.com/Fizzadar/pyinfra/blob/006f751f7db2e07d32522c0285160783de2feb79/pyinfra/modules/ssh.py#L112-L154 | train |
Fizzadar/pyinfra | pyinfra/api/util.py | pop_op_kwargs | def pop_op_kwargs(state, kwargs):
'''
Pop and return operation global keyword arguments.
'''
meta_kwargs = state.deploy_kwargs or {}
def get_kwarg(key, default=None):
return kwargs.pop(key, meta_kwargs.get(key, default))
# Get the env for this host: config env followed by command-leve... | python | def pop_op_kwargs(state, kwargs):
'''
Pop and return operation global keyword arguments.
'''
meta_kwargs = state.deploy_kwargs or {}
def get_kwarg(key, default=None):
return kwargs.pop(key, meta_kwargs.get(key, default))
# Get the env for this host: config env followed by command-leve... | [
"def",
"pop_op_kwargs",
"(",
"state",
",",
"kwargs",
")",
":",
"meta_kwargs",
"=",
"state",
".",
"deploy_kwargs",
"or",
"{",
"}",
"def",
"get_kwarg",
"(",
"key",
",",
"default",
"=",
"None",
")",
":",
"return",
"kwargs",
".",
"pop",
"(",
"key",
",",
... | Pop and return operation global keyword arguments. | [
"Pop",
"and",
"return",
"operation",
"global",
"keyword",
"arguments",
"."
] | 006f751f7db2e07d32522c0285160783de2feb79 | https://github.com/Fizzadar/pyinfra/blob/006f751f7db2e07d32522c0285160783de2feb79/pyinfra/api/util.py#L119-L177 | train |
Fizzadar/pyinfra | pyinfra/api/util.py | get_template | def get_template(filename_or_string, is_string=False):
'''
Gets a jinja2 ``Template`` object for the input filename or string, with caching
based on the filename of the template, or the SHA1 of the input string.
'''
# Cache against string sha or just the filename
cache_key = sha1_hash(filename_... | python | def get_template(filename_or_string, is_string=False):
'''
Gets a jinja2 ``Template`` object for the input filename or string, with caching
based on the filename of the template, or the SHA1 of the input string.
'''
# Cache against string sha or just the filename
cache_key = sha1_hash(filename_... | [
"def",
"get_template",
"(",
"filename_or_string",
",",
"is_string",
"=",
"False",
")",
":",
"cache_key",
"=",
"sha1_hash",
"(",
"filename_or_string",
")",
"if",
"is_string",
"else",
"filename_or_string",
"if",
"cache_key",
"in",
"TEMPLATES",
":",
"return",
"TEMPLA... | Gets a jinja2 ``Template`` object for the input filename or string, with caching
based on the filename of the template, or the SHA1 of the input string. | [
"Gets",
"a",
"jinja2",
"Template",
"object",
"for",
"the",
"input",
"filename",
"or",
"string",
"with",
"caching",
"based",
"on",
"the",
"filename",
"of",
"the",
"template",
"or",
"the",
"SHA1",
"of",
"the",
"input",
"string",
"."
] | 006f751f7db2e07d32522c0285160783de2feb79 | https://github.com/Fizzadar/pyinfra/blob/006f751f7db2e07d32522c0285160783de2feb79/pyinfra/api/util.py#L202-L224 | train |
Fizzadar/pyinfra | pyinfra/api/util.py | underscore | def underscore(name):
'''
Transform CamelCase -> snake_case.
'''
s1 = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', name)
return re.sub('([a-z0-9])([A-Z])', r'\1_\2', s1).lower() | python | def underscore(name):
'''
Transform CamelCase -> snake_case.
'''
s1 = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', name)
return re.sub('([a-z0-9])([A-Z])', r'\1_\2', s1).lower() | [
"def",
"underscore",
"(",
"name",
")",
":",
"s1",
"=",
"re",
".",
"sub",
"(",
"'(.)([A-Z][a-z]+)'",
",",
"r'\\1_\\2'",
",",
"name",
")",
"return",
"re",
".",
"sub",
"(",
"'([a-z0-9])([A-Z])'",
",",
"r'\\1_\\2'",
",",
"s1",
")",
".",
"lower",
"(",
")"
] | Transform CamelCase -> snake_case. | [
"Transform",
"CamelCase",
"-",
">",
"snake_case",
"."
] | 006f751f7db2e07d32522c0285160783de2feb79 | https://github.com/Fizzadar/pyinfra/blob/006f751f7db2e07d32522c0285160783de2feb79/pyinfra/api/util.py#L227-L233 | train |
Fizzadar/pyinfra | pyinfra/api/util.py | sha1_hash | def sha1_hash(string):
'''
Return the SHA1 of the input string.
'''
hasher = sha1()
hasher.update(string.encode())
return hasher.hexdigest() | python | def sha1_hash(string):
'''
Return the SHA1 of the input string.
'''
hasher = sha1()
hasher.update(string.encode())
return hasher.hexdigest() | [
"def",
"sha1_hash",
"(",
"string",
")",
":",
"hasher",
"=",
"sha1",
"(",
")",
"hasher",
".",
"update",
"(",
"string",
".",
"encode",
"(",
")",
")",
"return",
"hasher",
".",
"hexdigest",
"(",
")"
] | Return the SHA1 of the input string. | [
"Return",
"the",
"SHA1",
"of",
"the",
"input",
"string",
"."
] | 006f751f7db2e07d32522c0285160783de2feb79 | https://github.com/Fizzadar/pyinfra/blob/006f751f7db2e07d32522c0285160783de2feb79/pyinfra/api/util.py#L236-L243 | train |
Fizzadar/pyinfra | pyinfra/api/util.py | make_command | def make_command(
command,
env=None,
su_user=None,
sudo=False,
sudo_user=None,
preserve_sudo_env=False,
):
'''
Builds a shell command with various kwargs.
'''
debug_meta = {}
for key, value in (
('sudo', sudo),
('sudo_user', sudo_user),
('su_user', s... | python | def make_command(
command,
env=None,
su_user=None,
sudo=False,
sudo_user=None,
preserve_sudo_env=False,
):
'''
Builds a shell command with various kwargs.
'''
debug_meta = {}
for key, value in (
('sudo', sudo),
('sudo_user', sudo_user),
('su_user', s... | [
"def",
"make_command",
"(",
"command",
",",
"env",
"=",
"None",
",",
"su_user",
"=",
"None",
",",
"sudo",
"=",
"False",
",",
"sudo_user",
"=",
"None",
",",
"preserve_sudo_env",
"=",
"False",
",",
")",
":",
"debug_meta",
"=",
"{",
"}",
"for",
"key",
"... | Builds a shell command with various kwargs. | [
"Builds",
"a",
"shell",
"command",
"with",
"various",
"kwargs",
"."
] | 006f751f7db2e07d32522c0285160783de2feb79 | https://github.com/Fizzadar/pyinfra/blob/006f751f7db2e07d32522c0285160783de2feb79/pyinfra/api/util.py#L280-L339 | train |
Fizzadar/pyinfra | pyinfra/api/util.py | make_hash | def make_hash(obj):
'''
Make a hash from an arbitrary nested dictionary, list, tuple or set, used to generate
ID's for operations based on their name & arguments.
'''
if isinstance(obj, (set, tuple, list)):
hash_string = ''.join([make_hash(e) for e in obj])
elif isinstance(obj, dict):
... | python | def make_hash(obj):
'''
Make a hash from an arbitrary nested dictionary, list, tuple or set, used to generate
ID's for operations based on their name & arguments.
'''
if isinstance(obj, (set, tuple, list)):
hash_string = ''.join([make_hash(e) for e in obj])
elif isinstance(obj, dict):
... | [
"def",
"make_hash",
"(",
"obj",
")",
":",
"if",
"isinstance",
"(",
"obj",
",",
"(",
"set",
",",
"tuple",
",",
"list",
")",
")",
":",
"hash_string",
"=",
"''",
".",
"join",
"(",
"[",
"make_hash",
"(",
"e",
")",
"for",
"e",
"in",
"obj",
"]",
")",... | Make a hash from an arbitrary nested dictionary, list, tuple or set, used to generate
ID's for operations based on their name & arguments. | [
"Make",
"a",
"hash",
"from",
"an",
"arbitrary",
"nested",
"dictionary",
"list",
"tuple",
"or",
"set",
"used",
"to",
"generate",
"ID",
"s",
"for",
"operations",
"based",
"on",
"their",
"name",
"&",
"arguments",
"."
] | 006f751f7db2e07d32522c0285160783de2feb79 | https://github.com/Fizzadar/pyinfra/blob/006f751f7db2e07d32522c0285160783de2feb79/pyinfra/api/util.py#L376-L406 | train |
Fizzadar/pyinfra | pyinfra/api/util.py | get_file_sha1 | def get_file_sha1(filename_or_io):
'''
Calculates the SHA1 of a file or file object using a buffer to handle larger files.
'''
file_data = get_file_io(filename_or_io)
cache_key = file_data.cache_key
if cache_key and cache_key in FILE_SHAS:
return FILE_SHAS[cache_key]
with file_dat... | python | def get_file_sha1(filename_or_io):
'''
Calculates the SHA1 of a file or file object using a buffer to handle larger files.
'''
file_data = get_file_io(filename_or_io)
cache_key = file_data.cache_key
if cache_key and cache_key in FILE_SHAS:
return FILE_SHAS[cache_key]
with file_dat... | [
"def",
"get_file_sha1",
"(",
"filename_or_io",
")",
":",
"file_data",
"=",
"get_file_io",
"(",
"filename_or_io",
")",
"cache_key",
"=",
"file_data",
".",
"cache_key",
"if",
"cache_key",
"and",
"cache_key",
"in",
"FILE_SHAS",
":",
"return",
"FILE_SHAS",
"[",
"cac... | Calculates the SHA1 of a file or file object using a buffer to handle larger files. | [
"Calculates",
"the",
"SHA1",
"of",
"a",
"file",
"or",
"file",
"object",
"using",
"a",
"buffer",
"to",
"handle",
"larger",
"files",
"."
] | 006f751f7db2e07d32522c0285160783de2feb79 | https://github.com/Fizzadar/pyinfra/blob/006f751f7db2e07d32522c0285160783de2feb79/pyinfra/api/util.py#L459-L486 | train |
Fizzadar/pyinfra | pyinfra/api/util.py | read_buffer | def read_buffer(io, print_output=False, print_func=None):
'''
Reads a file-like buffer object into lines and optionally prints the output.
'''
# TODO: research this further - some steps towards handling stdin (ie password requests
# from programs that don't notice there's no TTY to accept passwords... | python | def read_buffer(io, print_output=False, print_func=None):
'''
Reads a file-like buffer object into lines and optionally prints the output.
'''
# TODO: research this further - some steps towards handling stdin (ie password requests
# from programs that don't notice there's no TTY to accept passwords... | [
"def",
"read_buffer",
"(",
"io",
",",
"print_output",
"=",
"False",
",",
"print_func",
"=",
"None",
")",
":",
"def",
"_print",
"(",
"line",
")",
":",
"if",
"print_output",
":",
"if",
"print_func",
":",
"formatted_line",
"=",
"print_func",
"(",
"line",
")... | Reads a file-like buffer object into lines and optionally prints the output. | [
"Reads",
"a",
"file",
"-",
"like",
"buffer",
"object",
"into",
"lines",
"and",
"optionally",
"prints",
"the",
"output",
"."
] | 006f751f7db2e07d32522c0285160783de2feb79 | https://github.com/Fizzadar/pyinfra/blob/006f751f7db2e07d32522c0285160783de2feb79/pyinfra/api/util.py#L489-L555 | train |
Fizzadar/pyinfra | pyinfra/modules/vzctl.py | start | def start(state, host, ctid, force=False):
'''
Start OpenVZ containers.
+ ctid: CTID of the container to start
+ force: whether to force container start
'''
args = ['{0}'.format(ctid)]
if force:
args.append('--force')
yield 'vzctl start {0}'.format(' '.join(args)) | python | def start(state, host, ctid, force=False):
'''
Start OpenVZ containers.
+ ctid: CTID of the container to start
+ force: whether to force container start
'''
args = ['{0}'.format(ctid)]
if force:
args.append('--force')
yield 'vzctl start {0}'.format(' '.join(args)) | [
"def",
"start",
"(",
"state",
",",
"host",
",",
"ctid",
",",
"force",
"=",
"False",
")",
":",
"args",
"=",
"[",
"'{0}'",
".",
"format",
"(",
"ctid",
")",
"]",
"if",
"force",
":",
"args",
".",
"append",
"(",
"'--force'",
")",
"yield",
"'vzctl start ... | Start OpenVZ containers.
+ ctid: CTID of the container to start
+ force: whether to force container start | [
"Start",
"OpenVZ",
"containers",
"."
] | 006f751f7db2e07d32522c0285160783de2feb79 | https://github.com/Fizzadar/pyinfra/blob/006f751f7db2e07d32522c0285160783de2feb79/pyinfra/modules/vzctl.py#L15-L28 | train |
Fizzadar/pyinfra | pyinfra/modules/vzctl.py | stop | def stop(state, host, ctid):
'''
Stop OpenVZ containers.
+ ctid: CTID of the container to stop
'''
args = ['{0}'.format(ctid)]
yield 'vzctl stop {0}'.format(' '.join(args)) | python | def stop(state, host, ctid):
'''
Stop OpenVZ containers.
+ ctid: CTID of the container to stop
'''
args = ['{0}'.format(ctid)]
yield 'vzctl stop {0}'.format(' '.join(args)) | [
"def",
"stop",
"(",
"state",
",",
"host",
",",
"ctid",
")",
":",
"args",
"=",
"[",
"'{0}'",
".",
"format",
"(",
"ctid",
")",
"]",
"yield",
"'vzctl stop {0}'",
".",
"format",
"(",
"' '",
".",
"join",
"(",
"args",
")",
")"
] | Stop OpenVZ containers.
+ ctid: CTID of the container to stop | [
"Stop",
"OpenVZ",
"containers",
"."
] | 006f751f7db2e07d32522c0285160783de2feb79 | https://github.com/Fizzadar/pyinfra/blob/006f751f7db2e07d32522c0285160783de2feb79/pyinfra/modules/vzctl.py#L32-L41 | train |
Fizzadar/pyinfra | pyinfra/modules/vzctl.py | restart | def restart(state, host, ctid, force=False):
'''
Restart OpenVZ containers.
+ ctid: CTID of the container to restart
+ force: whether to force container start
'''
yield stop(state, host, ctid)
yield start(state, host, ctid, force=force) | python | def restart(state, host, ctid, force=False):
'''
Restart OpenVZ containers.
+ ctid: CTID of the container to restart
+ force: whether to force container start
'''
yield stop(state, host, ctid)
yield start(state, host, ctid, force=force) | [
"def",
"restart",
"(",
"state",
",",
"host",
",",
"ctid",
",",
"force",
"=",
"False",
")",
":",
"yield",
"stop",
"(",
"state",
",",
"host",
",",
"ctid",
")",
"yield",
"start",
"(",
"state",
",",
"host",
",",
"ctid",
",",
"force",
"=",
"force",
")... | Restart OpenVZ containers.
+ ctid: CTID of the container to restart
+ force: whether to force container start | [
"Restart",
"OpenVZ",
"containers",
"."
] | 006f751f7db2e07d32522c0285160783de2feb79 | https://github.com/Fizzadar/pyinfra/blob/006f751f7db2e07d32522c0285160783de2feb79/pyinfra/modules/vzctl.py#L45-L54 | train |
Fizzadar/pyinfra | pyinfra/modules/vzctl.py | create | def create(state, host, ctid, template=None):
'''
Create OpenVZ containers.
+ ctid: CTID of the container to create
'''
# Check we don't already have a container with this CTID
current_containers = host.fact.openvz_containers
if ctid in current_containers:
raise OperationError(
... | python | def create(state, host, ctid, template=None):
'''
Create OpenVZ containers.
+ ctid: CTID of the container to create
'''
# Check we don't already have a container with this CTID
current_containers = host.fact.openvz_containers
if ctid in current_containers:
raise OperationError(
... | [
"def",
"create",
"(",
"state",
",",
"host",
",",
"ctid",
",",
"template",
"=",
"None",
")",
":",
"current_containers",
"=",
"host",
".",
"fact",
".",
"openvz_containers",
"if",
"ctid",
"in",
"current_containers",
":",
"raise",
"OperationError",
"(",
"'An Ope... | Create OpenVZ containers.
+ ctid: CTID of the container to create | [
"Create",
"OpenVZ",
"containers",
"."
] | 006f751f7db2e07d32522c0285160783de2feb79 | https://github.com/Fizzadar/pyinfra/blob/006f751f7db2e07d32522c0285160783de2feb79/pyinfra/modules/vzctl.py#L91-L110 | train |
Fizzadar/pyinfra | pyinfra/modules/vzctl.py | set | def set(state, host, ctid, save=True, **settings):
'''
Set OpenVZ container details.
+ ctid: CTID of the container to set
+ save: whether to save the changes
+ settings: settings/arguments to apply to the container
Settings/arguments:
these are mapped directly to ``vztctl`` arguments, ... | python | def set(state, host, ctid, save=True, **settings):
'''
Set OpenVZ container details.
+ ctid: CTID of the container to set
+ save: whether to save the changes
+ settings: settings/arguments to apply to the container
Settings/arguments:
these are mapped directly to ``vztctl`` arguments, ... | [
"def",
"set",
"(",
"state",
",",
"host",
",",
"ctid",
",",
"save",
"=",
"True",
",",
"**",
"settings",
")",
":",
"args",
"=",
"[",
"'{0}'",
".",
"format",
"(",
"ctid",
")",
"]",
"if",
"save",
":",
"args",
".",
"append",
"(",
"'--save'",
")",
"f... | Set OpenVZ container details.
+ ctid: CTID of the container to set
+ save: whether to save the changes
+ settings: settings/arguments to apply to the container
Settings/arguments:
these are mapped directly to ``vztctl`` arguments, eg
``hostname='my-host.net'`` becomes ``--hostname my-h... | [
"Set",
"OpenVZ",
"container",
"details",
"."
] | 006f751f7db2e07d32522c0285160783de2feb79 | https://github.com/Fizzadar/pyinfra/blob/006f751f7db2e07d32522c0285160783de2feb79/pyinfra/modules/vzctl.py#L114-L139 | train |
Fizzadar/pyinfra | pyinfra_cli/util.py | exec_file | def exec_file(filename, return_locals=False, is_deploy_code=False):
'''
Execute a Python file and optionally return it's attributes as a dict.
'''
if filename not in PYTHON_CODES:
with open(filename, 'r') as f:
code = f.read()
code = compile(code, filename, 'exec')
... | python | def exec_file(filename, return_locals=False, is_deploy_code=False):
'''
Execute a Python file and optionally return it's attributes as a dict.
'''
if filename not in PYTHON_CODES:
with open(filename, 'r') as f:
code = f.read()
code = compile(code, filename, 'exec')
... | [
"def",
"exec_file",
"(",
"filename",
",",
"return_locals",
"=",
"False",
",",
"is_deploy_code",
"=",
"False",
")",
":",
"if",
"filename",
"not",
"in",
"PYTHON_CODES",
":",
"with",
"open",
"(",
"filename",
",",
"'r'",
")",
"as",
"f",
":",
"code",
"=",
"... | Execute a Python file and optionally return it's attributes as a dict. | [
"Execute",
"a",
"Python",
"file",
"and",
"optionally",
"return",
"it",
"s",
"attributes",
"as",
"a",
"dict",
"."
] | 006f751f7db2e07d32522c0285160783de2feb79 | https://github.com/Fizzadar/pyinfra/blob/006f751f7db2e07d32522c0285160783de2feb79/pyinfra_cli/util.py#L37-L58 | train |
Fizzadar/pyinfra | pyinfra/modules/server.py | shell | def shell(state, host, commands, chdir=None):
'''
Run raw shell code.
+ commands: command or list of commands to execute on the remote server
+ chdir: directory to cd into before executing commands
'''
# Ensure we have a list
if isinstance(commands, six.string_types):
commands = [c... | python | def shell(state, host, commands, chdir=None):
'''
Run raw shell code.
+ commands: command or list of commands to execute on the remote server
+ chdir: directory to cd into before executing commands
'''
# Ensure we have a list
if isinstance(commands, six.string_types):
commands = [c... | [
"def",
"shell",
"(",
"state",
",",
"host",
",",
"commands",
",",
"chdir",
"=",
"None",
")",
":",
"if",
"isinstance",
"(",
"commands",
",",
"six",
".",
"string_types",
")",
":",
"commands",
"=",
"[",
"commands",
"]",
"for",
"command",
"in",
"commands",
... | Run raw shell code.
+ commands: command or list of commands to execute on the remote server
+ chdir: directory to cd into before executing commands | [
"Run",
"raw",
"shell",
"code",
"."
] | 006f751f7db2e07d32522c0285160783de2feb79 | https://github.com/Fizzadar/pyinfra/blob/006f751f7db2e07d32522c0285160783de2feb79/pyinfra/modules/server.py#L39-L55 | train |
Fizzadar/pyinfra | pyinfra/modules/server.py | script | def script(state, host, filename, chdir=None):
'''
Upload and execute a local script on the remote host.
+ filename: local script filename to upload & execute
+ chdir: directory to cd into before executing the script
'''
temp_file = state.get_temp_filename(filename)
yield files.put(state, ... | python | def script(state, host, filename, chdir=None):
'''
Upload and execute a local script on the remote host.
+ filename: local script filename to upload & execute
+ chdir: directory to cd into before executing the script
'''
temp_file = state.get_temp_filename(filename)
yield files.put(state, ... | [
"def",
"script",
"(",
"state",
",",
"host",
",",
"filename",
",",
"chdir",
"=",
"None",
")",
":",
"temp_file",
"=",
"state",
".",
"get_temp_filename",
"(",
"filename",
")",
"yield",
"files",
".",
"put",
"(",
"state",
",",
"host",
",",
"filename",
",",
... | Upload and execute a local script on the remote host.
+ filename: local script filename to upload & execute
+ chdir: directory to cd into before executing the script | [
"Upload",
"and",
"execute",
"a",
"local",
"script",
"on",
"the",
"remote",
"host",
"."
] | 006f751f7db2e07d32522c0285160783de2feb79 | https://github.com/Fizzadar/pyinfra/blob/006f751f7db2e07d32522c0285160783de2feb79/pyinfra/modules/server.py#L59-L75 | train |
Fizzadar/pyinfra | pyinfra/modules/server.py | script_template | def script_template(state, host, template_filename, chdir=None, **data):
'''
Generate, upload and execute a local script template on the remote host.
+ template_filename: local script template filename
+ chdir: directory to cd into before executing the script
'''
temp_file = state.get_temp_fil... | python | def script_template(state, host, template_filename, chdir=None, **data):
'''
Generate, upload and execute a local script template on the remote host.
+ template_filename: local script template filename
+ chdir: directory to cd into before executing the script
'''
temp_file = state.get_temp_fil... | [
"def",
"script_template",
"(",
"state",
",",
"host",
",",
"template_filename",
",",
"chdir",
"=",
"None",
",",
"**",
"data",
")",
":",
"temp_file",
"=",
"state",
".",
"get_temp_filename",
"(",
"template_filename",
")",
"yield",
"files",
".",
"template",
"(",... | Generate, upload and execute a local script template on the remote host.
+ template_filename: local script template filename
+ chdir: directory to cd into before executing the script | [
"Generate",
"upload",
"and",
"execute",
"a",
"local",
"script",
"template",
"on",
"the",
"remote",
"host",
"."
] | 006f751f7db2e07d32522c0285160783de2feb79 | https://github.com/Fizzadar/pyinfra/blob/006f751f7db2e07d32522c0285160783de2feb79/pyinfra/modules/server.py#L79-L95 | train |
Fizzadar/pyinfra | pyinfra/modules/server.py | hostname | def hostname(state, host, hostname, hostname_file=None):
'''
Set the system hostname.
+ hostname: the hostname that should be set
+ hostname_file: the file that permanently sets the hostname
Hostname file:
By default pyinfra will auto detect this by targetting ``/etc/hostname``
on ... | python | def hostname(state, host, hostname, hostname_file=None):
'''
Set the system hostname.
+ hostname: the hostname that should be set
+ hostname_file: the file that permanently sets the hostname
Hostname file:
By default pyinfra will auto detect this by targetting ``/etc/hostname``
on ... | [
"def",
"hostname",
"(",
"state",
",",
"host",
",",
"hostname",
",",
"hostname_file",
"=",
"None",
")",
":",
"if",
"hostname_file",
"is",
"None",
":",
"os",
"=",
"host",
".",
"fact",
".",
"os",
"if",
"os",
"==",
"'Linux'",
":",
"hostname_file",
"=",
"... | Set the system hostname.
+ hostname: the hostname that should be set
+ hostname_file: the file that permanently sets the hostname
Hostname file:
By default pyinfra will auto detect this by targetting ``/etc/hostname``
on Linux and ``/etc/myname`` on OpenBSD. | [
"Set",
"the",
"system",
"hostname",
"."
] | 006f751f7db2e07d32522c0285160783de2feb79 | https://github.com/Fizzadar/pyinfra/blob/006f751f7db2e07d32522c0285160783de2feb79/pyinfra/modules/server.py#L125-L158 | train |
Fizzadar/pyinfra | pyinfra/modules/server.py | sysctl | def sysctl(
state, host, name, value,
persist=False, persist_file='/etc/sysctl.conf',
):
'''
Edit sysctl configuration.
+ name: name of the sysctl setting to ensure
+ value: the value or list of values the sysctl should be
+ persist: whether to write this sysctl to the config
+ persist_... | python | def sysctl(
state, host, name, value,
persist=False, persist_file='/etc/sysctl.conf',
):
'''
Edit sysctl configuration.
+ name: name of the sysctl setting to ensure
+ value: the value or list of values the sysctl should be
+ persist: whether to write this sysctl to the config
+ persist_... | [
"def",
"sysctl",
"(",
"state",
",",
"host",
",",
"name",
",",
"value",
",",
"persist",
"=",
"False",
",",
"persist_file",
"=",
"'/etc/sysctl.conf'",
",",
")",
":",
"string_value",
"=",
"(",
"' '",
".",
"join",
"(",
"value",
")",
"if",
"isinstance",
"("... | Edit sysctl configuration.
+ name: name of the sysctl setting to ensure
+ value: the value or list of values the sysctl should be
+ persist: whether to write this sysctl to the config
+ persist_file: file to write the sysctl to persist on reboot | [
"Edit",
"sysctl",
"configuration",
"."
] | 006f751f7db2e07d32522c0285160783de2feb79 | https://github.com/Fizzadar/pyinfra/blob/006f751f7db2e07d32522c0285160783de2feb79/pyinfra/modules/server.py#L162-L191 | train |
Fizzadar/pyinfra | pyinfra/modules/files.py | download | def download(
state, host, source_url, destination,
user=None, group=None, mode=None, cache_time=None, force=False,
):
'''
Download files from remote locations.
+ source_url: source URl of the file
+ destination: where to save the file
+ user: user to own the files
+ group: group to own... | python | def download(
state, host, source_url, destination,
user=None, group=None, mode=None, cache_time=None, force=False,
):
'''
Download files from remote locations.
+ source_url: source URl of the file
+ destination: where to save the file
+ user: user to own the files
+ group: group to own... | [
"def",
"download",
"(",
"state",
",",
"host",
",",
"source_url",
",",
"destination",
",",
"user",
"=",
"None",
",",
"group",
"=",
"None",
",",
"mode",
"=",
"None",
",",
"cache_time",
"=",
"None",
",",
"force",
"=",
"False",
",",
")",
":",
"info",
"... | Download files from remote locations.
+ source_url: source URl of the file
+ destination: where to save the file
+ user: user to own the files
+ group: group to own the files
+ mode: permissions of the files
+ cache_time: if the file exists already, re-download after this time (in s)
+ forc... | [
"Download",
"files",
"from",
"remote",
"locations",
"."
] | 006f751f7db2e07d32522c0285160783de2feb79 | https://github.com/Fizzadar/pyinfra/blob/006f751f7db2e07d32522c0285160783de2feb79/pyinfra/modules/files.py#L30-L79 | train |
Fizzadar/pyinfra | pyinfra/modules/files.py | replace | def replace(state, host, name, match, replace, flags=None):
'''
A simple shortcut for replacing text in files with sed.
+ name: target remote file to edit
+ match: text/regex to match for
+ replace: text to replace with
+ flags: list of flaggs to pass to sed
'''
yield sed_replace(name,... | python | def replace(state, host, name, match, replace, flags=None):
'''
A simple shortcut for replacing text in files with sed.
+ name: target remote file to edit
+ match: text/regex to match for
+ replace: text to replace with
+ flags: list of flaggs to pass to sed
'''
yield sed_replace(name,... | [
"def",
"replace",
"(",
"state",
",",
"host",
",",
"name",
",",
"match",
",",
"replace",
",",
"flags",
"=",
"None",
")",
":",
"yield",
"sed_replace",
"(",
"name",
",",
"match",
",",
"replace",
",",
"flags",
"=",
"flags",
")"
] | A simple shortcut for replacing text in files with sed.
+ name: target remote file to edit
+ match: text/regex to match for
+ replace: text to replace with
+ flags: list of flaggs to pass to sed | [
"A",
"simple",
"shortcut",
"for",
"replacing",
"text",
"in",
"files",
"with",
"sed",
"."
] | 006f751f7db2e07d32522c0285160783de2feb79 | https://github.com/Fizzadar/pyinfra/blob/006f751f7db2e07d32522c0285160783de2feb79/pyinfra/modules/files.py#L169-L179 | train |
Fizzadar/pyinfra | pyinfra/modules/files.py | sync | def sync(
state, host, source, destination,
user=None, group=None, mode=None, delete=False,
exclude=None, exclude_dir=None, add_deploy_dir=True,
):
'''
Syncs a local directory with a remote one, with delete support. Note that delete will
remove extra files on the remote side, but not extra direc... | python | def sync(
state, host, source, destination,
user=None, group=None, mode=None, delete=False,
exclude=None, exclude_dir=None, add_deploy_dir=True,
):
'''
Syncs a local directory with a remote one, with delete support. Note that delete will
remove extra files on the remote side, but not extra direc... | [
"def",
"sync",
"(",
"state",
",",
"host",
",",
"source",
",",
"destination",
",",
"user",
"=",
"None",
",",
"group",
"=",
"None",
",",
"mode",
"=",
"None",
",",
"delete",
"=",
"False",
",",
"exclude",
"=",
"None",
",",
"exclude_dir",
"=",
"None",
"... | Syncs a local directory with a remote one, with delete support. Note that delete will
remove extra files on the remote side, but not extra directories.
+ source: local directory to sync
+ destination: remote directory to sync to
+ user: user to own the files and directories
+ group: group to own th... | [
"Syncs",
"a",
"local",
"directory",
"with",
"a",
"remote",
"one",
"with",
"delete",
"support",
".",
"Note",
"that",
"delete",
"will",
"remove",
"extra",
"files",
"on",
"the",
"remote",
"side",
"but",
"not",
"extra",
"directories",
"."
] | 006f751f7db2e07d32522c0285160783de2feb79 | https://github.com/Fizzadar/pyinfra/blob/006f751f7db2e07d32522c0285160783de2feb79/pyinfra/modules/files.py#L185-L290 | train |
Fizzadar/pyinfra | pyinfra/modules/files.py | put | def put(
state, host, local_filename, remote_filename,
user=None, group=None, mode=None, add_deploy_dir=True,
):
'''
Copy a local file to the remote system.
+ local_filename: local filename
+ remote_filename: remote filename
+ user: user to own the files
+ group: group to own the files
... | python | def put(
state, host, local_filename, remote_filename,
user=None, group=None, mode=None, add_deploy_dir=True,
):
'''
Copy a local file to the remote system.
+ local_filename: local filename
+ remote_filename: remote filename
+ user: user to own the files
+ group: group to own the files
... | [
"def",
"put",
"(",
"state",
",",
"host",
",",
"local_filename",
",",
"remote_filename",
",",
"user",
"=",
"None",
",",
"group",
"=",
"None",
",",
"mode",
"=",
"None",
",",
"add_deploy_dir",
"=",
"True",
",",
")",
":",
"if",
"hasattr",
"(",
"local_filen... | Copy a local file to the remote system.
+ local_filename: local filename
+ remote_filename: remote filename
+ user: user to own the files
+ group: group to own the files
+ mode: permissions of the files | [
"Copy",
"a",
"local",
"file",
"to",
"the",
"remote",
"system",
"."
] | 006f751f7db2e07d32522c0285160783de2feb79 | https://github.com/Fizzadar/pyinfra/blob/006f751f7db2e07d32522c0285160783de2feb79/pyinfra/modules/files.py#L297-L364 | train |
Fizzadar/pyinfra | pyinfra/modules/files.py | template | def template(
state, host, template_filename, remote_filename,
user=None, group=None, mode=None, **data
):
'''
Generate a template and write it to the remote system.
+ template_filename: local template filename
+ remote_filename: remote filename
+ user: user to own the files
+ group: gr... | python | def template(
state, host, template_filename, remote_filename,
user=None, group=None, mode=None, **data
):
'''
Generate a template and write it to the remote system.
+ template_filename: local template filename
+ remote_filename: remote filename
+ user: user to own the files
+ group: gr... | [
"def",
"template",
"(",
"state",
",",
"host",
",",
"template_filename",
",",
"remote_filename",
",",
"user",
"=",
"None",
",",
"group",
"=",
"None",
",",
"mode",
"=",
"None",
",",
"**",
"data",
")",
":",
"if",
"state",
".",
"deploy_dir",
":",
"template... | Generate a template and write it to the remote system.
+ template_filename: local template filename
+ remote_filename: remote filename
+ user: user to own the files
+ group: group to own the files
+ mode: permissions of the files | [
"Generate",
"a",
"template",
"and",
"write",
"it",
"to",
"the",
"remote",
"system",
"."
] | 006f751f7db2e07d32522c0285160783de2feb79 | https://github.com/Fizzadar/pyinfra/blob/006f751f7db2e07d32522c0285160783de2feb79/pyinfra/modules/files.py#L368-L424 | train |
Fizzadar/pyinfra | pyinfra/modules/postgresql.py | sql | def sql(
state, host, sql,
database=None,
# Details for speaking to PostgreSQL via `psql` CLI
postgresql_user=None, postgresql_password=None,
postgresql_host=None, postgresql_port=None,
):
'''
Execute arbitrary SQL against PostgreSQL.
+ sql: SQL command(s) to execute
+ database: opt... | python | def sql(
state, host, sql,
database=None,
# Details for speaking to PostgreSQL via `psql` CLI
postgresql_user=None, postgresql_password=None,
postgresql_host=None, postgresql_port=None,
):
'''
Execute arbitrary SQL against PostgreSQL.
+ sql: SQL command(s) to execute
+ database: opt... | [
"def",
"sql",
"(",
"state",
",",
"host",
",",
"sql",
",",
"database",
"=",
"None",
",",
"postgresql_user",
"=",
"None",
",",
"postgresql_password",
"=",
"None",
",",
"postgresql_host",
"=",
"None",
",",
"postgresql_port",
"=",
"None",
",",
")",
":",
"yie... | Execute arbitrary SQL against PostgreSQL.
+ sql: SQL command(s) to execute
+ database: optional database to execute against
+ postgresql_*: global module arguments, see above | [
"Execute",
"arbitrary",
"SQL",
"against",
"PostgreSQL",
"."
] | 006f751f7db2e07d32522c0285160783de2feb79 | https://github.com/Fizzadar/pyinfra/blob/006f751f7db2e07d32522c0285160783de2feb79/pyinfra/modules/postgresql.py#L22-L44 | train |
Fizzadar/pyinfra | pyinfra/modules/postgresql.py | dump | def dump(
state, host,
remote_filename, database=None,
# Details for speaking to PostgreSQL via `psql` CLI
postgresql_user=None, postgresql_password=None,
postgresql_host=None, postgresql_port=None,
):
'''
Dump a PostgreSQL database into a ``.sql`` file. Requires ``mysqldump``.
+ databa... | python | def dump(
state, host,
remote_filename, database=None,
# Details for speaking to PostgreSQL via `psql` CLI
postgresql_user=None, postgresql_password=None,
postgresql_host=None, postgresql_port=None,
):
'''
Dump a PostgreSQL database into a ``.sql`` file. Requires ``mysqldump``.
+ databa... | [
"def",
"dump",
"(",
"state",
",",
"host",
",",
"remote_filename",
",",
"database",
"=",
"None",
",",
"postgresql_user",
"=",
"None",
",",
"postgresql_password",
"=",
"None",
",",
"postgresql_host",
"=",
"None",
",",
"postgresql_port",
"=",
"None",
",",
")",
... | Dump a PostgreSQL database into a ``.sql`` file. Requires ``mysqldump``.
+ database: name of the database to dump
+ remote_filename: name of the file to dump the SQL to
+ postgresql_*: global module arguments, see above | [
"Dump",
"a",
"PostgreSQL",
"database",
"into",
"a",
".",
"sql",
"file",
".",
"Requires",
"mysqldump",
"."
] | 006f751f7db2e07d32522c0285160783de2feb79 | https://github.com/Fizzadar/pyinfra/blob/006f751f7db2e07d32522c0285160783de2feb79/pyinfra/modules/postgresql.py#L201-L223 | train |
Fizzadar/pyinfra | pyinfra/api/facts.py | get_fact | def get_fact(state, host, name):
'''
Wrapper around ``get_facts`` returning facts for one host or a function
that does.
'''
# Expecting a function to return
if callable(getattr(FACTS[name], 'command', None)):
def wrapper(*args):
fact_data = get_facts(state, name, args=args, ... | python | def get_fact(state, host, name):
'''
Wrapper around ``get_facts`` returning facts for one host or a function
that does.
'''
# Expecting a function to return
if callable(getattr(FACTS[name], 'command', None)):
def wrapper(*args):
fact_data = get_facts(state, name, args=args, ... | [
"def",
"get_fact",
"(",
"state",
",",
"host",
",",
"name",
")",
":",
"if",
"callable",
"(",
"getattr",
"(",
"FACTS",
"[",
"name",
"]",
",",
"'command'",
",",
"None",
")",
")",
":",
"def",
"wrapper",
"(",
"*",
"args",
")",
":",
"fact_data",
"=",
"... | Wrapper around ``get_facts`` returning facts for one host or a function
that does. | [
"Wrapper",
"around",
"get_facts",
"returning",
"facts",
"for",
"one",
"host",
"or",
"a",
"function",
"that",
"does",
"."
] | 006f751f7db2e07d32522c0285160783de2feb79 | https://github.com/Fizzadar/pyinfra/blob/006f751f7db2e07d32522c0285160783de2feb79/pyinfra/api/facts.py#L249-L268 | train |
Fizzadar/pyinfra | pyinfra/modules/apt.py | key | def key(state, host, key=None, keyserver=None, keyid=None):
'''
Add apt gpg keys with ``apt-key``.
+ key: filename or URL
+ keyserver: URL of keyserver to fetch key from
+ keyid: key identifier when using keyserver
Note:
Always returns an add command, not state checking.
keyserver... | python | def key(state, host, key=None, keyserver=None, keyid=None):
'''
Add apt gpg keys with ``apt-key``.
+ key: filename or URL
+ keyserver: URL of keyserver to fetch key from
+ keyid: key identifier when using keyserver
Note:
Always returns an add command, not state checking.
keyserver... | [
"def",
"key",
"(",
"state",
",",
"host",
",",
"key",
"=",
"None",
",",
"keyserver",
"=",
"None",
",",
"keyid",
"=",
"None",
")",
":",
"if",
"key",
":",
"if",
"urlparse",
"(",
"key",
")",
".",
"scheme",
":",
"yield",
"'wget -O- {0} | apt-key add -'",
... | Add apt gpg keys with ``apt-key``.
+ key: filename or URL
+ keyserver: URL of keyserver to fetch key from
+ keyid: key identifier when using keyserver
Note:
Always returns an add command, not state checking.
keyserver/id:
These must be provided together. | [
"Add",
"apt",
"gpg",
"keys",
"with",
"apt",
"-",
"key",
"."
] | 006f751f7db2e07d32522c0285160783de2feb79 | https://github.com/Fizzadar/pyinfra/blob/006f751f7db2e07d32522c0285160783de2feb79/pyinfra/modules/apt.py#L40-L64 | train |
Fizzadar/pyinfra | pyinfra/modules/apt.py | update | def update(state, host, cache_time=None, touch_periodic=False):
'''
Updates apt repos.
+ cache_time: cache updates for this many seconds
+ touch_periodic: touch ``/var/lib/apt/periodic/update-success-stamp`` after update
'''
# If cache_time check when apt was last updated, prevent updates if w... | python | def update(state, host, cache_time=None, touch_periodic=False):
'''
Updates apt repos.
+ cache_time: cache updates for this many seconds
+ touch_periodic: touch ``/var/lib/apt/periodic/update-success-stamp`` after update
'''
# If cache_time check when apt was last updated, prevent updates if w... | [
"def",
"update",
"(",
"state",
",",
"host",
",",
"cache_time",
"=",
"None",
",",
"touch_periodic",
"=",
"False",
")",
":",
"if",
"cache_time",
":",
"cache_info",
"=",
"host",
".",
"fact",
".",
"file",
"(",
"APT_UPDATE_FILENAME",
")",
"host_cache_time",
"="... | Updates apt repos.
+ cache_time: cache updates for this many seconds
+ touch_periodic: touch ``/var/lib/apt/periodic/update-success-stamp`` after update | [
"Updates",
"apt",
"repos",
"."
] | 006f751f7db2e07d32522c0285160783de2feb79 | https://github.com/Fizzadar/pyinfra/blob/006f751f7db2e07d32522c0285160783de2feb79/pyinfra/modules/apt.py#L188-L213 | train |
Fizzadar/pyinfra | pyinfra/api/connectors/local.py | run_shell_command | def run_shell_command(
state, host, command,
get_pty=False, timeout=None, print_output=False,
**command_kwargs
):
'''
Execute a command on the local machine.
Args:
state (``pyinfra.api.State`` obj): state object for this command
hostname (string): hostname of the target
... | python | def run_shell_command(
state, host, command,
get_pty=False, timeout=None, print_output=False,
**command_kwargs
):
'''
Execute a command on the local machine.
Args:
state (``pyinfra.api.State`` obj): state object for this command
hostname (string): hostname of the target
... | [
"def",
"run_shell_command",
"(",
"state",
",",
"host",
",",
"command",
",",
"get_pty",
"=",
"False",
",",
"timeout",
"=",
"None",
",",
"print_output",
"=",
"False",
",",
"**",
"command_kwargs",
")",
":",
"command",
"=",
"make_command",
"(",
"command",
",",... | Execute a command on the local machine.
Args:
state (``pyinfra.api.State`` obj): state object for this command
hostname (string): hostname of the target
command (string): actual command to execute
sudo (boolean): whether to wrap the command with sudo
sudo_user (string): user... | [
"Execute",
"a",
"command",
"on",
"the",
"local",
"machine",
"."
] | 006f751f7db2e07d32522c0285160783de2feb79 | https://github.com/Fizzadar/pyinfra/blob/006f751f7db2e07d32522c0285160783de2feb79/pyinfra/api/connectors/local.py#L39-L110 | train |
Fizzadar/pyinfra | pyinfra/modules/init.py | upstart | def upstart(
state, host, name,
running=True, restarted=False, reloaded=False,
command=None, enabled=None,
):
'''
Manage the state of upstart managed services.
+ name: name of the service to manage
+ running: whether the service should be running
+ restarted: whether the service should ... | python | def upstart(
state, host, name,
running=True, restarted=False, reloaded=False,
command=None, enabled=None,
):
'''
Manage the state of upstart managed services.
+ name: name of the service to manage
+ running: whether the service should be running
+ restarted: whether the service should ... | [
"def",
"upstart",
"(",
"state",
",",
"host",
",",
"name",
",",
"running",
"=",
"True",
",",
"restarted",
"=",
"False",
",",
"reloaded",
"=",
"False",
",",
"command",
"=",
"None",
",",
"enabled",
"=",
"None",
",",
")",
":",
"yield",
"_handle_service_con... | Manage the state of upstart managed services.
+ name: name of the service to manage
+ running: whether the service should be running
+ restarted: whether the service should be restarted
+ reloaded: whether the service should be reloaded
+ command: custom command to pass like: ``/etc/rc.d/<name> <co... | [
"Manage",
"the",
"state",
"of",
"upstart",
"managed",
"services",
"."
] | 006f751f7db2e07d32522c0285160783de2feb79 | https://github.com/Fizzadar/pyinfra/blob/006f751f7db2e07d32522c0285160783de2feb79/pyinfra/modules/init.py#L209-L248 | train |
Fizzadar/pyinfra | pyinfra/modules/init.py | service | def service(
state, host,
*args, **kwargs
):
'''
Manage the state of services. This command checks for the presence of all the
init systems pyinfra can handle and executes the relevant operation. See init
system sepcific operation for arguments.
'''
if host.fact.which('systemctl'):
... | python | def service(
state, host,
*args, **kwargs
):
'''
Manage the state of services. This command checks for the presence of all the
init systems pyinfra can handle and executes the relevant operation. See init
system sepcific operation for arguments.
'''
if host.fact.which('systemctl'):
... | [
"def",
"service",
"(",
"state",
",",
"host",
",",
"*",
"args",
",",
"**",
"kwargs",
")",
":",
"if",
"host",
".",
"fact",
".",
"which",
"(",
"'systemctl'",
")",
":",
"yield",
"systemd",
"(",
"state",
",",
"host",
",",
"*",
"args",
",",
"**",
"kwar... | Manage the state of services. This command checks for the presence of all the
init systems pyinfra can handle and executes the relevant operation. See init
system sepcific operation for arguments. | [
"Manage",
"the",
"state",
"of",
"services",
".",
"This",
"command",
"checks",
"for",
"the",
"presence",
"of",
"all",
"the",
"init",
"systems",
"pyinfra",
"can",
"handle",
"and",
"executes",
"the",
"relevant",
"operation",
".",
"See",
"init",
"system",
"sepci... | 006f751f7db2e07d32522c0285160783de2feb79 | https://github.com/Fizzadar/pyinfra/blob/006f751f7db2e07d32522c0285160783de2feb79/pyinfra/modules/init.py#L321-L350 | train |
Fizzadar/pyinfra | pyinfra/api/connectors/ssh.py | connect | def connect(state, host, for_fact=None):
'''
Connect to a single host. Returns the SSH client if succesful. Stateless by
design so can be run in parallel.
'''
kwargs = _make_paramiko_kwargs(state, host)
logger.debug('Connecting to: {0} ({1})'.format(host.name, kwargs))
# Hostname can be pr... | python | def connect(state, host, for_fact=None):
'''
Connect to a single host. Returns the SSH client if succesful. Stateless by
design so can be run in parallel.
'''
kwargs = _make_paramiko_kwargs(state, host)
logger.debug('Connecting to: {0} ({1})'.format(host.name, kwargs))
# Hostname can be pr... | [
"def",
"connect",
"(",
"state",
",",
"host",
",",
"for_fact",
"=",
"None",
")",
":",
"kwargs",
"=",
"_make_paramiko_kwargs",
"(",
"state",
",",
"host",
")",
"logger",
".",
"debug",
"(",
"'Connecting to: {0} ({1})'",
".",
"format",
"(",
"host",
".",
"name",... | Connect to a single host. Returns the SSH client if succesful. Stateless by
design so can be run in parallel. | [
"Connect",
"to",
"a",
"single",
"host",
".",
"Returns",
"the",
"SSH",
"client",
"if",
"succesful",
".",
"Stateless",
"by",
"design",
"so",
"can",
"be",
"run",
"in",
"parallel",
"."
] | 006f751f7db2e07d32522c0285160783de2feb79 | https://github.com/Fizzadar/pyinfra/blob/006f751f7db2e07d32522c0285160783de2feb79/pyinfra/api/connectors/ssh.py#L150-L219 | train |
Fizzadar/pyinfra | pyinfra/api/connectors/ssh.py | run_shell_command | def run_shell_command(
state, host, command,
get_pty=False, timeout=None, print_output=False,
**command_kwargs
):
'''
Execute a command on the specified host.
Args:
state (``pyinfra.api.State`` obj): state object for this command
hostname (string): hostname of the target
... | python | def run_shell_command(
state, host, command,
get_pty=False, timeout=None, print_output=False,
**command_kwargs
):
'''
Execute a command on the specified host.
Args:
state (``pyinfra.api.State`` obj): state object for this command
hostname (string): hostname of the target
... | [
"def",
"run_shell_command",
"(",
"state",
",",
"host",
",",
"command",
",",
"get_pty",
"=",
"False",
",",
"timeout",
"=",
"None",
",",
"print_output",
"=",
"False",
",",
"**",
"command_kwargs",
")",
":",
"command",
"=",
"make_command",
"(",
"command",
",",... | Execute a command on the specified host.
Args:
state (``pyinfra.api.State`` obj): state object for this command
hostname (string): hostname of the target
command (string): actual command to execute
sudo (boolean): whether to wrap the command with sudo
sudo_user (string): use... | [
"Execute",
"a",
"command",
"on",
"the",
"specified",
"host",
"."
] | 006f751f7db2e07d32522c0285160783de2feb79 | https://github.com/Fizzadar/pyinfra/blob/006f751f7db2e07d32522c0285160783de2feb79/pyinfra/api/connectors/ssh.py#L222-L298 | train |
Fizzadar/pyinfra | pyinfra/api/connectors/ssh.py | put_file | def put_file(
state, host, filename_or_io, remote_filename,
sudo=False, sudo_user=None, su_user=None, print_output=False,
):
'''
Upload file-ios to the specified host using SFTP. Supports uploading files
with sudo by uploading to a temporary directory then moving & chowning.
'''
# sudo/su a... | python | def put_file(
state, host, filename_or_io, remote_filename,
sudo=False, sudo_user=None, su_user=None, print_output=False,
):
'''
Upload file-ios to the specified host using SFTP. Supports uploading files
with sudo by uploading to a temporary directory then moving & chowning.
'''
# sudo/su a... | [
"def",
"put_file",
"(",
"state",
",",
"host",
",",
"filename_or_io",
",",
"remote_filename",
",",
"sudo",
"=",
"False",
",",
"sudo_user",
"=",
"None",
",",
"su_user",
"=",
"None",
",",
"print_output",
"=",
"False",
",",
")",
":",
"if",
"sudo",
"or",
"s... | Upload file-ios to the specified host using SFTP. Supports uploading files
with sudo by uploading to a temporary directory then moving & chowning. | [
"Upload",
"file",
"-",
"ios",
"to",
"the",
"specified",
"host",
"using",
"SFTP",
".",
"Supports",
"uploading",
"files",
"with",
"sudo",
"by",
"uploading",
"to",
"a",
"temporary",
"directory",
"then",
"moving",
"&",
"chowning",
"."
] | 006f751f7db2e07d32522c0285160783de2feb79 | https://github.com/Fizzadar/pyinfra/blob/006f751f7db2e07d32522c0285160783de2feb79/pyinfra/api/connectors/ssh.py#L331-L378 | train |
Fizzadar/pyinfra | pyinfra/api/state.py | State.deploy | def deploy(self, name, kwargs, data, line_number, in_deploy=True):
'''
Wraps a group of operations as a deploy, this should not be used
directly, instead use ``pyinfra.api.deploy.deploy``.
'''
# Handle nested deploy names
if self.deploy_name:
name = _make_nam... | python | def deploy(self, name, kwargs, data, line_number, in_deploy=True):
'''
Wraps a group of operations as a deploy, this should not be used
directly, instead use ``pyinfra.api.deploy.deploy``.
'''
# Handle nested deploy names
if self.deploy_name:
name = _make_nam... | [
"def",
"deploy",
"(",
"self",
",",
"name",
",",
"kwargs",
",",
"data",
",",
"line_number",
",",
"in_deploy",
"=",
"True",
")",
":",
"if",
"self",
".",
"deploy_name",
":",
"name",
"=",
"_make_name",
"(",
"self",
".",
"deploy_name",
",",
"name",
")",
"... | Wraps a group of operations as a deploy, this should not be used
directly, instead use ``pyinfra.api.deploy.deploy``. | [
"Wraps",
"a",
"group",
"of",
"operations",
"as",
"a",
"deploy",
"this",
"should",
"not",
"be",
"used",
"directly",
"instead",
"use",
"pyinfra",
".",
"api",
".",
"deploy",
".",
"deploy",
"."
] | 006f751f7db2e07d32522c0285160783de2feb79 | https://github.com/Fizzadar/pyinfra/blob/006f751f7db2e07d32522c0285160783de2feb79/pyinfra/api/state.py#L275-L334 | train |
Fizzadar/pyinfra | pyinfra/api/state.py | State.activate_host | def activate_host(self, host):
'''
Flag a host as active.
'''
logger.debug('Activating host: {0}'.format(host))
# Add to *both* activated and active - active will reduce as hosts fail
# but connected will not, enabling us to track failed %.
self.activated_hosts.... | python | def activate_host(self, host):
'''
Flag a host as active.
'''
logger.debug('Activating host: {0}'.format(host))
# Add to *both* activated and active - active will reduce as hosts fail
# but connected will not, enabling us to track failed %.
self.activated_hosts.... | [
"def",
"activate_host",
"(",
"self",
",",
"host",
")",
":",
"logger",
".",
"debug",
"(",
"'Activating host: {0}'",
".",
"format",
"(",
"host",
")",
")",
"self",
".",
"activated_hosts",
".",
"add",
"(",
"host",
")",
"self",
".",
"active_hosts",
".",
"add"... | Flag a host as active. | [
"Flag",
"a",
"host",
"as",
"active",
"."
] | 006f751f7db2e07d32522c0285160783de2feb79 | https://github.com/Fizzadar/pyinfra/blob/006f751f7db2e07d32522c0285160783de2feb79/pyinfra/api/state.py#L345-L355 | train |
Fizzadar/pyinfra | pyinfra/api/state.py | State.fail_hosts | def fail_hosts(self, hosts_to_fail, activated_count=None):
'''
Flag a ``set`` of hosts as failed, error for ``config.FAIL_PERCENT``.
'''
if not hosts_to_fail:
return
activated_count = activated_count or len(self.activated_hosts)
logger.debug('Failing hosts:... | python | def fail_hosts(self, hosts_to_fail, activated_count=None):
'''
Flag a ``set`` of hosts as failed, error for ``config.FAIL_PERCENT``.
'''
if not hosts_to_fail:
return
activated_count = activated_count or len(self.activated_hosts)
logger.debug('Failing hosts:... | [
"def",
"fail_hosts",
"(",
"self",
",",
"hosts_to_fail",
",",
"activated_count",
"=",
"None",
")",
":",
"if",
"not",
"hosts_to_fail",
":",
"return",
"activated_count",
"=",
"activated_count",
"or",
"len",
"(",
"self",
".",
"activated_hosts",
")",
"logger",
".",... | Flag a ``set`` of hosts as failed, error for ``config.FAIL_PERCENT``. | [
"Flag",
"a",
"set",
"of",
"hosts",
"as",
"failed",
"error",
"for",
"config",
".",
"FAIL_PERCENT",
"."
] | 006f751f7db2e07d32522c0285160783de2feb79 | https://github.com/Fizzadar/pyinfra/blob/006f751f7db2e07d32522c0285160783de2feb79/pyinfra/api/state.py#L365-L398 | train |
Fizzadar/pyinfra | pyinfra/api/state.py | State.is_host_in_limit | def is_host_in_limit(self, host):
'''
Returns a boolean indicating if the host is within the current state limit.
'''
limit_hosts = self.limit_hosts
if not isinstance(limit_hosts, list):
return True
return host in limit_hosts | python | def is_host_in_limit(self, host):
'''
Returns a boolean indicating if the host is within the current state limit.
'''
limit_hosts = self.limit_hosts
if not isinstance(limit_hosts, list):
return True
return host in limit_hosts | [
"def",
"is_host_in_limit",
"(",
"self",
",",
"host",
")",
":",
"limit_hosts",
"=",
"self",
".",
"limit_hosts",
"if",
"not",
"isinstance",
"(",
"limit_hosts",
",",
"list",
")",
":",
"return",
"True",
"return",
"host",
"in",
"limit_hosts"
] | Returns a boolean indicating if the host is within the current state limit. | [
"Returns",
"a",
"boolean",
"indicating",
"if",
"the",
"host",
"is",
"within",
"the",
"current",
"state",
"limit",
"."
] | 006f751f7db2e07d32522c0285160783de2feb79 | https://github.com/Fizzadar/pyinfra/blob/006f751f7db2e07d32522c0285160783de2feb79/pyinfra/api/state.py#L400-L409 | train |
Fizzadar/pyinfra | pyinfra/api/state.py | State.get_temp_filename | def get_temp_filename(self, hash_key=None):
'''
Generate a temporary filename for this deploy.
'''
if not hash_key:
hash_key = six.text_type(uuid4())
temp_filename = '{0}/{1}'.format(
self.config.TEMP_DIR, sha1_hash(hash_key),
)
return t... | python | def get_temp_filename(self, hash_key=None):
'''
Generate a temporary filename for this deploy.
'''
if not hash_key:
hash_key = six.text_type(uuid4())
temp_filename = '{0}/{1}'.format(
self.config.TEMP_DIR, sha1_hash(hash_key),
)
return t... | [
"def",
"get_temp_filename",
"(",
"self",
",",
"hash_key",
"=",
"None",
")",
":",
"if",
"not",
"hash_key",
":",
"hash_key",
"=",
"six",
".",
"text_type",
"(",
"uuid4",
"(",
")",
")",
"temp_filename",
"=",
"'{0}/{1}'",
".",
"format",
"(",
"self",
".",
"c... | Generate a temporary filename for this deploy. | [
"Generate",
"a",
"temporary",
"filename",
"for",
"this",
"deploy",
"."
] | 006f751f7db2e07d32522c0285160783de2feb79 | https://github.com/Fizzadar/pyinfra/blob/006f751f7db2e07d32522c0285160783de2feb79/pyinfra/api/state.py#L411-L423 | train |
Fizzadar/pyinfra | pyinfra/api/operations.py | _run_server_ops | def _run_server_ops(state, host, progress=None):
'''
Run all ops for a single server.
'''
logger.debug('Running all ops on {0}'.format(host))
for op_hash in state.get_op_order():
op_meta = state.op_meta[op_hash]
logger.info('--> {0} {1} on {2}'.format(
click.style('-->... | python | def _run_server_ops(state, host, progress=None):
'''
Run all ops for a single server.
'''
logger.debug('Running all ops on {0}'.format(host))
for op_hash in state.get_op_order():
op_meta = state.op_meta[op_hash]
logger.info('--> {0} {1} on {2}'.format(
click.style('-->... | [
"def",
"_run_server_ops",
"(",
"state",
",",
"host",
",",
"progress",
"=",
"None",
")",
":",
"logger",
".",
"debug",
"(",
"'Running all ops on {0}'",
".",
"format",
"(",
"host",
")",
")",
"for",
"op_hash",
"in",
"state",
".",
"get_op_order",
"(",
")",
":... | Run all ops for a single server. | [
"Run",
"all",
"ops",
"for",
"a",
"single",
"server",
"."
] | 006f751f7db2e07d32522c0285160783de2feb79 | https://github.com/Fizzadar/pyinfra/blob/006f751f7db2e07d32522c0285160783de2feb79/pyinfra/api/operations.py#L216-L244 | train |
Fizzadar/pyinfra | pyinfra/api/operations.py | _run_serial_ops | def _run_serial_ops(state):
'''
Run all ops for all servers, one server at a time.
'''
for host in list(state.inventory):
host_operations = product([host], state.get_op_order())
with progress_spinner(host_operations) as progress:
try:
_run_server_ops(
... | python | def _run_serial_ops(state):
'''
Run all ops for all servers, one server at a time.
'''
for host in list(state.inventory):
host_operations = product([host], state.get_op_order())
with progress_spinner(host_operations) as progress:
try:
_run_server_ops(
... | [
"def",
"_run_serial_ops",
"(",
"state",
")",
":",
"for",
"host",
"in",
"list",
"(",
"state",
".",
"inventory",
")",
":",
"host_operations",
"=",
"product",
"(",
"[",
"host",
"]",
",",
"state",
".",
"get_op_order",
"(",
")",
")",
"with",
"progress_spinner... | Run all ops for all servers, one server at a time. | [
"Run",
"all",
"ops",
"for",
"all",
"servers",
"one",
"server",
"at",
"a",
"time",
"."
] | 006f751f7db2e07d32522c0285160783de2feb79 | https://github.com/Fizzadar/pyinfra/blob/006f751f7db2e07d32522c0285160783de2feb79/pyinfra/api/operations.py#L247-L261 | train |
Fizzadar/pyinfra | pyinfra/api/operations.py | _run_no_wait_ops | def _run_no_wait_ops(state):
'''
Run all ops for all servers at once.
'''
hosts_operations = product(state.inventory, state.get_op_order())
with progress_spinner(hosts_operations) as progress:
# Spawn greenlet for each host to run *all* ops
greenlets = [
state.pool.spawn... | python | def _run_no_wait_ops(state):
'''
Run all ops for all servers at once.
'''
hosts_operations = product(state.inventory, state.get_op_order())
with progress_spinner(hosts_operations) as progress:
# Spawn greenlet for each host to run *all* ops
greenlets = [
state.pool.spawn... | [
"def",
"_run_no_wait_ops",
"(",
"state",
")",
":",
"hosts_operations",
"=",
"product",
"(",
"state",
".",
"inventory",
",",
"state",
".",
"get_op_order",
"(",
")",
")",
"with",
"progress_spinner",
"(",
"hosts_operations",
")",
"as",
"progress",
":",
"greenlets... | Run all ops for all servers at once. | [
"Run",
"all",
"ops",
"for",
"all",
"servers",
"at",
"once",
"."
] | 006f751f7db2e07d32522c0285160783de2feb79 | https://github.com/Fizzadar/pyinfra/blob/006f751f7db2e07d32522c0285160783de2feb79/pyinfra/api/operations.py#L264-L279 | train |
Fizzadar/pyinfra | pyinfra/api/operations.py | _run_single_op | def _run_single_op(state, op_hash):
'''
Run a single operation for all servers. Can be configured to run in serial.
'''
op_meta = state.op_meta[op_hash]
op_types = []
if op_meta['serial']:
op_types.append('serial')
if op_meta['run_once']:
op_types.append('run once')
... | python | def _run_single_op(state, op_hash):
'''
Run a single operation for all servers. Can be configured to run in serial.
'''
op_meta = state.op_meta[op_hash]
op_types = []
if op_meta['serial']:
op_types.append('serial')
if op_meta['run_once']:
op_types.append('run once')
... | [
"def",
"_run_single_op",
"(",
"state",
",",
"op_hash",
")",
":",
"op_meta",
"=",
"state",
".",
"op_meta",
"[",
"op_hash",
"]",
"op_types",
"=",
"[",
"]",
"if",
"op_meta",
"[",
"'serial'",
"]",
":",
"op_types",
".",
"append",
"(",
"'serial'",
")",
"if",... | Run a single operation for all servers. Can be configured to run in serial. | [
"Run",
"a",
"single",
"operation",
"for",
"all",
"servers",
".",
"Can",
"be",
"configured",
"to",
"run",
"in",
"serial",
"."
] | 006f751f7db2e07d32522c0285160783de2feb79 | https://github.com/Fizzadar/pyinfra/blob/006f751f7db2e07d32522c0285160783de2feb79/pyinfra/api/operations.py#L282-L354 | train |
Fizzadar/pyinfra | pyinfra/api/operations.py | run_ops | def run_ops(state, serial=False, no_wait=False):
'''
Runs all operations across all servers in a configurable manner.
Args:
state (``pyinfra.api.State`` obj): the deploy state to execute
serial (boolean): whether to run operations host by host
no_wait (boolean): whether to wait for ... | python | def run_ops(state, serial=False, no_wait=False):
'''
Runs all operations across all servers in a configurable manner.
Args:
state (``pyinfra.api.State`` obj): the deploy state to execute
serial (boolean): whether to run operations host by host
no_wait (boolean): whether to wait for ... | [
"def",
"run_ops",
"(",
"state",
",",
"serial",
"=",
"False",
",",
"no_wait",
"=",
"False",
")",
":",
"state",
".",
"deploying",
"=",
"True",
"if",
"serial",
":",
"_run_serial_ops",
"(",
"state",
")",
"elif",
"no_wait",
":",
"_run_no_wait_ops",
"(",
"stat... | Runs all operations across all servers in a configurable manner.
Args:
state (``pyinfra.api.State`` obj): the deploy state to execute
serial (boolean): whether to run operations host by host
no_wait (boolean): whether to wait for all hosts between operations | [
"Runs",
"all",
"operations",
"across",
"all",
"servers",
"in",
"a",
"configurable",
"manner",
"."
] | 006f751f7db2e07d32522c0285160783de2feb79 | https://github.com/Fizzadar/pyinfra/blob/006f751f7db2e07d32522c0285160783de2feb79/pyinfra/api/operations.py#L357-L380 | train |
eruvanos/openbrokerapi | openbrokerapi/api.py | serve | def serve(service_brokers: Union[List[ServiceBroker], ServiceBroker],
credentials: Union[List[BrokerCredentials], BrokerCredentials, None],
logger: logging.Logger = logging.root,
port=5000,
debug=False):
"""
Starts flask with the given brokers.
You can provide a list ... | python | def serve(service_brokers: Union[List[ServiceBroker], ServiceBroker],
credentials: Union[List[BrokerCredentials], BrokerCredentials, None],
logger: logging.Logger = logging.root,
port=5000,
debug=False):
"""
Starts flask with the given brokers.
You can provide a list ... | [
"def",
"serve",
"(",
"service_brokers",
":",
"Union",
"[",
"List",
"[",
"ServiceBroker",
"]",
",",
"ServiceBroker",
"]",
",",
"credentials",
":",
"Union",
"[",
"List",
"[",
"BrokerCredentials",
"]",
",",
"BrokerCredentials",
",",
"None",
"]",
",",
"logger",
... | Starts flask with the given brokers.
You can provide a list or just one ServiceBroker
:param service_brokers: ServicesBroker for services to provide
:param credentials: Username and password that will be required to communicate with service broker
:param logger: Used for api logs. This will not influen... | [
"Starts",
"flask",
"with",
"the",
"given",
"brokers",
".",
"You",
"can",
"provide",
"a",
"list",
"or",
"just",
"one",
"ServiceBroker"
] | 29d514e5932f2eac27e03995dd41c8cecf40bb10 | https://github.com/eruvanos/openbrokerapi/blob/29d514e5932f2eac27e03995dd41c8cecf40bb10/openbrokerapi/api.py#L320-L348 | train |
romana/multi-ping | multiping/__init__.py | multi_ping | def multi_ping(dest_addrs, timeout, retry=0, ignore_lookup_errors=False):
"""
Combine send and receive measurement into single function.
This offers a retry mechanism: Overall timeout time is divided by
number of retries. Additional ICMPecho packets are sent to those
addresses from which we have no... | python | def multi_ping(dest_addrs, timeout, retry=0, ignore_lookup_errors=False):
"""
Combine send and receive measurement into single function.
This offers a retry mechanism: Overall timeout time is divided by
number of retries. Additional ICMPecho packets are sent to those
addresses from which we have no... | [
"def",
"multi_ping",
"(",
"dest_addrs",
",",
"timeout",
",",
"retry",
"=",
"0",
",",
"ignore_lookup_errors",
"=",
"False",
")",
":",
"retry",
"=",
"int",
"(",
"retry",
")",
"if",
"retry",
"<",
"0",
":",
"retry",
"=",
"0",
"timeout",
"=",
"float",
"("... | Combine send and receive measurement into single function.
This offers a retry mechanism: Overall timeout time is divided by
number of retries. Additional ICMPecho packets are sent to those
addresses from which we have not received answers, yet.
The retry mechanism is useful, because individual ICMP p... | [
"Combine",
"send",
"and",
"receive",
"measurement",
"into",
"single",
"function",
"."
] | 59f024c867a17fae5b4a7b52f97effc6fb1b0ca5 | https://github.com/romana/multi-ping/blob/59f024c867a17fae5b4a7b52f97effc6fb1b0ca5/multiping/__init__.py#L460-L506 | train |
romana/multi-ping | multiping/__init__.py | MultiPing._checksum | def _checksum(self, msg):
"""
Calculate the checksum of a packet.
This is inspired by a response on StackOverflow here:
https://stackoverflow.com/a/1769267/7242672
Thank you to StackOverflow user Jason Orendorff.
"""
def carry_around_add(a, b):
c = ... | python | def _checksum(self, msg):
"""
Calculate the checksum of a packet.
This is inspired by a response on StackOverflow here:
https://stackoverflow.com/a/1769267/7242672
Thank you to StackOverflow user Jason Orendorff.
"""
def carry_around_add(a, b):
c = ... | [
"def",
"_checksum",
"(",
"self",
",",
"msg",
")",
":",
"def",
"carry_around_add",
"(",
"a",
",",
"b",
")",
":",
"c",
"=",
"a",
"+",
"b",
"return",
"(",
"c",
"&",
"0xffff",
")",
"+",
"(",
"c",
">>",
"16",
")",
"s",
"=",
"0",
"for",
"i",
"in"... | Calculate the checksum of a packet.
This is inspired by a response on StackOverflow here:
https://stackoverflow.com/a/1769267/7242672
Thank you to StackOverflow user Jason Orendorff. | [
"Calculate",
"the",
"checksum",
"of",
"a",
"packet",
"."
] | 59f024c867a17fae5b4a7b52f97effc6fb1b0ca5 | https://github.com/romana/multi-ping/blob/59f024c867a17fae5b4a7b52f97effc6fb1b0ca5/multiping/__init__.py#L187-L207 | train |
romana/multi-ping | multiping/__init__.py | MultiPing.send | def send(self):
"""
Send pings to multiple addresses, ensuring unique IDs for each request.
This operation is non-blocking. Use 'receive' to get the results.
Send can be called multiple times. If there are any addresses left from
the previous send, from which results have not b... | python | def send(self):
"""
Send pings to multiple addresses, ensuring unique IDs for each request.
This operation is non-blocking. Use 'receive' to get the results.
Send can be called multiple times. If there are any addresses left from
the previous send, from which results have not b... | [
"def",
"send",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"_receive_has_been_called",
":",
"all_addrs",
"=",
"self",
".",
"_dest_addrs",
"else",
":",
"all_addrs",
"=",
"[",
"a",
"for",
"(",
"i",
",",
"a",
")",
"in",
"list",
"(",
"self",
".",
... | Send pings to multiple addresses, ensuring unique IDs for each request.
This operation is non-blocking. Use 'receive' to get the results.
Send can be called multiple times. If there are any addresses left from
the previous send, from which results have not been received yet, then
it wi... | [
"Send",
"pings",
"to",
"multiple",
"addresses",
"ensuring",
"unique",
"IDs",
"for",
"each",
"request",
"."
] | 59f024c867a17fae5b4a7b52f97effc6fb1b0ca5 | https://github.com/romana/multi-ping/blob/59f024c867a17fae5b4a7b52f97effc6fb1b0ca5/multiping/__init__.py#L268-L303 | train |
romana/multi-ping | multiping/__init__.py | MultiPing._read_all_from_socket | def _read_all_from_socket(self, timeout):
"""
Read all packets we currently can on the socket.
Returns list of tuples. Each tuple contains a packet and the time at
which it was received. NOTE: The receive time is the time when our
recv() call returned, which greatly depends on w... | python | def _read_all_from_socket(self, timeout):
"""
Read all packets we currently can on the socket.
Returns list of tuples. Each tuple contains a packet and the time at
which it was received. NOTE: The receive time is the time when our
recv() call returned, which greatly depends on w... | [
"def",
"_read_all_from_socket",
"(",
"self",
",",
"timeout",
")",
":",
"pkts",
"=",
"[",
"]",
"try",
":",
"self",
".",
"_sock",
".",
"settimeout",
"(",
"timeout",
")",
"while",
"True",
":",
"p",
"=",
"self",
".",
"_sock",
".",
"recv",
"(",
"64",
")... | Read all packets we currently can on the socket.
Returns list of tuples. Each tuple contains a packet and the time at
which it was received. NOTE: The receive time is the time when our
recv() call returned, which greatly depends on when it was called. The
time is NOT the time at which t... | [
"Read",
"all",
"packets",
"we",
"currently",
"can",
"on",
"the",
"socket",
"."
] | 59f024c867a17fae5b4a7b52f97effc6fb1b0ca5 | https://github.com/romana/multi-ping/blob/59f024c867a17fae5b4a7b52f97effc6fb1b0ca5/multiping/__init__.py#L305-L367 | train |
numat/midas | midas/driver.py | GasDetector.get | async def get(self):
"""Get current state from the Midas gas detector."""
try:
return self._parse(await self.read_registers(0, 16))
except TimeoutError:
return {'ip': self.ip, 'connected': False} | python | async def get(self):
"""Get current state from the Midas gas detector."""
try:
return self._parse(await self.read_registers(0, 16))
except TimeoutError:
return {'ip': self.ip, 'connected': False} | [
"async",
"def",
"get",
"(",
"self",
")",
":",
"try",
":",
"return",
"self",
".",
"_parse",
"(",
"await",
"self",
".",
"read_registers",
"(",
"0",
",",
"16",
")",
")",
"except",
"TimeoutError",
":",
"return",
"{",
"'ip'",
":",
"self",
".",
"ip",
","... | Get current state from the Midas gas detector. | [
"Get",
"current",
"state",
"from",
"the",
"Midas",
"gas",
"detector",
"."
] | c3a97a6cd67df1283831c3c78bf3f984212e97a8 | https://github.com/numat/midas/blob/c3a97a6cd67df1283831c3c78bf3f984212e97a8/midas/driver.py#L65-L70 | train |
numat/midas | midas/driver.py | GasDetector._parse | def _parse(self, registers):
"""Parse the response, returning a dictionary."""
result = {'ip': self.ip, 'connected': True}
decoder = BinaryPayloadDecoder.fromRegisters(registers,
byteorder=Endian.Big,
... | python | def _parse(self, registers):
"""Parse the response, returning a dictionary."""
result = {'ip': self.ip, 'connected': True}
decoder = BinaryPayloadDecoder.fromRegisters(registers,
byteorder=Endian.Big,
... | [
"def",
"_parse",
"(",
"self",
",",
"registers",
")",
":",
"result",
"=",
"{",
"'ip'",
":",
"self",
".",
"ip",
",",
"'connected'",
":",
"True",
"}",
"decoder",
"=",
"BinaryPayloadDecoder",
".",
"fromRegisters",
"(",
"registers",
",",
"byteorder",
"=",
"En... | Parse the response, returning a dictionary. | [
"Parse",
"the",
"response",
"returning",
"a",
"dictionary",
"."
] | c3a97a6cd67df1283831c3c78bf3f984212e97a8 | https://github.com/numat/midas/blob/c3a97a6cd67df1283831c3c78bf3f984212e97a8/midas/driver.py#L72-L130 | train |
numat/midas | midas/util.py | AsyncioModbusClient._connect | async def _connect(self):
"""Start asynchronous reconnect loop."""
self.waiting = True
await self.client.start(self.ip)
self.waiting = False
if self.client.protocol is None:
raise IOError("Could not connect to '{}'.".format(self.ip))
self.open = True | python | async def _connect(self):
"""Start asynchronous reconnect loop."""
self.waiting = True
await self.client.start(self.ip)
self.waiting = False
if self.client.protocol is None:
raise IOError("Could not connect to '{}'.".format(self.ip))
self.open = True | [
"async",
"def",
"_connect",
"(",
"self",
")",
":",
"self",
".",
"waiting",
"=",
"True",
"await",
"self",
".",
"client",
".",
"start",
"(",
"self",
".",
"ip",
")",
"self",
".",
"waiting",
"=",
"False",
"if",
"self",
".",
"client",
".",
"protocol",
"... | Start asynchronous reconnect loop. | [
"Start",
"asynchronous",
"reconnect",
"loop",
"."
] | c3a97a6cd67df1283831c3c78bf3f984212e97a8 | https://github.com/numat/midas/blob/c3a97a6cd67df1283831c3c78bf3f984212e97a8/midas/util.py#L36-L43 | train |
numat/midas | midas/util.py | AsyncioModbusClient.read_registers | async def read_registers(self, address, count):
"""Read modbus registers.
The Modbus protocol doesn't allow responses longer than 250 bytes
(ie. 125 registers, 62 DF addresses), which this function manages by
chunking larger requests.
"""
registers = []
while cou... | python | async def read_registers(self, address, count):
"""Read modbus registers.
The Modbus protocol doesn't allow responses longer than 250 bytes
(ie. 125 registers, 62 DF addresses), which this function manages by
chunking larger requests.
"""
registers = []
while cou... | [
"async",
"def",
"read_registers",
"(",
"self",
",",
"address",
",",
"count",
")",
":",
"registers",
"=",
"[",
"]",
"while",
"count",
">",
"124",
":",
"r",
"=",
"await",
"self",
".",
"_request",
"(",
"'read_holding_registers'",
",",
"address",
",",
"124",... | Read modbus registers.
The Modbus protocol doesn't allow responses longer than 250 bytes
(ie. 125 registers, 62 DF addresses), which this function manages by
chunking larger requests. | [
"Read",
"modbus",
"registers",
"."
] | c3a97a6cd67df1283831c3c78bf3f984212e97a8 | https://github.com/numat/midas/blob/c3a97a6cd67df1283831c3c78bf3f984212e97a8/midas/util.py#L49-L63 | train |
numat/midas | midas/util.py | AsyncioModbusClient.write_register | async def write_register(self, address, value, skip_encode=False):
"""Write a modbus register."""
await self._request('write_registers', address, value, skip_encode=skip_encode) | python | async def write_register(self, address, value, skip_encode=False):
"""Write a modbus register."""
await self._request('write_registers', address, value, skip_encode=skip_encode) | [
"async",
"def",
"write_register",
"(",
"self",
",",
"address",
",",
"value",
",",
"skip_encode",
"=",
"False",
")",
":",
"await",
"self",
".",
"_request",
"(",
"'write_registers'",
",",
"address",
",",
"value",
",",
"skip_encode",
"=",
"skip_encode",
")"
] | Write a modbus register. | [
"Write",
"a",
"modbus",
"register",
"."
] | c3a97a6cd67df1283831c3c78bf3f984212e97a8 | https://github.com/numat/midas/blob/c3a97a6cd67df1283831c3c78bf3f984212e97a8/midas/util.py#L73-L75 | train |
numat/midas | midas/util.py | AsyncioModbusClient.write_registers | async def write_registers(self, address, values, skip_encode=False):
"""Write modbus registers.
The Modbus protocol doesn't allow requests longer than 250 bytes
(ie. 125 registers, 62 DF addresses), which this function manages by
chunking larger requests.
"""
while len(v... | python | async def write_registers(self, address, values, skip_encode=False):
"""Write modbus registers.
The Modbus protocol doesn't allow requests longer than 250 bytes
(ie. 125 registers, 62 DF addresses), which this function manages by
chunking larger requests.
"""
while len(v... | [
"async",
"def",
"write_registers",
"(",
"self",
",",
"address",
",",
"values",
",",
"skip_encode",
"=",
"False",
")",
":",
"while",
"len",
"(",
"values",
")",
">",
"62",
":",
"await",
"self",
".",
"_request",
"(",
"'write_registers'",
",",
"address",
","... | Write modbus registers.
The Modbus protocol doesn't allow requests longer than 250 bytes
(ie. 125 registers, 62 DF addresses), which this function manages by
chunking larger requests. | [
"Write",
"modbus",
"registers",
"."
] | c3a97a6cd67df1283831c3c78bf3f984212e97a8 | https://github.com/numat/midas/blob/c3a97a6cd67df1283831c3c78bf3f984212e97a8/midas/util.py#L77-L89 | train |
numat/midas | midas/util.py | AsyncioModbusClient._request | async def _request(self, method, *args, **kwargs):
"""Send a request to the device and awaits a response.
This mainly ensures that requests are sent serially, as the Modbus
protocol does not allow simultaneous requests (it'll ignore any
request sent while it's processing something). The... | python | async def _request(self, method, *args, **kwargs):
"""Send a request to the device and awaits a response.
This mainly ensures that requests are sent serially, as the Modbus
protocol does not allow simultaneous requests (it'll ignore any
request sent while it's processing something). The... | [
"async",
"def",
"_request",
"(",
"self",
",",
"method",
",",
"*",
"args",
",",
"**",
"kwargs",
")",
":",
"if",
"not",
"self",
".",
"open",
":",
"await",
"self",
".",
"_connect",
"(",
")",
"while",
"self",
".",
"waiting",
":",
"await",
"asyncio",
".... | Send a request to the device and awaits a response.
This mainly ensures that requests are sent serially, as the Modbus
protocol does not allow simultaneous requests (it'll ignore any
request sent while it's processing something). The driver handles this
by assuming there is only one cli... | [
"Send",
"a",
"request",
"to",
"the",
"device",
"and",
"awaits",
"a",
"response",
"."
] | c3a97a6cd67df1283831c3c78bf3f984212e97a8 | https://github.com/numat/midas/blob/c3a97a6cd67df1283831c3c78bf3f984212e97a8/midas/util.py#L91-L125 | train |
numat/midas | midas/util.py | AsyncioModbusClient._close | def _close(self):
"""Close the TCP connection."""
self.client.stop()
self.open = False
self.waiting = False | python | def _close(self):
"""Close the TCP connection."""
self.client.stop()
self.open = False
self.waiting = False | [
"def",
"_close",
"(",
"self",
")",
":",
"self",
".",
"client",
".",
"stop",
"(",
")",
"self",
".",
"open",
"=",
"False",
"self",
".",
"waiting",
"=",
"False"
] | Close the TCP connection. | [
"Close",
"the",
"TCP",
"connection",
"."
] | c3a97a6cd67df1283831c3c78bf3f984212e97a8 | https://github.com/numat/midas/blob/c3a97a6cd67df1283831c3c78bf3f984212e97a8/midas/util.py#L127-L131 | train |
numat/midas | midas/__init__.py | command_line | def command_line():
"""Command-line tool for Midas gas detector communication."""
import argparse
import asyncio
import json
parser = argparse.ArgumentParser(description="Read a Honeywell Midas gas "
"detector state from the command line.")
parser.add_argume... | python | def command_line():
"""Command-line tool for Midas gas detector communication."""
import argparse
import asyncio
import json
parser = argparse.ArgumentParser(description="Read a Honeywell Midas gas "
"detector state from the command line.")
parser.add_argume... | [
"def",
"command_line",
"(",
")",
":",
"import",
"argparse",
"import",
"asyncio",
"import",
"json",
"parser",
"=",
"argparse",
".",
"ArgumentParser",
"(",
"description",
"=",
"\"Read a Honeywell Midas gas \"",
"\"detector state from the command line.\"",
")",
"parser",
"... | Command-line tool for Midas gas detector communication. | [
"Command",
"-",
"line",
"tool",
"for",
"Midas",
"gas",
"detector",
"communication",
"."
] | c3a97a6cd67df1283831c3c78bf3f984212e97a8 | https://github.com/numat/midas/blob/c3a97a6cd67df1283831c3c78bf3f984212e97a8/midas/__init__.py#L11-L28 | train |
bioinf-jku/FCD | build/lib/fcd/FCD.py | build_masked_loss | def build_masked_loss(loss_function, mask_value):
"""Builds a loss function that masks based on targets
Args:
loss_function: The loss function to mask
mask_value: The value to mask in the targets
Returns:
function: a loss function that acts like loss_function with masked inputs
... | python | def build_masked_loss(loss_function, mask_value):
"""Builds a loss function that masks based on targets
Args:
loss_function: The loss function to mask
mask_value: The value to mask in the targets
Returns:
function: a loss function that acts like loss_function with masked inputs
... | [
"def",
"build_masked_loss",
"(",
"loss_function",
",",
"mask_value",
")",
":",
"def",
"masked_loss_function",
"(",
"y_true",
",",
"y_pred",
")",
":",
"mask",
"=",
"K",
".",
"cast",
"(",
"K",
".",
"not_equal",
"(",
"y_true",
",",
"mask_value",
")",
",",
"... | Builds a loss function that masks based on targets
Args:
loss_function: The loss function to mask
mask_value: The value to mask in the targets
Returns:
function: a loss function that acts like loss_function with masked inputs | [
"Builds",
"a",
"loss",
"function",
"that",
"masks",
"based",
"on",
"targets"
] | fe542b16d72a2d0899989374e1a86cc930d891e1 | https://github.com/bioinf-jku/FCD/blob/fe542b16d72a2d0899989374e1a86cc930d891e1/build/lib/fcd/FCD.py#L88-L103 | train |
google/python-gflags | gflags2man.py | ProgramInfo.Run | def Run(self):
"""Run it and collect output.
Returns:
1 (true) If everything went well.
0 (false) If there were problems.
"""
if not self.executable:
logging.error('Could not locate "%s"' % self.long_name)
return 0
finfo = os.stat(self.executable)
self.date = time.lo... | python | def Run(self):
"""Run it and collect output.
Returns:
1 (true) If everything went well.
0 (false) If there were problems.
"""
if not self.executable:
logging.error('Could not locate "%s"' % self.long_name)
return 0
finfo = os.stat(self.executable)
self.date = time.lo... | [
"def",
"Run",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"executable",
":",
"logging",
".",
"error",
"(",
"'Could not locate \"%s\"'",
"%",
"self",
".",
"long_name",
")",
"return",
"0",
"finfo",
"=",
"os",
".",
"stat",
"(",
"self",
".",
"executab... | Run it and collect output.
Returns:
1 (true) If everything went well.
0 (false) If there were problems. | [
"Run",
"it",
"and",
"collect",
"output",
"."
] | 4f06c3d0d6cbe9b1fb90ee9fb1c082b3bf9285f6 | https://github.com/google/python-gflags/blob/4f06c3d0d6cbe9b1fb90ee9fb1c082b3bf9285f6/gflags2man.py#L185-L214 | train |
google/python-gflags | gflags2man.py | ProgramInfo.Parse | def Parse(self):
"""Parse program output."""
(start_line, lang) = self.ParseDesc()
if start_line < 0:
return
if 'python' == lang:
self.ParsePythonFlags(start_line)
elif 'c' == lang:
self.ParseCFlags(start_line)
elif 'java' == lang:
self.ParseJavaFlags(start_line) | python | def Parse(self):
"""Parse program output."""
(start_line, lang) = self.ParseDesc()
if start_line < 0:
return
if 'python' == lang:
self.ParsePythonFlags(start_line)
elif 'c' == lang:
self.ParseCFlags(start_line)
elif 'java' == lang:
self.ParseJavaFlags(start_line) | [
"def",
"Parse",
"(",
"self",
")",
":",
"(",
"start_line",
",",
"lang",
")",
"=",
"self",
".",
"ParseDesc",
"(",
")",
"if",
"start_line",
"<",
"0",
":",
"return",
"if",
"'python'",
"==",
"lang",
":",
"self",
".",
"ParsePythonFlags",
"(",
"start_line",
... | Parse program output. | [
"Parse",
"program",
"output",
"."
] | 4f06c3d0d6cbe9b1fb90ee9fb1c082b3bf9285f6 | https://github.com/google/python-gflags/blob/4f06c3d0d6cbe9b1fb90ee9fb1c082b3bf9285f6/gflags2man.py#L216-L226 | train |
google/python-gflags | gflags2man.py | ProgramInfo.ParseDesc | def ParseDesc(self, start_line=0):
"""Parse the initial description.
This could be Python or C++.
Returns:
(start_line, lang_type)
start_line Line to start parsing flags on (int)
lang_type Either 'python' or 'c'
(-1, '') if the flags start could not be found
"""
ex... | python | def ParseDesc(self, start_line=0):
"""Parse the initial description.
This could be Python or C++.
Returns:
(start_line, lang_type)
start_line Line to start parsing flags on (int)
lang_type Either 'python' or 'c'
(-1, '') if the flags start could not be found
"""
ex... | [
"def",
"ParseDesc",
"(",
"self",
",",
"start_line",
"=",
"0",
")",
":",
"exec_mod_start",
"=",
"self",
".",
"executable",
"+",
"':'",
"after_blank",
"=",
"0",
"start_line",
"=",
"0",
"for",
"start_line",
"in",
"range",
"(",
"start_line",
",",
"len",
"(",... | Parse the initial description.
This could be Python or C++.
Returns:
(start_line, lang_type)
start_line Line to start parsing flags on (int)
lang_type Either 'python' or 'c'
(-1, '') if the flags start could not be found | [
"Parse",
"the",
"initial",
"description",
"."
] | 4f06c3d0d6cbe9b1fb90ee9fb1c082b3bf9285f6 | https://github.com/google/python-gflags/blob/4f06c3d0d6cbe9b1fb90ee9fb1c082b3bf9285f6/gflags2man.py#L228-L272 | train |
google/python-gflags | gflags2man.py | ProgramInfo.ParseCFlags | def ParseCFlags(self, start_line=0):
"""Parse C style flags."""
modname = None # name of current module
modlist = []
flag = None
for line_num in range(start_line, len(self.output)): # collect flags
line = self.output[line_num].rstrip()
if not line: ... | python | def ParseCFlags(self, start_line=0):
"""Parse C style flags."""
modname = None # name of current module
modlist = []
flag = None
for line_num in range(start_line, len(self.output)): # collect flags
line = self.output[line_num].rstrip()
if not line: ... | [
"def",
"ParseCFlags",
"(",
"self",
",",
"start_line",
"=",
"0",
")",
":",
"modname",
"=",
"None",
"modlist",
"=",
"[",
"]",
"flag",
"=",
"None",
"for",
"line_num",
"in",
"range",
"(",
"start_line",
",",
"len",
"(",
"self",
".",
"output",
")",
")",
... | Parse C style flags. | [
"Parse",
"C",
"style",
"flags",
"."
] | 4f06c3d0d6cbe9b1fb90ee9fb1c082b3bf9285f6 | https://github.com/google/python-gflags/blob/4f06c3d0d6cbe9b1fb90ee9fb1c082b3bf9285f6/gflags2man.py#L323-L362 | train |
google/python-gflags | gflags2man.py | ProgramInfo.Filter | def Filter(self):
"""Filter parsed data to create derived fields."""
if not self.desc:
self.short_desc = ''
return
for i in range(len(self.desc)): # replace full path with name
if self.desc[i].find(self.executable) >= 0:
self.desc[i] = self.desc[i].replace(self.executable, self.... | python | def Filter(self):
"""Filter parsed data to create derived fields."""
if not self.desc:
self.short_desc = ''
return
for i in range(len(self.desc)): # replace full path with name
if self.desc[i].find(self.executable) >= 0:
self.desc[i] = self.desc[i].replace(self.executable, self.... | [
"def",
"Filter",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"desc",
":",
"self",
".",
"short_desc",
"=",
"''",
"return",
"for",
"i",
"in",
"range",
"(",
"len",
"(",
"self",
".",
"desc",
")",
")",
":",
"if",
"self",
".",
"desc",
"[",
"i",
... | Filter parsed data to create derived fields. | [
"Filter",
"parsed",
"data",
"to",
"create",
"derived",
"fields",
"."
] | 4f06c3d0d6cbe9b1fb90ee9fb1c082b3bf9285f6 | https://github.com/google/python-gflags/blob/4f06c3d0d6cbe9b1fb90ee9fb1c082b3bf9285f6/gflags2man.py#L411-L431 | train |
google/python-gflags | gflags2man.py | GenerateDoc.Output | def Output(self):
"""Output all sections of the page."""
self.Open()
self.Header()
self.Body()
self.Footer() | python | def Output(self):
"""Output all sections of the page."""
self.Open()
self.Header()
self.Body()
self.Footer() | [
"def",
"Output",
"(",
"self",
")",
":",
"self",
".",
"Open",
"(",
")",
"self",
".",
"Header",
"(",
")",
"self",
".",
"Body",
"(",
")",
"self",
".",
"Footer",
"(",
")"
] | Output all sections of the page. | [
"Output",
"all",
"sections",
"of",
"the",
"page",
"."
] | 4f06c3d0d6cbe9b1fb90ee9fb1c082b3bf9285f6 | https://github.com/google/python-gflags/blob/4f06c3d0d6cbe9b1fb90ee9fb1c082b3bf9285f6/gflags2man.py#L446-L451 | train |
google/python-gflags | gflags/_helpers.py | GetFlagSuggestions | def GetFlagSuggestions(attempt, longopt_list):
"""Get helpful similar matches for an invalid flag."""
# Don't suggest on very short strings, or if no longopts are specified.
if len(attempt) <= 2 or not longopt_list:
return []
option_names = [v.split('=')[0] for v in longopt_list]
# Find close approximat... | python | def GetFlagSuggestions(attempt, longopt_list):
"""Get helpful similar matches for an invalid flag."""
# Don't suggest on very short strings, or if no longopts are specified.
if len(attempt) <= 2 or not longopt_list:
return []
option_names = [v.split('=')[0] for v in longopt_list]
# Find close approximat... | [
"def",
"GetFlagSuggestions",
"(",
"attempt",
",",
"longopt_list",
")",
":",
"if",
"len",
"(",
"attempt",
")",
"<=",
"2",
"or",
"not",
"longopt_list",
":",
"return",
"[",
"]",
"option_names",
"=",
"[",
"v",
".",
"split",
"(",
"'='",
")",
"[",
"0",
"]"... | Get helpful similar matches for an invalid flag. | [
"Get",
"helpful",
"similar",
"matches",
"for",
"an",
"invalid",
"flag",
"."
] | 4f06c3d0d6cbe9b1fb90ee9fb1c082b3bf9285f6 | https://github.com/google/python-gflags/blob/4f06c3d0d6cbe9b1fb90ee9fb1c082b3bf9285f6/gflags/_helpers.py#L216-L241 | train |
google/python-gflags | gflags/_helpers.py | _DamerauLevenshtein | def _DamerauLevenshtein(a, b):
"""Damerau-Levenshtein edit distance from a to b."""
memo = {}
def Distance(x, y):
"""Recursively defined string distance with memoization."""
if (x, y) in memo:
return memo[x, y]
if not x:
d = len(y)
elif not y:
d = len(x)
else:
d = min(... | python | def _DamerauLevenshtein(a, b):
"""Damerau-Levenshtein edit distance from a to b."""
memo = {}
def Distance(x, y):
"""Recursively defined string distance with memoization."""
if (x, y) in memo:
return memo[x, y]
if not x:
d = len(y)
elif not y:
d = len(x)
else:
d = min(... | [
"def",
"_DamerauLevenshtein",
"(",
"a",
",",
"b",
")",
":",
"memo",
"=",
"{",
"}",
"def",
"Distance",
"(",
"x",
",",
"y",
")",
":",
"if",
"(",
"x",
",",
"y",
")",
"in",
"memo",
":",
"return",
"memo",
"[",
"x",
",",
"y",
"]",
"if",
"not",
"x... | Damerau-Levenshtein edit distance from a to b. | [
"Damerau",
"-",
"Levenshtein",
"edit",
"distance",
"from",
"a",
"to",
"b",
"."
] | 4f06c3d0d6cbe9b1fb90ee9fb1c082b3bf9285f6 | https://github.com/google/python-gflags/blob/4f06c3d0d6cbe9b1fb90ee9fb1c082b3bf9285f6/gflags/_helpers.py#L244-L269 | train |
google/python-gflags | gflags/_helpers.py | FlagDictToArgs | def FlagDictToArgs(flag_map):
"""Convert a dict of values into process call parameters.
This method is used to convert a dictionary into a sequence of parameters
for a binary that parses arguments using this module.
Args:
flag_map: a mapping where the keys are flag names (strings).
values are treate... | python | def FlagDictToArgs(flag_map):
"""Convert a dict of values into process call parameters.
This method is used to convert a dictionary into a sequence of parameters
for a binary that parses arguments using this module.
Args:
flag_map: a mapping where the keys are flag names (strings).
values are treate... | [
"def",
"FlagDictToArgs",
"(",
"flag_map",
")",
":",
"for",
"key",
",",
"value",
"in",
"six",
".",
"iteritems",
"(",
"flag_map",
")",
":",
"if",
"value",
"is",
"None",
":",
"yield",
"'--%s'",
"%",
"key",
"elif",
"isinstance",
"(",
"value",
",",
"bool",
... | Convert a dict of values into process call parameters.
This method is used to convert a dictionary into a sequence of parameters
for a binary that parses arguments using this module.
Args:
flag_map: a mapping where the keys are flag names (strings).
values are treated according to their type:
* ... | [
"Convert",
"a",
"dict",
"of",
"values",
"into",
"process",
"call",
"parameters",
"."
] | 4f06c3d0d6cbe9b1fb90ee9fb1c082b3bf9285f6 | https://github.com/google/python-gflags/blob/4f06c3d0d6cbe9b1fb90ee9fb1c082b3bf9285f6/gflags/_helpers.py#L329-L364 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.