repository_name stringlengths 5 67 | func_path_in_repository stringlengths 4 234 | func_name stringlengths 0 314 | whole_func_string stringlengths 52 3.87M | language stringclasses 6
values | func_code_string stringlengths 52 3.87M | func_code_tokens listlengths 15 672k | func_documentation_string stringlengths 1 47.2k | func_documentation_tokens listlengths 1 3.92k | split_name stringclasses 1
value | func_code_url stringlengths 85 339 |
|---|---|---|---|---|---|---|---|---|---|---|
mar10/pyftpsync | ftpsync/util.py | ansi_code | def ansi_code(name):
"""Return ansi color or style codes or '' if colorama is not available."""
try:
obj = colorama
for part in name.split("."):
obj = getattr(obj, part)
return obj
except AttributeError:
return "" | python | def ansi_code(name):
"""Return ansi color or style codes or '' if colorama is not available."""
try:
obj = colorama
for part in name.split("."):
obj = getattr(obj, part)
return obj
except AttributeError:
return "" | [
"def",
"ansi_code",
"(",
"name",
")",
":",
"try",
":",
"obj",
"=",
"colorama",
"for",
"part",
"in",
"name",
".",
"split",
"(",
"\".\"",
")",
":",
"obj",
"=",
"getattr",
"(",
"obj",
",",
"part",
")",
"return",
"obj",
"except",
"AttributeError",
":",
... | Return ansi color or style codes or '' if colorama is not available. | [
"Return",
"ansi",
"color",
"or",
"style",
"codes",
"or",
"if",
"colorama",
"is",
"not",
"available",
"."
] | train | https://github.com/mar10/pyftpsync/blob/bbdc94186975cdc1cc4f678474bdce08bce7bb76/ftpsync/util.py#L332-L340 |
mar10/pyftpsync | ftpsync/util.py | byte_compare | def byte_compare(stream_a, stream_b):
"""Byte compare two files (early out on first difference).
Returns:
(bool, int): offset of first mismatch or 0 if equal
"""
bufsize = 16 * 1024
equal = True
ofs = 0
while True:
b1 = stream_a.read(bufsize)
b2 = stream_b.read(bufsi... | python | def byte_compare(stream_a, stream_b):
"""Byte compare two files (early out on first difference).
Returns:
(bool, int): offset of first mismatch or 0 if equal
"""
bufsize = 16 * 1024
equal = True
ofs = 0
while True:
b1 = stream_a.read(bufsize)
b2 = stream_b.read(bufsi... | [
"def",
"byte_compare",
"(",
"stream_a",
",",
"stream_b",
")",
":",
"bufsize",
"=",
"16",
"*",
"1024",
"equal",
"=",
"True",
"ofs",
"=",
"0",
"while",
"True",
":",
"b1",
"=",
"stream_a",
".",
"read",
"(",
"bufsize",
")",
"b2",
"=",
"stream_b",
".",
... | Byte compare two files (early out on first difference).
Returns:
(bool, int): offset of first mismatch or 0 if equal | [
"Byte",
"compare",
"two",
"files",
"(",
"early",
"out",
"on",
"first",
"difference",
")",
"."
] | train | https://github.com/mar10/pyftpsync/blob/bbdc94186975cdc1cc4f678474bdce08bce7bb76/ftpsync/util.py#L343-L367 |
mar10/pyftpsync | ftpsync/util.py | decode_dict_keys | def decode_dict_keys(d, coding="utf-8"):
"""Convert all keys to unicde (recursively)."""
assert compat.PY2
res = {}
for k, v in d.items(): #
if type(k) is str:
k = k.decode(coding)
if type(v) is dict:
v = decode_dict_keys(v, coding)
res[k] = v
return ... | python | def decode_dict_keys(d, coding="utf-8"):
"""Convert all keys to unicde (recursively)."""
assert compat.PY2
res = {}
for k, v in d.items(): #
if type(k) is str:
k = k.decode(coding)
if type(v) is dict:
v = decode_dict_keys(v, coding)
res[k] = v
return ... | [
"def",
"decode_dict_keys",
"(",
"d",
",",
"coding",
"=",
"\"utf-8\"",
")",
":",
"assert",
"compat",
".",
"PY2",
"res",
"=",
"{",
"}",
"for",
"k",
",",
"v",
"in",
"d",
".",
"items",
"(",
")",
":",
"#",
"if",
"type",
"(",
"k",
")",
"is",
"str",
... | Convert all keys to unicde (recursively). | [
"Convert",
"all",
"keys",
"to",
"unicde",
"(",
"recursively",
")",
"."
] | train | https://github.com/mar10/pyftpsync/blob/bbdc94186975cdc1cc4f678474bdce08bce7bb76/ftpsync/util.py#L370-L380 |
mar10/pyftpsync | ftpsync/util.py | make_native_dict_keys | def make_native_dict_keys(d):
"""Convert all keys to native `str` type (recursively)."""
res = {}
for k, v in d.items(): #
k = compat.to_native(k)
if type(v) is dict:
v = make_native_dict_keys(v)
res[k] = v
return res | python | def make_native_dict_keys(d):
"""Convert all keys to native `str` type (recursively)."""
res = {}
for k, v in d.items(): #
k = compat.to_native(k)
if type(v) is dict:
v = make_native_dict_keys(v)
res[k] = v
return res | [
"def",
"make_native_dict_keys",
"(",
"d",
")",
":",
"res",
"=",
"{",
"}",
"for",
"k",
",",
"v",
"in",
"d",
".",
"items",
"(",
")",
":",
"#",
"k",
"=",
"compat",
".",
"to_native",
"(",
"k",
")",
"if",
"type",
"(",
"v",
")",
"is",
"dict",
":",
... | Convert all keys to native `str` type (recursively). | [
"Convert",
"all",
"keys",
"to",
"native",
"str",
"type",
"(",
"recursively",
")",
"."
] | train | https://github.com/mar10/pyftpsync/blob/bbdc94186975cdc1cc4f678474bdce08bce7bb76/ftpsync/util.py#L383-L391 |
mar10/pyftpsync | ftpsync/targets.py | make_target | def make_target(url, extra_opts=None):
"""Factory that creates `_Target` objects from URLs.
FTP targets must begin with the scheme ``ftp://`` or ``ftps://`` for TLS.
Note:
TLS is only supported on Python 2.7/3.2+.
Args:
url (str):
extra_opts (dict, optional): Passed to Target c... | python | def make_target(url, extra_opts=None):
"""Factory that creates `_Target` objects from URLs.
FTP targets must begin with the scheme ``ftp://`` or ``ftps://`` for TLS.
Note:
TLS is only supported on Python 2.7/3.2+.
Args:
url (str):
extra_opts (dict, optional): Passed to Target c... | [
"def",
"make_target",
"(",
"url",
",",
"extra_opts",
"=",
"None",
")",
":",
"# debug = extra_opts.get(\"debug\", 1)",
"parts",
"=",
"compat",
".",
"urlparse",
"(",
"url",
",",
"allow_fragments",
"=",
"False",
")",
"# scheme is case-insensitive according to https://tools... | Factory that creates `_Target` objects from URLs.
FTP targets must begin with the scheme ``ftp://`` or ``ftps://`` for TLS.
Note:
TLS is only supported on Python 2.7/3.2+.
Args:
url (str):
extra_opts (dict, optional): Passed to Target constructor. Default: None.
Returns:
... | [
"Factory",
"that",
"creates",
"_Target",
"objects",
"from",
"URLs",
"."
] | train | https://github.com/mar10/pyftpsync/blob/bbdc94186975cdc1cc4f678474bdce08bce7bb76/ftpsync/targets.py#L24-L59 |
mar10/pyftpsync | ftpsync/targets.py | _get_encoding_opt | def _get_encoding_opt(synchronizer, extra_opts, default):
"""Helper to figure out encoding setting inside constructors."""
encoding = default
# if synchronizer and "encoding" in synchronizer.options:
# encoding = synchronizer.options.get("encoding")
if extra_opts and "encoding" in extra_opts:
... | python | def _get_encoding_opt(synchronizer, extra_opts, default):
"""Helper to figure out encoding setting inside constructors."""
encoding = default
# if synchronizer and "encoding" in synchronizer.options:
# encoding = synchronizer.options.get("encoding")
if extra_opts and "encoding" in extra_opts:
... | [
"def",
"_get_encoding_opt",
"(",
"synchronizer",
",",
"extra_opts",
",",
"default",
")",
":",
"encoding",
"=",
"default",
"# if synchronizer and \"encoding\" in synchronizer.options:",
"# encoding = synchronizer.options.get(\"encoding\")",
"if",
"extra_opts",
"and",
"\"encodi... | Helper to figure out encoding setting inside constructors. | [
"Helper",
"to",
"figure",
"out",
"encoding",
"setting",
"inside",
"constructors",
"."
] | train | https://github.com/mar10/pyftpsync/blob/bbdc94186975cdc1cc4f678474bdce08bce7bb76/ftpsync/targets.py#L62-L73 |
mar10/pyftpsync | ftpsync/targets.py | _Target.get_options_dict | def get_options_dict(self):
"""Return options from synchronizer (possibly overridden by own extra_opts)."""
d = self.synchronizer.options if self.synchronizer else {}
d.update(self.extra_opts)
return d | python | def get_options_dict(self):
"""Return options from synchronizer (possibly overridden by own extra_opts)."""
d = self.synchronizer.options if self.synchronizer else {}
d.update(self.extra_opts)
return d | [
"def",
"get_options_dict",
"(",
"self",
")",
":",
"d",
"=",
"self",
".",
"synchronizer",
".",
"options",
"if",
"self",
".",
"synchronizer",
"else",
"{",
"}",
"d",
".",
"update",
"(",
"self",
".",
"extra_opts",
")",
"return",
"d"
] | Return options from synchronizer (possibly overridden by own extra_opts). | [
"Return",
"options",
"from",
"synchronizer",
"(",
"possibly",
"overridden",
"by",
"own",
"extra_opts",
")",
"."
] | train | https://github.com/mar10/pyftpsync/blob/bbdc94186975cdc1cc4f678474bdce08bce7bb76/ftpsync/targets.py#L172-L176 |
mar10/pyftpsync | ftpsync/targets.py | _Target.get_option | def get_option(self, key, default=None):
"""Return option from synchronizer (possibly overridden by target extra_opts)."""
if self.synchronizer:
return self.extra_opts.get(key, self.synchronizer.options.get(key, default))
return self.extra_opts.get(key, default) | python | def get_option(self, key, default=None):
"""Return option from synchronizer (possibly overridden by target extra_opts)."""
if self.synchronizer:
return self.extra_opts.get(key, self.synchronizer.options.get(key, default))
return self.extra_opts.get(key, default) | [
"def",
"get_option",
"(",
"self",
",",
"key",
",",
"default",
"=",
"None",
")",
":",
"if",
"self",
".",
"synchronizer",
":",
"return",
"self",
".",
"extra_opts",
".",
"get",
"(",
"key",
",",
"self",
".",
"synchronizer",
".",
"options",
".",
"get",
"(... | Return option from synchronizer (possibly overridden by target extra_opts). | [
"Return",
"option",
"from",
"synchronizer",
"(",
"possibly",
"overridden",
"by",
"target",
"extra_opts",
")",
"."
] | train | https://github.com/mar10/pyftpsync/blob/bbdc94186975cdc1cc4f678474bdce08bce7bb76/ftpsync/targets.py#L178-L182 |
mar10/pyftpsync | ftpsync/targets.py | _Target.check_write | def check_write(self, name):
"""Raise exception if writing cur_dir/name is not allowed."""
assert compat.is_native(name)
if self.readonly and name not in (
DirMetadata.META_FILE_NAME,
DirMetadata.LOCK_FILE_NAME,
):
raise RuntimeError("Target is read-on... | python | def check_write(self, name):
"""Raise exception if writing cur_dir/name is not allowed."""
assert compat.is_native(name)
if self.readonly and name not in (
DirMetadata.META_FILE_NAME,
DirMetadata.LOCK_FILE_NAME,
):
raise RuntimeError("Target is read-on... | [
"def",
"check_write",
"(",
"self",
",",
"name",
")",
":",
"assert",
"compat",
".",
"is_native",
"(",
"name",
")",
"if",
"self",
".",
"readonly",
"and",
"name",
"not",
"in",
"(",
"DirMetadata",
".",
"META_FILE_NAME",
",",
"DirMetadata",
".",
"LOCK_FILE_NAME... | Raise exception if writing cur_dir/name is not allowed. | [
"Raise",
"exception",
"if",
"writing",
"cur_dir",
"/",
"name",
"is",
"not",
"allowed",
"."
] | train | https://github.com/mar10/pyftpsync/blob/bbdc94186975cdc1cc4f678474bdce08bce7bb76/ftpsync/targets.py#L201-L208 |
mar10/pyftpsync | ftpsync/targets.py | _Target.get_sync_info | def get_sync_info(self, name, key=None):
"""Get mtime/size when this target's current dir was last synchronized with remote."""
peer_target = self.peer
if self.is_local():
info = self.cur_dir_meta.dir["peer_sync"].get(peer_target.get_id())
else:
info = peer_target... | python | def get_sync_info(self, name, key=None):
"""Get mtime/size when this target's current dir was last synchronized with remote."""
peer_target = self.peer
if self.is_local():
info = self.cur_dir_meta.dir["peer_sync"].get(peer_target.get_id())
else:
info = peer_target... | [
"def",
"get_sync_info",
"(",
"self",
",",
"name",
",",
"key",
"=",
"None",
")",
":",
"peer_target",
"=",
"self",
".",
"peer",
"if",
"self",
".",
"is_local",
"(",
")",
":",
"info",
"=",
"self",
".",
"cur_dir_meta",
".",
"dir",
"[",
"\"peer_sync\"",
"]... | Get mtime/size when this target's current dir was last synchronized with remote. | [
"Get",
"mtime",
"/",
"size",
"when",
"this",
"target",
"s",
"current",
"dir",
"was",
"last",
"synchronized",
"with",
"remote",
"."
] | train | https://github.com/mar10/pyftpsync/blob/bbdc94186975cdc1cc4f678474bdce08bce7bb76/ftpsync/targets.py#L213-L224 |
mar10/pyftpsync | ftpsync/targets.py | _Target.walk | def walk(self, pred=None, recursive=True):
"""Iterate over all target entries recursively.
Args:
pred (function, optional):
Callback(:class:`ftpsync.resources._Resource`) should return `False` to
ignore entry. Default: `None`.
recursive (bool, opt... | python | def walk(self, pred=None, recursive=True):
"""Iterate over all target entries recursively.
Args:
pred (function, optional):
Callback(:class:`ftpsync.resources._Resource`) should return `False` to
ignore entry. Default: `None`.
recursive (bool, opt... | [
"def",
"walk",
"(",
"self",
",",
"pred",
"=",
"None",
",",
"recursive",
"=",
"True",
")",
":",
"for",
"entry",
"in",
"self",
".",
"get_dir",
"(",
")",
":",
"if",
"pred",
"and",
"pred",
"(",
"entry",
")",
"is",
"False",
":",
"continue",
"yield",
"... | Iterate over all target entries recursively.
Args:
pred (function, optional):
Callback(:class:`ftpsync.resources._Resource`) should return `False` to
ignore entry. Default: `None`.
recursive (bool, optional):
Pass `False` to generate top l... | [
"Iterate",
"over",
"all",
"target",
"entries",
"recursively",
"."
] | train | https://github.com/mar10/pyftpsync/blob/bbdc94186975cdc1cc4f678474bdce08bce7bb76/ftpsync/targets.py#L255-L279 |
mar10/pyftpsync | ftpsync/targets.py | _Target.read_text | def read_text(self, name):
"""Read text string from cur_dir/name using open_readable()."""
with self.open_readable(name) as fp:
res = fp.read() # StringIO or file object
# try:
# res = fp.getvalue() # StringIO returned by FtpTarget
# except Attribute... | python | def read_text(self, name):
"""Read text string from cur_dir/name using open_readable()."""
with self.open_readable(name) as fp:
res = fp.read() # StringIO or file object
# try:
# res = fp.getvalue() # StringIO returned by FtpTarget
# except Attribute... | [
"def",
"read_text",
"(",
"self",
",",
"name",
")",
":",
"with",
"self",
".",
"open_readable",
"(",
"name",
")",
"as",
"fp",
":",
"res",
"=",
"fp",
".",
"read",
"(",
")",
"# StringIO or file object",
"# try:",
"# res = fp.getvalue() # StringIO returned by Ft... | Read text string from cur_dir/name using open_readable(). | [
"Read",
"text",
"string",
"from",
"cur_dir",
"/",
"name",
"using",
"open_readable",
"()",
"."
] | train | https://github.com/mar10/pyftpsync/blob/bbdc94186975cdc1cc4f678474bdce08bce7bb76/ftpsync/targets.py#L289-L298 |
mar10/pyftpsync | ftpsync/targets.py | _Target.write_text | def write_text(self, name, s):
"""Write string data to cur_dir/name using write_file()."""
buf = io.BytesIO(compat.to_bytes(s))
self.write_file(name, buf) | python | def write_text(self, name, s):
"""Write string data to cur_dir/name using write_file()."""
buf = io.BytesIO(compat.to_bytes(s))
self.write_file(name, buf) | [
"def",
"write_text",
"(",
"self",
",",
"name",
",",
"s",
")",
":",
"buf",
"=",
"io",
".",
"BytesIO",
"(",
"compat",
".",
"to_bytes",
"(",
"s",
")",
")",
"self",
".",
"write_file",
"(",
"name",
",",
"buf",
")"
] | Write string data to cur_dir/name using write_file(). | [
"Write",
"string",
"data",
"to",
"cur_dir",
"/",
"name",
"using",
"write_file",
"()",
"."
] | train | https://github.com/mar10/pyftpsync/blob/bbdc94186975cdc1cc4f678474bdce08bce7bb76/ftpsync/targets.py#L315-L318 |
mar10/pyftpsync | ftpsync/targets.py | _Target.set_sync_info | def set_sync_info(self, name, mtime, size):
"""Store mtime/size when this resource was last synchronized with remote."""
if not self.is_local():
return self.peer.set_sync_info(name, mtime, size)
return self.cur_dir_meta.set_sync_info(name, mtime, size) | python | def set_sync_info(self, name, mtime, size):
"""Store mtime/size when this resource was last synchronized with remote."""
if not self.is_local():
return self.peer.set_sync_info(name, mtime, size)
return self.cur_dir_meta.set_sync_info(name, mtime, size) | [
"def",
"set_sync_info",
"(",
"self",
",",
"name",
",",
"mtime",
",",
"size",
")",
":",
"if",
"not",
"self",
".",
"is_local",
"(",
")",
":",
"return",
"self",
".",
"peer",
".",
"set_sync_info",
"(",
"name",
",",
"mtime",
",",
"size",
")",
"return",
... | Store mtime/size when this resource was last synchronized with remote. | [
"Store",
"mtime",
"/",
"size",
"when",
"this",
"resource",
"was",
"last",
"synchronized",
"with",
"remote",
"."
] | train | https://github.com/mar10/pyftpsync/blob/bbdc94186975cdc1cc4f678474bdce08bce7bb76/ftpsync/targets.py#L327-L331 |
mar10/pyftpsync | ftpsync/targets.py | FsTarget.rmdir | def rmdir(self, dir_name):
"""Remove cur_dir/name."""
self.check_write(dir_name)
path = normpath_url(join_url(self.cur_dir, dir_name))
# write("REMOVE %r" % path)
shutil.rmtree(path) | python | def rmdir(self, dir_name):
"""Remove cur_dir/name."""
self.check_write(dir_name)
path = normpath_url(join_url(self.cur_dir, dir_name))
# write("REMOVE %r" % path)
shutil.rmtree(path) | [
"def",
"rmdir",
"(",
"self",
",",
"dir_name",
")",
":",
"self",
".",
"check_write",
"(",
"dir_name",
")",
"path",
"=",
"normpath_url",
"(",
"join_url",
"(",
"self",
".",
"cur_dir",
",",
"dir_name",
")",
")",
"# write(\"REMOVE %r\" % path)",
"shutil",
".",
... | Remove cur_dir/name. | [
"Remove",
"cur_dir",
"/",
"name",
"."
] | train | https://github.com/mar10/pyftpsync/blob/bbdc94186975cdc1cc4f678474bdce08bce7bb76/ftpsync/targets.py#L394-L399 |
mar10/pyftpsync | ftpsync/targets.py | FsTarget.remove_file | def remove_file(self, name):
"""Remove cur_dir/name."""
self.check_write(name)
path = os.path.join(self.cur_dir, name)
os.remove(path) | python | def remove_file(self, name):
"""Remove cur_dir/name."""
self.check_write(name)
path = os.path.join(self.cur_dir, name)
os.remove(path) | [
"def",
"remove_file",
"(",
"self",
",",
"name",
")",
":",
"self",
".",
"check_write",
"(",
"name",
")",
"path",
"=",
"os",
".",
"path",
".",
"join",
"(",
"self",
".",
"cur_dir",
",",
"name",
")",
"os",
".",
"remove",
"(",
"path",
")"
] | Remove cur_dir/name. | [
"Remove",
"cur_dir",
"/",
"name",
"."
] | train | https://github.com/mar10/pyftpsync/blob/bbdc94186975cdc1cc4f678474bdce08bce7bb76/ftpsync/targets.py#L474-L478 |
mar10/pyftpsync | ftpsync/targets.py | FsTarget.set_mtime | def set_mtime(self, name, mtime, size):
"""Set modification time on file."""
self.check_write(name)
os.utime(os.path.join(self.cur_dir, name), (-1, mtime)) | python | def set_mtime(self, name, mtime, size):
"""Set modification time on file."""
self.check_write(name)
os.utime(os.path.join(self.cur_dir, name), (-1, mtime)) | [
"def",
"set_mtime",
"(",
"self",
",",
"name",
",",
"mtime",
",",
"size",
")",
":",
"self",
".",
"check_write",
"(",
"name",
")",
"os",
".",
"utime",
"(",
"os",
".",
"path",
".",
"join",
"(",
"self",
".",
"cur_dir",
",",
"name",
")",
",",
"(",
"... | Set modification time on file. | [
"Set",
"modification",
"time",
"on",
"file",
"."
] | train | https://github.com/mar10/pyftpsync/blob/bbdc94186975cdc1cc4f678474bdce08bce7bb76/ftpsync/targets.py#L480-L483 |
mar10/pyftpsync | ftpsync/ftp_target.py | FtpTarget._lock | def _lock(self, break_existing=False):
"""Write a special file to the target root folder."""
# write("_lock")
data = {"lock_time": time.time(), "lock_holder": None}
try:
assert self.cur_dir == self.root_dir
self.write_text(DirMetadata.LOCK_FILE_NAME, json.... | python | def _lock(self, break_existing=False):
"""Write a special file to the target root folder."""
# write("_lock")
data = {"lock_time": time.time(), "lock_holder": None}
try:
assert self.cur_dir == self.root_dir
self.write_text(DirMetadata.LOCK_FILE_NAME, json.... | [
"def",
"_lock",
"(",
"self",
",",
"break_existing",
"=",
"False",
")",
":",
"# write(\"_lock\")\r",
"data",
"=",
"{",
"\"lock_time\"",
":",
"time",
".",
"time",
"(",
")",
",",
"\"lock_holder\"",
":",
"None",
"}",
"try",
":",
"assert",
"self",
".",
"cur_d... | Write a special file to the target root folder. | [
"Write",
"a",
"special",
"file",
"to",
"the",
"target",
"root",
"folder",
"."
] | train | https://github.com/mar10/pyftpsync/blob/bbdc94186975cdc1cc4f678474bdce08bce7bb76/ftpsync/ftp_target.py#L282-L305 |
mar10/pyftpsync | ftpsync/ftp_target.py | FtpTarget._unlock | def _unlock(self, closing=False):
"""Remove lock file to the target root folder.
"""
# write("_unlock", closing)
try:
if self.cur_dir != self.root_dir:
if closing:
write(
"Changing to ftp root folder to rem... | python | def _unlock(self, closing=False):
"""Remove lock file to the target root folder.
"""
# write("_unlock", closing)
try:
if self.cur_dir != self.root_dir:
if closing:
write(
"Changing to ftp root folder to rem... | [
"def",
"_unlock",
"(",
"self",
",",
"closing",
"=",
"False",
")",
":",
"# write(\"_unlock\", closing)\r",
"try",
":",
"if",
"self",
".",
"cur_dir",
"!=",
"self",
".",
"root_dir",
":",
"if",
"closing",
":",
"write",
"(",
"\"Changing to ftp root folder to remove l... | Remove lock file to the target root folder. | [
"Remove",
"lock",
"file",
"to",
"the",
"target",
"root",
"folder",
"."
] | train | https://github.com/mar10/pyftpsync/blob/bbdc94186975cdc1cc4f678474bdce08bce7bb76/ftpsync/ftp_target.py#L307-L351 |
mar10/pyftpsync | ftpsync/ftp_target.py | FtpTarget._probe_lock_file | def _probe_lock_file(self, reported_mtime):
"""Called by get_dir"""
delta = reported_mtime - self.lock_data["lock_time"]
# delta2 = reported_mtime - self.lock_write_time
self.server_time_ofs = delta
if self.get_option("verbose", 3) >= 4:
write("Server time offse... | python | def _probe_lock_file(self, reported_mtime):
"""Called by get_dir"""
delta = reported_mtime - self.lock_data["lock_time"]
# delta2 = reported_mtime - self.lock_write_time
self.server_time_ofs = delta
if self.get_option("verbose", 3) >= 4:
write("Server time offse... | [
"def",
"_probe_lock_file",
"(",
"self",
",",
"reported_mtime",
")",
":",
"delta",
"=",
"reported_mtime",
"-",
"self",
".",
"lock_data",
"[",
"\"lock_time\"",
"]",
"# delta2 = reported_mtime - self.lock_write_time\r",
"self",
".",
"server_time_ofs",
"=",
"delta",
"if",... | Called by get_dir | [
"Called",
"by",
"get_dir"
] | train | https://github.com/mar10/pyftpsync/blob/bbdc94186975cdc1cc4f678474bdce08bce7bb76/ftpsync/ftp_target.py#L353-L359 |
mar10/pyftpsync | ftpsync/ftp_target.py | FtpTarget.open_readable | def open_readable(self, name):
"""Open cur_dir/name for reading.
Note: we read everything into a buffer that supports .read().
Args:
name (str): file name, located in self.curdir
Returns:
file-like (must support read() method)
"""
# pri... | python | def open_readable(self, name):
"""Open cur_dir/name for reading.
Note: we read everything into a buffer that supports .read().
Args:
name (str): file name, located in self.curdir
Returns:
file-like (must support read() method)
"""
# pri... | [
"def",
"open_readable",
"(",
"self",
",",
"name",
")",
":",
"# print(\"FTP open_readable({})\".format(name))\r",
"assert",
"compat",
".",
"is_native",
"(",
"name",
")",
"out",
"=",
"SpooledTemporaryFile",
"(",
"max_size",
"=",
"self",
".",
"MAX_SPOOL_MEM",
",",
"m... | Open cur_dir/name for reading.
Note: we read everything into a buffer that supports .read().
Args:
name (str): file name, located in self.curdir
Returns:
file-like (must support read() method) | [
"Open",
"cur_dir",
"/",
"name",
"for",
"reading",
".",
"Note",
":",
"we",
"read",
"everything",
"into",
"a",
"buffer",
"that",
"supports",
".",
"read",
"()",
".",
"Args",
":",
"name",
"(",
"str",
")",
":",
"file",
"name",
"located",
"in",
"self",
"."... | train | https://github.com/mar10/pyftpsync/blob/bbdc94186975cdc1cc4f678474bdce08bce7bb76/ftpsync/ftp_target.py#L585-L602 |
mar10/pyftpsync | ftpsync/ftp_target.py | FtpTarget.write_file | def write_file(self, name, fp_src, blocksize=DEFAULT_BLOCKSIZE, callback=None):
"""Write file-like `fp_src` to cur_dir/name.
Args:
name (str): file name, located in self.curdir
fp_src (file-like): must support read() method
blocksize (int, optional):
... | python | def write_file(self, name, fp_src, blocksize=DEFAULT_BLOCKSIZE, callback=None):
"""Write file-like `fp_src` to cur_dir/name.
Args:
name (str): file name, located in self.curdir
fp_src (file-like): must support read() method
blocksize (int, optional):
... | [
"def",
"write_file",
"(",
"self",
",",
"name",
",",
"fp_src",
",",
"blocksize",
"=",
"DEFAULT_BLOCKSIZE",
",",
"callback",
"=",
"None",
")",
":",
"# print(\"FTP write_file({})\".format(name), blocksize)\r",
"assert",
"compat",
".",
"is_native",
"(",
"name",
")",
"... | Write file-like `fp_src` to cur_dir/name.
Args:
name (str): file name, located in self.curdir
fp_src (file-like): must support read() method
blocksize (int, optional):
callback (function, optional):
Called like `func(buf)` for every written... | [
"Write",
"file",
"-",
"like",
"fp_src",
"to",
"cur_dir",
"/",
"name",
".",
"Args",
":",
"name",
"(",
"str",
")",
":",
"file",
"name",
"located",
"in",
"self",
".",
"curdir",
"fp_src",
"(",
"file",
"-",
"like",
")",
":",
"must",
"support",
"read",
"... | train | https://github.com/mar10/pyftpsync/blob/bbdc94186975cdc1cc4f678474bdce08bce7bb76/ftpsync/ftp_target.py#L604-L617 |
mar10/pyftpsync | ftpsync/ftp_target.py | FtpTarget.copy_to_file | def copy_to_file(self, name, fp_dest, callback=None):
"""Write cur_dir/name to file-like `fp_dest`.
Args:
name (str): file name, located in self.curdir
fp_dest (file-like): must support write() method
callback (function, optional):
Called like ... | python | def copy_to_file(self, name, fp_dest, callback=None):
"""Write cur_dir/name to file-like `fp_dest`.
Args:
name (str): file name, located in self.curdir
fp_dest (file-like): must support write() method
callback (function, optional):
Called like ... | [
"def",
"copy_to_file",
"(",
"self",
",",
"name",
",",
"fp_dest",
",",
"callback",
"=",
"None",
")",
":",
"assert",
"compat",
".",
"is_native",
"(",
"name",
")",
"def",
"_write_to_file",
"(",
"data",
")",
":",
"# print(\"_write_to_file() {} bytes.\".format(len(da... | Write cur_dir/name to file-like `fp_dest`.
Args:
name (str): file name, located in self.curdir
fp_dest (file-like): must support write() method
callback (function, optional):
Called like `func(buf)` for every written chunk | [
"Write",
"cur_dir",
"/",
"name",
"to",
"file",
"-",
"like",
"fp_dest",
".",
"Args",
":",
"name",
"(",
"str",
")",
":",
"file",
"name",
"located",
"in",
"self",
".",
"curdir",
"fp_dest",
"(",
"file",
"-",
"like",
")",
":",
"must",
"support",
"write",
... | train | https://github.com/mar10/pyftpsync/blob/bbdc94186975cdc1cc4f678474bdce08bce7bb76/ftpsync/ftp_target.py#L620-L639 |
mar10/pyftpsync | ftpsync/ftp_target.py | FtpTarget.remove_file | def remove_file(self, name):
"""Remove cur_dir/name."""
assert compat.is_native(name)
self.check_write(name)
# self.cur_dir_meta.remove(name)
self.ftp.delete(name)
self.remove_sync_info(name) | python | def remove_file(self, name):
"""Remove cur_dir/name."""
assert compat.is_native(name)
self.check_write(name)
# self.cur_dir_meta.remove(name)
self.ftp.delete(name)
self.remove_sync_info(name) | [
"def",
"remove_file",
"(",
"self",
",",
"name",
")",
":",
"assert",
"compat",
".",
"is_native",
"(",
"name",
")",
"self",
".",
"check_write",
"(",
"name",
")",
"# self.cur_dir_meta.remove(name)\r",
"self",
".",
"ftp",
".",
"delete",
"(",
"name",
")",
"self... | Remove cur_dir/name. | [
"Remove",
"cur_dir",
"/",
"name",
"."
] | train | https://github.com/mar10/pyftpsync/blob/bbdc94186975cdc1cc4f678474bdce08bce7bb76/ftpsync/ftp_target.py#L641-L647 |
mar10/pyftpsync | ftpsync/ftp_target.py | FtpTarget._ftp_pwd | def _ftp_pwd(self):
"""Variant of `self.ftp.pwd()` that supports encoding-fallback.
Returns:
Current working directory as native string.
"""
try:
return self.ftp.pwd()
except UnicodeEncodeError:
if compat.PY2 or self.ftp.encoding != "... | python | def _ftp_pwd(self):
"""Variant of `self.ftp.pwd()` that supports encoding-fallback.
Returns:
Current working directory as native string.
"""
try:
return self.ftp.pwd()
except UnicodeEncodeError:
if compat.PY2 or self.ftp.encoding != "... | [
"def",
"_ftp_pwd",
"(",
"self",
")",
":",
"try",
":",
"return",
"self",
".",
"ftp",
".",
"pwd",
"(",
")",
"except",
"UnicodeEncodeError",
":",
"if",
"compat",
".",
"PY2",
"or",
"self",
".",
"ftp",
".",
"encoding",
"!=",
"\"utf-8\"",
":",
"raise",
"# ... | Variant of `self.ftp.pwd()` that supports encoding-fallback.
Returns:
Current working directory as native string. | [
"Variant",
"of",
"self",
".",
"ftp",
".",
"pwd",
"()",
"that",
"supports",
"encoding",
"-",
"fallback",
".",
"Returns",
":",
"Current",
"working",
"directory",
"as",
"native",
"string",
"."
] | train | https://github.com/mar10/pyftpsync/blob/bbdc94186975cdc1cc4f678474bdce08bce7bb76/ftpsync/ftp_target.py#L658-L675 |
mar10/pyftpsync | ftpsync/ftp_target.py | FtpTarget._ftp_nlst | def _ftp_nlst(self, dir_name):
"""Variant of `self.ftp.nlst()` that supports encoding-fallback."""
assert compat.is_native(dir_name)
lines = []
def _add_line(status, line):
lines.append(line)
cmd = "NLST " + dir_name
self._ftp_retrlines_native(cmd, ... | python | def _ftp_nlst(self, dir_name):
"""Variant of `self.ftp.nlst()` that supports encoding-fallback."""
assert compat.is_native(dir_name)
lines = []
def _add_line(status, line):
lines.append(line)
cmd = "NLST " + dir_name
self._ftp_retrlines_native(cmd, ... | [
"def",
"_ftp_nlst",
"(",
"self",
",",
"dir_name",
")",
":",
"assert",
"compat",
".",
"is_native",
"(",
"dir_name",
")",
"lines",
"=",
"[",
"]",
"def",
"_add_line",
"(",
"status",
",",
"line",
")",
":",
"lines",
".",
"append",
"(",
"line",
")",
"cmd",... | Variant of `self.ftp.nlst()` that supports encoding-fallback. | [
"Variant",
"of",
"self",
".",
"ftp",
".",
"nlst",
"()",
"that",
"supports",
"encoding",
"-",
"fallback",
"."
] | train | https://github.com/mar10/pyftpsync/blob/bbdc94186975cdc1cc4f678474bdce08bce7bb76/ftpsync/ftp_target.py#L677-L688 |
mar10/pyftpsync | ftpsync/ftp_target.py | FtpTarget._ftp_retrlines_native | def _ftp_retrlines_native(self, command, callback, encoding):
"""A re-implementation of ftp.retrlines that returns lines as native `str`.
This is needed on Python 3, where `ftp.retrlines()` returns unicode `str`
by decoding the incoming command response using `ftp.encoding`.
This w... | python | def _ftp_retrlines_native(self, command, callback, encoding):
"""A re-implementation of ftp.retrlines that returns lines as native `str`.
This is needed on Python 3, where `ftp.retrlines()` returns unicode `str`
by decoding the incoming command response using `ftp.encoding`.
This w... | [
"def",
"_ftp_retrlines_native",
"(",
"self",
",",
"command",
",",
"callback",
",",
"encoding",
")",
":",
"LF",
"=",
"b\"\\n\"",
"buffer",
"=",
"b\"\"",
"# needed to access buffer accross function scope\r",
"local_var",
"=",
"{",
"\"buffer\"",
":",
"buffer",
"}",
"... | A re-implementation of ftp.retrlines that returns lines as native `str`.
This is needed on Python 3, where `ftp.retrlines()` returns unicode `str`
by decoding the incoming command response using `ftp.encoding`.
This would fail for the whole request if a single line of the MLSD listing
... | [
"A",
"re",
"-",
"implementation",
"of",
"ftp",
".",
"retrlines",
"that",
"returns",
"lines",
"as",
"native",
"str",
".",
"This",
"is",
"needed",
"on",
"Python",
"3",
"where",
"ftp",
".",
"retrlines",
"()",
"returns",
"unicode",
"str",
"by",
"decoding",
"... | train | https://github.com/mar10/pyftpsync/blob/bbdc94186975cdc1cc4f678474bdce08bce7bb76/ftpsync/ftp_target.py#L690-L774 |
mar10/pyftpsync | ftpsync/pyftpsync.py | run | def run():
"""CLI main entry point."""
# Use print() instead of logging when running in CLI mode:
set_pyftpsync_logger(None)
parser = argparse.ArgumentParser(
description="Synchronize folders over FTP.",
epilog="See also https://github.com/mar10/pyftpsync",
parents=[ve... | python | def run():
"""CLI main entry point."""
# Use print() instead of logging when running in CLI mode:
set_pyftpsync_logger(None)
parser = argparse.ArgumentParser(
description="Synchronize folders over FTP.",
epilog="See also https://github.com/mar10/pyftpsync",
parents=[ve... | [
"def",
"run",
"(",
")",
":",
"# Use print() instead of logging when running in CLI mode:\r",
"set_pyftpsync_logger",
"(",
"None",
")",
"parser",
"=",
"argparse",
".",
"ArgumentParser",
"(",
"description",
"=",
"\"Synchronize folders over FTP.\"",
",",
"epilog",
"=",
"\"Se... | CLI main entry point. | [
"CLI",
"main",
"entry",
"point",
"."
] | train | https://github.com/mar10/pyftpsync/blob/bbdc94186975cdc1cc4f678474bdce08bce7bb76/ftpsync/pyftpsync.py#L45-L271 |
mar10/pyftpsync | ftpsync/resources.py | EntryPair.is_same_time | def is_same_time(self):
"""Return True if local.mtime == remote.mtime."""
return (
self.local
and self.remote
and FileEntry._eps_compare(self.local.mtime, self.remote.mtime) == 0
) | python | def is_same_time(self):
"""Return True if local.mtime == remote.mtime."""
return (
self.local
and self.remote
and FileEntry._eps_compare(self.local.mtime, self.remote.mtime) == 0
) | [
"def",
"is_same_time",
"(",
"self",
")",
":",
"return",
"(",
"self",
".",
"local",
"and",
"self",
".",
"remote",
"and",
"FileEntry",
".",
"_eps_compare",
"(",
"self",
".",
"local",
".",
"mtime",
",",
"self",
".",
"remote",
".",
"mtime",
")",
"==",
"0... | Return True if local.mtime == remote.mtime. | [
"Return",
"True",
"if",
"local",
".",
"mtime",
"==",
"remote",
".",
"mtime",
"."
] | train | https://github.com/mar10/pyftpsync/blob/bbdc94186975cdc1cc4f678474bdce08bce7bb76/ftpsync/resources.py#L118-L124 |
mar10/pyftpsync | ftpsync/resources.py | EntryPair.override_operation | def override_operation(self, operation, reason):
"""Re-Classify entry pair."""
prev_class = (self.local_classification, self.remote_classification)
prev_op = self.operation
assert operation != prev_op
assert operation in PAIR_OPERATIONS
if self.any_entry.target.synchroniz... | python | def override_operation(self, operation, reason):
"""Re-Classify entry pair."""
prev_class = (self.local_classification, self.remote_classification)
prev_op = self.operation
assert operation != prev_op
assert operation in PAIR_OPERATIONS
if self.any_entry.target.synchroniz... | [
"def",
"override_operation",
"(",
"self",
",",
"operation",
",",
"reason",
")",
":",
"prev_class",
"=",
"(",
"self",
".",
"local_classification",
",",
"self",
".",
"remote_classification",
")",
"prev_op",
"=",
"self",
".",
"operation",
"assert",
"operation",
"... | Re-Classify entry pair. | [
"Re",
"-",
"Classify",
"entry",
"pair",
"."
] | train | https://github.com/mar10/pyftpsync/blob/bbdc94186975cdc1cc4f678474bdce08bce7bb76/ftpsync/resources.py#L126-L140 |
mar10/pyftpsync | ftpsync/resources.py | EntryPair.classify | def classify(self, peer_dir_meta):
"""Classify entry pair."""
assert self.operation is None
# write("CLASSIFIY", self, peer_dir_meta)
# Note: We pass False if the entry is not listed in the metadata.
# We pass None if we don't have metadata all.
peer_entry_meta = pe... | python | def classify(self, peer_dir_meta):
"""Classify entry pair."""
assert self.operation is None
# write("CLASSIFIY", self, peer_dir_meta)
# Note: We pass False if the entry is not listed in the metadata.
# We pass None if we don't have metadata all.
peer_entry_meta = pe... | [
"def",
"classify",
"(",
"self",
",",
"peer_dir_meta",
")",
":",
"assert",
"self",
".",
"operation",
"is",
"None",
"# write(\"CLASSIFIY\", self, peer_dir_meta)",
"# Note: We pass False if the entry is not listed in the metadata.",
"# We pass None if we don't have metadata all.",... | Classify entry pair. | [
"Classify",
"entry",
"pair",
"."
] | train | https://github.com/mar10/pyftpsync/blob/bbdc94186975cdc1cc4f678474bdce08bce7bb76/ftpsync/resources.py#L142-L179 |
mar10/pyftpsync | ftpsync/resources.py | _Resource.classify | def classify(self, peer_dir_meta):
"""Classify this entry as 'new', 'unmodified', or 'modified'."""
assert self.classification is None
peer_entry_meta = None
if peer_dir_meta:
# Metadata is generally available, so we can detect 'new' or 'modified'
peer_entry_meta ... | python | def classify(self, peer_dir_meta):
"""Classify this entry as 'new', 'unmodified', or 'modified'."""
assert self.classification is None
peer_entry_meta = None
if peer_dir_meta:
# Metadata is generally available, so we can detect 'new' or 'modified'
peer_entry_meta ... | [
"def",
"classify",
"(",
"self",
",",
"peer_dir_meta",
")",
":",
"assert",
"self",
".",
"classification",
"is",
"None",
"peer_entry_meta",
"=",
"None",
"if",
"peer_dir_meta",
":",
"# Metadata is generally available, so we can detect 'new' or 'modified'",
"peer_entry_meta",
... | Classify this entry as 'new', 'unmodified', or 'modified'. | [
"Classify",
"this",
"entry",
"as",
"new",
"unmodified",
"or",
"modified",
"."
] | train | https://github.com/mar10/pyftpsync/blob/bbdc94186975cdc1cc4f678474bdce08bce7bb76/ftpsync/resources.py#L288-L331 |
mar10/pyftpsync | ftpsync/resources.py | FileEntry.was_modified_since_last_sync | def was_modified_since_last_sync(self):
"""Return True if this resource was modified since last sync.
None is returned if we don't know (because of missing meta data).
"""
info = self.get_sync_info()
if not info:
return None
if self.size != info["s"]:
... | python | def was_modified_since_last_sync(self):
"""Return True if this resource was modified since last sync.
None is returned if we don't know (because of missing meta data).
"""
info = self.get_sync_info()
if not info:
return None
if self.size != info["s"]:
... | [
"def",
"was_modified_since_last_sync",
"(",
"self",
")",
":",
"info",
"=",
"self",
".",
"get_sync_info",
"(",
")",
"if",
"not",
"info",
":",
"return",
"None",
"if",
"self",
".",
"size",
"!=",
"info",
"[",
"\"s\"",
"]",
":",
"return",
"True",
"if",
"sel... | Return True if this resource was modified since last sync.
None is returned if we don't know (because of missing meta data). | [
"Return",
"True",
"if",
"this",
"resource",
"was",
"modified",
"since",
"last",
"sync",
"."
] | train | https://github.com/mar10/pyftpsync/blob/bbdc94186975cdc1cc4f678474bdce08bce7bb76/ftpsync/resources.py#L377-L389 |
mar10/pyftpsync | ftpsync/metadata.py | DirMetadata.set_mtime | def set_mtime(self, filename, mtime, size):
"""Store real file mtime in meta data.
This is needed on FTP targets, because FTP servers don't allow to set
file mtime, but use to the upload time instead.
We also record size and upload time, so we can detect if the file was
changed ... | python | def set_mtime(self, filename, mtime, size):
"""Store real file mtime in meta data.
This is needed on FTP targets, because FTP servers don't allow to set
file mtime, but use to the upload time instead.
We also record size and upload time, so we can detect if the file was
changed ... | [
"def",
"set_mtime",
"(",
"self",
",",
"filename",
",",
"mtime",
",",
"size",
")",
":",
"ut",
"=",
"time",
".",
"time",
"(",
")",
"# UTC time stamp",
"if",
"self",
".",
"target",
".",
"server_time_ofs",
":",
"# We add the estimated time offset, so the stored 'u' ... | Store real file mtime in meta data.
This is needed on FTP targets, because FTP servers don't allow to set
file mtime, but use to the upload time instead.
We also record size and upload time, so we can detect if the file was
changed by other means and we have to discard our meta data. | [
"Store",
"real",
"file",
"mtime",
"in",
"meta",
"data",
"."
] | train | https://github.com/mar10/pyftpsync/blob/bbdc94186975cdc1cc4f678474bdce08bce7bb76/ftpsync/metadata.py#L70-L90 |
mar10/pyftpsync | ftpsync/metadata.py | DirMetadata.set_sync_info | def set_sync_info(self, filename, mtime, size):
"""Store mtime/size when local and remote file was last synchronized.
This is stored in the local file's folder as meta data.
The information is used to detect conflicts, i.e. if both source and
remote had been modified by other means sinc... | python | def set_sync_info(self, filename, mtime, size):
"""Store mtime/size when local and remote file was last synchronized.
This is stored in the local file's folder as meta data.
The information is used to detect conflicts, i.e. if both source and
remote had been modified by other means sinc... | [
"def",
"set_sync_info",
"(",
"self",
",",
"filename",
",",
"mtime",
",",
"size",
")",
":",
"assert",
"self",
".",
"target",
".",
"is_local",
"(",
")",
"remote_target",
"=",
"self",
".",
"target",
".",
"peer",
"ps",
"=",
"self",
".",
"dir",
"[",
"\"pe... | Store mtime/size when local and remote file was last synchronized.
This is stored in the local file's folder as meta data.
The information is used to detect conflicts, i.e. if both source and
remote had been modified by other means since last synchronization. | [
"Store",
"mtime",
"/",
"size",
"when",
"local",
"and",
"remote",
"file",
"was",
"last",
"synchronized",
"."
] | train | https://github.com/mar10/pyftpsync/blob/bbdc94186975cdc1cc4f678474bdce08bce7bb76/ftpsync/metadata.py#L92-L111 |
mar10/pyftpsync | ftpsync/metadata.py | DirMetadata.remove | def remove(self, filename):
"""Remove any data for the given file name."""
if self.list.pop(filename, None):
self.modified_list = True
if self.target.peer: # otherwise `scan` command
if self.target.is_local():
remote_target = self.target.peer
... | python | def remove(self, filename):
"""Remove any data for the given file name."""
if self.list.pop(filename, None):
self.modified_list = True
if self.target.peer: # otherwise `scan` command
if self.target.is_local():
remote_target = self.target.peer
... | [
"def",
"remove",
"(",
"self",
",",
"filename",
")",
":",
"if",
"self",
".",
"list",
".",
"pop",
"(",
"filename",
",",
"None",
")",
":",
"self",
".",
"modified_list",
"=",
"True",
"if",
"self",
".",
"target",
".",
"peer",
":",
"# otherwise `scan` comman... | Remove any data for the given file name. | [
"Remove",
"any",
"data",
"for",
"the",
"given",
"file",
"name",
"."
] | train | https://github.com/mar10/pyftpsync/blob/bbdc94186975cdc1cc4f678474bdce08bce7bb76/ftpsync/metadata.py#L113-L125 |
mar10/pyftpsync | ftpsync/metadata.py | DirMetadata.read | def read(self):
"""Initialize self from .pyftpsync-meta.json file."""
assert self.path == self.target.cur_dir
try:
self.modified_list = False
self.modified_sync = False
is_valid_file = False
s = self.target.read_text(self.filename)
# p... | python | def read(self):
"""Initialize self from .pyftpsync-meta.json file."""
assert self.path == self.target.cur_dir
try:
self.modified_list = False
self.modified_sync = False
is_valid_file = False
s = self.target.read_text(self.filename)
# p... | [
"def",
"read",
"(",
"self",
")",
":",
"assert",
"self",
".",
"path",
"==",
"self",
".",
"target",
".",
"cur_dir",
"try",
":",
"self",
".",
"modified_list",
"=",
"False",
"self",
".",
"modified_sync",
"=",
"False",
"is_valid_file",
"=",
"False",
"s",
"=... | Initialize self from .pyftpsync-meta.json file. | [
"Initialize",
"self",
"from",
".",
"pyftpsync",
"-",
"meta",
".",
"json",
"file",
"."
] | train | https://github.com/mar10/pyftpsync/blob/bbdc94186975cdc1cc4f678474bdce08bce7bb76/ftpsync/metadata.py#L127-L175 |
mar10/pyftpsync | ftpsync/metadata.py | DirMetadata.flush | def flush(self):
"""Write self to .pyftpsync-meta.json."""
# We DO write meta files even on read-only targets, but not in dry-run mode
# if self.target.readonly:
# write("DirMetadata.flush(%s): read-only; nothing to do" % self.target)
# return
assert self.path == ... | python | def flush(self):
"""Write self to .pyftpsync-meta.json."""
# We DO write meta files even on read-only targets, but not in dry-run mode
# if self.target.readonly:
# write("DirMetadata.flush(%s): read-only; nothing to do" % self.target)
# return
assert self.path == ... | [
"def",
"flush",
"(",
"self",
")",
":",
"# We DO write meta files even on read-only targets, but not in dry-run mode",
"# if self.target.readonly:",
"# write(\"DirMetadata.flush(%s): read-only; nothing to do\" % self.target)",
"# return",
"assert",
"self",
".",
"path",
"==",
"se... | Write self to .pyftpsync-meta.json. | [
"Write",
"self",
"to",
".",
"pyftpsync",
"-",
"meta",
".",
"json",
"."
] | train | https://github.com/mar10/pyftpsync/blob/bbdc94186975cdc1cc4f678474bdce08bce7bb76/ftpsync/metadata.py#L177-L228 |
mar10/pyftpsync | ftpsync/scan_command.py | scan_handler | def scan_handler(parser, args):
"""Implement `scan` sub-command."""
opts = namespace_to_dict(args)
opts.update({"ftp_debug": args.verbose >= 6})
target = make_target(args.target, opts)
target.readonly = True
root_depth = target.root_dir.count("/")
start = time.time()
dir_count = 1
fi... | python | def scan_handler(parser, args):
"""Implement `scan` sub-command."""
opts = namespace_to_dict(args)
opts.update({"ftp_debug": args.verbose >= 6})
target = make_target(args.target, opts)
target.readonly = True
root_depth = target.root_dir.count("/")
start = time.time()
dir_count = 1
fi... | [
"def",
"scan_handler",
"(",
"parser",
",",
"args",
")",
":",
"opts",
"=",
"namespace_to_dict",
"(",
"args",
")",
"opts",
".",
"update",
"(",
"{",
"\"ftp_debug\"",
":",
"args",
".",
"verbose",
">=",
"6",
"}",
")",
"target",
"=",
"make_target",
"(",
"arg... | Implement `scan` sub-command. | [
"Implement",
"scan",
"sub",
"-",
"command",
"."
] | train | https://github.com/mar10/pyftpsync/blob/bbdc94186975cdc1cc4f678474bdce08bce7bb76/ftpsync/scan_command.py#L61-L141 |
weblyzard/inscriptis | src/inscriptis/table_engine.py | TableCell.get_format_spec | def get_format_spec(self):
'''
The format specification according to the values of `align` and `width`
'''
return u"{{:{align}{width}}}".format(align=self.align, width=self.width) | python | def get_format_spec(self):
'''
The format specification according to the values of `align` and `width`
'''
return u"{{:{align}{width}}}".format(align=self.align, width=self.width) | [
"def",
"get_format_spec",
"(",
"self",
")",
":",
"return",
"u\"{{:{align}{width}}}\"",
".",
"format",
"(",
"align",
"=",
"self",
".",
"align",
",",
"width",
"=",
"self",
".",
"width",
")"
] | The format specification according to the values of `align` and `width` | [
"The",
"format",
"specification",
"according",
"to",
"the",
"values",
"of",
"align",
"and",
"width"
] | train | https://github.com/weblyzard/inscriptis/blob/0d04f81e69d643bb5f470f33b4ca67b62fc1037c/src/inscriptis/table_engine.py#L31-L35 |
weblyzard/inscriptis | src/inscriptis/table_engine.py | Table.compute_column_width_and_height | def compute_column_width_and_height(self):
'''
compute and set the column width for all colls in the table
'''
# skip tables with no row
if not self.rows:
return
# determine row height
for row in self.rows:
max_row_height = max((len(cell.g... | python | def compute_column_width_and_height(self):
'''
compute and set the column width for all colls in the table
'''
# skip tables with no row
if not self.rows:
return
# determine row height
for row in self.rows:
max_row_height = max((len(cell.g... | [
"def",
"compute_column_width_and_height",
"(",
"self",
")",
":",
"# skip tables with no row",
"if",
"not",
"self",
".",
"rows",
":",
"return",
"# determine row height",
"for",
"row",
"in",
"self",
".",
"rows",
":",
"max_row_height",
"=",
"max",
"(",
"(",
"len",
... | compute and set the column width for all colls in the table | [
"compute",
"and",
"set",
"the",
"column",
"width",
"for",
"all",
"colls",
"in",
"the",
"table"
] | train | https://github.com/weblyzard/inscriptis/blob/0d04f81e69d643bb5f470f33b4ca67b62fc1037c/src/inscriptis/table_engine.py#L66-L91 |
weblyzard/inscriptis | src/inscriptis/table_engine.py | Table.get_text | def get_text(self):
'''
::returns:
a rendered string representation of the given table
'''
self.compute_column_width_and_height()
return '\n'.join((row.get_text() for row in self.rows)) | python | def get_text(self):
'''
::returns:
a rendered string representation of the given table
'''
self.compute_column_width_and_height()
return '\n'.join((row.get_text() for row in self.rows)) | [
"def",
"get_text",
"(",
"self",
")",
":",
"self",
".",
"compute_column_width_and_height",
"(",
")",
"return",
"'\\n'",
".",
"join",
"(",
"(",
"row",
".",
"get_text",
"(",
")",
"for",
"row",
"in",
"self",
".",
"rows",
")",
")"
] | ::returns:
a rendered string representation of the given table | [
"::",
"returns",
":",
"a",
"rendered",
"string",
"representation",
"of",
"the",
"given",
"table"
] | train | https://github.com/weblyzard/inscriptis/blob/0d04f81e69d643bb5f470f33b4ca67b62fc1037c/src/inscriptis/table_engine.py#L93-L99 |
weblyzard/inscriptis | src/inscriptis/table_engine.py | Row.get_cell_lines | def get_cell_lines(self, column_idx):
'''
''returns:
the lines of the cell specified by the column_idx or an empty list if the column does not exist
'''
return [] if column_idx >= len(self.columns) else self.columns[column_idx].get_cell_lines() | python | def get_cell_lines(self, column_idx):
'''
''returns:
the lines of the cell specified by the column_idx or an empty list if the column does not exist
'''
return [] if column_idx >= len(self.columns) else self.columns[column_idx].get_cell_lines() | [
"def",
"get_cell_lines",
"(",
"self",
",",
"column_idx",
")",
":",
"return",
"[",
"]",
"if",
"column_idx",
">=",
"len",
"(",
"self",
".",
"columns",
")",
"else",
"self",
".",
"columns",
"[",
"column_idx",
"]",
".",
"get_cell_lines",
"(",
")"
] | ''returns:
the lines of the cell specified by the column_idx or an empty list if the column does not exist | [
"returns",
":",
"the",
"lines",
"of",
"the",
"cell",
"specified",
"by",
"the",
"column_idx",
"or",
"an",
"empty",
"list",
"if",
"the",
"column",
"does",
"not",
"exist"
] | train | https://github.com/weblyzard/inscriptis/blob/0d04f81e69d643bb5f470f33b4ca67b62fc1037c/src/inscriptis/table_engine.py#L109-L114 |
weblyzard/inscriptis | src/inscriptis/table_engine.py | Row.get_text | def get_text(self):
'''
::returns:
a rendered string representation of the given row
'''
row_lines = []
for line in zip_longest(*[column.get_cell_lines() for column in self.columns], fillvalue=' '):
row_lines.append(' '.join(line))
return '\n'... | python | def get_text(self):
'''
::returns:
a rendered string representation of the given row
'''
row_lines = []
for line in zip_longest(*[column.get_cell_lines() for column in self.columns], fillvalue=' '):
row_lines.append(' '.join(line))
return '\n'... | [
"def",
"get_text",
"(",
"self",
")",
":",
"row_lines",
"=",
"[",
"]",
"for",
"line",
"in",
"zip_longest",
"(",
"*",
"[",
"column",
".",
"get_cell_lines",
"(",
")",
"for",
"column",
"in",
"self",
".",
"columns",
"]",
",",
"fillvalue",
"=",
"' '",
")",... | ::returns:
a rendered string representation of the given row | [
"::",
"returns",
":",
"a",
"rendered",
"string",
"representation",
"of",
"the",
"given",
"row"
] | train | https://github.com/weblyzard/inscriptis/blob/0d04f81e69d643bb5f470f33b4ca67b62fc1037c/src/inscriptis/table_engine.py#L116-L124 |
weblyzard/inscriptis | src/inscriptis/__init__.py | get_text | def get_text(html_content, display_images=False, deduplicate_captions=False, display_links=False):
'''
::param: html_content
::returns:
a text representation of the html content.
'''
html_content = html_content.strip()
if not html_content:
return ""
# strip XML declaration, ... | python | def get_text(html_content, display_images=False, deduplicate_captions=False, display_links=False):
'''
::param: html_content
::returns:
a text representation of the html content.
'''
html_content = html_content.strip()
if not html_content:
return ""
# strip XML declaration, ... | [
"def",
"get_text",
"(",
"html_content",
",",
"display_images",
"=",
"False",
",",
"deduplicate_captions",
"=",
"False",
",",
"display_links",
"=",
"False",
")",
":",
"html_content",
"=",
"html_content",
".",
"strip",
"(",
")",
"if",
"not",
"html_content",
":",... | ::param: html_content
::returns:
a text representation of the html content. | [
"::",
"param",
":",
"html_content",
"::",
"returns",
":",
"a",
"text",
"representation",
"of",
"the",
"html",
"content",
"."
] | train | https://github.com/weblyzard/inscriptis/blob/0d04f81e69d643bb5f470f33b4ca67b62fc1037c/src/inscriptis/__init__.py#L18-L34 |
weblyzard/inscriptis | scripts/inscript.py | get_parser | def get_parser():
""" Parses the arguments if script is run directly via console """
parser = argparse.ArgumentParser(description='Converts HTML from file or url to a clean text version')
parser.add_argument('input', nargs='?', default=None, help='Html input either from a file or an url (default:stdin)')
... | python | def get_parser():
""" Parses the arguments if script is run directly via console """
parser = argparse.ArgumentParser(description='Converts HTML from file or url to a clean text version')
parser.add_argument('input', nargs='?', default=None, help='Html input either from a file or an url (default:stdin)')
... | [
"def",
"get_parser",
"(",
")",
":",
"parser",
"=",
"argparse",
".",
"ArgumentParser",
"(",
"description",
"=",
"'Converts HTML from file or url to a clean text version'",
")",
"parser",
".",
"add_argument",
"(",
"'input'",
",",
"nargs",
"=",
"'?'",
",",
"default",
... | Parses the arguments if script is run directly via console | [
"Parses",
"the",
"arguments",
"if",
"script",
"is",
"run",
"directly",
"via",
"console"
] | train | https://github.com/weblyzard/inscriptis/blob/0d04f81e69d643bb5f470f33b4ca67b62fc1037c/scripts/inscript.py#L28-L37 |
weblyzard/inscriptis | src/inscriptis/html_engine.py | Inscriptis.write_line | def write_line(self, force=False):
'''
Writes the current line to the buffer, provided that there is any
data to write.
::returns:
True, if a line has been writer, otherwise False
'''
# only break the line if there is any relevant content
if not force... | python | def write_line(self, force=False):
'''
Writes the current line to the buffer, provided that there is any
data to write.
::returns:
True, if a line has been writer, otherwise False
'''
# only break the line if there is any relevant content
if not force... | [
"def",
"write_line",
"(",
"self",
",",
"force",
"=",
"False",
")",
":",
"# only break the line if there is any relevant content",
"if",
"not",
"force",
"and",
"(",
"not",
"self",
".",
"current_line",
"[",
"-",
"1",
"]",
".",
"content",
"or",
"self",
".",
"cu... | Writes the current line to the buffer, provided that there is any
data to write.
::returns:
True, if a line has been writer, otherwise False | [
"Writes",
"the",
"current",
"line",
"to",
"the",
"buffer",
"provided",
"that",
"there",
"is",
"any",
"data",
"to",
"write",
"."
] | train | https://github.com/weblyzard/inscriptis/blob/0d04f81e69d643bb5f470f33b4ca67b62fc1037c/src/inscriptis/html_engine.py#L114-L132 |
weblyzard/inscriptis | src/inscriptis/css.py | HtmlElement.clone | def clone(self):
'''
::return: \
a clone of the current HtmlElement
'''
return HtmlElement(self.tag, self.prefix, self.suffix, self.display,
self.margin_before, self.margin_after, self.padding,
self.whitespace) | python | def clone(self):
'''
::return: \
a clone of the current HtmlElement
'''
return HtmlElement(self.tag, self.prefix, self.suffix, self.display,
self.margin_before, self.margin_after, self.padding,
self.whitespace) | [
"def",
"clone",
"(",
"self",
")",
":",
"return",
"HtmlElement",
"(",
"self",
".",
"tag",
",",
"self",
".",
"prefix",
",",
"self",
".",
"suffix",
",",
"self",
".",
"display",
",",
"self",
".",
"margin_before",
",",
"self",
".",
"margin_after",
",",
"s... | ::return: \
a clone of the current HtmlElement | [
"::",
"return",
":",
"\\",
"a",
"clone",
"of",
"the",
"current",
"HtmlElement"
] | train | https://github.com/weblyzard/inscriptis/blob/0d04f81e69d643bb5f470f33b4ca67b62fc1037c/src/inscriptis/css.py#L28-L35 |
weblyzard/inscriptis | src/inscriptis/css.py | CssParse.get_style_attribute | def get_style_attribute(style_attribute, html_element):
'''
::param: style_directive \
The attribute value of the given style sheet.
Example: display: none
::param: html_element: \
The HtmlElement to which the given style is applied
::returns:
... | python | def get_style_attribute(style_attribute, html_element):
'''
::param: style_directive \
The attribute value of the given style sheet.
Example: display: none
::param: html_element: \
The HtmlElement to which the given style is applied
::returns:
... | [
"def",
"get_style_attribute",
"(",
"style_attribute",
",",
"html_element",
")",
":",
"custome_html_element",
"=",
"html_element",
".",
"clone",
"(",
")",
"for",
"style_directive",
"in",
"style_attribute",
".",
"lower",
"(",
")",
".",
"split",
"(",
"';'",
")",
... | ::param: style_directive \
The attribute value of the given style sheet.
Example: display: none
::param: html_element: \
The HtmlElement to which the given style is applied
::returns:
A HtmlElement that merges the given element with
the style attri... | [
"::",
"param",
":",
"style_directive",
"\\",
"The",
"attribute",
"value",
"of",
"the",
"given",
"style",
"sheet",
".",
"Example",
":",
"display",
":",
"none"
] | train | https://github.com/weblyzard/inscriptis/blob/0d04f81e69d643bb5f470f33b4ca67b62fc1037c/src/inscriptis/css.py#L62-L89 |
weblyzard/inscriptis | src/inscriptis/css.py | CssParse._get_em | def _get_em(length):
'''
::param: length \
the length specified in the CSS.
::return:
the length in em's.
'''
m = CssParse.RE_UNIT.search(length)
value = float(m.group(1))
unit = m.group(2)
if unit not in ('em', 'qem', 'rem'):
... | python | def _get_em(length):
'''
::param: length \
the length specified in the CSS.
::return:
the length in em's.
'''
m = CssParse.RE_UNIT.search(length)
value = float(m.group(1))
unit = m.group(2)
if unit not in ('em', 'qem', 'rem'):
... | [
"def",
"_get_em",
"(",
"length",
")",
":",
"m",
"=",
"CssParse",
".",
"RE_UNIT",
".",
"search",
"(",
"length",
")",
"value",
"=",
"float",
"(",
"m",
".",
"group",
"(",
"1",
")",
")",
"unit",
"=",
"m",
".",
"group",
"(",
"2",
")",
"if",
"unit",
... | ::param: length \
the length specified in the CSS.
::return:
the length in em's. | [
"::",
"param",
":",
"length",
"\\",
"the",
"length",
"specified",
"in",
"the",
"CSS",
"."
] | train | https://github.com/weblyzard/inscriptis/blob/0d04f81e69d643bb5f470f33b4ca67b62fc1037c/src/inscriptis/css.py#L92-L107 |
weblyzard/inscriptis | src/inscriptis/css.py | CssParse._attr_display | def _attr_display(value, html_element):
'''
Set the display value
'''
if value == 'block':
html_element.display = Display.block
elif value == 'none':
html_element.display = Display.none
else:
html_element.display = Display.inline | python | def _attr_display(value, html_element):
'''
Set the display value
'''
if value == 'block':
html_element.display = Display.block
elif value == 'none':
html_element.display = Display.none
else:
html_element.display = Display.inline | [
"def",
"_attr_display",
"(",
"value",
",",
"html_element",
")",
":",
"if",
"value",
"==",
"'block'",
":",
"html_element",
".",
"display",
"=",
"Display",
".",
"block",
"elif",
"value",
"==",
"'none'",
":",
"html_element",
".",
"display",
"=",
"Display",
".... | Set the display value | [
"Set",
"the",
"display",
"value"
] | train | https://github.com/weblyzard/inscriptis/blob/0d04f81e69d643bb5f470f33b4ca67b62fc1037c/src/inscriptis/css.py#L114-L123 |
astrofrog/mpl-scatter-density | mpl_scatter_density/scatter_density_axes.py | ScatterDensityAxes.scatter_density | def scatter_density(self, x, y, dpi=72, downres_factor=4, color=None, cmap=None,
alpha=1.0, norm=None, **kwargs):
"""
Make a density plot of the (x, y) scatter data.
Parameters
----------
x, y : iterable
The data to plot
dpi : int or `... | python | def scatter_density(self, x, y, dpi=72, downres_factor=4, color=None, cmap=None,
alpha=1.0, norm=None, **kwargs):
"""
Make a density plot of the (x, y) scatter data.
Parameters
----------
x, y : iterable
The data to plot
dpi : int or `... | [
"def",
"scatter_density",
"(",
"self",
",",
"x",
",",
"y",
",",
"dpi",
"=",
"72",
",",
"downres_factor",
"=",
"4",
",",
"color",
"=",
"None",
",",
"cmap",
"=",
"None",
",",
"alpha",
"=",
"1.0",
",",
"norm",
"=",
"None",
",",
"*",
"*",
"kwargs",
... | Make a density plot of the (x, y) scatter data.
Parameters
----------
x, y : iterable
The data to plot
dpi : int or `None`
The number of dots per inch to include in the density map. To use
the native resolution of the drawing device, set this to None.... | [
"Make",
"a",
"density",
"plot",
"of",
"the",
"(",
"x",
"y",
")",
"scatter",
"data",
"."
] | train | https://github.com/astrofrog/mpl-scatter-density/blob/1b99277d96c758b607ed93078e064ae49107ba3c/mpl_scatter_density/scatter_density_axes.py#L20-L58 |
fabiocaccamo/django-maintenance-mode | maintenance_mode/io.py | read_file | def read_file(file_path, default_content=''):
"""
Read file at the specified path.
If file doesn't exist, it will be created with default-content.
Returns the file content.
"""
if not os.path.exists(file_path):
write_file(file_path, default_content)
handler = open(file_path, 'r')
... | python | def read_file(file_path, default_content=''):
"""
Read file at the specified path.
If file doesn't exist, it will be created with default-content.
Returns the file content.
"""
if not os.path.exists(file_path):
write_file(file_path, default_content)
handler = open(file_path, 'r')
... | [
"def",
"read_file",
"(",
"file_path",
",",
"default_content",
"=",
"''",
")",
":",
"if",
"not",
"os",
".",
"path",
".",
"exists",
"(",
"file_path",
")",
":",
"write_file",
"(",
"file_path",
",",
"default_content",
")",
"handler",
"=",
"open",
"(",
"file_... | Read file at the specified path.
If file doesn't exist, it will be created with default-content.
Returns the file content. | [
"Read",
"file",
"at",
"the",
"specified",
"path",
".",
"If",
"file",
"doesn",
"t",
"exist",
"it",
"will",
"be",
"created",
"with",
"default",
"-",
"content",
".",
"Returns",
"the",
"file",
"content",
"."
] | train | https://github.com/fabiocaccamo/django-maintenance-mode/blob/008221a6b8a687667c2480fa799c7a4228598441/maintenance_mode/io.py#L6-L18 |
fabiocaccamo/django-maintenance-mode | maintenance_mode/io.py | write_file | def write_file(file_path, content):
"""
Write file at the specified path with content.
If file exists, it will be overwritten.
"""
handler = open(file_path, 'w+')
handler.write(content)
handler.close() | python | def write_file(file_path, content):
"""
Write file at the specified path with content.
If file exists, it will be overwritten.
"""
handler = open(file_path, 'w+')
handler.write(content)
handler.close() | [
"def",
"write_file",
"(",
"file_path",
",",
"content",
")",
":",
"handler",
"=",
"open",
"(",
"file_path",
",",
"'w+'",
")",
"handler",
".",
"write",
"(",
"content",
")",
"handler",
".",
"close",
"(",
")"
] | Write file at the specified path with content.
If file exists, it will be overwritten. | [
"Write",
"file",
"at",
"the",
"specified",
"path",
"with",
"content",
".",
"If",
"file",
"exists",
"it",
"will",
"be",
"overwritten",
"."
] | train | https://github.com/fabiocaccamo/django-maintenance-mode/blob/008221a6b8a687667c2480fa799c7a4228598441/maintenance_mode/io.py#L21-L28 |
fabiocaccamo/django-maintenance-mode | maintenance_mode/core.py | set_maintenance_mode | def set_maintenance_mode(value):
"""
Set maintenance_mode state to state file.
"""
# If maintenance mode is defined in settings, it can't be changed.
if settings.MAINTENANCE_MODE is not None:
raise ImproperlyConfigured(
'Maintenance mode cannot be set dynamically '
'... | python | def set_maintenance_mode(value):
"""
Set maintenance_mode state to state file.
"""
# If maintenance mode is defined in settings, it can't be changed.
if settings.MAINTENANCE_MODE is not None:
raise ImproperlyConfigured(
'Maintenance mode cannot be set dynamically '
'... | [
"def",
"set_maintenance_mode",
"(",
"value",
")",
":",
"# If maintenance mode is defined in settings, it can't be changed.",
"if",
"settings",
".",
"MAINTENANCE_MODE",
"is",
"not",
"None",
":",
"raise",
"ImproperlyConfigured",
"(",
"'Maintenance mode cannot be set dynamically '",... | Set maintenance_mode state to state file. | [
"Set",
"maintenance_mode",
"state",
"to",
"state",
"file",
"."
] | train | https://github.com/fabiocaccamo/django-maintenance-mode/blob/008221a6b8a687667c2480fa799c7a4228598441/maintenance_mode/core.py#L60-L75 |
fabiocaccamo/django-maintenance-mode | maintenance_mode/http.py | get_maintenance_response | def get_maintenance_response(request):
"""
Return a '503 Service Unavailable' maintenance response.
"""
if settings.MAINTENANCE_MODE_REDIRECT_URL:
return redirect(settings.MAINTENANCE_MODE_REDIRECT_URL)
context = {}
if settings.MAINTENANCE_MODE_GET_TEMPLATE_CONTEXT:
try:
... | python | def get_maintenance_response(request):
"""
Return a '503 Service Unavailable' maintenance response.
"""
if settings.MAINTENANCE_MODE_REDIRECT_URL:
return redirect(settings.MAINTENANCE_MODE_REDIRECT_URL)
context = {}
if settings.MAINTENANCE_MODE_GET_TEMPLATE_CONTEXT:
try:
... | [
"def",
"get_maintenance_response",
"(",
"request",
")",
":",
"if",
"settings",
".",
"MAINTENANCE_MODE_REDIRECT_URL",
":",
"return",
"redirect",
"(",
"settings",
".",
"MAINTENANCE_MODE_REDIRECT_URL",
")",
"context",
"=",
"{",
"}",
"if",
"settings",
".",
"MAINTENANCE_... | Return a '503 Service Unavailable' maintenance response. | [
"Return",
"a",
"503",
"Service",
"Unavailable",
"maintenance",
"response",
"."
] | train | https://github.com/fabiocaccamo/django-maintenance-mode/blob/008221a6b8a687667c2480fa799c7a4228598441/maintenance_mode/http.py#L34-L65 |
fabiocaccamo/django-maintenance-mode | maintenance_mode/http.py | need_maintenance_response | def need_maintenance_response(request):
"""
Tells if the given request needs a maintenance response or not.
"""
try:
view_match = resolve(request.path)
view_func = view_match[0]
view_dict = view_func.__dict__
view_force_maintenance_mode_off = view_dict.get(
... | python | def need_maintenance_response(request):
"""
Tells if the given request needs a maintenance response or not.
"""
try:
view_match = resolve(request.path)
view_func = view_match[0]
view_dict = view_func.__dict__
view_force_maintenance_mode_off = view_dict.get(
... | [
"def",
"need_maintenance_response",
"(",
"request",
")",
":",
"try",
":",
"view_match",
"=",
"resolve",
"(",
"request",
".",
"path",
")",
"view_func",
"=",
"view_match",
"[",
"0",
"]",
"view_dict",
"=",
"view_func",
".",
"__dict__",
"view_force_maintenance_mode_... | Tells if the given request needs a maintenance response or not. | [
"Tells",
"if",
"the",
"given",
"request",
"needs",
"a",
"maintenance",
"response",
"or",
"not",
"."
] | train | https://github.com/fabiocaccamo/django-maintenance-mode/blob/008221a6b8a687667c2480fa799c7a4228598441/maintenance_mode/http.py#L68-L204 |
ContinuumIO/flask-ldap-login | flask_ldap_login/forms.py | LDAPLoginForm.validate_ldap | def validate_ldap(self):
'Validate the username/password data against ldap directory'
ldap_mgr = current_app.ldap_login_manager
username = self.username.data
password = self.password.data
try:
userdata = ldap_mgr.ldap_login(username, password)
except ldap.INVA... | python | def validate_ldap(self):
'Validate the username/password data against ldap directory'
ldap_mgr = current_app.ldap_login_manager
username = self.username.data
password = self.password.data
try:
userdata = ldap_mgr.ldap_login(username, password)
except ldap.INVA... | [
"def",
"validate_ldap",
"(",
"self",
")",
":",
"ldap_mgr",
"=",
"current_app",
".",
"ldap_login_manager",
"username",
"=",
"self",
".",
"username",
".",
"data",
"password",
"=",
"self",
".",
"password",
".",
"data",
"try",
":",
"userdata",
"=",
"ldap_mgr",
... | Validate the username/password data against ldap directory | [
"Validate",
"the",
"username",
"/",
"password",
"data",
"against",
"ldap",
"directory"
] | train | https://github.com/ContinuumIO/flask-ldap-login/blob/09a08be45f861823cb08f95883ee1e092a618c37/flask_ldap_login/forms.py#L19-L42 |
ContinuumIO/flask-ldap-login | flask_ldap_login/forms.py | LDAPLoginForm.validate | def validate(self, *args, **kwargs):
"""
Validates the form by calling `validate` on each field, passing any
extra `Form.validate_<fieldname>` validators to the field validator.
also calls `validate_ldap`
"""
valid = Form.validate(self, *args, **kwargs)
... | python | def validate(self, *args, **kwargs):
"""
Validates the form by calling `validate` on each field, passing any
extra `Form.validate_<fieldname>` validators to the field validator.
also calls `validate_ldap`
"""
valid = Form.validate(self, *args, **kwargs)
... | [
"def",
"validate",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"valid",
"=",
"Form",
".",
"validate",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
"if",
"not",
"valid",
":",
"return",
"valid",
"return",
"self... | Validates the form by calling `validate` on each field, passing any
extra `Form.validate_<fieldname>` validators to the field validator.
also calls `validate_ldap` | [
"Validates",
"the",
"form",
"by",
"calling",
"validate",
"on",
"each",
"field",
"passing",
"any",
"extra",
"Form",
".",
"validate_<fieldname",
">",
"validators",
"to",
"the",
"field",
"validator",
".",
"also",
"calls",
"validate_ldap"
] | train | https://github.com/ContinuumIO/flask-ldap-login/blob/09a08be45f861823cb08f95883ee1e092a618c37/flask_ldap_login/forms.py#L45-L56 |
ContinuumIO/flask-ldap-login | flask_ldap_login/__init__.py | scalar | def scalar(value):
"""
Take return a value[0] if `value` is a list of length 1
"""
if isinstance(value, (list, tuple)) and len(value) == 1:
return value[0]
return value | python | def scalar(value):
"""
Take return a value[0] if `value` is a list of length 1
"""
if isinstance(value, (list, tuple)) and len(value) == 1:
return value[0]
return value | [
"def",
"scalar",
"(",
"value",
")",
":",
"if",
"isinstance",
"(",
"value",
",",
"(",
"list",
",",
"tuple",
")",
")",
"and",
"len",
"(",
"value",
")",
"==",
"1",
":",
"return",
"value",
"[",
"0",
"]",
"return",
"value"
] | Take return a value[0] if `value` is a list of length 1 | [
"Take",
"return",
"a",
"value",
"[",
"0",
"]",
"if",
"value",
"is",
"a",
"list",
"of",
"length",
"1"
] | train | https://github.com/ContinuumIO/flask-ldap-login/blob/09a08be45f861823cb08f95883ee1e092a618c37/flask_ldap_login/__init__.py#L52-L58 |
ContinuumIO/flask-ldap-login | flask_ldap_login/__init__.py | LDAPLoginManager.init_app | def init_app(self, app):
'''
Configures an application. This registers an `after_request` call, and
attaches this `LoginManager` to it as `app.login_manager`.
'''
self._config = app.config.get('LDAP', {})
app.ldap_login_manager = self
self.config.setdefault('BIN... | python | def init_app(self, app):
'''
Configures an application. This registers an `after_request` call, and
attaches this `LoginManager` to it as `app.login_manager`.
'''
self._config = app.config.get('LDAP', {})
app.ldap_login_manager = self
self.config.setdefault('BIN... | [
"def",
"init_app",
"(",
"self",
",",
"app",
")",
":",
"self",
".",
"_config",
"=",
"app",
".",
"config",
".",
"get",
"(",
"'LDAP'",
",",
"{",
"}",
")",
"app",
".",
"ldap_login_manager",
"=",
"self",
"self",
".",
"config",
".",
"setdefault",
"(",
"'... | Configures an application. This registers an `after_request` call, and
attaches this `LoginManager` to it as `app.login_manager`. | [
"Configures",
"an",
"application",
".",
"This",
"registers",
"an",
"after_request",
"call",
"and",
"attaches",
"this",
"LoginManager",
"to",
"it",
"as",
"app",
".",
"login_manager",
"."
] | train | https://github.com/ContinuumIO/flask-ldap-login/blob/09a08be45f861823cb08f95883ee1e092a618c37/flask_ldap_login/__init__.py#L94-L111 |
ContinuumIO/flask-ldap-login | flask_ldap_login/__init__.py | LDAPLoginManager.format_results | def format_results(self, results):
"""
Format the ldap results object into somthing that is reasonable
"""
if not results:
return None
userdn = results[0][0]
userobj = results[0][1]
userobj['dn'] = userdn
keymap = self.config.get('KEY_MAP')
... | python | def format_results(self, results):
"""
Format the ldap results object into somthing that is reasonable
"""
if not results:
return None
userdn = results[0][0]
userobj = results[0][1]
userobj['dn'] = userdn
keymap = self.config.get('KEY_MAP')
... | [
"def",
"format_results",
"(",
"self",
",",
"results",
")",
":",
"if",
"not",
"results",
":",
"return",
"None",
"userdn",
"=",
"results",
"[",
"0",
"]",
"[",
"0",
"]",
"userobj",
"=",
"results",
"[",
"0",
"]",
"[",
"1",
"]",
"userobj",
"[",
"'dn'",
... | Format the ldap results object into somthing that is reasonable | [
"Format",
"the",
"ldap",
"results",
"object",
"into",
"somthing",
"that",
"is",
"reasonable"
] | train | https://github.com/ContinuumIO/flask-ldap-login/blob/09a08be45f861823cb08f95883ee1e092a618c37/flask_ldap_login/__init__.py#L113-L127 |
ContinuumIO/flask-ldap-login | flask_ldap_login/__init__.py | LDAPLoginManager.attrlist | def attrlist(self):
'Transform the KEY_MAP paramiter into an attrlist for ldap filters'
keymap = self.config.get('KEY_MAP')
if keymap:
# https://github.com/ContinuumIO/flask-ldap-login/issues/11
# https://continuumsupport.zendesk.com/agent/tickets/393
return [... | python | def attrlist(self):
'Transform the KEY_MAP paramiter into an attrlist for ldap filters'
keymap = self.config.get('KEY_MAP')
if keymap:
# https://github.com/ContinuumIO/flask-ldap-login/issues/11
# https://continuumsupport.zendesk.com/agent/tickets/393
return [... | [
"def",
"attrlist",
"(",
"self",
")",
":",
"keymap",
"=",
"self",
".",
"config",
".",
"get",
"(",
"'KEY_MAP'",
")",
"if",
"keymap",
":",
"# https://github.com/ContinuumIO/flask-ldap-login/issues/11",
"# https://continuumsupport.zendesk.com/agent/tickets/393",
"return",
"["... | Transform the KEY_MAP paramiter into an attrlist for ldap filters | [
"Transform",
"the",
"KEY_MAP",
"paramiter",
"into",
"an",
"attrlist",
"for",
"ldap",
"filters"
] | train | https://github.com/ContinuumIO/flask-ldap-login/blob/09a08be45f861823cb08f95883ee1e092a618c37/flask_ldap_login/__init__.py#L146-L154 |
ContinuumIO/flask-ldap-login | flask_ldap_login/__init__.py | LDAPLoginManager.bind_search | def bind_search(self, username, password):
"""
Bind to BIND_DN/BIND_AUTH then search for user to perform lookup.
"""
log.debug("Performing bind/search")
ctx = {'username':username, 'password':password}
user = self.config['BIND_DN'] % ctx
bind_auth = self.confi... | python | def bind_search(self, username, password):
"""
Bind to BIND_DN/BIND_AUTH then search for user to perform lookup.
"""
log.debug("Performing bind/search")
ctx = {'username':username, 'password':password}
user = self.config['BIND_DN'] % ctx
bind_auth = self.confi... | [
"def",
"bind_search",
"(",
"self",
",",
"username",
",",
"password",
")",
":",
"log",
".",
"debug",
"(",
"\"Performing bind/search\"",
")",
"ctx",
"=",
"{",
"'username'",
":",
"username",
",",
"'password'",
":",
"password",
"}",
"user",
"=",
"self",
".",
... | Bind to BIND_DN/BIND_AUTH then search for user to perform lookup. | [
"Bind",
"to",
"BIND_DN",
"/",
"BIND_AUTH",
"then",
"search",
"for",
"user",
"to",
"perform",
"lookup",
"."
] | train | https://github.com/ContinuumIO/flask-ldap-login/blob/09a08be45f861823cb08f95883ee1e092a618c37/flask_ldap_login/__init__.py#L157-L211 |
ContinuumIO/flask-ldap-login | flask_ldap_login/__init__.py | LDAPLoginManager.direct_bind | def direct_bind(self, username, password):
"""
Bind to username/password directly
"""
log.debug("Performing direct bind")
ctx = {'username':username, 'password':password}
scope = self.config.get('SCOPE', ldap.SCOPE_SUBTREE)
user = self.config['BIND_DN'] % ctx
... | python | def direct_bind(self, username, password):
"""
Bind to username/password directly
"""
log.debug("Performing direct bind")
ctx = {'username':username, 'password':password}
scope = self.config.get('SCOPE', ldap.SCOPE_SUBTREE)
user = self.config['BIND_DN'] % ctx
... | [
"def",
"direct_bind",
"(",
"self",
",",
"username",
",",
"password",
")",
":",
"log",
".",
"debug",
"(",
"\"Performing direct bind\"",
")",
"ctx",
"=",
"{",
"'username'",
":",
"username",
",",
"'password'",
":",
"password",
"}",
"scope",
"=",
"self",
".",
... | Bind to username/password directly | [
"Bind",
"to",
"username",
"/",
"password",
"directly"
] | train | https://github.com/ContinuumIO/flask-ldap-login/blob/09a08be45f861823cb08f95883ee1e092a618c37/flask_ldap_login/__init__.py#L214-L233 |
ContinuumIO/flask-ldap-login | flask_ldap_login/__init__.py | LDAPLoginManager.connect | def connect(self):
'initialize ldap connection and set options'
log.debug("Connecting to ldap server %s" % self.config['URI'])
self.conn = ldap.initialize(self.config['URI'])
# There are some settings that can't be changed at runtime without a context restart.
# It's possible to... | python | def connect(self):
'initialize ldap connection and set options'
log.debug("Connecting to ldap server %s" % self.config['URI'])
self.conn = ldap.initialize(self.config['URI'])
# There are some settings that can't be changed at runtime without a context restart.
# It's possible to... | [
"def",
"connect",
"(",
"self",
")",
":",
"log",
".",
"debug",
"(",
"\"Connecting to ldap server %s\"",
"%",
"self",
".",
"config",
"[",
"'URI'",
"]",
")",
"self",
".",
"conn",
"=",
"ldap",
".",
"initialize",
"(",
"self",
".",
"config",
"[",
"'URI'",
"]... | initialize ldap connection and set options | [
"initialize",
"ldap",
"connection",
"and",
"set",
"options"
] | train | https://github.com/ContinuumIO/flask-ldap-login/blob/09a08be45f861823cb08f95883ee1e092a618c37/flask_ldap_login/__init__.py#L236-L262 |
ContinuumIO/flask-ldap-login | flask_ldap_login/__init__.py | LDAPLoginManager.ldap_login | def ldap_login(self, username, password):
"""
Authenticate a user using ldap. This will return a userdata dict
if successfull.
ldap_login will return None if the user does not exist or if the credentials are invalid
"""
self.connect()
if self.config.get('USER_SEA... | python | def ldap_login(self, username, password):
"""
Authenticate a user using ldap. This will return a userdata dict
if successfull.
ldap_login will return None if the user does not exist or if the credentials are invalid
"""
self.connect()
if self.config.get('USER_SEA... | [
"def",
"ldap_login",
"(",
"self",
",",
"username",
",",
"password",
")",
":",
"self",
".",
"connect",
"(",
")",
"if",
"self",
".",
"config",
".",
"get",
"(",
"'USER_SEARCH'",
")",
":",
"result",
"=",
"self",
".",
"bind_search",
"(",
"username",
",",
... | Authenticate a user using ldap. This will return a userdata dict
if successfull.
ldap_login will return None if the user does not exist or if the credentials are invalid | [
"Authenticate",
"a",
"user",
"using",
"ldap",
".",
"This",
"will",
"return",
"a",
"userdata",
"dict",
"if",
"successfull",
".",
"ldap_login",
"will",
"return",
"None",
"if",
"the",
"user",
"does",
"not",
"exist",
"or",
"if",
"the",
"credentials",
"are",
"i... | train | https://github.com/ContinuumIO/flask-ldap-login/blob/09a08be45f861823cb08f95883ee1e092a618c37/flask_ldap_login/__init__.py#L264-L276 |
ChristianTremblay/BAC0 | BAC0/core/io/Simulate.py | Simulation.sim | def sim(self, args):
"""
Simulate I/O points by setting the Out_Of_Service property, then doing a
WriteProperty to the point's Present_Value.
:param args: String with <addr> <type> <inst> <prop> <value> [ <indx> ] [ <priority> ]
"""
if not self._started:
... | python | def sim(self, args):
"""
Simulate I/O points by setting the Out_Of_Service property, then doing a
WriteProperty to the point's Present_Value.
:param args: String with <addr> <type> <inst> <prop> <value> [ <indx> ] [ <priority> ]
"""
if not self._started:
... | [
"def",
"sim",
"(",
"self",
",",
"args",
")",
":",
"if",
"not",
"self",
".",
"_started",
":",
"raise",
"ApplicationNotStarted",
"(",
"\"BACnet stack not running - use startApp()\"",
")",
"# with self.this_application._lock: if use lock...won't be able to call read...\r",
"args... | Simulate I/O points by setting the Out_Of_Service property, then doing a
WriteProperty to the point's Present_Value.
:param args: String with <addr> <type> <inst> <prop> <value> [ <indx> ] [ <priority> ] | [
"Simulate",
"I",
"/",
"O",
"points",
"by",
"setting",
"the",
"Out_Of_Service",
"property",
"then",
"doing",
"a",
"WriteProperty",
"to",
"the",
"point",
"s",
"Present_Value",
".",
":",
"param",
"args",
":",
"String",
"with",
"<addr",
">",
"<type",
">",
"<in... | train | https://github.com/ChristianTremblay/BAC0/blob/8d95b065ea068524a08f5b0c34322ebeeba95d06/BAC0/core/io/Simulate.py#L30-L67 |
ChristianTremblay/BAC0 | BAC0/core/io/Simulate.py | Simulation.out_of_service | def out_of_service(self, args):
"""
Set the Out_Of_Service property so the Present_Value of an I/O may be written.
:param args: String with <addr> <type> <inst> <prop> <value> [ <indx> ] [ <priority> ]
"""
if not self._started:
raise ApplicationNotStarted("B... | python | def out_of_service(self, args):
"""
Set the Out_Of_Service property so the Present_Value of an I/O may be written.
:param args: String with <addr> <type> <inst> <prop> <value> [ <indx> ] [ <priority> ]
"""
if not self._started:
raise ApplicationNotStarted("B... | [
"def",
"out_of_service",
"(",
"self",
",",
"args",
")",
":",
"if",
"not",
"self",
".",
"_started",
":",
"raise",
"ApplicationNotStarted",
"(",
"\"BACnet stack not running - use startApp()\"",
")",
"# with self.this_application._lock: if use lock...won't be able to call read...\... | Set the Out_Of_Service property so the Present_Value of an I/O may be written.
:param args: String with <addr> <type> <inst> <prop> <value> [ <indx> ] [ <priority> ] | [
"Set",
"the",
"Out_Of_Service",
"property",
"so",
"the",
"Present_Value",
"of",
"an",
"I",
"/",
"O",
"may",
"be",
"written",
".",
":",
"param",
"args",
":",
"String",
"with",
"<addr",
">",
"<type",
">",
"<inst",
">",
"<prop",
">",
"<value",
">",
"[",
... | train | https://github.com/ChristianTremblay/BAC0/blob/8d95b065ea068524a08f5b0c34322ebeeba95d06/BAC0/core/io/Simulate.py#L69-L85 |
ChristianTremblay/BAC0 | BAC0/core/io/Simulate.py | Simulation.release | def release(self, args):
"""
Set the Out_Of_Service property to False - to release the I/O point back to
the controller's control.
:param args: String with <addr> <type> <inst>
"""
if not self._started:
raise ApplicationNotStarted("BACnet stack not... | python | def release(self, args):
"""
Set the Out_Of_Service property to False - to release the I/O point back to
the controller's control.
:param args: String with <addr> <type> <inst>
"""
if not self._started:
raise ApplicationNotStarted("BACnet stack not... | [
"def",
"release",
"(",
"self",
",",
"args",
")",
":",
"if",
"not",
"self",
".",
"_started",
":",
"raise",
"ApplicationNotStarted",
"(",
"\"BACnet stack not running - use startApp()\"",
")",
"args",
"=",
"args",
".",
"split",
"(",
")",
"addr",
",",
"obj_type",
... | Set the Out_Of_Service property to False - to release the I/O point back to
the controller's control.
:param args: String with <addr> <type> <inst> | [
"Set",
"the",
"Out_Of_Service",
"property",
"to",
"False",
"-",
"to",
"release",
"the",
"I",
"/",
"O",
"point",
"back",
"to",
"the",
"controller",
"s",
"control",
".",
":",
"param",
"args",
":",
"String",
"with",
"<addr",
">",
"<type",
">",
"<inst",
">... | train | https://github.com/ChristianTremblay/BAC0/blob/8d95b065ea068524a08f5b0c34322ebeeba95d06/BAC0/core/io/Simulate.py#L87-L111 |
ChristianTremblay/BAC0 | BAC0/core/functions/GetIPAddr.py | HostIP.ip_address_subnet | def ip_address_subnet(self):
"""
IP Address/subnet
"""
return "{}/{}".format(
self.interface.ip.compressed, self.interface.exploded.split("/")[-1]
) | python | def ip_address_subnet(self):
"""
IP Address/subnet
"""
return "{}/{}".format(
self.interface.ip.compressed, self.interface.exploded.split("/")[-1]
) | [
"def",
"ip_address_subnet",
"(",
"self",
")",
":",
"return",
"\"{}/{}\"",
".",
"format",
"(",
"self",
".",
"interface",
".",
"ip",
".",
"compressed",
",",
"self",
".",
"interface",
".",
"exploded",
".",
"split",
"(",
"\"/\"",
")",
"[",
"-",
"1",
"]",
... | IP Address/subnet | [
"IP",
"Address",
"/",
"subnet"
] | train | https://github.com/ChristianTremblay/BAC0/blob/8d95b065ea068524a08f5b0c34322ebeeba95d06/BAC0/core/functions/GetIPAddr.py#L37-L43 |
ChristianTremblay/BAC0 | BAC0/core/functions/GetIPAddr.py | HostIP.address | def address(self):
"""
IP Address using bacpypes Address format
"""
port = ""
if self._port:
port = ":{}".format(self._port)
return Address(
"{}/{}{}".format(
self.interface.ip.compressed,
self.interface.exploded.spl... | python | def address(self):
"""
IP Address using bacpypes Address format
"""
port = ""
if self._port:
port = ":{}".format(self._port)
return Address(
"{}/{}{}".format(
self.interface.ip.compressed,
self.interface.exploded.spl... | [
"def",
"address",
"(",
"self",
")",
":",
"port",
"=",
"\"\"",
"if",
"self",
".",
"_port",
":",
"port",
"=",
"\":{}\"",
".",
"format",
"(",
"self",
".",
"_port",
")",
"return",
"Address",
"(",
"\"{}/{}{}\"",
".",
"format",
"(",
"self",
".",
"interface... | IP Address using bacpypes Address format | [
"IP",
"Address",
"using",
"bacpypes",
"Address",
"format"
] | train | https://github.com/ChristianTremblay/BAC0/blob/8d95b065ea068524a08f5b0c34322ebeeba95d06/BAC0/core/functions/GetIPAddr.py#L53-L66 |
ChristianTremblay/BAC0 | BAC0/core/functions/GetIPAddr.py | HostIP._findIPAddr | def _findIPAddr(self):
"""
Retrieve the IP address connected to internet... used as
a default IP address when defining Script
:returns: IP Adress as String
"""
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
try:
s.connect(("google.com", 0))
... | python | def _findIPAddr(self):
"""
Retrieve the IP address connected to internet... used as
a default IP address when defining Script
:returns: IP Adress as String
"""
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
try:
s.connect(("google.com", 0))
... | [
"def",
"_findIPAddr",
"(",
"self",
")",
":",
"s",
"=",
"socket",
".",
"socket",
"(",
"socket",
".",
"AF_INET",
",",
"socket",
".",
"SOCK_DGRAM",
")",
"try",
":",
"s",
".",
"connect",
"(",
"(",
"\"google.com\"",
",",
"0",
")",
")",
"addr",
"=",
"s",... | Retrieve the IP address connected to internet... used as
a default IP address when defining Script
:returns: IP Adress as String | [
"Retrieve",
"the",
"IP",
"address",
"connected",
"to",
"internet",
"...",
"used",
"as",
"a",
"default",
"IP",
"address",
"when",
"defining",
"Script"
] | train | https://github.com/ChristianTremblay/BAC0/blob/8d95b065ea068524a08f5b0c34322ebeeba95d06/BAC0/core/functions/GetIPAddr.py#L82-L99 |
ChristianTremblay/BAC0 | BAC0/core/functions/GetIPAddr.py | HostIP._findSubnetMask | def _findSubnetMask(self, ip):
"""
Retrieve the broadcast IP address connected to internet... used as
a default IP address when defining Script
:param ip: (str) optionnal IP address. If not provided, default to getIPAddr()
:param mask: (str) optionnal subnet mask. If not provide... | python | def _findSubnetMask(self, ip):
"""
Retrieve the broadcast IP address connected to internet... used as
a default IP address when defining Script
:param ip: (str) optionnal IP address. If not provided, default to getIPAddr()
:param mask: (str) optionnal subnet mask. If not provide... | [
"def",
"_findSubnetMask",
"(",
"self",
",",
"ip",
")",
":",
"ip",
"=",
"ip",
"if",
"\"win32\"",
"in",
"sys",
".",
"platform",
":",
"try",
":",
"proc",
"=",
"subprocess",
".",
"Popen",
"(",
"\"ipconfig\"",
",",
"stdout",
"=",
"subprocess",
".",
"PIPE",
... | Retrieve the broadcast IP address connected to internet... used as
a default IP address when defining Script
:param ip: (str) optionnal IP address. If not provided, default to getIPAddr()
:param mask: (str) optionnal subnet mask. If not provided, will try to find one using ipconfig (Windows) or... | [
"Retrieve",
"the",
"broadcast",
"IP",
"address",
"connected",
"to",
"internet",
"...",
"used",
"as",
"a",
"default",
"IP",
"address",
"when",
"defining",
"Script"
] | train | https://github.com/ChristianTremblay/BAC0/blob/8d95b065ea068524a08f5b0c34322ebeeba95d06/BAC0/core/functions/GetIPAddr.py#L101-L150 |
ChristianTremblay/BAC0 | BAC0/sql/sql.py | SQLMixin._read_from_sql | def _read_from_sql(self, request, db_name):
"""
Using the contextlib, I hope to close the connection to database when
not in use
"""
with contextlib.closing(sqlite3.connect("{}.db".format(db_name))) as con:
return sql.read_sql(sql=request, con=con) | python | def _read_from_sql(self, request, db_name):
"""
Using the contextlib, I hope to close the connection to database when
not in use
"""
with contextlib.closing(sqlite3.connect("{}.db".format(db_name))) as con:
return sql.read_sql(sql=request, con=con) | [
"def",
"_read_from_sql",
"(",
"self",
",",
"request",
",",
"db_name",
")",
":",
"with",
"contextlib",
".",
"closing",
"(",
"sqlite3",
".",
"connect",
"(",
"\"{}.db\"",
".",
"format",
"(",
"db_name",
")",
")",
")",
"as",
"con",
":",
"return",
"sql",
"."... | Using the contextlib, I hope to close the connection to database when
not in use | [
"Using",
"the",
"contextlib",
"I",
"hope",
"to",
"close",
"the",
"connection",
"to",
"database",
"when",
"not",
"in",
"use"
] | train | https://github.com/ChristianTremblay/BAC0/blob/8d95b065ea068524a08f5b0c34322ebeeba95d06/BAC0/sql/sql.py#L42-L48 |
ChristianTremblay/BAC0 | BAC0/sql/sql.py | SQLMixin.points_properties_df | def points_properties_df(self):
"""
Return a dictionary of point/point_properties in preparation for storage in SQL.
"""
pprops = {}
for each in self.points:
p = each.properties.asdict.copy()
p.pop("device", None)
p.pop("network", None)
... | python | def points_properties_df(self):
"""
Return a dictionary of point/point_properties in preparation for storage in SQL.
"""
pprops = {}
for each in self.points:
p = each.properties.asdict.copy()
p.pop("device", None)
p.pop("network", None)
... | [
"def",
"points_properties_df",
"(",
"self",
")",
":",
"pprops",
"=",
"{",
"}",
"for",
"each",
"in",
"self",
".",
"points",
":",
"p",
"=",
"each",
".",
"properties",
".",
"asdict",
".",
"copy",
"(",
")",
"p",
".",
"pop",
"(",
"\"device\"",
",",
"Non... | Return a dictionary of point/point_properties in preparation for storage in SQL. | [
"Return",
"a",
"dictionary",
"of",
"point",
"/",
"point_properties",
"in",
"preparation",
"for",
"storage",
"in",
"SQL",
"."
] | train | https://github.com/ChristianTremblay/BAC0/blob/8d95b065ea068524a08f5b0c34322ebeeba95d06/BAC0/sql/sql.py#L56-L70 |
ChristianTremblay/BAC0 | BAC0/sql/sql.py | SQLMixin.backup_histories_df | def backup_histories_df(self):
"""
Build a dataframe of the point histories
"""
backup = {}
for point in self.points:
if point.history.dtypes == object:
backup[point.properties.name] = (
point.history.replace(["inactive", "active"],... | python | def backup_histories_df(self):
"""
Build a dataframe of the point histories
"""
backup = {}
for point in self.points:
if point.history.dtypes == object:
backup[point.properties.name] = (
point.history.replace(["inactive", "active"],... | [
"def",
"backup_histories_df",
"(",
"self",
")",
":",
"backup",
"=",
"{",
"}",
"for",
"point",
"in",
"self",
".",
"points",
":",
"if",
"point",
".",
"history",
".",
"dtypes",
"==",
"object",
":",
"backup",
"[",
"point",
".",
"properties",
".",
"name",
... | Build a dataframe of the point histories | [
"Build",
"a",
"dataframe",
"of",
"the",
"point",
"histories"
] | train | https://github.com/ChristianTremblay/BAC0/blob/8d95b065ea068524a08f5b0c34322ebeeba95d06/BAC0/sql/sql.py#L72-L88 |
ChristianTremblay/BAC0 | BAC0/sql/sql.py | SQLMixin.save | def save(self, filename=None):
"""
Save the point histories to sqlite3 database.
Save the device object properties to a pickle file so the device can be reloaded.
"""
if filename:
if ".db" in filename:
filename = filename.split(".")[0]
se... | python | def save(self, filename=None):
"""
Save the point histories to sqlite3 database.
Save the device object properties to a pickle file so the device can be reloaded.
"""
if filename:
if ".db" in filename:
filename = filename.split(".")[0]
se... | [
"def",
"save",
"(",
"self",
",",
"filename",
"=",
"None",
")",
":",
"if",
"filename",
":",
"if",
"\".db\"",
"in",
"filename",
":",
"filename",
"=",
"filename",
".",
"split",
"(",
"\".\"",
")",
"[",
"0",
"]",
"self",
".",
"properties",
".",
"db_name",... | Save the point histories to sqlite3 database.
Save the device object properties to a pickle file so the device can be reloaded. | [
"Save",
"the",
"point",
"histories",
"to",
"sqlite3",
"database",
".",
"Save",
"the",
"device",
"object",
"properties",
"to",
"a",
"pickle",
"file",
"so",
"the",
"device",
"can",
"be",
"reloaded",
"."
] | train | https://github.com/ChristianTremblay/BAC0/blob/8d95b065ea068524a08f5b0c34322ebeeba95d06/BAC0/sql/sql.py#L90-L138 |
ChristianTremblay/BAC0 | BAC0/sql/sql.py | SQLMixin.points_from_sql | def points_from_sql(self, db_name):
"""
Retrieve point list from SQL database
"""
points = self._read_from_sql("SELECT * FROM history;", db_name)
return list(points.columns.values)[1:] | python | def points_from_sql(self, db_name):
"""
Retrieve point list from SQL database
"""
points = self._read_from_sql("SELECT * FROM history;", db_name)
return list(points.columns.values)[1:] | [
"def",
"points_from_sql",
"(",
"self",
",",
"db_name",
")",
":",
"points",
"=",
"self",
".",
"_read_from_sql",
"(",
"\"SELECT * FROM history;\"",
",",
"db_name",
")",
"return",
"list",
"(",
"points",
".",
"columns",
".",
"values",
")",
"[",
"1",
":",
"]"
] | Retrieve point list from SQL database | [
"Retrieve",
"point",
"list",
"from",
"SQL",
"database"
] | train | https://github.com/ChristianTremblay/BAC0/blob/8d95b065ea068524a08f5b0c34322ebeeba95d06/BAC0/sql/sql.py#L140-L145 |
ChristianTremblay/BAC0 | BAC0/sql/sql.py | SQLMixin.his_from_sql | def his_from_sql(self, db_name, point):
"""
Retrive point histories from SQL database
"""
his = self._read_from_sql('select * from "%s"' % "history", db_name)
his.index = his["index"].apply(Timestamp)
return his.set_index("index")[point] | python | def his_from_sql(self, db_name, point):
"""
Retrive point histories from SQL database
"""
his = self._read_from_sql('select * from "%s"' % "history", db_name)
his.index = his["index"].apply(Timestamp)
return his.set_index("index")[point] | [
"def",
"his_from_sql",
"(",
"self",
",",
"db_name",
",",
"point",
")",
":",
"his",
"=",
"self",
".",
"_read_from_sql",
"(",
"'select * from \"%s\"'",
"%",
"\"history\"",
",",
"db_name",
")",
"his",
".",
"index",
"=",
"his",
"[",
"\"index\"",
"]",
".",
"a... | Retrive point histories from SQL database | [
"Retrive",
"point",
"histories",
"from",
"SQL",
"database"
] | train | https://github.com/ChristianTremblay/BAC0/blob/8d95b065ea068524a08f5b0c34322ebeeba95d06/BAC0/sql/sql.py#L147-L153 |
ChristianTremblay/BAC0 | BAC0/sql/sql.py | SQLMixin.read_point_prop | def read_point_prop(self, device_name, point):
"""
Points properties retrieved from pickle
"""
with open("%s.bin" % device_name, "rb") as file:
return pickle.load(file)["points"][point] | python | def read_point_prop(self, device_name, point):
"""
Points properties retrieved from pickle
"""
with open("%s.bin" % device_name, "rb") as file:
return pickle.load(file)["points"][point] | [
"def",
"read_point_prop",
"(",
"self",
",",
"device_name",
",",
"point",
")",
":",
"with",
"open",
"(",
"\"%s.bin\"",
"%",
"device_name",
",",
"\"rb\"",
")",
"as",
"file",
":",
"return",
"pickle",
".",
"load",
"(",
"file",
")",
"[",
"\"points\"",
"]",
... | Points properties retrieved from pickle | [
"Points",
"properties",
"retrieved",
"from",
"pickle"
] | train | https://github.com/ChristianTremblay/BAC0/blob/8d95b065ea068524a08f5b0c34322ebeeba95d06/BAC0/sql/sql.py#L161-L166 |
ChristianTremblay/BAC0 | BAC0/sql/sql.py | SQLMixin.read_dev_prop | def read_dev_prop(self, device_name):
"""
Device properties retrieved from pickle
"""
with open("{}.bin".format(device_name), "rb") as file:
return pickle.load(file)["device"] | python | def read_dev_prop(self, device_name):
"""
Device properties retrieved from pickle
"""
with open("{}.bin".format(device_name), "rb") as file:
return pickle.load(file)["device"] | [
"def",
"read_dev_prop",
"(",
"self",
",",
"device_name",
")",
":",
"with",
"open",
"(",
"\"{}.bin\"",
".",
"format",
"(",
"device_name",
")",
",",
"\"rb\"",
")",
"as",
"file",
":",
"return",
"pickle",
".",
"load",
"(",
"file",
")",
"[",
"\"device\"",
"... | Device properties retrieved from pickle | [
"Device",
"properties",
"retrieved",
"from",
"pickle"
] | train | https://github.com/ChristianTremblay/BAC0/blob/8d95b065ea068524a08f5b0c34322ebeeba95d06/BAC0/sql/sql.py#L168-L173 |
ChristianTremblay/BAC0 | BAC0/core/devices/Points.py | BooleanPoint.value | def value(self):
"""
Read the value from BACnet network
"""
try:
res = self.properties.device.properties.network.read(
"{} {} {} presentValue".format(
self.properties.device.properties.address,
self.properties.type,
... | python | def value(self):
"""
Read the value from BACnet network
"""
try:
res = self.properties.device.properties.network.read(
"{} {} {} presentValue".format(
self.properties.device.properties.address,
self.properties.type,
... | [
"def",
"value",
"(",
"self",
")",
":",
"try",
":",
"res",
"=",
"self",
".",
"properties",
".",
"device",
".",
"properties",
".",
"network",
".",
"read",
"(",
"\"{} {} {} presentValue\"",
".",
"format",
"(",
"self",
".",
"properties",
".",
"device",
".",
... | Read the value from BACnet network | [
"Read",
"the",
"value",
"from",
"BACnet",
"network"
] | train | https://github.com/ChristianTremblay/BAC0/blob/8d95b065ea068524a08f5b0c34322ebeeba95d06/BAC0/core/devices/Points.py#L628-L651 |
ChristianTremblay/BAC0 | BAC0/core/devices/Points.py | BooleanPoint.boolValue | def boolValue(self):
"""
returns : (boolean) Value
"""
if self.lastValue == 1 or self.lastValue == "active":
self._key = 1
self._boolKey = True
else:
self._key = 0
self._boolKey = False
return self._boolKey | python | def boolValue(self):
"""
returns : (boolean) Value
"""
if self.lastValue == 1 or self.lastValue == "active":
self._key = 1
self._boolKey = True
else:
self._key = 0
self._boolKey = False
return self._boolKey | [
"def",
"boolValue",
"(",
"self",
")",
":",
"if",
"self",
".",
"lastValue",
"==",
"1",
"or",
"self",
".",
"lastValue",
"==",
"\"active\"",
":",
"self",
".",
"_key",
"=",
"1",
"self",
".",
"_boolKey",
"=",
"True",
"else",
":",
"self",
".",
"_key",
"=... | returns : (boolean) Value | [
"returns",
":",
"(",
"boolean",
")",
"Value"
] | train | https://github.com/ChristianTremblay/BAC0/blob/8d95b065ea068524a08f5b0c34322ebeeba95d06/BAC0/core/devices/Points.py#L654-L664 |
ChristianTremblay/BAC0 | BAC0/core/devices/Points.py | EnumPoint.enumValue | def enumValue(self):
"""
returns: (str) Enum state value
"""
try:
return self.properties.units_state[int(self.lastValue) - 1]
except IndexError:
value = "unknown"
except ValueError:
value = "NaN"
return value | python | def enumValue(self):
"""
returns: (str) Enum state value
"""
try:
return self.properties.units_state[int(self.lastValue) - 1]
except IndexError:
value = "unknown"
except ValueError:
value = "NaN"
return value | [
"def",
"enumValue",
"(",
"self",
")",
":",
"try",
":",
"return",
"self",
".",
"properties",
".",
"units_state",
"[",
"int",
"(",
"self",
".",
"lastValue",
")",
"-",
"1",
"]",
"except",
"IndexError",
":",
"value",
"=",
"\"unknown\"",
"except",
"ValueError... | returns: (str) Enum state value | [
"returns",
":",
"(",
"str",
")",
"Enum",
"state",
"value"
] | train | https://github.com/ChristianTremblay/BAC0/blob/8d95b065ea068524a08f5b0c34322ebeeba95d06/BAC0/core/devices/Points.py#L734-L744 |
ChristianTremblay/BAC0 | BAC0/core/devices/Points.py | EnumPointOffline.value | def value(self):
"""
Take last known value as the value
"""
try:
value = self.lastValue
except IndexError:
value = "NaN"
except ValueError:
value = "NaN"
return value | python | def value(self):
"""
Take last known value as the value
"""
try:
value = self.lastValue
except IndexError:
value = "NaN"
except ValueError:
value = "NaN"
return value | [
"def",
"value",
"(",
"self",
")",
":",
"try",
":",
"value",
"=",
"self",
".",
"lastValue",
"except",
"IndexError",
":",
"value",
"=",
"\"NaN\"",
"except",
"ValueError",
":",
"value",
"=",
"\"NaN\"",
"return",
"value"
] | Take last known value as the value | [
"Take",
"last",
"known",
"value",
"as",
"the",
"value"
] | train | https://github.com/ChristianTremblay/BAC0/blob/8d95b065ea068524a08f5b0c34322ebeeba95d06/BAC0/core/devices/Points.py#L902-L912 |
ChristianTremblay/BAC0 | BAC0/core/devices/mixins/read_mixin.py | ReadPropertyMultiple._batches | def _batches(self, request, points_per_request):
"""
Generator for creating 'request batches'. Each batch contains a maximum of "points_per_request"
points to read.
:params: request a list of point_name as a list
:params: (int) points_per_request
:returns: (iter) ... | python | def _batches(self, request, points_per_request):
"""
Generator for creating 'request batches'. Each batch contains a maximum of "points_per_request"
points to read.
:params: request a list of point_name as a list
:params: (int) points_per_request
:returns: (iter) ... | [
"def",
"_batches",
"(",
"self",
",",
"request",
",",
"points_per_request",
")",
":",
"for",
"i",
"in",
"range",
"(",
"0",
",",
"len",
"(",
"request",
")",
",",
"points_per_request",
")",
":",
"yield",
"request",
"[",
"i",
":",
"i",
"+",
"points_per_req... | Generator for creating 'request batches'. Each batch contains a maximum of "points_per_request"
points to read.
:params: request a list of point_name as a list
:params: (int) points_per_request
:returns: (iter) list of point_name of size <= points_per_request | [
"Generator",
"for",
"creating",
"request",
"batches",
".",
"Each",
"batch",
"contains",
"a",
"maximum",
"of",
"points_per_request",
"points",
"to",
"read",
".",
":",
"params",
":",
"request",
"a",
"list",
"of",
"point_name",
"as",
"a",
"list",
":",
"params",... | train | https://github.com/ChristianTremblay/BAC0/blob/8d95b065ea068524a08f5b0c34322ebeeba95d06/BAC0/core/devices/mixins/read_mixin.py#L38-L47 |
ChristianTremblay/BAC0 | BAC0/core/devices/mixins/read_mixin.py | ReadPropertyMultiple._rpm_request_by_name | def _rpm_request_by_name(self, point_list):
"""
:param point_list: a list of point
:returns: (tuple) read request for each points, points
"""
points = []
requests = []
for each in point_list:
str_list = []
point = self._findPoint(e... | python | def _rpm_request_by_name(self, point_list):
"""
:param point_list: a list of point
:returns: (tuple) read request for each points, points
"""
points = []
requests = []
for each in point_list:
str_list = []
point = self._findPoint(e... | [
"def",
"_rpm_request_by_name",
"(",
"self",
",",
"point_list",
")",
":",
"points",
"=",
"[",
"]",
"requests",
"=",
"[",
"]",
"for",
"each",
"in",
"point_list",
":",
"str_list",
"=",
"[",
"]",
"point",
"=",
"self",
".",
"_findPoint",
"(",
"each",
",",
... | :param point_list: a list of point
:returns: (tuple) read request for each points, points | [
":",
"param",
"point_list",
":",
"a",
"list",
"of",
"point",
":",
"returns",
":",
"(",
"tuple",
")",
"read",
"request",
"for",
"each",
"points",
"points"
] | train | https://github.com/ChristianTremblay/BAC0/blob/8d95b065ea068524a08f5b0c34322ebeeba95d06/BAC0/core/devices/mixins/read_mixin.py#L49-L67 |
ChristianTremblay/BAC0 | BAC0/core/devices/mixins/read_mixin.py | ReadPropertyMultiple.read_multiple | def read_multiple(
self,
points_list,
*,
points_per_request=25,
discover_request=(None, 6),
force_single=False
):
"""
Read points from a device using a ReadPropertyMultiple request.
[ReadProperty requests are very slow in comparison].... | python | def read_multiple(
self,
points_list,
*,
points_per_request=25,
discover_request=(None, 6),
force_single=False
):
"""
Read points from a device using a ReadPropertyMultiple request.
[ReadProperty requests are very slow in comparison].... | [
"def",
"read_multiple",
"(",
"self",
",",
"points_list",
",",
"*",
",",
"points_per_request",
"=",
"25",
",",
"discover_request",
"=",
"(",
"None",
",",
"6",
")",
",",
"force_single",
"=",
"False",
")",
":",
"if",
"not",
"self",
".",
"properties",
".",
... | Read points from a device using a ReadPropertyMultiple request.
[ReadProperty requests are very slow in comparison].
:param points_list: (list) a list of all point_name as str
:param points_per_request: (int) number of points in the request
Requesting many points results big requ... | [
"Read",
"points",
"from",
"a",
"device",
"using",
"a",
"ReadPropertyMultiple",
"request",
".",
"[",
"ReadProperty",
"requests",
"are",
"very",
"slow",
"in",
"comparison",
"]",
".",
":",
"param",
"points_list",
":",
"(",
"list",
")",
"a",
"list",
"of",
"all... | train | https://github.com/ChristianTremblay/BAC0/blob/8d95b065ea068524a08f5b0c34322ebeeba95d06/BAC0/core/devices/mixins/read_mixin.py#L69-L165 |
ChristianTremblay/BAC0 | BAC0/core/devices/mixins/read_mixin.py | ReadProperty.read_multiple | def read_multiple(
self, points_list, *, points_per_request=1, discover_request=(None, 6)
):
"""
Functions to read points from a device using the ReadPropertyMultiple request.
Using readProperty request can be very slow to read a lot of data.
:param points_list: (list... | python | def read_multiple(
self, points_list, *, points_per_request=1, discover_request=(None, 6)
):
"""
Functions to read points from a device using the ReadPropertyMultiple request.
Using readProperty request can be very slow to read a lot of data.
:param points_list: (list... | [
"def",
"read_multiple",
"(",
"self",
",",
"points_list",
",",
"*",
",",
"points_per_request",
"=",
"1",
",",
"discover_request",
"=",
"(",
"None",
",",
"6",
")",
")",
":",
"# print('PSS : %s' % self.properties.pss['readPropertyMultiple'])\r",
"if",
"isinstance",
"("... | Functions to read points from a device using the ReadPropertyMultiple request.
Using readProperty request can be very slow to read a lot of data.
:param points_list: (list) a list of all point_name as str
:param points_per_request: (int) number of points in the request
Using too ... | [
"Functions",
"to",
"read",
"points",
"from",
"a",
"device",
"using",
"the",
"ReadPropertyMultiple",
"request",
".",
"Using",
"readProperty",
"request",
"can",
"be",
"very",
"slow",
"to",
"read",
"a",
"lot",
"of",
"data",
".",
":",
"param",
"points_list",
":"... | train | https://github.com/ChristianTremblay/BAC0/blob/8d95b065ea068524a08f5b0c34322ebeeba95d06/BAC0/core/devices/mixins/read_mixin.py#L528-L555 |
ChristianTremblay/BAC0 | BAC0/core/devices/mixins/read_mixin.py | ReadProperty.poll | def poll(self, command="start", *, delay=120):
"""
Poll a point every x seconds (delay=x sec)
Can be stopped by using point.poll('stop') or .poll(0) or .poll(False)
or by setting a delay = 0
:param command: (str) start or stop polling
:param delay: (int) time dela... | python | def poll(self, command="start", *, delay=120):
"""
Poll a point every x seconds (delay=x sec)
Can be stopped by using point.poll('stop') or .poll(0) or .poll(False)
or by setting a delay = 0
:param command: (str) start or stop polling
:param delay: (int) time dela... | [
"def",
"poll",
"(",
"self",
",",
"command",
"=",
"\"start\"",
",",
"*",
",",
"delay",
"=",
"120",
")",
":",
"if",
"delay",
">",
"120",
":",
"self",
".",
"_log",
".",
"warning",
"(",
"\"Segmentation not supported, forcing delay to 120 seconds (or higher)\"",
")... | Poll a point every x seconds (delay=x sec)
Can be stopped by using point.poll('stop') or .poll(0) or .poll(False)
or by setting a delay = 0
:param command: (str) start or stop polling
:param delay: (int) time delay between polls in seconds
:type command: str
:type... | [
"Poll",
"a",
"point",
"every",
"x",
"seconds",
"(",
"delay",
"=",
"x",
"sec",
")",
"Can",
"be",
"stopped",
"by",
"using",
"point",
".",
"poll",
"(",
"stop",
")",
"or",
".",
"poll",
"(",
"0",
")",
"or",
".",
"poll",
"(",
"False",
")",
"or",
"by"... | train | https://github.com/ChristianTremblay/BAC0/blob/8d95b065ea068524a08f5b0c34322ebeeba95d06/BAC0/core/devices/mixins/read_mixin.py#L703-L763 |
ChristianTremblay/BAC0 | BAC0/scripts/Complete.py | Stats_Mixin.network_stats | def network_stats(self):
"""
Used by Flask to show informations on the network
"""
statistics = {}
mstp_networks = []
mstp_map = {}
ip_devices = []
bacoids = []
mstp_devices = []
for address, bacoid in self.whois_answer[0].keys():
... | python | def network_stats(self):
"""
Used by Flask to show informations on the network
"""
statistics = {}
mstp_networks = []
mstp_map = {}
ip_devices = []
bacoids = []
mstp_devices = []
for address, bacoid in self.whois_answer[0].keys():
... | [
"def",
"network_stats",
"(",
"self",
")",
":",
"statistics",
"=",
"{",
"}",
"mstp_networks",
"=",
"[",
"]",
"mstp_map",
"=",
"{",
"}",
"ip_devices",
"=",
"[",
"]",
"bacoids",
"=",
"[",
"]",
"mstp_devices",
"=",
"[",
"]",
"for",
"address",
",",
"bacoi... | Used by Flask to show informations on the network | [
"Used",
"by",
"Flask",
"to",
"show",
"informations",
"on",
"the",
"network"
] | train | https://github.com/ChristianTremblay/BAC0/blob/8d95b065ea068524a08f5b0c34322ebeeba95d06/BAC0/scripts/Complete.py#L101-L135 |
ChristianTremblay/BAC0 | BAC0/core/devices/Device.py | DeviceConnected.connect | def connect(self, *, db=None):
"""
A connected device can be switched to 'database mode' where the device will
not use the BACnet network but instead obtain its contents from a previously
stored database.
"""
if db:
self.poll(command="stop")
... | python | def connect(self, *, db=None):
"""
A connected device can be switched to 'database mode' where the device will
not use the BACnet network but instead obtain its contents from a previously
stored database.
"""
if db:
self.poll(command="stop")
... | [
"def",
"connect",
"(",
"self",
",",
"*",
",",
"db",
"=",
"None",
")",
":",
"if",
"db",
":",
"self",
".",
"poll",
"(",
"command",
"=",
"\"stop\"",
")",
"self",
".",
"properties",
".",
"db_name",
"=",
"db",
".",
"split",
"(",
"\".\"",
")",
"[",
"... | A connected device can be switched to 'database mode' where the device will
not use the BACnet network but instead obtain its contents from a previously
stored database. | [
"A",
"connected",
"device",
"can",
"be",
"switched",
"to",
"database",
"mode",
"where",
"the",
"device",
"will",
"not",
"use",
"the",
"BACnet",
"network",
"but",
"instead",
"obtain",
"its",
"contents",
"from",
"a",
"previously",
"stored",
"database",
"."
] | train | https://github.com/ChristianTremblay/BAC0/blob/8d95b065ea068524a08f5b0c34322ebeeba95d06/BAC0/core/devices/Device.py#L453-L466 |
ChristianTremblay/BAC0 | BAC0/core/devices/Device.py | DeviceConnected.df | def df(self, list_of_points, force_read=True):
"""
When connected, calling DF should force a reading on the network.
"""
his = []
for point in list_of_points:
try:
his.append(self._findPoint(point, force_read=force_read).history)
... | python | def df(self, list_of_points, force_read=True):
"""
When connected, calling DF should force a reading on the network.
"""
his = []
for point in list_of_points:
try:
his.append(self._findPoint(point, force_read=force_read).history)
... | [
"def",
"df",
"(",
"self",
",",
"list_of_points",
",",
"force_read",
"=",
"True",
")",
":",
"his",
"=",
"[",
"]",
"for",
"point",
"in",
"list_of_points",
":",
"try",
":",
"his",
".",
"append",
"(",
"self",
".",
"_findPoint",
"(",
"point",
",",
"force_... | When connected, calling DF should force a reading on the network. | [
"When",
"connected",
"calling",
"DF",
"should",
"force",
"a",
"reading",
"on",
"the",
"network",
"."
] | train | https://github.com/ChristianTremblay/BAC0/blob/8d95b065ea068524a08f5b0c34322ebeeba95d06/BAC0/core/devices/Device.py#L468-L482 |
ChristianTremblay/BAC0 | BAC0/core/devices/Device.py | DeviceConnected._buildPointList | def _buildPointList(self):
"""
Upon connection to build the device point list and properties.
"""
try:
self.properties.pss.value = self.properties.network.read(
"{} device {} protocolServicesSupported".format(
self.properties.address... | python | def _buildPointList(self):
"""
Upon connection to build the device point list and properties.
"""
try:
self.properties.pss.value = self.properties.network.read(
"{} device {} protocolServicesSupported".format(
self.properties.address... | [
"def",
"_buildPointList",
"(",
"self",
")",
":",
"try",
":",
"self",
".",
"properties",
".",
"pss",
".",
"value",
"=",
"self",
".",
"properties",
".",
"network",
".",
"read",
"(",
"\"{} device {} protocolServicesSupported\"",
".",
"format",
"(",
"self",
".",... | Upon connection to build the device point list and properties. | [
"Upon",
"connection",
"to",
"build",
"the",
"device",
"point",
"list",
"and",
"properties",
"."
] | train | https://github.com/ChristianTremblay/BAC0/blob/8d95b065ea068524a08f5b0c34322ebeeba95d06/BAC0/core/devices/Device.py#L484-L527 |
ChristianTremblay/BAC0 | BAC0/core/devices/Device.py | DeviceConnected.analog_units | def analog_units(self):
"""
Shortcut to retrieve all analog points units [Used by Bokeh trending feature]
"""
au = []
us = []
for each in self.points:
if isinstance(each, NumericPoint):
au.append(each.properties.name)
u... | python | def analog_units(self):
"""
Shortcut to retrieve all analog points units [Used by Bokeh trending feature]
"""
au = []
us = []
for each in self.points:
if isinstance(each, NumericPoint):
au.append(each.properties.name)
u... | [
"def",
"analog_units",
"(",
"self",
")",
":",
"au",
"=",
"[",
"]",
"us",
"=",
"[",
"]",
"for",
"each",
"in",
"self",
".",
"points",
":",
"if",
"isinstance",
"(",
"each",
",",
"NumericPoint",
")",
":",
"au",
".",
"append",
"(",
"each",
".",
"prope... | Shortcut to retrieve all analog points units [Used by Bokeh trending feature] | [
"Shortcut",
"to",
"retrieve",
"all",
"analog",
"points",
"units",
"[",
"Used",
"by",
"Bokeh",
"trending",
"feature",
"]"
] | train | https://github.com/ChristianTremblay/BAC0/blob/8d95b065ea068524a08f5b0c34322ebeeba95d06/BAC0/core/devices/Device.py#L584-L594 |
ChristianTremblay/BAC0 | BAC0/core/devices/Device.py | DeviceConnected._findPoint | def _findPoint(self, name, force_read=True):
"""
Used by getter and setter functions
"""
for point in self.points:
if point.properties.name == name:
if force_read:
point.value
return point
raise ValueError("... | python | def _findPoint(self, name, force_read=True):
"""
Used by getter and setter functions
"""
for point in self.points:
if point.properties.name == name:
if force_read:
point.value
return point
raise ValueError("... | [
"def",
"_findPoint",
"(",
"self",
",",
"name",
",",
"force_read",
"=",
"True",
")",
":",
"for",
"point",
"in",
"self",
".",
"points",
":",
"if",
"point",
".",
"properties",
".",
"name",
"==",
"name",
":",
"if",
"force_read",
":",
"point",
".",
"value... | Used by getter and setter functions | [
"Used",
"by",
"getter",
"and",
"setter",
"functions"
] | train | https://github.com/ChristianTremblay/BAC0/blob/8d95b065ea068524a08f5b0c34322ebeeba95d06/BAC0/core/devices/Device.py#L629-L638 |
ChristianTremblay/BAC0 | BAC0/core/devices/Device.py | DeviceDisconnected.connect | def connect(self, *, db=None):
"""
Attempt to connect to device. If unable, attempt to connect to a controller database
(so the user can use previously saved data).
"""
if not self.properties.network:
self.new_state(DeviceFromDB)
else:
t... | python | def connect(self, *, db=None):
"""
Attempt to connect to device. If unable, attempt to connect to a controller database
(so the user can use previously saved data).
"""
if not self.properties.network:
self.new_state(DeviceFromDB)
else:
t... | [
"def",
"connect",
"(",
"self",
",",
"*",
",",
"db",
"=",
"None",
")",
":",
"if",
"not",
"self",
".",
"properties",
".",
"network",
":",
"self",
".",
"new_state",
"(",
"DeviceFromDB",
")",
"else",
":",
"try",
":",
"name",
"=",
"self",
".",
"properti... | Attempt to connect to device. If unable, attempt to connect to a controller database
(so the user can use previously saved data). | [
"Attempt",
"to",
"connect",
"to",
"device",
".",
"If",
"unable",
"attempt",
"to",
"connect",
"to",
"a",
"controller",
"database",
"(",
"so",
"the",
"user",
"can",
"use",
"previously",
"saved",
"data",
")",
"."
] | train | https://github.com/ChristianTremblay/BAC0/blob/8d95b065ea068524a08f5b0c34322ebeeba95d06/BAC0/core/devices/Device.py#L677-L727 |
ChristianTremblay/BAC0 | BAC0/core/devices/Device.py | DeviceFromDB.connect | def connect(self, *, network=None, from_backup=None):
"""
In DBState, a device can be reconnected to BACnet using:
device.connect(network=bacnet) (bacnet = BAC0.connect())
"""
if network and from_backup:
raise WrongParameter("Please provide network OR from_b... | python | def connect(self, *, network=None, from_backup=None):
"""
In DBState, a device can be reconnected to BACnet using:
device.connect(network=bacnet) (bacnet = BAC0.connect())
"""
if network and from_backup:
raise WrongParameter("Please provide network OR from_b... | [
"def",
"connect",
"(",
"self",
",",
"*",
",",
"network",
"=",
"None",
",",
"from_backup",
"=",
"None",
")",
":",
"if",
"network",
"and",
"from_backup",
":",
"raise",
"WrongParameter",
"(",
"\"Please provide network OR from_backup\"",
")",
"elif",
"network",
":... | In DBState, a device can be reconnected to BACnet using:
device.connect(network=bacnet) (bacnet = BAC0.connect()) | [
"In",
"DBState",
"a",
"device",
"can",
"be",
"reconnected",
"to",
"BACnet",
"using",
":",
"device",
".",
"connect",
"(",
"network",
"=",
"bacnet",
")",
"(",
"bacnet",
"=",
"BAC0",
".",
"connect",
"()",
")"
] | train | https://github.com/ChristianTremblay/BAC0/blob/8d95b065ea068524a08f5b0c34322ebeeba95d06/BAC0/core/devices/Device.py#L819-L863 |
ChristianTremblay/BAC0 | BAC0/core/utils/notes.py | update_log_level | def update_log_level(level=None, *, file=None, stderr=None, stdout=None):
"""
Typical usage :
Normal
BAC0.log_level(file='warning', stdout='warning', stderr='error')
Info on console....but not in file
BAC0.log_level(file='warning', stdout='info', stderr='error')
Debug
... | python | def update_log_level(level=None, *, file=None, stderr=None, stdout=None):
"""
Typical usage :
Normal
BAC0.log_level(file='warning', stdout='warning', stderr='error')
Info on console....but not in file
BAC0.log_level(file='warning', stdout='info', stderr='error')
Debug
... | [
"def",
"update_log_level",
"(",
"level",
"=",
"None",
",",
"*",
",",
"file",
"=",
"None",
",",
"stderr",
"=",
"None",
",",
"stdout",
"=",
"None",
")",
":",
"if",
"level",
":",
"file",
"=",
"level",
"stderr",
"=",
"level",
"stdout",
"=",
"level",
"f... | Typical usage :
Normal
BAC0.log_level(file='warning', stdout='warning', stderr='error')
Info on console....but not in file
BAC0.log_level(file='warning', stdout='info', stderr='error')
Debug
BAC0.log_level(file='debug', stdout='info', stderr='error') | [
"Typical",
"usage",
":",
"Normal",
"BAC0",
".",
"log_level",
"(",
"file",
"=",
"warning",
"stdout",
"=",
"warning",
"stderr",
"=",
"error",
")",
"Info",
"on",
"console",
"....",
"but",
"not",
"in",
"file",
"BAC0",
".",
"log_level",
"(",
"file",
"=",
"w... | train | https://github.com/ChristianTremblay/BAC0/blob/8d95b065ea068524a08f5b0c34322ebeeba95d06/BAC0/core/utils/notes.py#L44-L85 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.