repo
stringlengths
7
55
path
stringlengths
4
127
func_name
stringlengths
1
88
original_string
stringlengths
75
19.8k
language
stringclasses
1 value
code
stringlengths
75
19.8k
code_tokens
list
docstring
stringlengths
3
17.3k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
87
242
partition
stringclasses
1 value
thunder-project/thunder
thunder/series/series.py
Series.tobinary
def tobinary(self, path, prefix='series', overwrite=False, credentials=None): """ Write data to binary files. Parameters ---------- path : string path or URI to directory to be created Output files will be written underneath path. Directory will be create...
python
def tobinary(self, path, prefix='series', overwrite=False, credentials=None): """ Write data to binary files. Parameters ---------- path : string path or URI to directory to be created Output files will be written underneath path. Directory will be create...
[ "def", "tobinary", "(", "self", ",", "path", ",", "prefix", "=", "'series'", ",", "overwrite", "=", "False", ",", "credentials", "=", "None", ")", ":", "from", "thunder", ".", "series", ".", "writers", "import", "tobinary", "tobinary", "(", "self", ",", ...
Write data to binary files. Parameters ---------- path : string path or URI to directory to be created Output files will be written underneath path. Directory will be created as a result of this call. prefix : str, optional, default = 'series' String...
[ "Write", "data", "to", "binary", "files", "." ]
967ff8f3e7c2fabe1705743d95eb2746d4329786
https://github.com/thunder-project/thunder/blob/967ff8f3e7c2fabe1705743d95eb2746d4329786/thunder/series/series.py#L1110-L1128
train
thunder-project/thunder
thunder/readers.py
addextension
def addextension(path, ext=None): """ Helper function for handling of paths given separately passed file extensions. """ if ext: if '*' in path: return path elif os.path.splitext(path)[1]: return path else: if not ext.startswith('.'): ...
python
def addextension(path, ext=None): """ Helper function for handling of paths given separately passed file extensions. """ if ext: if '*' in path: return path elif os.path.splitext(path)[1]: return path else: if not ext.startswith('.'): ...
[ "def", "addextension", "(", "path", ",", "ext", "=", "None", ")", ":", "if", "ext", ":", "if", "'*'", "in", "path", ":", "return", "path", "elif", "os", ".", "path", ".", "splitext", "(", "path", ")", "[", "1", "]", ":", "return", "path", "else",...
Helper function for handling of paths given separately passed file extensions.
[ "Helper", "function", "for", "handling", "of", "paths", "given", "separately", "passed", "file", "extensions", "." ]
967ff8f3e7c2fabe1705743d95eb2746d4329786
https://github.com/thunder-project/thunder/blob/967ff8f3e7c2fabe1705743d95eb2746d4329786/thunder/readers.py#L21-L40
train
thunder-project/thunder
thunder/readers.py
select
def select(files, start, stop): """ Helper function for handling start and stop indices """ if start or stop: if start is None: start = 0 if stop is None: stop = len(files) files = files[start:stop] return files
python
def select(files, start, stop): """ Helper function for handling start and stop indices """ if start or stop: if start is None: start = 0 if stop is None: stop = len(files) files = files[start:stop] return files
[ "def", "select", "(", "files", ",", "start", ",", "stop", ")", ":", "if", "start", "or", "stop", ":", "if", "start", "is", "None", ":", "start", "=", "0", "if", "stop", "is", "None", ":", "stop", "=", "len", "(", "files", ")", "files", "=", "fi...
Helper function for handling start and stop indices
[ "Helper", "function", "for", "handling", "start", "and", "stop", "indices" ]
967ff8f3e7c2fabe1705743d95eb2746d4329786
https://github.com/thunder-project/thunder/blob/967ff8f3e7c2fabe1705743d95eb2746d4329786/thunder/readers.py#L42-L52
train
thunder-project/thunder
thunder/readers.py
listrecursive
def listrecursive(path, ext=None): """ List files recurisvely """ filenames = set() for root, dirs, files in os.walk(path): if ext: if ext == 'tif' or ext == 'tiff': tmp = fnmatch.filter(files, '*.' + 'tiff') files = tmp + fnmatch.filter(files, '*....
python
def listrecursive(path, ext=None): """ List files recurisvely """ filenames = set() for root, dirs, files in os.walk(path): if ext: if ext == 'tif' or ext == 'tiff': tmp = fnmatch.filter(files, '*.' + 'tiff') files = tmp + fnmatch.filter(files, '*....
[ "def", "listrecursive", "(", "path", ",", "ext", "=", "None", ")", ":", "filenames", "=", "set", "(", ")", "for", "root", ",", "dirs", ",", "files", "in", "os", ".", "walk", "(", "path", ")", ":", "if", "ext", ":", "if", "ext", "==", "'tif'", "...
List files recurisvely
[ "List", "files", "recurisvely" ]
967ff8f3e7c2fabe1705743d95eb2746d4329786
https://github.com/thunder-project/thunder/blob/967ff8f3e7c2fabe1705743d95eb2746d4329786/thunder/readers.py#L72-L88
train
thunder-project/thunder
thunder/readers.py
listflat
def listflat(path, ext=None): """ List files without recursion """ if os.path.isdir(path): if ext: if ext == 'tif' or ext == 'tiff': files = glob.glob(os.path.join(path, '*.tif')) files = files + glob.glob(os.path.join(path, '*.tiff')) else...
python
def listflat(path, ext=None): """ List files without recursion """ if os.path.isdir(path): if ext: if ext == 'tif' or ext == 'tiff': files = glob.glob(os.path.join(path, '*.tif')) files = files + glob.glob(os.path.join(path, '*.tiff')) else...
[ "def", "listflat", "(", "path", ",", "ext", "=", "None", ")", ":", "if", "os", ".", "path", ".", "isdir", "(", "path", ")", ":", "if", "ext", ":", "if", "ext", "==", "'tif'", "or", "ext", "==", "'tiff'", ":", "files", "=", "glob", ".", "glob", ...
List files without recursion
[ "List", "files", "without", "recursion" ]
967ff8f3e7c2fabe1705743d95eb2746d4329786
https://github.com/thunder-project/thunder/blob/967ff8f3e7c2fabe1705743d95eb2746d4329786/thunder/readers.py#L90-L107
train
thunder-project/thunder
thunder/readers.py
normalize_scheme
def normalize_scheme(path, ext): """ Normalize scheme for paths related to hdfs """ path = addextension(path, ext) parsed = urlparse(path) if parsed.scheme: # this appears to already be a fully-qualified URI return path else: # this looks like a local path spec ...
python
def normalize_scheme(path, ext): """ Normalize scheme for paths related to hdfs """ path = addextension(path, ext) parsed = urlparse(path) if parsed.scheme: # this appears to already be a fully-qualified URI return path else: # this looks like a local path spec ...
[ "def", "normalize_scheme", "(", "path", ",", "ext", ")", ":", "path", "=", "addextension", "(", "path", ",", "ext", ")", "parsed", "=", "urlparse", "(", "path", ")", "if", "parsed", ".", "scheme", ":", "# this appears to already be a fully-qualified URI", "ret...
Normalize scheme for paths related to hdfs
[ "Normalize", "scheme", "for", "paths", "related", "to", "hdfs" ]
967ff8f3e7c2fabe1705743d95eb2746d4329786
https://github.com/thunder-project/thunder/blob/967ff8f3e7c2fabe1705743d95eb2746d4329786/thunder/readers.py#L620-L638
train
thunder-project/thunder
thunder/readers.py
LocalParallelReader.list
def list(path, ext=None, start=None, stop=None, recursive=False): """ Get sorted list of file paths matching path and extension """ files = listflat(path, ext) if not recursive else listrecursive(path, ext) if len(files) < 1: raise FileNotFoundError('Cannot find files...
python
def list(path, ext=None, start=None, stop=None, recursive=False): """ Get sorted list of file paths matching path and extension """ files = listflat(path, ext) if not recursive else listrecursive(path, ext) if len(files) < 1: raise FileNotFoundError('Cannot find files...
[ "def", "list", "(", "path", ",", "ext", "=", "None", ",", "start", "=", "None", ",", "stop", "=", "None", ",", "recursive", "=", "False", ")", ":", "files", "=", "listflat", "(", "path", ",", "ext", ")", "if", "not", "recursive", "else", "listrecur...
Get sorted list of file paths matching path and extension
[ "Get", "sorted", "list", "of", "file", "paths", "matching", "path", "and", "extension" ]
967ff8f3e7c2fabe1705743d95eb2746d4329786
https://github.com/thunder-project/thunder/blob/967ff8f3e7c2fabe1705743d95eb2746d4329786/thunder/readers.py#L133-L143
train
thunder-project/thunder
thunder/readers.py
LocalParallelReader.read
def read(self, path, ext=None, start=None, stop=None, recursive=False, npartitions=None): """ Sets up Spark RDD across files specified by dataPath on local filesystem. Returns RDD of <integer file index, string buffer> k/v pairs. """ path = uri_to_path(path) files = self...
python
def read(self, path, ext=None, start=None, stop=None, recursive=False, npartitions=None): """ Sets up Spark RDD across files specified by dataPath on local filesystem. Returns RDD of <integer file index, string buffer> k/v pairs. """ path = uri_to_path(path) files = self...
[ "def", "read", "(", "self", ",", "path", ",", "ext", "=", "None", ",", "start", "=", "None", ",", "stop", "=", "None", ",", "recursive", "=", "False", ",", "npartitions", "=", "None", ")", ":", "path", "=", "uri_to_path", "(", "path", ")", "files",...
Sets up Spark RDD across files specified by dataPath on local filesystem. Returns RDD of <integer file index, string buffer> k/v pairs.
[ "Sets", "up", "Spark", "RDD", "across", "files", "specified", "by", "dataPath", "on", "local", "filesystem", "." ]
967ff8f3e7c2fabe1705743d95eb2746d4329786
https://github.com/thunder-project/thunder/blob/967ff8f3e7c2fabe1705743d95eb2746d4329786/thunder/readers.py#L145-L162
train
thunder-project/thunder
thunder/readers.py
LocalFileReader.list
def list(path, filename=None, start=None, stop=None, recursive=False, directories=False): """ List files specified by dataPath. Datapath may include a single wildcard ('*') in the filename specifier. Returns sorted list of absolute path strings. """ path = uri_to_path(p...
python
def list(path, filename=None, start=None, stop=None, recursive=False, directories=False): """ List files specified by dataPath. Datapath may include a single wildcard ('*') in the filename specifier. Returns sorted list of absolute path strings. """ path = uri_to_path(p...
[ "def", "list", "(", "path", ",", "filename", "=", "None", ",", "start", "=", "None", ",", "stop", "=", "None", ",", "recursive", "=", "False", ",", "directories", "=", "False", ")", ":", "path", "=", "uri_to_path", "(", "path", ")", "if", "not", "f...
List files specified by dataPath. Datapath may include a single wildcard ('*') in the filename specifier. Returns sorted list of absolute path strings.
[ "List", "files", "specified", "by", "dataPath", "." ]
967ff8f3e7c2fabe1705743d95eb2746d4329786
https://github.com/thunder-project/thunder/blob/967ff8f3e7c2fabe1705743d95eb2746d4329786/thunder/readers.py#L173-L202
train
thunder-project/thunder
thunder/readers.py
BotoClient.parse_query
def parse_query(query, delim='/'): """ Parse a boto query """ key = '' prefix = '' postfix = '' parsed = urlparse(query) query = parsed.path.lstrip(delim) bucket = parsed.netloc if not parsed.scheme.lower() in ('', "gs", "s3", "s3n"): ...
python
def parse_query(query, delim='/'): """ Parse a boto query """ key = '' prefix = '' postfix = '' parsed = urlparse(query) query = parsed.path.lstrip(delim) bucket = parsed.netloc if not parsed.scheme.lower() in ('', "gs", "s3", "s3n"): ...
[ "def", "parse_query", "(", "query", ",", "delim", "=", "'/'", ")", ":", "key", "=", "''", "prefix", "=", "''", "postfix", "=", "''", "parsed", "=", "urlparse", "(", "query", ")", "query", "=", "parsed", ".", "path", ".", "lstrip", "(", "delim", ")"...
Parse a boto query
[ "Parse", "a", "boto", "query" ]
967ff8f3e7c2fabe1705743d95eb2746d4329786
https://github.com/thunder-project/thunder/blob/967ff8f3e7c2fabe1705743d95eb2746d4329786/thunder/readers.py#L233-L278
train
thunder-project/thunder
thunder/readers.py
BotoClient.retrieve_keys
def retrieve_keys(bucket, key, prefix='', postfix='', delim='/', directories=False, recursive=False): """ Retrieve keys from a bucket """ if key and prefix: assert key.endswith(delim) key += prefix # check whether key is a directory ...
python
def retrieve_keys(bucket, key, prefix='', postfix='', delim='/', directories=False, recursive=False): """ Retrieve keys from a bucket """ if key and prefix: assert key.endswith(delim) key += prefix # check whether key is a directory ...
[ "def", "retrieve_keys", "(", "bucket", ",", "key", ",", "prefix", "=", "''", ",", "postfix", "=", "''", ",", "delim", "=", "'/'", ",", "directories", "=", "False", ",", "recursive", "=", "False", ")", ":", "if", "key", "and", "prefix", ":", "assert",...
Retrieve keys from a bucket
[ "Retrieve", "keys", "from", "a", "bucket" ]
967ff8f3e7c2fabe1705743d95eb2746d4329786
https://github.com/thunder-project/thunder/blob/967ff8f3e7c2fabe1705743d95eb2746d4329786/thunder/readers.py#L291-L316
train
thunder-project/thunder
thunder/readers.py
BotoParallelReader.getfiles
def getfiles(self, path, ext=None, start=None, stop=None, recursive=False): """ Get scheme, bucket, and keys for a set of files """ from .utils import connection_with_anon, connection_with_gs parse = BotoClient.parse_query(path) scheme = parse[0] bucket_name = p...
python
def getfiles(self, path, ext=None, start=None, stop=None, recursive=False): """ Get scheme, bucket, and keys for a set of files """ from .utils import connection_with_anon, connection_with_gs parse = BotoClient.parse_query(path) scheme = parse[0] bucket_name = p...
[ "def", "getfiles", "(", "self", ",", "path", ",", "ext", "=", "None", ",", "start", "=", "None", ",", "stop", "=", "None", ",", "recursive", "=", "False", ")", ":", "from", ".", "utils", "import", "connection_with_anon", ",", "connection_with_gs", "parse...
Get scheme, bucket, and keys for a set of files
[ "Get", "scheme", "bucket", "and", "keys", "for", "a", "set", "of", "files" ]
967ff8f3e7c2fabe1705743d95eb2746d4329786
https://github.com/thunder-project/thunder/blob/967ff8f3e7c2fabe1705743d95eb2746d4329786/thunder/readers.py#L328-L361
train
thunder-project/thunder
thunder/readers.py
BotoParallelReader.list
def list(self, dataPath, ext=None, start=None, stop=None, recursive=False): """ List files from remote storage """ scheme, bucket_name, keylist = self.getfiles( dataPath, ext=ext, start=start, stop=stop, recursive=recursive) return ["%s:///%s/%s" % (scheme, bucket_na...
python
def list(self, dataPath, ext=None, start=None, stop=None, recursive=False): """ List files from remote storage """ scheme, bucket_name, keylist = self.getfiles( dataPath, ext=ext, start=start, stop=stop, recursive=recursive) return ["%s:///%s/%s" % (scheme, bucket_na...
[ "def", "list", "(", "self", ",", "dataPath", ",", "ext", "=", "None", ",", "start", "=", "None", ",", "stop", "=", "None", ",", "recursive", "=", "False", ")", ":", "scheme", ",", "bucket_name", ",", "keylist", "=", "self", ".", "getfiles", "(", "d...
List files from remote storage
[ "List", "files", "from", "remote", "storage" ]
967ff8f3e7c2fabe1705743d95eb2746d4329786
https://github.com/thunder-project/thunder/blob/967ff8f3e7c2fabe1705743d95eb2746d4329786/thunder/readers.py#L363-L370
train
thunder-project/thunder
thunder/readers.py
BotoParallelReader.read
def read(self, path, ext=None, start=None, stop=None, recursive=False, npartitions=None): """ Sets up Spark RDD across S3 or GS objects specified by dataPath. Returns RDD of <string bucket keyname, string buffer> k/v pairs. """ from .utils import connection_with_anon, connection...
python
def read(self, path, ext=None, start=None, stop=None, recursive=False, npartitions=None): """ Sets up Spark RDD across S3 or GS objects specified by dataPath. Returns RDD of <string bucket keyname, string buffer> k/v pairs. """ from .utils import connection_with_anon, connection...
[ "def", "read", "(", "self", ",", "path", ",", "ext", "=", "None", ",", "start", "=", "None", ",", "stop", "=", "None", ",", "recursive", "=", "False", ",", "npartitions", "=", "None", ")", ":", "from", ".", "utils", "import", "connection_with_anon", ...
Sets up Spark RDD across S3 or GS objects specified by dataPath. Returns RDD of <string bucket keyname, string buffer> k/v pairs.
[ "Sets", "up", "Spark", "RDD", "across", "S3", "or", "GS", "objects", "specified", "by", "dataPath", "." ]
967ff8f3e7c2fabe1705743d95eb2746d4329786
https://github.com/thunder-project/thunder/blob/967ff8f3e7c2fabe1705743d95eb2746d4329786/thunder/readers.py#L372-L430
train
thunder-project/thunder
thunder/readers.py
BotoFileReader.getkeys
def getkeys(self, path, filename=None, directories=False, recursive=False): """ Get matching keys for a path """ from .utils import connection_with_anon, connection_with_gs parse = BotoClient.parse_query(path) scheme = parse[0] bucket_name = parse[1] key...
python
def getkeys(self, path, filename=None, directories=False, recursive=False): """ Get matching keys for a path """ from .utils import connection_with_anon, connection_with_gs parse = BotoClient.parse_query(path) scheme = parse[0] bucket_name = parse[1] key...
[ "def", "getkeys", "(", "self", ",", "path", ",", "filename", "=", "None", ",", "directories", "=", "False", ",", "recursive", "=", "False", ")", ":", "from", ".", "utils", "import", "connection_with_anon", ",", "connection_with_gs", "parse", "=", "BotoClient...
Get matching keys for a path
[ "Get", "matching", "keys", "for", "a", "path" ]
967ff8f3e7c2fabe1705743d95eb2746d4329786
https://github.com/thunder-project/thunder/blob/967ff8f3e7c2fabe1705743d95eb2746d4329786/thunder/readers.py#L437-L472
train
thunder-project/thunder
thunder/readers.py
BotoFileReader.getkey
def getkey(self, path, filename=None): """ Get single matching key for a path """ scheme, keys = self.getkeys(path, filename=filename) try: key = next(keys) except StopIteration: raise FileNotFoundError("Could not find object for: '%s'" % path) ...
python
def getkey(self, path, filename=None): """ Get single matching key for a path """ scheme, keys = self.getkeys(path, filename=filename) try: key = next(keys) except StopIteration: raise FileNotFoundError("Could not find object for: '%s'" % path) ...
[ "def", "getkey", "(", "self", ",", "path", ",", "filename", "=", "None", ")", ":", "scheme", ",", "keys", "=", "self", ".", "getkeys", "(", "path", ",", "filename", "=", "filename", ")", "try", ":", "key", "=", "next", "(", "keys", ")", "except", ...
Get single matching key for a path
[ "Get", "single", "matching", "key", "for", "a", "path" ]
967ff8f3e7c2fabe1705743d95eb2746d4329786
https://github.com/thunder-project/thunder/blob/967ff8f3e7c2fabe1705743d95eb2746d4329786/thunder/readers.py#L474-L492
train
thunder-project/thunder
thunder/readers.py
BotoFileReader.list
def list(self, path, filename=None, start=None, stop=None, recursive=False, directories=False): """ List objects specified by path. Returns sorted list of 'gs://' or 's3n://' URIs. """ storageScheme, keys = self.getkeys( path, filename=filename, directories=directori...
python
def list(self, path, filename=None, start=None, stop=None, recursive=False, directories=False): """ List objects specified by path. Returns sorted list of 'gs://' or 's3n://' URIs. """ storageScheme, keys = self.getkeys( path, filename=filename, directories=directori...
[ "def", "list", "(", "self", ",", "path", ",", "filename", "=", "None", ",", "start", "=", "None", ",", "stop", "=", "None", ",", "recursive", "=", "False", ",", "directories", "=", "False", ")", ":", "storageScheme", ",", "keys", "=", "self", ".", ...
List objects specified by path. Returns sorted list of 'gs://' or 's3n://' URIs.
[ "List", "objects", "specified", "by", "path", "." ]
967ff8f3e7c2fabe1705743d95eb2746d4329786
https://github.com/thunder-project/thunder/blob/967ff8f3e7c2fabe1705743d95eb2746d4329786/thunder/readers.py#L494-L505
train
thunder-project/thunder
thunder/readers.py
BotoFileReader.read
def read(self, path, filename=None, offset=None, size=-1): """ Read a file specified by path. """ storageScheme, key = self.getkey(path, filename=filename) if offset or (size > -1): if not offset: offset = 0 if size > -1: s...
python
def read(self, path, filename=None, offset=None, size=-1): """ Read a file specified by path. """ storageScheme, key = self.getkey(path, filename=filename) if offset or (size > -1): if not offset: offset = 0 if size > -1: s...
[ "def", "read", "(", "self", ",", "path", ",", "filename", "=", "None", ",", "offset", "=", "None", ",", "size", "=", "-", "1", ")", ":", "storageScheme", ",", "key", "=", "self", ".", "getkey", "(", "path", ",", "filename", "=", "filename", ")", ...
Read a file specified by path.
[ "Read", "a", "file", "specified", "by", "path", "." ]
967ff8f3e7c2fabe1705743d95eb2746d4329786
https://github.com/thunder-project/thunder/blob/967ff8f3e7c2fabe1705743d95eb2746d4329786/thunder/readers.py#L507-L523
train
thunder-project/thunder
thunder/readers.py
BotoFileReader.open
def open(self, path, filename=None): """ Open a file specified by path. """ scheme, key = self.getkey(path, filename=filename) return BotoReadFileHandle(scheme, key)
python
def open(self, path, filename=None): """ Open a file specified by path. """ scheme, key = self.getkey(path, filename=filename) return BotoReadFileHandle(scheme, key)
[ "def", "open", "(", "self", ",", "path", ",", "filename", "=", "None", ")", ":", "scheme", ",", "key", "=", "self", ".", "getkey", "(", "path", ",", "filename", "=", "filename", ")", "return", "BotoReadFileHandle", "(", "scheme", ",", "key", ")" ]
Open a file specified by path.
[ "Open", "a", "file", "specified", "by", "path", "." ]
967ff8f3e7c2fabe1705743d95eb2746d4329786
https://github.com/thunder-project/thunder/blob/967ff8f3e7c2fabe1705743d95eb2746d4329786/thunder/readers.py#L525-L530
train
thunder-project/thunder
thunder/utils.py
check_path
def check_path(path, credentials=None): """ Check that specified output path does not already exist The ValueError message will suggest calling with overwrite=True; this function is expected to be called from the various output methods that accept an 'overwrite' keyword argument. """ from t...
python
def check_path(path, credentials=None): """ Check that specified output path does not already exist The ValueError message will suggest calling with overwrite=True; this function is expected to be called from the various output methods that accept an 'overwrite' keyword argument. """ from t...
[ "def", "check_path", "(", "path", ",", "credentials", "=", "None", ")", ":", "from", "thunder", ".", "readers", "import", "get_file_reader", "reader", "=", "get_file_reader", "(", "path", ")", "(", "credentials", "=", "credentials", ")", "existing", "=", "re...
Check that specified output path does not already exist The ValueError message will suggest calling with overwrite=True; this function is expected to be called from the various output methods that accept an 'overwrite' keyword argument.
[ "Check", "that", "specified", "output", "path", "does", "not", "already", "exist" ]
967ff8f3e7c2fabe1705743d95eb2746d4329786
https://github.com/thunder-project/thunder/blob/967ff8f3e7c2fabe1705743d95eb2746d4329786/thunder/utils.py#L18-L31
train
thunder-project/thunder
thunder/utils.py
connection_with_anon
def connection_with_anon(credentials, anon=True): """ Connect to S3 with automatic handling for anonymous access. Parameters ---------- credentials : dict AWS access key ('access') and secret access key ('secret') anon : boolean, optional, default = True Whether to make an anon...
python
def connection_with_anon(credentials, anon=True): """ Connect to S3 with automatic handling for anonymous access. Parameters ---------- credentials : dict AWS access key ('access') and secret access key ('secret') anon : boolean, optional, default = True Whether to make an anon...
[ "def", "connection_with_anon", "(", "credentials", ",", "anon", "=", "True", ")", ":", "from", "boto", ".", "s3", ".", "connection", "import", "S3Connection", "from", "boto", ".", "exception", "import", "NoAuthHandlerFound", "try", ":", "conn", "=", "S3Connect...
Connect to S3 with automatic handling for anonymous access. Parameters ---------- credentials : dict AWS access key ('access') and secret access key ('secret') anon : boolean, optional, default = True Whether to make an anonymous connection if credentials fail to authenticate
[ "Connect", "to", "S3", "with", "automatic", "handling", "for", "anonymous", "access", "." ]
967ff8f3e7c2fabe1705743d95eb2746d4329786
https://github.com/thunder-project/thunder/blob/967ff8f3e7c2fabe1705743d95eb2746d4329786/thunder/utils.py#L33-L58
train
thunder-project/thunder
thunder/writers.py
BotoWriter.activate
def activate(self, path, isdirectory): """ Set up a boto connection. """ from .utils import connection_with_anon, connection_with_gs parsed = BotoClient.parse_query(path) scheme = parsed[0] bucket_name = parsed[1] key = parsed[2] if scheme == 's...
python
def activate(self, path, isdirectory): """ Set up a boto connection. """ from .utils import connection_with_anon, connection_with_gs parsed = BotoClient.parse_query(path) scheme = parsed[0] bucket_name = parsed[1] key = parsed[2] if scheme == 's...
[ "def", "activate", "(", "self", ",", "path", ",", "isdirectory", ")", ":", "from", ".", "utils", "import", "connection_with_anon", ",", "connection_with_gs", "parsed", "=", "BotoClient", ".", "parse_query", "(", "path", ")", "scheme", "=", "parsed", "[", "0"...
Set up a boto connection.
[ "Set", "up", "a", "boto", "connection", "." ]
967ff8f3e7c2fabe1705743d95eb2746d4329786
https://github.com/thunder-project/thunder/blob/967ff8f3e7c2fabe1705743d95eb2746d4329786/thunder/writers.py#L50-L78
train
thunder-project/thunder
thunder/images/writers.py
topng
def topng(images, path, prefix="image", overwrite=False, credentials=None): """ Write out PNG files for 2d image data. See also -------- thunder.data.images.topng """ value_shape = images.value_shape if not len(value_shape) in [2, 3]: raise ValueError("Only 2D or 3D images can b...
python
def topng(images, path, prefix="image", overwrite=False, credentials=None): """ Write out PNG files for 2d image data. See also -------- thunder.data.images.topng """ value_shape = images.value_shape if not len(value_shape) in [2, 3]: raise ValueError("Only 2D or 3D images can b...
[ "def", "topng", "(", "images", ",", "path", ",", "prefix", "=", "\"image\"", ",", "overwrite", "=", "False", ",", "credentials", "=", "None", ")", ":", "value_shape", "=", "images", ".", "value_shape", "if", "not", "len", "(", "value_shape", ")", "in", ...
Write out PNG files for 2d image data. See also -------- thunder.data.images.topng
[ "Write", "out", "PNG", "files", "for", "2d", "image", "data", "." ]
967ff8f3e7c2fabe1705743d95eb2746d4329786
https://github.com/thunder-project/thunder/blob/967ff8f3e7c2fabe1705743d95eb2746d4329786/thunder/images/writers.py#L4-L29
train
thunder-project/thunder
thunder/images/writers.py
tobinary
def tobinary(images, path, prefix="image", overwrite=False, credentials=None): """ Write out images as binary files. See also -------- thunder.data.images.tobinary """ from thunder.writers import get_parallel_writer def tobuffer(kv): key, img = kv fname = prefix + "-" +...
python
def tobinary(images, path, prefix="image", overwrite=False, credentials=None): """ Write out images as binary files. See also -------- thunder.data.images.tobinary """ from thunder.writers import get_parallel_writer def tobuffer(kv): key, img = kv fname = prefix + "-" +...
[ "def", "tobinary", "(", "images", ",", "path", ",", "prefix", "=", "\"image\"", ",", "overwrite", "=", "False", ",", "credentials", "=", "None", ")", ":", "from", "thunder", ".", "writers", "import", "get_parallel_writer", "def", "tobuffer", "(", "kv", ")"...
Write out images as binary files. See also -------- thunder.data.images.tobinary
[ "Write", "out", "images", "as", "binary", "files", "." ]
967ff8f3e7c2fabe1705743d95eb2746d4329786
https://github.com/thunder-project/thunder/blob/967ff8f3e7c2fabe1705743d95eb2746d4329786/thunder/images/writers.py#L58-L75
train
lidaobing/python-lunardate
lunardate.py
yearInfo2yearDay
def yearInfo2yearDay(yearInfo): '''calculate the days in a lunar year from the lunar year's info >>> yearInfo2yearDay(0) # no leap month, and every month has 29 days. 348 >>> yearInfo2yearDay(1) # 1 leap month, and every month has 29 days. 377 >>> yearInfo2yearDay((2**12-1)*16) # no leap month,...
python
def yearInfo2yearDay(yearInfo): '''calculate the days in a lunar year from the lunar year's info >>> yearInfo2yearDay(0) # no leap month, and every month has 29 days. 348 >>> yearInfo2yearDay(1) # 1 leap month, and every month has 29 days. 377 >>> yearInfo2yearDay((2**12-1)*16) # no leap month,...
[ "def", "yearInfo2yearDay", "(", "yearInfo", ")", ":", "yearInfo", "=", "int", "(", "yearInfo", ")", "res", "=", "29", "*", "12", "leap", "=", "False", "if", "yearInfo", "%", "16", "!=", "0", ":", "leap", "=", "True", "res", "+=", "29", "yearInfo", ...
calculate the days in a lunar year from the lunar year's info >>> yearInfo2yearDay(0) # no leap month, and every month has 29 days. 348 >>> yearInfo2yearDay(1) # 1 leap month, and every month has 29 days. 377 >>> yearInfo2yearDay((2**12-1)*16) # no leap month, and every month has 30 days. 360 ...
[ "calculate", "the", "days", "in", "a", "lunar", "year", "from", "the", "lunar", "year", "s", "info" ]
261334a27d772489c9fc70b8ecef129ba3c13118
https://github.com/lidaobing/python-lunardate/blob/261334a27d772489c9fc70b8ecef129ba3c13118/lunardate.py#L367-L397
train
plone/plone.app.mosaic
src/plone/app/mosaic/browser/upload.py
MosaicUploadView.cleanupFilename
def cleanupFilename(self, name): """Generate a unique id which doesn't match the system generated ids""" context = self.context id = '' name = name.replace('\\', '/') # Fixup Windows filenames name = name.split('/')[-1] # Throw away any path part. for c in name: ...
python
def cleanupFilename(self, name): """Generate a unique id which doesn't match the system generated ids""" context = self.context id = '' name = name.replace('\\', '/') # Fixup Windows filenames name = name.split('/')[-1] # Throw away any path part. for c in name: ...
[ "def", "cleanupFilename", "(", "self", ",", "name", ")", ":", "context", "=", "self", ".", "context", "id", "=", "''", "name", "=", "name", ".", "replace", "(", "'\\\\'", ",", "'/'", ")", "# Fixup Windows filenames", "name", "=", "name", ".", "split", ...
Generate a unique id which doesn't match the system generated ids
[ "Generate", "a", "unique", "id", "which", "doesn", "t", "match", "the", "system", "generated", "ids" ]
73b6acb18905025a76b239c86de9543ed9350991
https://github.com/plone/plone.app.mosaic/blob/73b6acb18905025a76b239c86de9543ed9350991/src/plone/app/mosaic/browser/upload.py#L80-L106
train
plone/plone.app.mosaic
src/plone/app/mosaic/browser/main_template.py
parse_data_slots
def parse_data_slots(value): """Parse data-slots value into slots used to wrap node, prepend to node or append to node. >>> parse_data_slots('') ([], [], []) >>> parse_data_slots('foo bar') (['foo', 'bar'], [], []) >>> parse_data_slots('foo bar > foobar') (['foo', 'b...
python
def parse_data_slots(value): """Parse data-slots value into slots used to wrap node, prepend to node or append to node. >>> parse_data_slots('') ([], [], []) >>> parse_data_slots('foo bar') (['foo', 'bar'], [], []) >>> parse_data_slots('foo bar > foobar') (['foo', 'b...
[ "def", "parse_data_slots", "(", "value", ")", ":", "value", "=", "unquote", "(", "value", ")", "if", "'>'", "in", "value", ":", "wrappers", ",", "children", "=", "value", ".", "split", "(", "'>'", ",", "1", ")", "else", ":", "wrappers", "=", "value",...
Parse data-slots value into slots used to wrap node, prepend to node or append to node. >>> parse_data_slots('') ([], [], []) >>> parse_data_slots('foo bar') (['foo', 'bar'], [], []) >>> parse_data_slots('foo bar > foobar') (['foo', 'bar'], ['foobar'], []) >>> pa...
[ "Parse", "data", "-", "slots", "value", "into", "slots", "used", "to", "wrap", "node", "prepend", "to", "node", "or", "append", "to", "node", "." ]
73b6acb18905025a76b239c86de9543ed9350991
https://github.com/plone/plone.app.mosaic/blob/73b6acb18905025a76b239c86de9543ed9350991/src/plone/app/mosaic/browser/main_template.py#L65-L107
train
plone/plone.app.mosaic
src/plone/app/mosaic/browser/main_template.py
cook_layout
def cook_layout(layout, ajax): """Return main_template compatible layout""" # Fix XHTML layouts with CR[+LF] line endings layout = re.sub('\r', '\n', re.sub('\r\n', '\n', layout)) # Parse layout if isinstance(layout, six.text_type): result = getHTMLSerializer([layout.encode('utf-8')], encod...
python
def cook_layout(layout, ajax): """Return main_template compatible layout""" # Fix XHTML layouts with CR[+LF] line endings layout = re.sub('\r', '\n', re.sub('\r\n', '\n', layout)) # Parse layout if isinstance(layout, six.text_type): result = getHTMLSerializer([layout.encode('utf-8')], encod...
[ "def", "cook_layout", "(", "layout", ",", "ajax", ")", ":", "# Fix XHTML layouts with CR[+LF] line endings", "layout", "=", "re", ".", "sub", "(", "'\\r'", ",", "'\\n'", ",", "re", ".", "sub", "(", "'\\r\\n'", ",", "'\\n'", ",", "layout", ")", ")", "# Pars...
Return main_template compatible layout
[ "Return", "main_template", "compatible", "layout" ]
73b6acb18905025a76b239c86de9543ed9350991
https://github.com/plone/plone.app.mosaic/blob/73b6acb18905025a76b239c86de9543ed9350991/src/plone/app/mosaic/browser/main_template.py#L138-L179
train
plone/plone.app.mosaic
src/plone/app/mosaic/browser/editor.py
ManageLayoutView.existing
def existing(self): """ find existing content assigned to this layout""" catalog = api.portal.get_tool('portal_catalog') results = [] layout_path = self._get_layout_path( self.request.form.get('layout', '') ) for brain in catalog(layout=layout_path): ...
python
def existing(self): """ find existing content assigned to this layout""" catalog = api.portal.get_tool('portal_catalog') results = [] layout_path = self._get_layout_path( self.request.form.get('layout', '') ) for brain in catalog(layout=layout_path): ...
[ "def", "existing", "(", "self", ")", ":", "catalog", "=", "api", ".", "portal", ".", "get_tool", "(", "'portal_catalog'", ")", "results", "=", "[", "]", "layout_path", "=", "self", ".", "_get_layout_path", "(", "self", ".", "request", ".", "form", ".", ...
find existing content assigned to this layout
[ "find", "existing", "content", "assigned", "to", "this", "layout" ]
73b6acb18905025a76b239c86de9543ed9350991
https://github.com/plone/plone.app.mosaic/blob/73b6acb18905025a76b239c86de9543ed9350991/src/plone/app/mosaic/browser/editor.py#L127-L142
train
sergiocorreia/panflute
panflute/io.py
load_reader_options
def load_reader_options(): """ Retrieve Pandoc Reader options from the environment """ options = os.environ['PANDOC_READER_OPTIONS'] options = json.loads(options, object_pairs_hook=OrderedDict) return options
python
def load_reader_options(): """ Retrieve Pandoc Reader options from the environment """ options = os.environ['PANDOC_READER_OPTIONS'] options = json.loads(options, object_pairs_hook=OrderedDict) return options
[ "def", "load_reader_options", "(", ")", ":", "options", "=", "os", ".", "environ", "[", "'PANDOC_READER_OPTIONS'", "]", "options", "=", "json", ".", "loads", "(", "options", ",", "object_pairs_hook", "=", "OrderedDict", ")", "return", "options" ]
Retrieve Pandoc Reader options from the environment
[ "Retrieve", "Pandoc", "Reader", "options", "from", "the", "environment" ]
65c2d570c26a190deb600cab5e2ad8a828a3302e
https://github.com/sergiocorreia/panflute/blob/65c2d570c26a190deb600cab5e2ad8a828a3302e/panflute/io.py#L263-L269
train
sergiocorreia/panflute
panflute/tools.py
yaml_filter
def yaml_filter(element, doc, tag=None, function=None, tags=None, strict_yaml=False): ''' Convenience function for parsing code blocks with YAML options This function is useful to create a filter that applies to code blocks that have specific classes. It is used as an argument of `...
python
def yaml_filter(element, doc, tag=None, function=None, tags=None, strict_yaml=False): ''' Convenience function for parsing code blocks with YAML options This function is useful to create a filter that applies to code blocks that have specific classes. It is used as an argument of `...
[ "def", "yaml_filter", "(", "element", ",", "doc", ",", "tag", "=", "None", ",", "function", "=", "None", ",", "tags", "=", "None", ",", "strict_yaml", "=", "False", ")", ":", "# Allow for either tag+function or a dict {tag: function}", "assert", "(", "tag", "i...
Convenience function for parsing code blocks with YAML options This function is useful to create a filter that applies to code blocks that have specific classes. It is used as an argument of ``run_filter``, with two additional options: ``tag`` and ``function``. Using this is equivalent to having ...
[ "Convenience", "function", "for", "parsing", "code", "blocks", "with", "YAML", "options" ]
65c2d570c26a190deb600cab5e2ad8a828a3302e
https://github.com/sergiocorreia/panflute/blob/65c2d570c26a190deb600cab5e2ad8a828a3302e/panflute/tools.py#L44-L158
train
sergiocorreia/panflute
panflute/base.py
Element._set_content
def _set_content(self, value, oktypes): """ Similar to content.setter but when there are no existing oktypes """ if value is None: value = [] self._content = ListContainer(*value, oktypes=oktypes, parent=self)
python
def _set_content(self, value, oktypes): """ Similar to content.setter but when there are no existing oktypes """ if value is None: value = [] self._content = ListContainer(*value, oktypes=oktypes, parent=self)
[ "def", "_set_content", "(", "self", ",", "value", ",", "oktypes", ")", ":", "if", "value", "is", "None", ":", "value", "=", "[", "]", "self", ".", "_content", "=", "ListContainer", "(", "*", "value", ",", "oktypes", "=", "oktypes", ",", "parent", "="...
Similar to content.setter but when there are no existing oktypes
[ "Similar", "to", "content", ".", "setter", "but", "when", "there", "are", "no", "existing", "oktypes" ]
65c2d570c26a190deb600cab5e2ad8a828a3302e
https://github.com/sergiocorreia/panflute/blob/65c2d570c26a190deb600cab5e2ad8a828a3302e/panflute/base.py#L123-L129
train
sergiocorreia/panflute
panflute/base.py
Element.offset
def offset(self, n): """ Return a sibling element offset by n :rtype: :class:`Element` | ``None`` """ idx = self.index if idx is not None: sibling = idx + n container = self.container if 0 <= sibling < len(container): ...
python
def offset(self, n): """ Return a sibling element offset by n :rtype: :class:`Element` | ``None`` """ idx = self.index if idx is not None: sibling = idx + n container = self.container if 0 <= sibling < len(container): ...
[ "def", "offset", "(", "self", ",", "n", ")", ":", "idx", "=", "self", ".", "index", "if", "idx", "is", "not", "None", ":", "sibling", "=", "idx", "+", "n", "container", "=", "self", ".", "container", "if", "0", "<=", "sibling", "<", "len", "(", ...
Return a sibling element offset by n :rtype: :class:`Element` | ``None``
[ "Return", "a", "sibling", "element", "offset", "by", "n" ]
65c2d570c26a190deb600cab5e2ad8a828a3302e
https://github.com/sergiocorreia/panflute/blob/65c2d570c26a190deb600cab5e2ad8a828a3302e/panflute/base.py#L166-L178
train
laike9m/pdir2
pdir/api.py
PrettyDir.search
def search(self, term: str, case_sensitive: bool = False) -> 'PrettyDir': """Searches for names that match some pattern. Args: term: String used to match names. A name is returned if it matches the whole search term. case_sensitive: Boolean to match case or not, de...
python
def search(self, term: str, case_sensitive: bool = False) -> 'PrettyDir': """Searches for names that match some pattern. Args: term: String used to match names. A name is returned if it matches the whole search term. case_sensitive: Boolean to match case or not, de...
[ "def", "search", "(", "self", ",", "term", ":", "str", ",", "case_sensitive", ":", "bool", "=", "False", ")", "->", "'PrettyDir'", ":", "if", "case_sensitive", ":", "return", "PrettyDir", "(", "self", ".", "obj", ",", "[", "pattr", "for", "pattr", "in"...
Searches for names that match some pattern. Args: term: String used to match names. A name is returned if it matches the whole search term. case_sensitive: Boolean to match case or not, default is False (case insensitive). Return: A Prett...
[ "Searches", "for", "names", "that", "match", "some", "pattern", "." ]
c4550523fe9b54bf9b755ffa28900a5e9f493d02
https://github.com/laike9m/pdir2/blob/c4550523fe9b54bf9b755ffa28900a5e9f493d02/pdir/api.py#L74-L94
train
laike9m/pdir2
pdir/api.py
PrettyDir.properties
def properties(self) -> 'PrettyDir': """Returns all properties of the inspected object. Note that "properties" can mean "variables". """ return PrettyDir( self.obj, [ pattr for pattr in self.pattrs if category_match...
python
def properties(self) -> 'PrettyDir': """Returns all properties of the inspected object. Note that "properties" can mean "variables". """ return PrettyDir( self.obj, [ pattr for pattr in self.pattrs if category_match...
[ "def", "properties", "(", "self", ")", "->", "'PrettyDir'", ":", "return", "PrettyDir", "(", "self", ".", "obj", ",", "[", "pattr", "for", "pattr", "in", "self", ".", "pattrs", "if", "category_match", "(", "pattr", ".", "category", ",", "AttrCategory", "...
Returns all properties of the inspected object. Note that "properties" can mean "variables".
[ "Returns", "all", "properties", "of", "the", "inspected", "object", "." ]
c4550523fe9b54bf9b755ffa28900a5e9f493d02
https://github.com/laike9m/pdir2/blob/c4550523fe9b54bf9b755ffa28900a5e9f493d02/pdir/api.py#L104-L116
train
laike9m/pdir2
pdir/api.py
PrettyDir.methods
def methods(self) -> 'PrettyDir': """Returns all methods of the inspected object. Note that "methods" can mean "functions" when inspecting a module. """ return PrettyDir( self.obj, [ pattr for pattr in self.pattrs i...
python
def methods(self) -> 'PrettyDir': """Returns all methods of the inspected object. Note that "methods" can mean "functions" when inspecting a module. """ return PrettyDir( self.obj, [ pattr for pattr in self.pattrs i...
[ "def", "methods", "(", "self", ")", "->", "'PrettyDir'", ":", "return", "PrettyDir", "(", "self", ".", "obj", ",", "[", "pattr", "for", "pattr", "in", "self", ".", "pattrs", "if", "category_match", "(", "pattr", ".", "category", ",", "AttrCategory", ".",...
Returns all methods of the inspected object. Note that "methods" can mean "functions" when inspecting a module.
[ "Returns", "all", "methods", "of", "the", "inspected", "object", "." ]
c4550523fe9b54bf9b755ffa28900a5e9f493d02
https://github.com/laike9m/pdir2/blob/c4550523fe9b54bf9b755ffa28900a5e9f493d02/pdir/api.py#L119-L131
train
laike9m/pdir2
pdir/api.py
PrettyDir.public
def public(self) -> 'PrettyDir': """Returns public attributes of the inspected object.""" return PrettyDir( self.obj, [pattr for pattr in self.pattrs if not pattr.name.startswith('_')] )
python
def public(self) -> 'PrettyDir': """Returns public attributes of the inspected object.""" return PrettyDir( self.obj, [pattr for pattr in self.pattrs if not pattr.name.startswith('_')] )
[ "def", "public", "(", "self", ")", "->", "'PrettyDir'", ":", "return", "PrettyDir", "(", "self", ".", "obj", ",", "[", "pattr", "for", "pattr", "in", "self", ".", "pattrs", "if", "not", "pattr", ".", "name", ".", "startswith", "(", "'_'", ")", "]", ...
Returns public attributes of the inspected object.
[ "Returns", "public", "attributes", "of", "the", "inspected", "object", "." ]
c4550523fe9b54bf9b755ffa28900a5e9f493d02
https://github.com/laike9m/pdir2/blob/c4550523fe9b54bf9b755ffa28900a5e9f493d02/pdir/api.py#L134-L138
train
laike9m/pdir2
pdir/api.py
PrettyDir.own
def own(self) -> 'PrettyDir': """Returns attributes that are not inhterited from parent classes. Now we only use a simple judgement, it is expected that many attributes not get returned, especially invoked on a module. For instance, there's no way to distinguish between properties that...
python
def own(self) -> 'PrettyDir': """Returns attributes that are not inhterited from parent classes. Now we only use a simple judgement, it is expected that many attributes not get returned, especially invoked on a module. For instance, there's no way to distinguish between properties that...
[ "def", "own", "(", "self", ")", "->", "'PrettyDir'", ":", "return", "PrettyDir", "(", "self", ".", "obj", ",", "[", "pattr", "for", "pattr", "in", "self", ".", "pattrs", "if", "pattr", ".", "name", "in", "type", "(", "self", ".", "obj", ")", ".", ...
Returns attributes that are not inhterited from parent classes. Now we only use a simple judgement, it is expected that many attributes not get returned, especially invoked on a module. For instance, there's no way to distinguish between properties that are initialized in instance clas...
[ "Returns", "attributes", "that", "are", "not", "inhterited", "from", "parent", "classes", "." ]
c4550523fe9b54bf9b755ffa28900a5e9f493d02
https://github.com/laike9m/pdir2/blob/c4550523fe9b54bf9b755ffa28900a5e9f493d02/pdir/api.py#L141-L159
train
laike9m/pdir2
pdir/api.py
PrettyAttribute.get_oneline_doc
def get_oneline_doc(self) -> str: """ Doc doesn't necessarily mean doctring. It could be anything that should be put after the attr's name as an explanation. """ attr = self.attr_obj if self.display_group == AttrCategory.DESCRIPTOR: if isinstance(attr, propert...
python
def get_oneline_doc(self) -> str: """ Doc doesn't necessarily mean doctring. It could be anything that should be put after the attr's name as an explanation. """ attr = self.attr_obj if self.display_group == AttrCategory.DESCRIPTOR: if isinstance(attr, propert...
[ "def", "get_oneline_doc", "(", "self", ")", "->", "str", ":", "attr", "=", "self", ".", "attr_obj", "if", "self", ".", "display_group", "==", "AttrCategory", ".", "DESCRIPTOR", ":", "if", "isinstance", "(", "attr", ",", "property", ")", ":", "doc_list", ...
Doc doesn't necessarily mean doctring. It could be anything that should be put after the attr's name as an explanation.
[ "Doc", "doesn", "t", "necessarily", "mean", "doctring", ".", "It", "could", "be", "anything", "that", "should", "be", "put", "after", "the", "attr", "s", "name", "as", "an", "explanation", "." ]
c4550523fe9b54bf9b755ffa28900a5e9f493d02
https://github.com/laike9m/pdir2/blob/c4550523fe9b54bf9b755ffa28900a5e9f493d02/pdir/api.py#L183-L212
train
laike9m/pdir2
pdir/format.py
format_pattrs
def format_pattrs(pattrs: List['api.PrettyAttribute']) -> str: """Generates repr string given a list of pattrs.""" output = [] pattrs.sort( key=lambda x: ( _FORMATTER[x.display_group].display_index, x.display_group, x.name, ) ) for display_group, g...
python
def format_pattrs(pattrs: List['api.PrettyAttribute']) -> str: """Generates repr string given a list of pattrs.""" output = [] pattrs.sort( key=lambda x: ( _FORMATTER[x.display_group].display_index, x.display_group, x.name, ) ) for display_group, g...
[ "def", "format_pattrs", "(", "pattrs", ":", "List", "[", "'api.PrettyAttribute'", "]", ")", "->", "str", ":", "output", "=", "[", "]", "pattrs", ".", "sort", "(", "key", "=", "lambda", "x", ":", "(", "_FORMATTER", "[", "x", ".", "display_group", "]", ...
Generates repr string given a list of pattrs.
[ "Generates", "repr", "string", "given", "a", "list", "of", "pattrs", "." ]
c4550523fe9b54bf9b755ffa28900a5e9f493d02
https://github.com/laike9m/pdir2/blob/c4550523fe9b54bf9b755ffa28900a5e9f493d02/pdir/format.py#L14-L29
train
laike9m/pdir2
pdir/_internal_utils.py
get_attr_from_dict
def get_attr_from_dict(inspected_obj: Any, attr_name: str) -> Any: """Ensures we get descriptor object instead of its return value. """ if inspect.isclass(inspected_obj): obj_list = [inspected_obj] + list(inspected_obj.__mro__) else: obj_list = [inspected_obj] + list(inspected_obj.__clas...
python
def get_attr_from_dict(inspected_obj: Any, attr_name: str) -> Any: """Ensures we get descriptor object instead of its return value. """ if inspect.isclass(inspected_obj): obj_list = [inspected_obj] + list(inspected_obj.__mro__) else: obj_list = [inspected_obj] + list(inspected_obj.__clas...
[ "def", "get_attr_from_dict", "(", "inspected_obj", ":", "Any", ",", "attr_name", ":", "str", ")", "->", "Any", ":", "if", "inspect", ".", "isclass", "(", "inspected_obj", ")", ":", "obj_list", "=", "[", "inspected_obj", "]", "+", "list", "(", "inspected_ob...
Ensures we get descriptor object instead of its return value.
[ "Ensures", "we", "get", "descriptor", "object", "instead", "of", "its", "return", "value", "." ]
c4550523fe9b54bf9b755ffa28900a5e9f493d02
https://github.com/laike9m/pdir2/blob/c4550523fe9b54bf9b755ffa28900a5e9f493d02/pdir/_internal_utils.py#L9-L22
train
laike9m/pdir2
pdir/attr_category.py
attr_category_postprocess
def attr_category_postprocess(get_attr_category_func): """Unifies attr_category to a tuple, add AttrCategory.SLOT if needed.""" @functools.wraps(get_attr_category_func) def wrapped( name: str, attr: Any, obj: Any ) -> Tuple[AttrCategory, ...]: category = get_attr_category_func(name, attr...
python
def attr_category_postprocess(get_attr_category_func): """Unifies attr_category to a tuple, add AttrCategory.SLOT if needed.""" @functools.wraps(get_attr_category_func) def wrapped( name: str, attr: Any, obj: Any ) -> Tuple[AttrCategory, ...]: category = get_attr_category_func(name, attr...
[ "def", "attr_category_postprocess", "(", "get_attr_category_func", ")", ":", "@", "functools", ".", "wraps", "(", "get_attr_category_func", ")", "def", "wrapped", "(", "name", ":", "str", ",", "attr", ":", "Any", ",", "obj", ":", "Any", ")", "->", "Tuple", ...
Unifies attr_category to a tuple, add AttrCategory.SLOT if needed.
[ "Unifies", "attr_category", "to", "a", "tuple", "add", "AttrCategory", ".", "SLOT", "if", "needed", "." ]
c4550523fe9b54bf9b755ffa28900a5e9f493d02
https://github.com/laike9m/pdir2/blob/c4550523fe9b54bf9b755ffa28900a5e9f493d02/pdir/attr_category.py#L216-L230
train
mattloper/chumpy
chumpy/monitor.py
get_peak_mem
def get_peak_mem(): ''' this returns peak memory use since process starts till the moment its called ''' import resource rusage_denom = 1024. if sys.platform == 'darwin': # ... it seems that in OSX the output is different units ... rusage_denom = rusage_denom * rusage_denom m...
python
def get_peak_mem(): ''' this returns peak memory use since process starts till the moment its called ''' import resource rusage_denom = 1024. if sys.platform == 'darwin': # ... it seems that in OSX the output is different units ... rusage_denom = rusage_denom * rusage_denom m...
[ "def", "get_peak_mem", "(", ")", ":", "import", "resource", "rusage_denom", "=", "1024.", "if", "sys", ".", "platform", "==", "'darwin'", ":", "# ... it seems that in OSX the output is different units ...", "rusage_denom", "=", "rusage_denom", "*", "rusage_denom", "mem"...
this returns peak memory use since process starts till the moment its called
[ "this", "returns", "peak", "memory", "use", "since", "process", "starts", "till", "the", "moment", "its", "called" ]
a3cfdb1be3c8265c369c507b22f6f3f89414c772
https://github.com/mattloper/chumpy/blob/a3cfdb1be3c8265c369c507b22f6f3f89414c772/chumpy/monitor.py#L26-L36
train
mattloper/chumpy
chumpy/utils.py
dfs_do_func_on_graph
def dfs_do_func_on_graph(node, func, *args, **kwargs): ''' invoke func on each node of the dr graph ''' for _node in node.tree_iterator(): func(_node, *args, **kwargs)
python
def dfs_do_func_on_graph(node, func, *args, **kwargs): ''' invoke func on each node of the dr graph ''' for _node in node.tree_iterator(): func(_node, *args, **kwargs)
[ "def", "dfs_do_func_on_graph", "(", "node", ",", "func", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "for", "_node", "in", "node", ".", "tree_iterator", "(", ")", ":", "func", "(", "_node", ",", "*", "args", ",", "*", "*", "kwargs", ")" ]
invoke func on each node of the dr graph
[ "invoke", "func", "on", "each", "node", "of", "the", "dr", "graph" ]
a3cfdb1be3c8265c369c507b22f6f3f89414c772
https://github.com/mattloper/chumpy/blob/a3cfdb1be3c8265c369c507b22f6f3f89414c772/chumpy/utils.py#L36-L41
train
mattloper/chumpy
chumpy/utils.py
sparse_is_desireable
def sparse_is_desireable(lhs, rhs): ''' Examines a pair of matrices and determines if the result of their multiplication should be sparse or not. ''' return False if len(lhs.shape) == 1: return False else: lhs_rows, lhs_cols = lhs.shape if len(rhs.shape) == 1: rhs_ro...
python
def sparse_is_desireable(lhs, rhs): ''' Examines a pair of matrices and determines if the result of their multiplication should be sparse or not. ''' return False if len(lhs.shape) == 1: return False else: lhs_rows, lhs_cols = lhs.shape if len(rhs.shape) == 1: rhs_ro...
[ "def", "sparse_is_desireable", "(", "lhs", ",", "rhs", ")", ":", "return", "False", "if", "len", "(", "lhs", ".", "shape", ")", "==", "1", ":", "return", "False", "else", ":", "lhs_rows", ",", "lhs_cols", "=", "lhs", ".", "shape", "if", "len", "(", ...
Examines a pair of matrices and determines if the result of their multiplication should be sparse or not.
[ "Examines", "a", "pair", "of", "matrices", "and", "determines", "if", "the", "result", "of", "their", "multiplication", "should", "be", "sparse", "or", "not", "." ]
a3cfdb1be3c8265c369c507b22f6f3f89414c772
https://github.com/mattloper/chumpy/blob/a3cfdb1be3c8265c369c507b22f6f3f89414c772/chumpy/utils.py#L44-L78
train
mattloper/chumpy
chumpy/utils.py
convert_inputs_to_sparse_if_necessary
def convert_inputs_to_sparse_if_necessary(lhs, rhs): ''' This function checks to see if a sparse output is desireable given the inputs and if so, casts the inputs to sparse in order to make it so. ''' if not sp.issparse(lhs) or not sp.issparse(rhs): if sparse_is_desireable(lhs, rhs): ...
python
def convert_inputs_to_sparse_if_necessary(lhs, rhs): ''' This function checks to see if a sparse output is desireable given the inputs and if so, casts the inputs to sparse in order to make it so. ''' if not sp.issparse(lhs) or not sp.issparse(rhs): if sparse_is_desireable(lhs, rhs): ...
[ "def", "convert_inputs_to_sparse_if_necessary", "(", "lhs", ",", "rhs", ")", ":", "if", "not", "sp", ".", "issparse", "(", "lhs", ")", "or", "not", "sp", ".", "issparse", "(", "rhs", ")", ":", "if", "sparse_is_desireable", "(", "lhs", ",", "rhs", ")", ...
This function checks to see if a sparse output is desireable given the inputs and if so, casts the inputs to sparse in order to make it so.
[ "This", "function", "checks", "to", "see", "if", "a", "sparse", "output", "is", "desireable", "given", "the", "inputs", "and", "if", "so", "casts", "the", "inputs", "to", "sparse", "in", "order", "to", "make", "it", "so", "." ]
a3cfdb1be3c8265c369c507b22f6f3f89414c772
https://github.com/mattloper/chumpy/blob/a3cfdb1be3c8265c369c507b22f6f3f89414c772/chumpy/utils.py#L81-L93
train
mattloper/chumpy
chumpy/optimization_internal.py
ChInputsStacked.dr_wrt
def dr_wrt(self, wrt, profiler=None): ''' Loop over free variables and delete cache for the whole tree after finished each one ''' if wrt is self.x: jacs = [] for fvi, freevar in enumerate(self.free_variables): tm = timer() if isins...
python
def dr_wrt(self, wrt, profiler=None): ''' Loop over free variables and delete cache for the whole tree after finished each one ''' if wrt is self.x: jacs = [] for fvi, freevar in enumerate(self.free_variables): tm = timer() if isins...
[ "def", "dr_wrt", "(", "self", ",", "wrt", ",", "profiler", "=", "None", ")", ":", "if", "wrt", "is", "self", ".", "x", ":", "jacs", "=", "[", "]", "for", "fvi", ",", "freevar", "in", "enumerate", "(", "self", ".", "free_variables", ")", ":", "tm"...
Loop over free variables and delete cache for the whole tree after finished each one
[ "Loop", "over", "free", "variables", "and", "delete", "cache", "for", "the", "whole", "tree", "after", "finished", "each", "one" ]
a3cfdb1be3c8265c369c507b22f6f3f89414c772
https://github.com/mattloper/chumpy/blob/a3cfdb1be3c8265c369c507b22f6f3f89414c772/chumpy/optimization_internal.py#L34-L71
train
mattloper/chumpy
chumpy/optimization_internal.py
ChInputsStacked.J
def J(self): ''' Compute Jacobian. Analyze dr graph first to disable unnecessary caching ''' result = self.dr_wrt(self.x, profiler=self.profiler).copy() if self.profiler: self.profiler.harvest() return np.atleast_2d(result) if not sp.issparse(result) else resu...
python
def J(self): ''' Compute Jacobian. Analyze dr graph first to disable unnecessary caching ''' result = self.dr_wrt(self.x, profiler=self.profiler).copy() if self.profiler: self.profiler.harvest() return np.atleast_2d(result) if not sp.issparse(result) else resu...
[ "def", "J", "(", "self", ")", ":", "result", "=", "self", ".", "dr_wrt", "(", "self", ".", "x", ",", "profiler", "=", "self", ".", "profiler", ")", ".", "copy", "(", ")", "if", "self", ".", "profiler", ":", "self", ".", "profiler", ".", "harvest"...
Compute Jacobian. Analyze dr graph first to disable unnecessary caching
[ "Compute", "Jacobian", ".", "Analyze", "dr", "graph", "first", "to", "disable", "unnecessary", "caching" ]
a3cfdb1be3c8265c369c507b22f6f3f89414c772
https://github.com/mattloper/chumpy/blob/a3cfdb1be3c8265c369c507b22f6f3f89414c772/chumpy/optimization_internal.py#L101-L108
train
mattloper/chumpy
chumpy/ch.py
Ch.sid
def sid(self): """Semantic id.""" pnames = list(self.terms)+list(self.dterms) pnames.sort() return (self.__class__, tuple([(k, id(self.__dict__[k])) for k in pnames if k in self.__dict__]))
python
def sid(self): """Semantic id.""" pnames = list(self.terms)+list(self.dterms) pnames.sort() return (self.__class__, tuple([(k, id(self.__dict__[k])) for k in pnames if k in self.__dict__]))
[ "def", "sid", "(", "self", ")", ":", "pnames", "=", "list", "(", "self", ".", "terms", ")", "+", "list", "(", "self", ".", "dterms", ")", "pnames", ".", "sort", "(", ")", "return", "(", "self", ".", "__class__", ",", "tuple", "(", "[", "(", "k"...
Semantic id.
[ "Semantic", "id", "." ]
a3cfdb1be3c8265c369c507b22f6f3f89414c772
https://github.com/mattloper/chumpy/blob/a3cfdb1be3c8265c369c507b22f6f3f89414c772/chumpy/ch.py#L185-L189
train
mattloper/chumpy
chumpy/ch.py
Ch.compute_dr_wrt
def compute_dr_wrt(self,wrt): """Default method for objects that just contain a number or ndarray""" if wrt is self: # special base case return sp.eye(self.x.size, self.x.size) #return np.array([[1]]) return None
python
def compute_dr_wrt(self,wrt): """Default method for objects that just contain a number or ndarray""" if wrt is self: # special base case return sp.eye(self.x.size, self.x.size) #return np.array([[1]]) return None
[ "def", "compute_dr_wrt", "(", "self", ",", "wrt", ")", ":", "if", "wrt", "is", "self", ":", "# special base case ", "return", "sp", ".", "eye", "(", "self", ".", "x", ".", "size", ",", "self", ".", "x", ".", "size", ")", "#return np.array([[1]])", "re...
Default method for objects that just contain a number or ndarray
[ "Default", "method", "for", "objects", "that", "just", "contain", "a", "number", "or", "ndarray" ]
a3cfdb1be3c8265c369c507b22f6f3f89414c772
https://github.com/mattloper/chumpy/blob/a3cfdb1be3c8265c369c507b22f6f3f89414c772/chumpy/ch.py#L275-L280
train
juju/charm-helpers
charmhelpers/contrib/amulet/utils.py
AmuletUtils.get_ubuntu_release_from_sentry
def get_ubuntu_release_from_sentry(self, sentry_unit): """Get Ubuntu release codename from sentry unit. :param sentry_unit: amulet sentry/service unit pointer :returns: list of strings - release codename, failure message """ msg = None cmd = 'lsb_release -cs' rel...
python
def get_ubuntu_release_from_sentry(self, sentry_unit): """Get Ubuntu release codename from sentry unit. :param sentry_unit: amulet sentry/service unit pointer :returns: list of strings - release codename, failure message """ msg = None cmd = 'lsb_release -cs' rel...
[ "def", "get_ubuntu_release_from_sentry", "(", "self", ",", "sentry_unit", ")", ":", "msg", "=", "None", "cmd", "=", "'lsb_release -cs'", "release", ",", "code", "=", "sentry_unit", ".", "run", "(", "cmd", ")", "if", "code", "==", "0", ":", "self", ".", "...
Get Ubuntu release codename from sentry unit. :param sentry_unit: amulet sentry/service unit pointer :returns: list of strings - release codename, failure message
[ "Get", "Ubuntu", "release", "codename", "from", "sentry", "unit", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/amulet/utils.py#L83-L102
train
juju/charm-helpers
charmhelpers/contrib/amulet/utils.py
AmuletUtils.validate_services
def validate_services(self, commands): """Validate that lists of commands succeed on service units. Can be used to verify system services are running on the corresponding service units. :param commands: dict with sentry keys and arbitrary command list vals :returns: None ...
python
def validate_services(self, commands): """Validate that lists of commands succeed on service units. Can be used to verify system services are running on the corresponding service units. :param commands: dict with sentry keys and arbitrary command list vals :returns: None ...
[ "def", "validate_services", "(", "self", ",", "commands", ")", ":", "self", ".", "log", ".", "debug", "(", "'Checking status of system services...'", ")", "# /!\\ DEPRECATION WARNING (beisner):", "# New and existing tests should be rewritten to use", "# validate_services_by_name(...
Validate that lists of commands succeed on service units. Can be used to verify system services are running on the corresponding service units. :param commands: dict with sentry keys and arbitrary command list vals :returns: None if successful, Failure string message otherwise
[ "Validate", "that", "lists", "of", "commands", "succeed", "on", "service", "units", ".", "Can", "be", "used", "to", "verify", "system", "services", "are", "running", "on", "the", "corresponding", "service", "units", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/amulet/utils.py#L104-L129
train
juju/charm-helpers
charmhelpers/contrib/amulet/utils.py
AmuletUtils.validate_services_by_name
def validate_services_by_name(self, sentry_services): """Validate system service status by service name, automatically detecting init system based on Ubuntu release codename. :param sentry_services: dict with sentry keys and svc list values :returns: None if successful, Failure strin...
python
def validate_services_by_name(self, sentry_services): """Validate system service status by service name, automatically detecting init system based on Ubuntu release codename. :param sentry_services: dict with sentry keys and svc list values :returns: None if successful, Failure strin...
[ "def", "validate_services_by_name", "(", "self", ",", "sentry_services", ")", ":", "self", ".", "log", ".", "debug", "(", "'Checking status of system services...'", ")", "# Point at which systemd became a thing", "systemd_switch", "=", "self", ".", "ubuntu_releases", ".",...
Validate system service status by service name, automatically detecting init system based on Ubuntu release codename. :param sentry_services: dict with sentry keys and svc list values :returns: None if successful, Failure string message otherwise
[ "Validate", "system", "service", "status", "by", "service", "name", "automatically", "detecting", "init", "system", "based", "on", "Ubuntu", "release", "codename", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/amulet/utils.py#L131-L169
train
juju/charm-helpers
charmhelpers/contrib/amulet/utils.py
AmuletUtils._get_config
def _get_config(self, unit, filename): """Get a ConfigParser object for parsing a unit's config file.""" file_contents = unit.file_contents(filename) # NOTE(beisner): by default, ConfigParser does not handle options # with no value, such as the flags used in the mysql my.cnf file. ...
python
def _get_config(self, unit, filename): """Get a ConfigParser object for parsing a unit's config file.""" file_contents = unit.file_contents(filename) # NOTE(beisner): by default, ConfigParser does not handle options # with no value, such as the flags used in the mysql my.cnf file. ...
[ "def", "_get_config", "(", "self", ",", "unit", ",", "filename", ")", ":", "file_contents", "=", "unit", ".", "file_contents", "(", "filename", ")", "# NOTE(beisner): by default, ConfigParser does not handle options", "# with no value, such as the flags used in the mysql my.cn...
Get a ConfigParser object for parsing a unit's config file.
[ "Get", "a", "ConfigParser", "object", "for", "parsing", "a", "unit", "s", "config", "file", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/amulet/utils.py#L171-L180
train
juju/charm-helpers
charmhelpers/contrib/amulet/utils.py
AmuletUtils.validate_config_data
def validate_config_data(self, sentry_unit, config_file, section, expected): """Validate config file data. Verify that the specified section of the config file contains the expected option key:value pairs. Compare expected dictionary data vs actual...
python
def validate_config_data(self, sentry_unit, config_file, section, expected): """Validate config file data. Verify that the specified section of the config file contains the expected option key:value pairs. Compare expected dictionary data vs actual...
[ "def", "validate_config_data", "(", "self", ",", "sentry_unit", ",", "config_file", ",", "section", ",", "expected", ")", ":", "self", ".", "log", ".", "debug", "(", "'Validating config file data ({} in {} on {})'", "'...'", ".", "format", "(", "section", ",", "...
Validate config file data. Verify that the specified section of the config file contains the expected option key:value pairs. Compare expected dictionary data vs actual dictionary data. The values in the 'expected' dictionary can be strings, bools, ints, longs, o...
[ "Validate", "config", "file", "data", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/amulet/utils.py#L182-L219
train
juju/charm-helpers
charmhelpers/contrib/amulet/utils.py
AmuletUtils._validate_dict_data
def _validate_dict_data(self, expected, actual): """Validate dictionary data. Compare expected dictionary data vs actual dictionary data. The values in the 'expected' dictionary can be strings, bools, ints, longs, or can be a function that evaluates a variable and returns a ...
python
def _validate_dict_data(self, expected, actual): """Validate dictionary data. Compare expected dictionary data vs actual dictionary data. The values in the 'expected' dictionary can be strings, bools, ints, longs, or can be a function that evaluates a variable and returns a ...
[ "def", "_validate_dict_data", "(", "self", ",", "expected", ",", "actual", ")", ":", "self", ".", "log", ".", "debug", "(", "'actual: {}'", ".", "format", "(", "repr", "(", "actual", ")", ")", ")", "self", ".", "log", ".", "debug", "(", "'expected: {}'...
Validate dictionary data. Compare expected dictionary data vs actual dictionary data. The values in the 'expected' dictionary can be strings, bools, ints, longs, or can be a function that evaluates a variable and returns a bool.
[ "Validate", "dictionary", "data", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/amulet/utils.py#L221-L245
train
juju/charm-helpers
charmhelpers/contrib/amulet/utils.py
AmuletUtils.validate_relation_data
def validate_relation_data(self, sentry_unit, relation, expected): """Validate actual relation data based on expected relation data.""" actual = sentry_unit.relation(relation[0], relation[1]) return self._validate_dict_data(expected, actual)
python
def validate_relation_data(self, sentry_unit, relation, expected): """Validate actual relation data based on expected relation data.""" actual = sentry_unit.relation(relation[0], relation[1]) return self._validate_dict_data(expected, actual)
[ "def", "validate_relation_data", "(", "self", ",", "sentry_unit", ",", "relation", ",", "expected", ")", ":", "actual", "=", "sentry_unit", ".", "relation", "(", "relation", "[", "0", "]", ",", "relation", "[", "1", "]", ")", "return", "self", ".", "_val...
Validate actual relation data based on expected relation data.
[ "Validate", "actual", "relation", "data", "based", "on", "expected", "relation", "data", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/amulet/utils.py#L247-L250
train
juju/charm-helpers
charmhelpers/contrib/amulet/utils.py
AmuletUtils._validate_list_data
def _validate_list_data(self, expected, actual): """Compare expected list vs actual list data.""" for e in expected: if e not in actual: return "expected item {} not found in actual list".format(e) return None
python
def _validate_list_data(self, expected, actual): """Compare expected list vs actual list data.""" for e in expected: if e not in actual: return "expected item {} not found in actual list".format(e) return None
[ "def", "_validate_list_data", "(", "self", ",", "expected", ",", "actual", ")", ":", "for", "e", "in", "expected", ":", "if", "e", "not", "in", "actual", ":", "return", "\"expected item {} not found in actual list\"", ".", "format", "(", "e", ")", "return", ...
Compare expected list vs actual list data.
[ "Compare", "expected", "list", "vs", "actual", "list", "data", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/amulet/utils.py#L252-L257
train
juju/charm-helpers
charmhelpers/contrib/amulet/utils.py
AmuletUtils.service_restarted
def service_restarted(self, sentry_unit, service, filename, pgrep_full=None, sleep_time=20): """Check if service was restarted. Compare a service's start time vs a file's last modification time (such as a config file for that service) to determine if the service ...
python
def service_restarted(self, sentry_unit, service, filename, pgrep_full=None, sleep_time=20): """Check if service was restarted. Compare a service's start time vs a file's last modification time (such as a config file for that service) to determine if the service ...
[ "def", "service_restarted", "(", "self", ",", "sentry_unit", ",", "service", ",", "filename", ",", "pgrep_full", "=", "None", ",", "sleep_time", "=", "20", ")", ":", "# /!\\ DEPRECATION WARNING (beisner):", "# This method is prone to races in that no before-time is known.",...
Check if service was restarted. Compare a service's start time vs a file's last modification time (such as a config file for that service) to determine if the service has been restarted.
[ "Check", "if", "service", "was", "restarted", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/amulet/utils.py#L294-L318
train
juju/charm-helpers
charmhelpers/contrib/amulet/utils.py
AmuletUtils.service_restarted_since
def service_restarted_since(self, sentry_unit, mtime, service, pgrep_full=None, sleep_time=20, retry_count=30, retry_sleep_time=10): """Check if service was been started after a given time. Args: sentry_unit (sentry): The sentry ...
python
def service_restarted_since(self, sentry_unit, mtime, service, pgrep_full=None, sleep_time=20, retry_count=30, retry_sleep_time=10): """Check if service was been started after a given time. Args: sentry_unit (sentry): The sentry ...
[ "def", "service_restarted_since", "(", "self", ",", "sentry_unit", ",", "mtime", ",", "service", ",", "pgrep_full", "=", "None", ",", "sleep_time", "=", "20", ",", "retry_count", "=", "30", ",", "retry_sleep_time", "=", "10", ")", ":", "# NOTE(beisner) pgrep_f...
Check if service was been started after a given time. Args: sentry_unit (sentry): The sentry unit to check for the service on mtime (float): The epoch time to check against service (string): service name to look for in process table pgrep_full: [Deprecated] Use full comm...
[ "Check", "if", "service", "was", "been", "started", "after", "a", "given", "time", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/amulet/utils.py#L320-L378
train
juju/charm-helpers
charmhelpers/contrib/amulet/utils.py
AmuletUtils.config_updated_since
def config_updated_since(self, sentry_unit, filename, mtime, sleep_time=20, retry_count=30, retry_sleep_time=10): """Check if file was modified after a given time. Args: sentry_unit (sentry): The sentry unit to check the file mtime on ...
python
def config_updated_since(self, sentry_unit, filename, mtime, sleep_time=20, retry_count=30, retry_sleep_time=10): """Check if file was modified after a given time. Args: sentry_unit (sentry): The sentry unit to check the file mtime on ...
[ "def", "config_updated_since", "(", "self", ",", "sentry_unit", ",", "filename", ",", "mtime", ",", "sleep_time", "=", "20", ",", "retry_count", "=", "30", ",", "retry_sleep_time", "=", "10", ")", ":", "unit_name", "=", "sentry_unit", ".", "info", "[", "'u...
Check if file was modified after a given time. Args: sentry_unit (sentry): The sentry unit to check the file mtime on filename (string): The file to check mtime of mtime (float): The epoch time to check against sleep_time (int): Initial sleep time (s) before looking for ...
[ "Check", "if", "file", "was", "modified", "after", "a", "given", "time", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/amulet/utils.py#L380-L431
train
juju/charm-helpers
charmhelpers/contrib/amulet/utils.py
AmuletUtils.validate_service_config_changed
def validate_service_config_changed(self, sentry_unit, mtime, service, filename, pgrep_full=None, sleep_time=20, retry_count=30, retry_sleep_time=10): """Check service and file were updated af...
python
def validate_service_config_changed(self, sentry_unit, mtime, service, filename, pgrep_full=None, sleep_time=20, retry_count=30, retry_sleep_time=10): """Check service and file were updated af...
[ "def", "validate_service_config_changed", "(", "self", ",", "sentry_unit", ",", "mtime", ",", "service", ",", "filename", ",", "pgrep_full", "=", "None", ",", "sleep_time", "=", "20", ",", "retry_count", "=", "30", ",", "retry_sleep_time", "=", "10", ")", ":...
Check service and file were updated after mtime Args: sentry_unit (sentry): The sentry unit to check for the service on mtime (float): The epoch time to check against service (string): service name to look for in process table filename (string): The file to check mtime o...
[ "Check", "service", "and", "file", "were", "updated", "after", "mtime" ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/amulet/utils.py#L433-L485
train
juju/charm-helpers
charmhelpers/contrib/amulet/utils.py
AmuletUtils.file_to_url
def file_to_url(self, file_rel_path): """Convert a relative file path to a file URL.""" _abs_path = os.path.abspath(file_rel_path) return urlparse.urlparse(_abs_path, scheme='file').geturl()
python
def file_to_url(self, file_rel_path): """Convert a relative file path to a file URL.""" _abs_path = os.path.abspath(file_rel_path) return urlparse.urlparse(_abs_path, scheme='file').geturl()
[ "def", "file_to_url", "(", "self", ",", "file_rel_path", ")", ":", "_abs_path", "=", "os", ".", "path", ".", "abspath", "(", "file_rel_path", ")", "return", "urlparse", ".", "urlparse", "(", "_abs_path", ",", "scheme", "=", "'file'", ")", ".", "geturl", ...
Convert a relative file path to a file URL.
[ "Convert", "a", "relative", "file", "path", "to", "a", "file", "URL", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/amulet/utils.py#L504-L507
train
juju/charm-helpers
charmhelpers/contrib/amulet/utils.py
AmuletUtils.check_commands_on_units
def check_commands_on_units(self, commands, sentry_units): """Check that all commands in a list exit zero on all sentry units in a list. :param commands: list of bash commands :param sentry_units: list of sentry unit pointers :returns: None if successful; Failure message other...
python
def check_commands_on_units(self, commands, sentry_units): """Check that all commands in a list exit zero on all sentry units in a list. :param commands: list of bash commands :param sentry_units: list of sentry unit pointers :returns: None if successful; Failure message other...
[ "def", "check_commands_on_units", "(", "self", ",", "commands", ",", "sentry_units", ")", ":", "self", ".", "log", ".", "debug", "(", "'Checking exit codes for {} commands on {} '", "'sentry units...'", ".", "format", "(", "len", "(", "commands", ")", ",", "len", ...
Check that all commands in a list exit zero on all sentry units in a list. :param commands: list of bash commands :param sentry_units: list of sentry unit pointers :returns: None if successful; Failure message otherwise
[ "Check", "that", "all", "commands", "in", "a", "list", "exit", "zero", "on", "all", "sentry", "units", "in", "a", "list", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/amulet/utils.py#L509-L531
train
juju/charm-helpers
charmhelpers/contrib/amulet/utils.py
AmuletUtils.get_unit_process_ids
def get_unit_process_ids( self, unit_processes, expect_success=True, pgrep_full=False): """Construct a dict containing unit sentries, process names, and process IDs. :param unit_processes: A dictionary of Amulet sentry instance to list of process names. :param ex...
python
def get_unit_process_ids( self, unit_processes, expect_success=True, pgrep_full=False): """Construct a dict containing unit sentries, process names, and process IDs. :param unit_processes: A dictionary of Amulet sentry instance to list of process names. :param ex...
[ "def", "get_unit_process_ids", "(", "self", ",", "unit_processes", ",", "expect_success", "=", "True", ",", "pgrep_full", "=", "False", ")", ":", "pid_dict", "=", "{", "}", "for", "sentry_unit", ",", "process_list", "in", "six", ".", "iteritems", "(", "unit_...
Construct a dict containing unit sentries, process names, and process IDs. :param unit_processes: A dictionary of Amulet sentry instance to list of process names. :param expect_success: if False expect the processes to not be running, raise if they are. :returns:...
[ "Construct", "a", "dict", "containing", "unit", "sentries", "process", "names", "and", "process", "IDs", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/amulet/utils.py#L558-L578
train
juju/charm-helpers
charmhelpers/contrib/amulet/utils.py
AmuletUtils.validate_unit_process_ids
def validate_unit_process_ids(self, expected, actual): """Validate process id quantities for services on units.""" self.log.debug('Checking units for running processes...') self.log.debug('Expected PIDs: {}'.format(expected)) self.log.debug('Actual PIDs: {}'.format(actual)) if l...
python
def validate_unit_process_ids(self, expected, actual): """Validate process id quantities for services on units.""" self.log.debug('Checking units for running processes...') self.log.debug('Expected PIDs: {}'.format(expected)) self.log.debug('Actual PIDs: {}'.format(actual)) if l...
[ "def", "validate_unit_process_ids", "(", "self", ",", "expected", ",", "actual", ")", ":", "self", ".", "log", ".", "debug", "(", "'Checking units for running processes...'", ")", "self", ".", "log", ".", "debug", "(", "'Expected PIDs: {}'", ".", "format", "(", ...
Validate process id quantities for services on units.
[ "Validate", "process", "id", "quantities", "for", "services", "on", "units", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/amulet/utils.py#L580-L636
train
juju/charm-helpers
charmhelpers/contrib/amulet/utils.py
AmuletUtils.validate_list_of_identical_dicts
def validate_list_of_identical_dicts(self, list_of_dicts): """Check that all dicts within a list are identical.""" hashes = [] for _dict in list_of_dicts: hashes.append(hash(frozenset(_dict.items()))) self.log.debug('Hashes: {}'.format(hashes)) if len(set(hashes)) ==...
python
def validate_list_of_identical_dicts(self, list_of_dicts): """Check that all dicts within a list are identical.""" hashes = [] for _dict in list_of_dicts: hashes.append(hash(frozenset(_dict.items()))) self.log.debug('Hashes: {}'.format(hashes)) if len(set(hashes)) ==...
[ "def", "validate_list_of_identical_dicts", "(", "self", ",", "list_of_dicts", ")", ":", "hashes", "=", "[", "]", "for", "_dict", "in", "list_of_dicts", ":", "hashes", ".", "append", "(", "hash", "(", "frozenset", "(", "_dict", ".", "items", "(", ")", ")", ...
Check that all dicts within a list are identical.
[ "Check", "that", "all", "dicts", "within", "a", "list", "are", "identical", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/amulet/utils.py#L638-L650
train
juju/charm-helpers
charmhelpers/contrib/amulet/utils.py
AmuletUtils.get_unit_hostnames
def get_unit_hostnames(self, units): """Return a dict of juju unit names to hostnames.""" host_names = {} for unit in units: host_names[unit.info['unit_name']] = \ str(unit.file_contents('/etc/hostname').strip()) self.log.debug('Unit host names: {}'.format(hos...
python
def get_unit_hostnames(self, units): """Return a dict of juju unit names to hostnames.""" host_names = {} for unit in units: host_names[unit.info['unit_name']] = \ str(unit.file_contents('/etc/hostname').strip()) self.log.debug('Unit host names: {}'.format(hos...
[ "def", "get_unit_hostnames", "(", "self", ",", "units", ")", ":", "host_names", "=", "{", "}", "for", "unit", "in", "units", ":", "host_names", "[", "unit", ".", "info", "[", "'unit_name'", "]", "]", "=", "str", "(", "unit", ".", "file_contents", "(", ...
Return a dict of juju unit names to hostnames.
[ "Return", "a", "dict", "of", "juju", "unit", "names", "to", "hostnames", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/amulet/utils.py#L669-L676
train
juju/charm-helpers
charmhelpers/contrib/amulet/utils.py
AmuletUtils.run_cmd_unit
def run_cmd_unit(self, sentry_unit, cmd): """Run a command on a unit, return the output and exit code.""" output, code = sentry_unit.run(cmd) if code == 0: self.log.debug('{} `{}` command returned {} ' '(OK)'.format(sentry_unit.info['unit_name'], ...
python
def run_cmd_unit(self, sentry_unit, cmd): """Run a command on a unit, return the output and exit code.""" output, code = sentry_unit.run(cmd) if code == 0: self.log.debug('{} `{}` command returned {} ' '(OK)'.format(sentry_unit.info['unit_name'], ...
[ "def", "run_cmd_unit", "(", "self", ",", "sentry_unit", ",", "cmd", ")", ":", "output", ",", "code", "=", "sentry_unit", ".", "run", "(", "cmd", ")", "if", "code", "==", "0", ":", "self", ".", "log", ".", "debug", "(", "'{} `{}` command returned {} '", ...
Run a command on a unit, return the output and exit code.
[ "Run", "a", "command", "on", "a", "unit", "return", "the", "output", "and", "exit", "code", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/amulet/utils.py#L678-L690
train
juju/charm-helpers
charmhelpers/contrib/amulet/utils.py
AmuletUtils.file_exists_on_unit
def file_exists_on_unit(self, sentry_unit, file_name): """Check if a file exists on a unit.""" try: sentry_unit.file_stat(file_name) return True except IOError: return False except Exception as e: msg = 'Error checking file {}: {}'.format(f...
python
def file_exists_on_unit(self, sentry_unit, file_name): """Check if a file exists on a unit.""" try: sentry_unit.file_stat(file_name) return True except IOError: return False except Exception as e: msg = 'Error checking file {}: {}'.format(f...
[ "def", "file_exists_on_unit", "(", "self", ",", "sentry_unit", ",", "file_name", ")", ":", "try", ":", "sentry_unit", ".", "file_stat", "(", "file_name", ")", "return", "True", "except", "IOError", ":", "return", "False", "except", "Exception", "as", "e", ":...
Check if a file exists on a unit.
[ "Check", "if", "a", "file", "exists", "on", "a", "unit", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/amulet/utils.py#L692-L701
train
juju/charm-helpers
charmhelpers/contrib/amulet/utils.py
AmuletUtils.file_contents_safe
def file_contents_safe(self, sentry_unit, file_name, max_wait=60, fatal=False): """Get file contents from a sentry unit. Wrap amulet file_contents with retry logic to address races where a file checks as existing, but no longer exists by the time file_contents is call...
python
def file_contents_safe(self, sentry_unit, file_name, max_wait=60, fatal=False): """Get file contents from a sentry unit. Wrap amulet file_contents with retry logic to address races where a file checks as existing, but no longer exists by the time file_contents is call...
[ "def", "file_contents_safe", "(", "self", ",", "sentry_unit", ",", "file_name", ",", "max_wait", "=", "60", ",", "fatal", "=", "False", ")", ":", "unit_name", "=", "sentry_unit", ".", "info", "[", "'unit_name'", "]", "file_contents", "=", "False", "tries", ...
Get file contents from a sentry unit. Wrap amulet file_contents with retry logic to address races where a file checks as existing, but no longer exists by the time file_contents is called. Return None if file not found. Optionally raise if fatal is True.
[ "Get", "file", "contents", "from", "a", "sentry", "unit", ".", "Wrap", "amulet", "file_contents", "with", "retry", "logic", "to", "address", "races", "where", "a", "file", "checks", "as", "existing", "but", "no", "longer", "exists", "by", "the", "time", "f...
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/amulet/utils.py#L703-L728
train
juju/charm-helpers
charmhelpers/contrib/amulet/utils.py
AmuletUtils.port_knock_tcp
def port_knock_tcp(self, host="localhost", port=22, timeout=15): """Open a TCP socket to check for a listening sevice on a host. :param host: host name or IP address, default to localhost :param port: TCP port number, default to 22 :param timeout: Connect timeout, default to 15 seconds ...
python
def port_knock_tcp(self, host="localhost", port=22, timeout=15): """Open a TCP socket to check for a listening sevice on a host. :param host: host name or IP address, default to localhost :param port: TCP port number, default to 22 :param timeout: Connect timeout, default to 15 seconds ...
[ "def", "port_knock_tcp", "(", "self", ",", "host", "=", "\"localhost\"", ",", "port", "=", "22", ",", "timeout", "=", "15", ")", ":", "# Resolve host name if possible", "try", ":", "connect_host", "=", "socket", ".", "gethostbyname", "(", "host", ")", "host_...
Open a TCP socket to check for a listening sevice on a host. :param host: host name or IP address, default to localhost :param port: TCP port number, default to 22 :param timeout: Connect timeout, default to 15 seconds :returns: True if successful, False if connect failed
[ "Open", "a", "TCP", "socket", "to", "check", "for", "a", "listening", "sevice", "on", "a", "host", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/amulet/utils.py#L730-L761
train
juju/charm-helpers
charmhelpers/contrib/amulet/utils.py
AmuletUtils.port_knock_units
def port_knock_units(self, sentry_units, port=22, timeout=15, expect_success=True): """Open a TCP socket to check for a listening sevice on each listed juju unit. :param sentry_units: list of sentry unit pointers :param port: TCP port number, default to 22 ...
python
def port_knock_units(self, sentry_units, port=22, timeout=15, expect_success=True): """Open a TCP socket to check for a listening sevice on each listed juju unit. :param sentry_units: list of sentry unit pointers :param port: TCP port number, default to 22 ...
[ "def", "port_knock_units", "(", "self", ",", "sentry_units", ",", "port", "=", "22", ",", "timeout", "=", "15", ",", "expect_success", "=", "True", ")", ":", "for", "unit", "in", "sentry_units", ":", "host", "=", "unit", ".", "info", "[", "'public-addres...
Open a TCP socket to check for a listening sevice on each listed juju unit. :param sentry_units: list of sentry unit pointers :param port: TCP port number, default to 22 :param timeout: Connect timeout, default to 15 seconds :expect_success: True by default, set False to invert ...
[ "Open", "a", "TCP", "socket", "to", "check", "for", "a", "listening", "sevice", "on", "each", "listed", "juju", "unit", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/amulet/utils.py#L763-L780
train
juju/charm-helpers
charmhelpers/contrib/amulet/utils.py
AmuletUtils.wait_on_action
def wait_on_action(self, action_id, _check_output=subprocess.check_output): """Wait for a given action, returning if it completed or not. action_id a string action uuid _check_output parameter is no longer used """ data = amulet.actions.get_action_output(action_id, full_output=T...
python
def wait_on_action(self, action_id, _check_output=subprocess.check_output): """Wait for a given action, returning if it completed or not. action_id a string action uuid _check_output parameter is no longer used """ data = amulet.actions.get_action_output(action_id, full_output=T...
[ "def", "wait_on_action", "(", "self", ",", "action_id", ",", "_check_output", "=", "subprocess", ".", "check_output", ")", ":", "data", "=", "amulet", ".", "actions", ".", "get_action_output", "(", "action_id", ",", "full_output", "=", "True", ")", "return", ...
Wait for a given action, returning if it completed or not. action_id a string action uuid _check_output parameter is no longer used
[ "Wait", "for", "a", "given", "action", "returning", "if", "it", "completed", "or", "not", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/amulet/utils.py#L804-L811
train
juju/charm-helpers
charmhelpers/contrib/amulet/utils.py
AmuletUtils.status_get
def status_get(self, unit): """Return the current service status of this unit.""" raw_status, return_code = unit.run( "status-get --format=json --include-data") if return_code != 0: return ("unknown", "") status = json.loads(raw_status) return (status["sta...
python
def status_get(self, unit): """Return the current service status of this unit.""" raw_status, return_code = unit.run( "status-get --format=json --include-data") if return_code != 0: return ("unknown", "") status = json.loads(raw_status) return (status["sta...
[ "def", "status_get", "(", "self", ",", "unit", ")", ":", "raw_status", ",", "return_code", "=", "unit", ".", "run", "(", "\"status-get --format=json --include-data\"", ")", "if", "return_code", "!=", "0", ":", "return", "(", "\"unknown\"", ",", "\"\"", ")", ...
Return the current service status of this unit.
[ "Return", "the", "current", "service", "status", "of", "this", "unit", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/amulet/utils.py#L813-L820
train
juju/charm-helpers
charmhelpers/contrib/database/mysql.py
MySQLHelper.execute
def execute(self, sql): """Execute arbitary SQL against the database.""" cursor = self.connection.cursor() try: cursor.execute(sql) finally: cursor.close()
python
def execute(self, sql): """Execute arbitary SQL against the database.""" cursor = self.connection.cursor() try: cursor.execute(sql) finally: cursor.close()
[ "def", "execute", "(", "self", ",", "sql", ")", ":", "cursor", "=", "self", ".", "connection", ".", "cursor", "(", ")", "try", ":", "cursor", ".", "execute", "(", "sql", ")", "finally", ":", "cursor", ".", "close", "(", ")" ]
Execute arbitary SQL against the database.
[ "Execute", "arbitary", "SQL", "against", "the", "database", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/database/mysql.py#L160-L166
train
juju/charm-helpers
charmhelpers/contrib/database/mysql.py
MySQLHelper.select
def select(self, sql): """ Execute arbitrary SQL select query against the database and return the results. :param sql: SQL select query to execute :type sql: string :returns: SQL select query result :rtype: list of lists :raises: MySQLdb.Error """...
python
def select(self, sql): """ Execute arbitrary SQL select query against the database and return the results. :param sql: SQL select query to execute :type sql: string :returns: SQL select query result :rtype: list of lists :raises: MySQLdb.Error """...
[ "def", "select", "(", "self", ",", "sql", ")", ":", "cursor", "=", "self", ".", "connection", ".", "cursor", "(", ")", "try", ":", "cursor", ".", "execute", "(", "sql", ")", "results", "=", "[", "list", "(", "i", ")", "for", "i", "in", "cursor", ...
Execute arbitrary SQL select query against the database and return the results. :param sql: SQL select query to execute :type sql: string :returns: SQL select query result :rtype: list of lists :raises: MySQLdb.Error
[ "Execute", "arbitrary", "SQL", "select", "query", "against", "the", "database", "and", "return", "the", "results", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/database/mysql.py#L168-L185
train
juju/charm-helpers
charmhelpers/contrib/database/mysql.py
MySQLHelper.migrate_passwords_to_leader_storage
def migrate_passwords_to_leader_storage(self, excludes=None): """Migrate any passwords storage on disk to leader storage.""" if not is_leader(): log("Skipping password migration as not the lead unit", level=DEBUG) return dirname = os.path.dirname(self.root...
python
def migrate_passwords_to_leader_storage(self, excludes=None): """Migrate any passwords storage on disk to leader storage.""" if not is_leader(): log("Skipping password migration as not the lead unit", level=DEBUG) return dirname = os.path.dirname(self.root...
[ "def", "migrate_passwords_to_leader_storage", "(", "self", ",", "excludes", "=", "None", ")", ":", "if", "not", "is_leader", "(", ")", ":", "log", "(", "\"Skipping password migration as not the lead unit\"", ",", "level", "=", "DEBUG", ")", "return", "dirname", "=...
Migrate any passwords storage on disk to leader storage.
[ "Migrate", "any", "passwords", "storage", "on", "disk", "to", "leader", "storage", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/database/mysql.py#L187-L212
train
juju/charm-helpers
charmhelpers/contrib/database/mysql.py
MySQLHelper.get_mysql_password_on_disk
def get_mysql_password_on_disk(self, username=None, password=None): """Retrieve, generate or store a mysql password for the provided username on disk.""" if username: template = self.user_passwd_file_template passwd_file = template.format(username) else: ...
python
def get_mysql_password_on_disk(self, username=None, password=None): """Retrieve, generate or store a mysql password for the provided username on disk.""" if username: template = self.user_passwd_file_template passwd_file = template.format(username) else: ...
[ "def", "get_mysql_password_on_disk", "(", "self", ",", "username", "=", "None", ",", "password", "=", "None", ")", ":", "if", "username", ":", "template", "=", "self", ".", "user_passwd_file_template", "passwd_file", "=", "template", ".", "format", "(", "usern...
Retrieve, generate or store a mysql password for the provided username on disk.
[ "Retrieve", "generate", "or", "store", "a", "mysql", "password", "for", "the", "provided", "username", "on", "disk", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/database/mysql.py#L214-L243
train
juju/charm-helpers
charmhelpers/contrib/database/mysql.py
MySQLHelper.passwd_keys
def passwd_keys(self, username): """Generator to return keys used to store passwords in peer store. NOTE: we support both legacy and new format to support mysql charm prior to refactor. This is necessary to avoid LP 1451890. """ keys = [] if username == 'mysql': ...
python
def passwd_keys(self, username): """Generator to return keys used to store passwords in peer store. NOTE: we support both legacy and new format to support mysql charm prior to refactor. This is necessary to avoid LP 1451890. """ keys = [] if username == 'mysql': ...
[ "def", "passwd_keys", "(", "self", ",", "username", ")", ":", "keys", "=", "[", "]", "if", "username", "==", "'mysql'", ":", "log", "(", "\"Bad username '%s'\"", "%", "(", "username", ")", ",", "level", "=", "WARNING", ")", "if", "username", ":", "# IM...
Generator to return keys used to store passwords in peer store. NOTE: we support both legacy and new format to support mysql charm prior to refactor. This is necessary to avoid LP 1451890.
[ "Generator", "to", "return", "keys", "used", "to", "store", "passwords", "in", "peer", "store", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/database/mysql.py#L245-L263
train
juju/charm-helpers
charmhelpers/contrib/database/mysql.py
MySQLHelper.get_mysql_password
def get_mysql_password(self, username=None, password=None): """Retrieve, generate or store a mysql password for the provided username using peer relation cluster.""" excludes = [] # First check peer relation. try: for key in self.passwd_keys(username): ...
python
def get_mysql_password(self, username=None, password=None): """Retrieve, generate or store a mysql password for the provided username using peer relation cluster.""" excludes = [] # First check peer relation. try: for key in self.passwd_keys(username): ...
[ "def", "get_mysql_password", "(", "self", ",", "username", "=", "None", ",", "password", "=", "None", ")", ":", "excludes", "=", "[", "]", "# First check peer relation.", "try", ":", "for", "key", "in", "self", ".", "passwd_keys", "(", "username", ")", ":"...
Retrieve, generate or store a mysql password for the provided username using peer relation cluster.
[ "Retrieve", "generate", "or", "store", "a", "mysql", "password", "for", "the", "provided", "username", "using", "peer", "relation", "cluster", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/database/mysql.py#L265-L293
train
juju/charm-helpers
charmhelpers/contrib/database/mysql.py
MySQLHelper.set_mysql_password
def set_mysql_password(self, username, password): """Update a mysql password for the provided username changing the leader settings To update root's password pass `None` in the username """ if username is None: username = 'root' # get root password via lead...
python
def set_mysql_password(self, username, password): """Update a mysql password for the provided username changing the leader settings To update root's password pass `None` in the username """ if username is None: username = 'root' # get root password via lead...
[ "def", "set_mysql_password", "(", "self", ",", "username", ",", "password", ")", ":", "if", "username", "is", "None", ":", "username", "=", "'root'", "# get root password via leader-get, it may be that in the past (when", "# changes to root-password were not supported) the user...
Update a mysql password for the provided username changing the leader settings To update root's password pass `None` in the username
[ "Update", "a", "mysql", "password", "for", "the", "provided", "username", "changing", "the", "leader", "settings" ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/database/mysql.py#L299-L370
train
juju/charm-helpers
charmhelpers/contrib/database/mysql.py
MySQLHelper.get_allowed_units
def get_allowed_units(self, database, username, relation_id=None): """Get list of units with access grants for database with username. This is typically used to provide shared-db relations with a list of which units have been granted access to the given database. """ self.connec...
python
def get_allowed_units(self, database, username, relation_id=None): """Get list of units with access grants for database with username. This is typically used to provide shared-db relations with a list of which units have been granted access to the given database. """ self.connec...
[ "def", "get_allowed_units", "(", "self", ",", "database", ",", "username", ",", "relation_id", "=", "None", ")", ":", "self", ".", "connect", "(", "password", "=", "self", ".", "get_mysql_root_password", "(", ")", ")", "allowed_units", "=", "set", "(", ")"...
Get list of units with access grants for database with username. This is typically used to provide shared-db relations with a list of which units have been granted access to the given database.
[ "Get", "list", "of", "units", "with", "access", "grants", "for", "database", "with", "username", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/database/mysql.py#L387-L426
train
juju/charm-helpers
charmhelpers/contrib/database/mysql.py
MySQLHelper.configure_db
def configure_db(self, hostname, database, username, admin=False): """Configure access to database for username from hostname.""" self.connect(password=self.get_mysql_root_password()) if not self.database_exists(database): self.create_database(database) remote_ip = self.norm...
python
def configure_db(self, hostname, database, username, admin=False): """Configure access to database for username from hostname.""" self.connect(password=self.get_mysql_root_password()) if not self.database_exists(database): self.create_database(database) remote_ip = self.norm...
[ "def", "configure_db", "(", "self", ",", "hostname", ",", "database", ",", "username", ",", "admin", "=", "False", ")", ":", "self", ".", "connect", "(", "password", "=", "self", ".", "get_mysql_root_password", "(", ")", ")", "if", "not", "self", ".", ...
Configure access to database for username from hostname.
[ "Configure", "access", "to", "database", "for", "username", "from", "hostname", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/database/mysql.py#L428-L443
train
juju/charm-helpers
charmhelpers/contrib/database/mysql.py
PerconaClusterHelper.human_to_bytes
def human_to_bytes(self, human): """Convert human readable configuration options to bytes.""" num_re = re.compile('^[0-9]+$') if num_re.match(human): return human factors = { 'K': 1024, 'M': 1048576, 'G': 1073741824, 'T': 10995...
python
def human_to_bytes(self, human): """Convert human readable configuration options to bytes.""" num_re = re.compile('^[0-9]+$') if num_re.match(human): return human factors = { 'K': 1024, 'M': 1048576, 'G': 1073741824, 'T': 10995...
[ "def", "human_to_bytes", "(", "self", ",", "human", ")", ":", "num_re", "=", "re", ".", "compile", "(", "'^[0-9]+$'", ")", "if", "num_re", ".", "match", "(", "human", ")", ":", "return", "human", "factors", "=", "{", "'K'", ":", "1024", ",", "'M'", ...
Convert human readable configuration options to bytes.
[ "Convert", "human", "readable", "configuration", "options", "to", "bytes", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/database/mysql.py#L470-L494
train
juju/charm-helpers
charmhelpers/contrib/database/mysql.py
PerconaClusterHelper.sys_mem_limit
def sys_mem_limit(self): """Determine the default memory limit for the current service unit.""" if platform.machine() in ['armv7l']: _mem_limit = self.human_to_bytes('2700M') # experimentally determined else: # Limit for x86 based 32bit systems _mem_limit = s...
python
def sys_mem_limit(self): """Determine the default memory limit for the current service unit.""" if platform.machine() in ['armv7l']: _mem_limit = self.human_to_bytes('2700M') # experimentally determined else: # Limit for x86 based 32bit systems _mem_limit = s...
[ "def", "sys_mem_limit", "(", "self", ")", ":", "if", "platform", ".", "machine", "(", ")", "in", "[", "'armv7l'", "]", ":", "_mem_limit", "=", "self", ".", "human_to_bytes", "(", "'2700M'", ")", "# experimentally determined", "else", ":", "# Limit for x86 base...
Determine the default memory limit for the current service unit.
[ "Determine", "the", "default", "memory", "limit", "for", "the", "current", "service", "unit", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/database/mysql.py#L503-L511
train
juju/charm-helpers
charmhelpers/contrib/database/mysql.py
PerconaClusterHelper.get_mem_total
def get_mem_total(self): """Calculate the total memory in the current service unit.""" with open('/proc/meminfo') as meminfo_file: for line in meminfo_file: key, mem = line.split(':', 2) if key == 'MemTotal': mtot, modifier = mem.strip().sp...
python
def get_mem_total(self): """Calculate the total memory in the current service unit.""" with open('/proc/meminfo') as meminfo_file: for line in meminfo_file: key, mem = line.split(':', 2) if key == 'MemTotal': mtot, modifier = mem.strip().sp...
[ "def", "get_mem_total", "(", "self", ")", ":", "with", "open", "(", "'/proc/meminfo'", ")", "as", "meminfo_file", ":", "for", "line", "in", "meminfo_file", ":", "key", ",", "mem", "=", "line", ".", "split", "(", "':'", ",", "2", ")", "if", "key", "==...
Calculate the total memory in the current service unit.
[ "Calculate", "the", "total", "memory", "in", "the", "current", "service", "unit", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/database/mysql.py#L513-L520
train
juju/charm-helpers
charmhelpers/contrib/database/mysql.py
PerconaClusterHelper.parse_config
def parse_config(self): """Parse charm configuration and calculate values for config files.""" config = config_get() mysql_config = {} if 'max-connections' in config: mysql_config['max_connections'] = config['max-connections'] if 'wait-timeout' in config: ...
python
def parse_config(self): """Parse charm configuration and calculate values for config files.""" config = config_get() mysql_config = {} if 'max-connections' in config: mysql_config['max_connections'] = config['max-connections'] if 'wait-timeout' in config: ...
[ "def", "parse_config", "(", "self", ")", ":", "config", "=", "config_get", "(", ")", "mysql_config", "=", "{", "}", "if", "'max-connections'", "in", "config", ":", "mysql_config", "[", "'max_connections'", "]", "=", "config", "[", "'max-connections'", "]", "...
Parse charm configuration and calculate values for config files.
[ "Parse", "charm", "configuration", "and", "calculate", "values", "for", "config", "files", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/database/mysql.py#L522-L577
train
juju/charm-helpers
charmhelpers/contrib/storage/linux/loopback.py
create_loopback
def create_loopback(file_path): ''' Create a loopback device for a given backing file. :returns: str: Full path to new loopback device (eg, /dev/loop0) ''' file_path = os.path.abspath(file_path) check_call(['losetup', '--find', file_path]) for d, f in six.iteritems(loopback_devices()): ...
python
def create_loopback(file_path): ''' Create a loopback device for a given backing file. :returns: str: Full path to new loopback device (eg, /dev/loop0) ''' file_path = os.path.abspath(file_path) check_call(['losetup', '--find', file_path]) for d, f in six.iteritems(loopback_devices()): ...
[ "def", "create_loopback", "(", "file_path", ")", ":", "file_path", "=", "os", ".", "path", ".", "abspath", "(", "file_path", ")", "check_call", "(", "[", "'losetup'", ",", "'--find'", ",", "file_path", "]", ")", "for", "d", ",", "f", "in", "six", ".", ...
Create a loopback device for a given backing file. :returns: str: Full path to new loopback device (eg, /dev/loop0)
[ "Create", "a", "loopback", "device", "for", "a", "given", "backing", "file", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/storage/linux/loopback.py#L48-L58
train
juju/charm-helpers
charmhelpers/contrib/storage/linux/loopback.py
ensure_loopback_device
def ensure_loopback_device(path, size): ''' Ensure a loopback device exists for a given backing file path and size. If it a loopback device is not mapped to file, a new one will be created. TODO: Confirm size of found loopback device. :returns: str: Full path to the ensured loopback device (eg, /d...
python
def ensure_loopback_device(path, size): ''' Ensure a loopback device exists for a given backing file path and size. If it a loopback device is not mapped to file, a new one will be created. TODO: Confirm size of found loopback device. :returns: str: Full path to the ensured loopback device (eg, /d...
[ "def", "ensure_loopback_device", "(", "path", ",", "size", ")", ":", "for", "d", ",", "f", "in", "six", ".", "iteritems", "(", "loopback_devices", "(", ")", ")", ":", "if", "f", "==", "path", ":", "return", "d", "if", "not", "os", ".", "path", ".",...
Ensure a loopback device exists for a given backing file path and size. If it a loopback device is not mapped to file, a new one will be created. TODO: Confirm size of found loopback device. :returns: str: Full path to the ensured loopback device (eg, /dev/loop0)
[ "Ensure", "a", "loopback", "device", "exists", "for", "a", "given", "backing", "file", "path", "and", "size", ".", "If", "it", "a", "loopback", "device", "is", "not", "mapped", "to", "file", "a", "new", "one", "will", "be", "created", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/storage/linux/loopback.py#L61-L78
train
juju/charm-helpers
charmhelpers/contrib/peerstorage/__init__.py
leader_get
def leader_get(attribute=None, rid=None): """Wrapper to ensure that settings are migrated from the peer relation. This is to support upgrading an environment that does not support Juju leadership election to one that does. If a setting is not extant in the leader-get but is on the relation-get pee...
python
def leader_get(attribute=None, rid=None): """Wrapper to ensure that settings are migrated from the peer relation. This is to support upgrading an environment that does not support Juju leadership election to one that does. If a setting is not extant in the leader-get but is on the relation-get pee...
[ "def", "leader_get", "(", "attribute", "=", "None", ",", "rid", "=", "None", ")", ":", "migration_key", "=", "'__leader_get_migrated_settings__'", "if", "not", "is_leader", "(", ")", ":", "return", "_leader_get", "(", "attribute", "=", "attribute", ")", "setti...
Wrapper to ensure that settings are migrated from the peer relation. This is to support upgrading an environment that does not support Juju leadership election to one that does. If a setting is not extant in the leader-get but is on the relation-get peer rel, it is migrated and marked as such so that ...
[ "Wrapper", "to", "ensure", "that", "settings", "are", "migrated", "from", "the", "peer", "relation", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/peerstorage/__init__.py#L60-L122
train
juju/charm-helpers
charmhelpers/contrib/peerstorage/__init__.py
relation_set
def relation_set(relation_id=None, relation_settings=None, **kwargs): """Attempt to use leader-set if supported in the current version of Juju, otherwise falls back on relation-set. Note that we only attempt to use leader-set if the provided relation_id is a peer relation id or no relation id is provid...
python
def relation_set(relation_id=None, relation_settings=None, **kwargs): """Attempt to use leader-set if supported in the current version of Juju, otherwise falls back on relation-set. Note that we only attempt to use leader-set if the provided relation_id is a peer relation id or no relation id is provid...
[ "def", "relation_set", "(", "relation_id", "=", "None", ",", "relation_settings", "=", "None", ",", "*", "*", "kwargs", ")", ":", "try", ":", "if", "relation_id", "in", "relation_ids", "(", "'cluster'", ")", ":", "return", "leader_set", "(", "settings", "=...
Attempt to use leader-set if supported in the current version of Juju, otherwise falls back on relation-set. Note that we only attempt to use leader-set if the provided relation_id is a peer relation id or no relation id is provided (in which case we assume we are within the peer relation context).
[ "Attempt", "to", "use", "leader", "-", "set", "if", "supported", "in", "the", "current", "version", "of", "Juju", "otherwise", "falls", "back", "on", "relation", "-", "set", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/peerstorage/__init__.py#L125-L140
train
juju/charm-helpers
charmhelpers/contrib/peerstorage/__init__.py
relation_get
def relation_get(attribute=None, unit=None, rid=None): """Attempt to use leader-get if supported in the current version of Juju, otherwise falls back on relation-get. Note that we only attempt to use leader-get if the provided rid is a peer relation id or no relation id is provided (in which case we as...
python
def relation_get(attribute=None, unit=None, rid=None): """Attempt to use leader-get if supported in the current version of Juju, otherwise falls back on relation-get. Note that we only attempt to use leader-get if the provided rid is a peer relation id or no relation id is provided (in which case we as...
[ "def", "relation_get", "(", "attribute", "=", "None", ",", "unit", "=", "None", ",", "rid", "=", "None", ")", ":", "try", ":", "if", "rid", "in", "relation_ids", "(", "'cluster'", ")", ":", "return", "leader_get", "(", "attribute", ",", "rid", ")", "...
Attempt to use leader-get if supported in the current version of Juju, otherwise falls back on relation-get. Note that we only attempt to use leader-get if the provided rid is a peer relation id or no relation id is provided (in which case we assume we are within the peer relation context).
[ "Attempt", "to", "use", "leader", "-", "get", "if", "supported", "in", "the", "current", "version", "of", "Juju", "otherwise", "falls", "back", "on", "relation", "-", "get", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/peerstorage/__init__.py#L143-L157
train
juju/charm-helpers
charmhelpers/contrib/peerstorage/__init__.py
peer_retrieve
def peer_retrieve(key, relation_name='cluster'): """Retrieve a named key from peer relation `relation_name`.""" cluster_rels = relation_ids(relation_name) if len(cluster_rels) > 0: cluster_rid = cluster_rels[0] return relation_get(attribute=key, rid=cluster_rid, u...
python
def peer_retrieve(key, relation_name='cluster'): """Retrieve a named key from peer relation `relation_name`.""" cluster_rels = relation_ids(relation_name) if len(cluster_rels) > 0: cluster_rid = cluster_rels[0] return relation_get(attribute=key, rid=cluster_rid, u...
[ "def", "peer_retrieve", "(", "key", ",", "relation_name", "=", "'cluster'", ")", ":", "cluster_rels", "=", "relation_ids", "(", "relation_name", ")", "if", "len", "(", "cluster_rels", ")", ">", "0", ":", "cluster_rid", "=", "cluster_rels", "[", "0", "]", "...
Retrieve a named key from peer relation `relation_name`.
[ "Retrieve", "a", "named", "key", "from", "peer", "relation", "relation_name", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/peerstorage/__init__.py#L160-L169
train
juju/charm-helpers
charmhelpers/contrib/peerstorage/__init__.py
peer_echo
def peer_echo(includes=None, force=False): """Echo filtered attributes back onto the same relation for storage. This is a requirement to use the peerstorage module - it needs to be called from the peer relation's changed hook. If Juju leader support exists this will be a noop unless force is True. ...
python
def peer_echo(includes=None, force=False): """Echo filtered attributes back onto the same relation for storage. This is a requirement to use the peerstorage module - it needs to be called from the peer relation's changed hook. If Juju leader support exists this will be a noop unless force is True. ...
[ "def", "peer_echo", "(", "includes", "=", "None", ",", "force", "=", "False", ")", ":", "try", ":", "is_leader", "(", ")", "except", "NotImplementedError", ":", "pass", "else", ":", "if", "not", "force", ":", "return", "# NOOP if leader-election is supported",...
Echo filtered attributes back onto the same relation for storage. This is a requirement to use the peerstorage module - it needs to be called from the peer relation's changed hook. If Juju leader support exists this will be a noop unless force is True.
[ "Echo", "filtered", "attributes", "back", "onto", "the", "same", "relation", "for", "storage", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/peerstorage/__init__.py#L204-L237
train
juju/charm-helpers
charmhelpers/contrib/peerstorage/__init__.py
peer_store_and_set
def peer_store_and_set(relation_id=None, peer_relation_name='cluster', peer_store_fatal=False, relation_settings=None, delimiter='_', **kwargs): """Store passed-in arguments both in argument relation and in peer storage. It functions like doing relation_set() and p...
python
def peer_store_and_set(relation_id=None, peer_relation_name='cluster', peer_store_fatal=False, relation_settings=None, delimiter='_', **kwargs): """Store passed-in arguments both in argument relation and in peer storage. It functions like doing relation_set() and p...
[ "def", "peer_store_and_set", "(", "relation_id", "=", "None", ",", "peer_relation_name", "=", "'cluster'", ",", "peer_store_fatal", "=", "False", ",", "relation_settings", "=", "None", ",", "delimiter", "=", "'_'", ",", "*", "*", "kwargs", ")", ":", "relation_...
Store passed-in arguments both in argument relation and in peer storage. It functions like doing relation_set() and peer_store() at the same time, with the same data. @param relation_id: the id of the relation to store the data on. Defaults to the current relation. @param peer_...
[ "Store", "passed", "-", "in", "arguments", "both", "in", "argument", "relation", "and", "in", "peer", "storage", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/peerstorage/__init__.py#L240-L267
train
juju/charm-helpers
charmhelpers/core/files.py
sed
def sed(filename, before, after, flags='g'): """ Search and replaces the given pattern on filename. :param filename: relative or absolute file path. :param before: expression to be replaced (see 'man sed') :param after: expression to replace with (see 'man sed') :param flags: sed-compatible reg...
python
def sed(filename, before, after, flags='g'): """ Search and replaces the given pattern on filename. :param filename: relative or absolute file path. :param before: expression to be replaced (see 'man sed') :param after: expression to replace with (see 'man sed') :param flags: sed-compatible reg...
[ "def", "sed", "(", "filename", ",", "before", ",", "after", ",", "flags", "=", "'g'", ")", ":", "expression", "=", "r's/{0}/{1}/{2}'", ".", "format", "(", "before", ",", "after", ",", "flags", ")", "return", "subprocess", ".", "check_call", "(", "[", "...
Search and replaces the given pattern on filename. :param filename: relative or absolute file path. :param before: expression to be replaced (see 'man sed') :param after: expression to replace with (see 'man sed') :param flags: sed-compatible regex flags in example, to make the search and replace ...
[ "Search", "and", "replaces", "the", "given", "pattern", "on", "filename", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/files.py#L24-L43
train
juju/charm-helpers
charmhelpers/contrib/hardening/ssh/checks/config.py
SSHConfigContext.get_listening
def get_listening(self, listen=['0.0.0.0']): """Returns a list of addresses SSH can list on Turns input into a sensible list of IPs SSH can listen on. Input must be a python list of interface names, IPs and/or CIDRs. :param listen: list of IPs, CIDRs, interface names :returns:...
python
def get_listening(self, listen=['0.0.0.0']): """Returns a list of addresses SSH can list on Turns input into a sensible list of IPs SSH can listen on. Input must be a python list of interface names, IPs and/or CIDRs. :param listen: list of IPs, CIDRs, interface names :returns:...
[ "def", "get_listening", "(", "self", ",", "listen", "=", "[", "'0.0.0.0'", "]", ")", ":", "if", "listen", "==", "[", "'0.0.0.0'", "]", ":", "return", "listen", "value", "=", "[", "]", "for", "network", "in", "listen", ":", "try", ":", "ip", "=", "g...
Returns a list of addresses SSH can list on Turns input into a sensible list of IPs SSH can listen on. Input must be a python list of interface names, IPs and/or CIDRs. :param listen: list of IPs, CIDRs, interface names :returns: list of IPs available on the host
[ "Returns", "a", "list", "of", "addresses", "SSH", "can", "list", "on" ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/hardening/ssh/checks/config.py#L135-L163
train
juju/charm-helpers
charmhelpers/contrib/openstack/templating.py
get_loader
def get_loader(templates_dir, os_release): """ Create a jinja2.ChoiceLoader containing template dirs up to and including os_release. If directory template directory is missing at templates_dir, it will be omitted from the loader. templates_dir is added to the bottom of the search list as a base ...
python
def get_loader(templates_dir, os_release): """ Create a jinja2.ChoiceLoader containing template dirs up to and including os_release. If directory template directory is missing at templates_dir, it will be omitted from the loader. templates_dir is added to the bottom of the search list as a base ...
[ "def", "get_loader", "(", "templates_dir", ",", "os_release", ")", ":", "tmpl_dirs", "=", "[", "(", "rel", ",", "os", ".", "path", ".", "join", "(", "templates_dir", ",", "rel", ")", ")", "for", "rel", "in", "six", ".", "itervalues", "(", "OPENSTACK_CO...
Create a jinja2.ChoiceLoader containing template dirs up to and including os_release. If directory template directory is missing at templates_dir, it will be omitted from the loader. templates_dir is added to the bottom of the search list as a base loading dir. A charm may also ship a templates di...
[ "Create", "a", "jinja2", ".", "ChoiceLoader", "containing", "template", "dirs", "up", "to", "and", "including", "os_release", ".", "If", "directory", "template", "directory", "is", "missing", "at", "templates_dir", "it", "will", "be", "omitted", "from", "the", ...
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/templating.py#L43-L88
train
juju/charm-helpers
charmhelpers/contrib/openstack/templating.py
OSConfigTemplate.complete_contexts
def complete_contexts(self): ''' Return a list of interfaces that have satisfied contexts. ''' if self._complete_contexts: return self._complete_contexts self.context() return self._complete_contexts
python
def complete_contexts(self): ''' Return a list of interfaces that have satisfied contexts. ''' if self._complete_contexts: return self._complete_contexts self.context() return self._complete_contexts
[ "def", "complete_contexts", "(", "self", ")", ":", "if", "self", ".", "_complete_contexts", ":", "return", "self", ".", "_complete_contexts", "self", ".", "context", "(", ")", "return", "self", ".", "_complete_contexts" ]
Return a list of interfaces that have satisfied contexts.
[ "Return", "a", "list", "of", "interfaces", "that", "have", "satisfied", "contexts", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/templating.py#L121-L128
train