id int32 0 252k | 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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
13,400 | buriburisuri/sugartensor | sugartensor/sg_main.py | sg_get_context | def sg_get_context():
r"""Get current context information
Returns:
tf.sg_opt class object which contains all context information
"""
global _context
# merge current context
res = tf.sg_opt()
for c in _context:
res += c
return res | python | def sg_get_context():
r"""Get current context information
Returns:
tf.sg_opt class object which contains all context information
"""
global _context
# merge current context
res = tf.sg_opt()
for c in _context:
res += c
return res | [
"def",
"sg_get_context",
"(",
")",
":",
"global",
"_context",
"# merge current context",
"res",
"=",
"tf",
".",
"sg_opt",
"(",
")",
"for",
"c",
"in",
"_context",
":",
"res",
"+=",
"c",
"return",
"res"
] | r"""Get current context information
Returns:
tf.sg_opt class object which contains all context information | [
"r",
"Get",
"current",
"context",
"information"
] | d2c039954777c7fbe3eb0c2ae40c45c9854deb40 | https://github.com/buriburisuri/sugartensor/blob/d2c039954777c7fbe3eb0c2ae40c45c9854deb40/sugartensor/sg_main.py#L135-L149 |
13,401 | buriburisuri/sugartensor | sugartensor/sg_main.py | sg_sugar_func | def sg_sugar_func(func):
r""" Decorates a function `func` so that it can be a sugar function.
Sugar function can be used in a chainable manner.
Args:
func: function to decorate
Returns:
A sugar function.
"""
@wraps(func)
def wrapper(tensor, **kwargs):
# call sugar fu... | python | def sg_sugar_func(func):
r""" Decorates a function `func` so that it can be a sugar function.
Sugar function can be used in a chainable manner.
Args:
func: function to decorate
Returns:
A sugar function.
"""
@wraps(func)
def wrapper(tensor, **kwargs):
# call sugar fu... | [
"def",
"sg_sugar_func",
"(",
"func",
")",
":",
"@",
"wraps",
"(",
"func",
")",
"def",
"wrapper",
"(",
"tensor",
",",
"*",
"*",
"kwargs",
")",
":",
"# call sugar function",
"out",
"=",
"func",
"(",
"tensor",
",",
"tf",
".",
"sg_opt",
"(",
"kwargs",
")... | r""" Decorates a function `func` so that it can be a sugar function.
Sugar function can be used in a chainable manner.
Args:
func: function to decorate
Returns:
A sugar function. | [
"r",
"Decorates",
"a",
"function",
"func",
"so",
"that",
"it",
"can",
"be",
"a",
"sugar",
"function",
".",
"Sugar",
"function",
"can",
"be",
"used",
"in",
"a",
"chainable",
"manner",
"."
] | d2c039954777c7fbe3eb0c2ae40c45c9854deb40 | https://github.com/buriburisuri/sugartensor/blob/d2c039954777c7fbe3eb0c2ae40c45c9854deb40/sugartensor/sg_main.py#L156-L177 |
13,402 | buriburisuri/sugartensor | sugartensor/sg_main.py | sg_reuse | def sg_reuse(tensor, **opt):
r""" Reconstruct computational graph of `tensor` so all the parameters
can be reused and replace its input tensor with `opt.input`.
Args:
tensor: A `Tensor` (automatically given by chaining).
**opt:
input: A `Tensor` that will replace the original input tens... | python | def sg_reuse(tensor, **opt):
r""" Reconstruct computational graph of `tensor` so all the parameters
can be reused and replace its input tensor with `opt.input`.
Args:
tensor: A `Tensor` (automatically given by chaining).
**opt:
input: A `Tensor` that will replace the original input tens... | [
"def",
"sg_reuse",
"(",
"tensor",
",",
"*",
"*",
"opt",
")",
":",
"opt",
"=",
"tf",
".",
"sg_opt",
"(",
"opt",
")",
"assert",
"hasattr",
"(",
"tensor",
",",
"'_sugar'",
")",
",",
"'cannot reuse this node.'",
"assert",
"opt",
".",
"input",
"is",
"not",
... | r""" Reconstruct computational graph of `tensor` so all the parameters
can be reused and replace its input tensor with `opt.input`.
Args:
tensor: A `Tensor` (automatically given by chaining).
**opt:
input: A `Tensor` that will replace the original input tensor.
Returns:
Reconstru... | [
"r",
"Reconstruct",
"computational",
"graph",
"of",
"tensor",
"so",
"all",
"the",
"parameters",
"can",
"be",
"reused",
"and",
"replace",
"its",
"input",
"tensor",
"with",
"opt",
".",
"input",
"."
] | d2c039954777c7fbe3eb0c2ae40c45c9854deb40 | https://github.com/buriburisuri/sugartensor/blob/d2c039954777c7fbe3eb0c2ae40c45c9854deb40/sugartensor/sg_main.py#L452-L487 |
13,403 | buriburisuri/sugartensor | sugartensor/sg_main.py | sg_input | def sg_input(shape=None, dtype=sg_floatx, name=None):
r"""Creates a placeholder.
Args:
shape: A tuple/list of integers. If an integers is given, it will turn to a list.
dtype: A data type. Default is float32.
name: A name for the placeholder.
Returns:
A wrapped placeholder `Tensor`... | python | def sg_input(shape=None, dtype=sg_floatx, name=None):
r"""Creates a placeholder.
Args:
shape: A tuple/list of integers. If an integers is given, it will turn to a list.
dtype: A data type. Default is float32.
name: A name for the placeholder.
Returns:
A wrapped placeholder `Tensor`... | [
"def",
"sg_input",
"(",
"shape",
"=",
"None",
",",
"dtype",
"=",
"sg_floatx",
",",
"name",
"=",
"None",
")",
":",
"if",
"shape",
"is",
"None",
":",
"return",
"tf",
".",
"placeholder",
"(",
"dtype",
",",
"shape",
"=",
"None",
",",
"name",
"=",
"name... | r"""Creates a placeholder.
Args:
shape: A tuple/list of integers. If an integers is given, it will turn to a list.
dtype: A data type. Default is float32.
name: A name for the placeholder.
Returns:
A wrapped placeholder `Tensor`. | [
"r",
"Creates",
"a",
"placeholder",
"."
] | d2c039954777c7fbe3eb0c2ae40c45c9854deb40 | https://github.com/buriburisuri/sugartensor/blob/d2c039954777c7fbe3eb0c2ae40c45c9854deb40/sugartensor/sg_main.py#L494-L510 |
13,404 | buriburisuri/sugartensor | sugartensor/sg_main.py | sg_inject | def sg_inject(path, mod_name):
r"""Converts all functions in the given Python module to sugar functions
so that they can be used in a chainable manner.
Args:
path: A string. Path to the Python module
mod_name: A string. The name of the Python module to inject.
Returns:
None
"""
... | python | def sg_inject(path, mod_name):
r"""Converts all functions in the given Python module to sugar functions
so that they can be used in a chainable manner.
Args:
path: A string. Path to the Python module
mod_name: A string. The name of the Python module to inject.
Returns:
None
"""
... | [
"def",
"sg_inject",
"(",
"path",
",",
"mod_name",
")",
":",
"# import module",
"import",
"sys",
"if",
"path",
"not",
"in",
"list",
"(",
"sys",
".",
"path",
")",
":",
"sys",
".",
"path",
".",
"append",
"(",
"path",
")",
"globals",
"(",
")",
"[",
"mo... | r"""Converts all functions in the given Python module to sugar functions
so that they can be used in a chainable manner.
Args:
path: A string. Path to the Python module
mod_name: A string. The name of the Python module to inject.
Returns:
None | [
"r",
"Converts",
"all",
"functions",
"in",
"the",
"given",
"Python",
"module",
"to",
"sugar",
"functions",
"so",
"that",
"they",
"can",
"be",
"used",
"in",
"a",
"chainable",
"manner",
"."
] | d2c039954777c7fbe3eb0c2ae40c45c9854deb40 | https://github.com/buriburisuri/sugartensor/blob/d2c039954777c7fbe3eb0c2ae40c45c9854deb40/sugartensor/sg_main.py#L517-L540 |
13,405 | buriburisuri/sugartensor | sugartensor/sg_main.py | sg_queue_context | def sg_queue_context(sess=None):
r"""Context helper for queue routines.
Args:
sess: A session to open queues. If not specified, a new session is created.
Returns:
None
"""
# default session
sess = tf.get_default_session() if sess is None else sess
# thread coordinator
coo... | python | def sg_queue_context(sess=None):
r"""Context helper for queue routines.
Args:
sess: A session to open queues. If not specified, a new session is created.
Returns:
None
"""
# default session
sess = tf.get_default_session() if sess is None else sess
# thread coordinator
coo... | [
"def",
"sg_queue_context",
"(",
"sess",
"=",
"None",
")",
":",
"# default session",
"sess",
"=",
"tf",
".",
"get_default_session",
"(",
")",
"if",
"sess",
"is",
"None",
"else",
"sess",
"# thread coordinator",
"coord",
"=",
"tf",
".",
"train",
".",
"Coordinat... | r"""Context helper for queue routines.
Args:
sess: A session to open queues. If not specified, a new session is created.
Returns:
None | [
"r",
"Context",
"helper",
"for",
"queue",
"routines",
"."
] | d2c039954777c7fbe3eb0c2ae40c45c9854deb40 | https://github.com/buriburisuri/sugartensor/blob/d2c039954777c7fbe3eb0c2ae40c45c9854deb40/sugartensor/sg_main.py#L565-L588 |
13,406 | buriburisuri/sugartensor | sugartensor/sg_main.py | sg_arg | def sg_arg():
r"""Gets current command line options
Returns:
tf.sg_opt instance that is updated with current commandd line options.
"""
if not tf.app.flags.FLAGS.__dict__['__parsed']:
tf.app.flags.FLAGS._parse_flags()
return tf.sg_opt(tf.app.flags.FLAGS.__dict__['__flags']) | python | def sg_arg():
r"""Gets current command line options
Returns:
tf.sg_opt instance that is updated with current commandd line options.
"""
if not tf.app.flags.FLAGS.__dict__['__parsed']:
tf.app.flags.FLAGS._parse_flags()
return tf.sg_opt(tf.app.flags.FLAGS.__dict__['__flags']) | [
"def",
"sg_arg",
"(",
")",
":",
"if",
"not",
"tf",
".",
"app",
".",
"flags",
".",
"FLAGS",
".",
"__dict__",
"[",
"'__parsed'",
"]",
":",
"tf",
".",
"app",
".",
"flags",
".",
"FLAGS",
".",
"_parse_flags",
"(",
")",
"return",
"tf",
".",
"sg_opt",
"... | r"""Gets current command line options
Returns:
tf.sg_opt instance that is updated with current commandd line options. | [
"r",
"Gets",
"current",
"command",
"line",
"options"
] | d2c039954777c7fbe3eb0c2ae40c45c9854deb40 | https://github.com/buriburisuri/sugartensor/blob/d2c039954777c7fbe3eb0c2ae40c45c9854deb40/sugartensor/sg_main.py#L632-L640 |
13,407 | buriburisuri/sugartensor | sugartensor/sg_main.py | sg_arg_def | def sg_arg_def(**kwargs):
r"""Defines command line options
Args:
**kwargs:
key: A name for the option.
value : Default value or a tuple of (default value, description).
Returns:
None
For example,
```
# Either of the following two lines will define `--n_epoch` comm... | python | def sg_arg_def(**kwargs):
r"""Defines command line options
Args:
**kwargs:
key: A name for the option.
value : Default value or a tuple of (default value, description).
Returns:
None
For example,
```
# Either of the following two lines will define `--n_epoch` comm... | [
"def",
"sg_arg_def",
"(",
"*",
"*",
"kwargs",
")",
":",
"for",
"k",
",",
"v",
"in",
"kwargs",
".",
"items",
"(",
")",
":",
"if",
"type",
"(",
"v",
")",
"is",
"tuple",
"or",
"type",
"(",
"v",
")",
"is",
"list",
":",
"v",
",",
"c",
"=",
"v",
... | r"""Defines command line options
Args:
**kwargs:
key: A name for the option.
value : Default value or a tuple of (default value, description).
Returns:
None
For example,
```
# Either of the following two lines will define `--n_epoch` command line argument and set its ... | [
"r",
"Defines",
"command",
"line",
"options"
] | d2c039954777c7fbe3eb0c2ae40c45c9854deb40 | https://github.com/buriburisuri/sugartensor/blob/d2c039954777c7fbe3eb0c2ae40c45c9854deb40/sugartensor/sg_main.py#L643-L675 |
13,408 | buriburisuri/sugartensor | sugartensor/sg_logging.py | sg_summary_loss | def sg_summary_loss(tensor, prefix='losses', name=None):
r"""Register `tensor` to summary report as `loss`
Args:
tensor: A `Tensor` to log as loss
prefix: A `string`. A prefix to display in the tensor board web UI.
name: A `string`. A name to display in the tensor board web UI.
Returns:
... | python | def sg_summary_loss(tensor, prefix='losses', name=None):
r"""Register `tensor` to summary report as `loss`
Args:
tensor: A `Tensor` to log as loss
prefix: A `string`. A prefix to display in the tensor board web UI.
name: A `string`. A name to display in the tensor board web UI.
Returns:
... | [
"def",
"sg_summary_loss",
"(",
"tensor",
",",
"prefix",
"=",
"'losses'",
",",
"name",
"=",
"None",
")",
":",
"# defaults",
"prefix",
"=",
"''",
"if",
"prefix",
"is",
"None",
"else",
"prefix",
"+",
"'/'",
"# summary name",
"name",
"=",
"prefix",
"+",
"_pr... | r"""Register `tensor` to summary report as `loss`
Args:
tensor: A `Tensor` to log as loss
prefix: A `string`. A prefix to display in the tensor board web UI.
name: A `string`. A name to display in the tensor board web UI.
Returns:
None | [
"r",
"Register",
"tensor",
"to",
"summary",
"report",
"as",
"loss"
] | d2c039954777c7fbe3eb0c2ae40c45c9854deb40 | https://github.com/buriburisuri/sugartensor/blob/d2c039954777c7fbe3eb0c2ae40c45c9854deb40/sugartensor/sg_logging.py#L19-L36 |
13,409 | buriburisuri/sugartensor | sugartensor/sg_logging.py | sg_summary_gradient | def sg_summary_gradient(tensor, gradient, prefix=None, name=None):
r"""Register `tensor` to summary report as `gradient`
Args:
tensor: A `Tensor` to log as gradient
gradient: A 0-D `Tensor`. A gradient to log
prefix: A `string`. A prefix to display in the tensor board web UI.
name: A `s... | python | def sg_summary_gradient(tensor, gradient, prefix=None, name=None):
r"""Register `tensor` to summary report as `gradient`
Args:
tensor: A `Tensor` to log as gradient
gradient: A 0-D `Tensor`. A gradient to log
prefix: A `string`. A prefix to display in the tensor board web UI.
name: A `s... | [
"def",
"sg_summary_gradient",
"(",
"tensor",
",",
"gradient",
",",
"prefix",
"=",
"None",
",",
"name",
"=",
"None",
")",
":",
"# defaults",
"prefix",
"=",
"''",
"if",
"prefix",
"is",
"None",
"else",
"prefix",
"+",
"'/'",
"# summary name",
"name",
"=",
"p... | r"""Register `tensor` to summary report as `gradient`
Args:
tensor: A `Tensor` to log as gradient
gradient: A 0-D `Tensor`. A gradient to log
prefix: A `string`. A prefix to display in the tensor board web UI.
name: A `string`. A name to display in the tensor board web UI.
Returns:
... | [
"r",
"Register",
"tensor",
"to",
"summary",
"report",
"as",
"gradient"
] | d2c039954777c7fbe3eb0c2ae40c45c9854deb40 | https://github.com/buriburisuri/sugartensor/blob/d2c039954777c7fbe3eb0c2ae40c45c9854deb40/sugartensor/sg_logging.py#L59-L78 |
13,410 | buriburisuri/sugartensor | sugartensor/sg_logging.py | sg_summary_activation | def sg_summary_activation(tensor, prefix=None, name=None):
r"""Register `tensor` to summary report as `activation`
Args:
tensor: A `Tensor` to log as activation
prefix: A `string`. A prefix to display in the tensor board web UI.
name: A `string`. A name to display in the tensor board web UI.
... | python | def sg_summary_activation(tensor, prefix=None, name=None):
r"""Register `tensor` to summary report as `activation`
Args:
tensor: A `Tensor` to log as activation
prefix: A `string`. A prefix to display in the tensor board web UI.
name: A `string`. A name to display in the tensor board web UI.
... | [
"def",
"sg_summary_activation",
"(",
"tensor",
",",
"prefix",
"=",
"None",
",",
"name",
"=",
"None",
")",
":",
"# defaults",
"prefix",
"=",
"''",
"if",
"prefix",
"is",
"None",
"else",
"prefix",
"+",
"'/'",
"# summary name",
"name",
"=",
"prefix",
"+",
"_... | r"""Register `tensor` to summary report as `activation`
Args:
tensor: A `Tensor` to log as activation
prefix: A `string`. A prefix to display in the tensor board web UI.
name: A `string`. A name to display in the tensor board web UI.
Returns:
None | [
"r",
"Register",
"tensor",
"to",
"summary",
"report",
"as",
"activation"
] | d2c039954777c7fbe3eb0c2ae40c45c9854deb40 | https://github.com/buriburisuri/sugartensor/blob/d2c039954777c7fbe3eb0c2ae40c45c9854deb40/sugartensor/sg_logging.py#L81-L99 |
13,411 | buriburisuri/sugartensor | sugartensor/sg_logging.py | sg_summary_param | def sg_summary_param(tensor, prefix=None, name=None):
r"""Register `tensor` to summary report as `parameters`
Args:
tensor: A `Tensor` to log as parameters
prefix: A `string`. A prefix to display in the tensor board web UI.
name: A `string`. A name to display in the tensor board web UI.
... | python | def sg_summary_param(tensor, prefix=None, name=None):
r"""Register `tensor` to summary report as `parameters`
Args:
tensor: A `Tensor` to log as parameters
prefix: A `string`. A prefix to display in the tensor board web UI.
name: A `string`. A name to display in the tensor board web UI.
... | [
"def",
"sg_summary_param",
"(",
"tensor",
",",
"prefix",
"=",
"None",
",",
"name",
"=",
"None",
")",
":",
"# defaults",
"prefix",
"=",
"''",
"if",
"prefix",
"is",
"None",
"else",
"prefix",
"+",
"'/'",
"# summary name",
"name",
"=",
"prefix",
"+",
"_prett... | r"""Register `tensor` to summary report as `parameters`
Args:
tensor: A `Tensor` to log as parameters
prefix: A `string`. A prefix to display in the tensor board web UI.
name: A `string`. A name to display in the tensor board web UI.
Returns:
None | [
"r",
"Register",
"tensor",
"to",
"summary",
"report",
"as",
"parameters"
] | d2c039954777c7fbe3eb0c2ae40c45c9854deb40 | https://github.com/buriburisuri/sugartensor/blob/d2c039954777c7fbe3eb0c2ae40c45c9854deb40/sugartensor/sg_logging.py#L102-L119 |
13,412 | buriburisuri/sugartensor | sugartensor/sg_logging.py | sg_summary_image | def sg_summary_image(tensor, prefix=None, name=None):
r"""Register `tensor` to summary report as `image`
Args:
tensor: A tensor to log as image
prefix: A `string`. A prefix to display in the tensor board web UI.
name: A `string`. A name to display in the tensor board web UI.
Returns:
... | python | def sg_summary_image(tensor, prefix=None, name=None):
r"""Register `tensor` to summary report as `image`
Args:
tensor: A tensor to log as image
prefix: A `string`. A prefix to display in the tensor board web UI.
name: A `string`. A name to display in the tensor board web UI.
Returns:
... | [
"def",
"sg_summary_image",
"(",
"tensor",
",",
"prefix",
"=",
"None",
",",
"name",
"=",
"None",
")",
":",
"# defaults",
"prefix",
"=",
"''",
"if",
"prefix",
"is",
"None",
"else",
"prefix",
"+",
"'/'",
"# summary name",
"name",
"=",
"prefix",
"+",
"_prett... | r"""Register `tensor` to summary report as `image`
Args:
tensor: A tensor to log as image
prefix: A `string`. A prefix to display in the tensor board web UI.
name: A `string`. A name to display in the tensor board web UI.
Returns:
None | [
"r",
"Register",
"tensor",
"to",
"summary",
"report",
"as",
"image"
] | d2c039954777c7fbe3eb0c2ae40c45c9854deb40 | https://github.com/buriburisuri/sugartensor/blob/d2c039954777c7fbe3eb0c2ae40c45c9854deb40/sugartensor/sg_logging.py#L122-L139 |
13,413 | buriburisuri/sugartensor | sugartensor/sg_logging.py | sg_summary_audio | def sg_summary_audio(tensor, sample_rate=16000, prefix=None, name=None):
r"""Register `tensor` to summary report as audio
Args:
tensor: A `Tensor` to log as audio
sample_rate : An int. Sample rate to report. Default is 16000.
prefix: A `string`. A prefix to display in the tensor board web UI.... | python | def sg_summary_audio(tensor, sample_rate=16000, prefix=None, name=None):
r"""Register `tensor` to summary report as audio
Args:
tensor: A `Tensor` to log as audio
sample_rate : An int. Sample rate to report. Default is 16000.
prefix: A `string`. A prefix to display in the tensor board web UI.... | [
"def",
"sg_summary_audio",
"(",
"tensor",
",",
"sample_rate",
"=",
"16000",
",",
"prefix",
"=",
"None",
",",
"name",
"=",
"None",
")",
":",
"# defaults",
"prefix",
"=",
"''",
"if",
"prefix",
"is",
"None",
"else",
"prefix",
"+",
"'/'",
"# summary name",
"... | r"""Register `tensor` to summary report as audio
Args:
tensor: A `Tensor` to log as audio
sample_rate : An int. Sample rate to report. Default is 16000.
prefix: A `string`. A prefix to display in the tensor board web UI.
name: A `string`. A name to display in the tensor board web UI.
R... | [
"r",
"Register",
"tensor",
"to",
"summary",
"report",
"as",
"audio"
] | d2c039954777c7fbe3eb0c2ae40c45c9854deb40 | https://github.com/buriburisuri/sugartensor/blob/d2c039954777c7fbe3eb0c2ae40c45c9854deb40/sugartensor/sg_logging.py#L142-L160 |
13,414 | buriburisuri/sugartensor | sugartensor/sg_train.py | sg_train | def sg_train(**kwargs):
r"""Trains the model.
Args:
**kwargs:
optim: A name for optimizer. 'MaxProp' (default), 'AdaMax', 'Adam', 'RMSProp' or 'sgd'.
loss: A 0-D `Tensor` containing the value to minimize.
lr: A Python Scalar (optional). Learning rate. Default is .001.
beta... | python | def sg_train(**kwargs):
r"""Trains the model.
Args:
**kwargs:
optim: A name for optimizer. 'MaxProp' (default), 'AdaMax', 'Adam', 'RMSProp' or 'sgd'.
loss: A 0-D `Tensor` containing the value to minimize.
lr: A Python Scalar (optional). Learning rate. Default is .001.
beta... | [
"def",
"sg_train",
"(",
"*",
"*",
"kwargs",
")",
":",
"opt",
"=",
"tf",
".",
"sg_opt",
"(",
"kwargs",
")",
"assert",
"opt",
".",
"loss",
"is",
"not",
"None",
",",
"'loss is mandatory.'",
"# default training options",
"opt",
"+=",
"tf",
".",
"sg_opt",
"("... | r"""Trains the model.
Args:
**kwargs:
optim: A name for optimizer. 'MaxProp' (default), 'AdaMax', 'Adam', 'RMSProp' or 'sgd'.
loss: A 0-D `Tensor` containing the value to minimize.
lr: A Python Scalar (optional). Learning rate. Default is .001.
beta1: A Python Scalar (optional... | [
"r",
"Trains",
"the",
"model",
"."
] | d2c039954777c7fbe3eb0c2ae40c45c9854deb40 | https://github.com/buriburisuri/sugartensor/blob/d2c039954777c7fbe3eb0c2ae40c45c9854deb40/sugartensor/sg_train.py#L13-L69 |
13,415 | buriburisuri/sugartensor | sugartensor/sg_train.py | sg_restore | def sg_restore(sess, save_path, category=''):
r""" Restores previously saved variables.
Args:
sess: A `Session` to use to restore the parameters.
save_path: Path where parameters were previously saved.
category: A `String` to filter variables starts with given category.
Returns:
"""... | python | def sg_restore(sess, save_path, category=''):
r""" Restores previously saved variables.
Args:
sess: A `Session` to use to restore the parameters.
save_path: Path where parameters were previously saved.
category: A `String` to filter variables starts with given category.
Returns:
"""... | [
"def",
"sg_restore",
"(",
"sess",
",",
"save_path",
",",
"category",
"=",
"''",
")",
":",
"# to list",
"if",
"not",
"isinstance",
"(",
"category",
",",
"(",
"tuple",
",",
"list",
")",
")",
":",
"category",
"=",
"[",
"category",
"]",
"# make variable list... | r""" Restores previously saved variables.
Args:
sess: A `Session` to use to restore the parameters.
save_path: Path where parameters were previously saved.
category: A `String` to filter variables starts with given category.
Returns: | [
"r",
"Restores",
"previously",
"saved",
"variables",
"."
] | d2c039954777c7fbe3eb0c2ae40c45c9854deb40 | https://github.com/buriburisuri/sugartensor/blob/d2c039954777c7fbe3eb0c2ae40c45c9854deb40/sugartensor/sg_train.py#L124-L148 |
13,416 | buriburisuri/sugartensor | sugartensor/sg_train.py | sg_regularizer_loss | def sg_regularizer_loss(scale=1.0):
r""" Get regularizer losss
Args:
scale: A scalar. A weight applied to regularizer loss
"""
return scale * tf.reduce_mean(tf.get_collection(tf.GraphKeys.REGULARIZATION_LOSSES)) | python | def sg_regularizer_loss(scale=1.0):
r""" Get regularizer losss
Args:
scale: A scalar. A weight applied to regularizer loss
"""
return scale * tf.reduce_mean(tf.get_collection(tf.GraphKeys.REGULARIZATION_LOSSES)) | [
"def",
"sg_regularizer_loss",
"(",
"scale",
"=",
"1.0",
")",
":",
"return",
"scale",
"*",
"tf",
".",
"reduce_mean",
"(",
"tf",
".",
"get_collection",
"(",
"tf",
".",
"GraphKeys",
".",
"REGULARIZATION_LOSSES",
")",
")"
] | r""" Get regularizer losss
Args:
scale: A scalar. A weight applied to regularizer loss | [
"r",
"Get",
"regularizer",
"losss"
] | d2c039954777c7fbe3eb0c2ae40c45c9854deb40 | https://github.com/buriburisuri/sugartensor/blob/d2c039954777c7fbe3eb0c2ae40c45c9854deb40/sugartensor/sg_train.py#L376-L382 |
13,417 | buriburisuri/sugartensor | sugartensor/sg_net.py | sg_densenet_layer | def sg_densenet_layer(x, opt):
r"""Applies basic architecture of densenet layer.
Note that the fc layers in the original architecture
will be replaced with fully convolutional layers.
For convenience, We still call them fc layers, though.
Args:
x: A `Tensor`.
opt:
dim: An... | python | def sg_densenet_layer(x, opt):
r"""Applies basic architecture of densenet layer.
Note that the fc layers in the original architecture
will be replaced with fully convolutional layers.
For convenience, We still call them fc layers, though.
Args:
x: A `Tensor`.
opt:
dim: An... | [
"def",
"sg_densenet_layer",
"(",
"x",
",",
"opt",
")",
":",
"assert",
"opt",
".",
"dim",
"is",
"not",
"None",
",",
"'dim is mandatory.'",
"assert",
"opt",
".",
"num",
"is",
"not",
"None",
",",
"'num is mandatory.'",
"# default stride",
"opt",
"+=",
"tf",
"... | r"""Applies basic architecture of densenet layer.
Note that the fc layers in the original architecture
will be replaced with fully convolutional layers.
For convenience, We still call them fc layers, though.
Args:
x: A `Tensor`.
opt:
dim: An integer. Dimension for this resnet... | [
"r",
"Applies",
"basic",
"architecture",
"of",
"densenet",
"layer",
"."
] | d2c039954777c7fbe3eb0c2ae40c45c9854deb40 | https://github.com/buriburisuri/sugartensor/blob/d2c039954777c7fbe3eb0c2ae40c45c9854deb40/sugartensor/sg_net.py#L432-L480 |
13,418 | thanethomson/statik | statik/utils.py | deep_merge_dict | def deep_merge_dict(a, b):
"""Deep merges dictionary b into dictionary a."""
if not isinstance(a, dict):
raise TypeError("a must be a dict, but found %s" % a.__class__.__name__)
if not isinstance(b, dict):
raise TypeError("b must be a dict, but found %s" % b.__class__.__name__)
_a = cop... | python | def deep_merge_dict(a, b):
"""Deep merges dictionary b into dictionary a."""
if not isinstance(a, dict):
raise TypeError("a must be a dict, but found %s" % a.__class__.__name__)
if not isinstance(b, dict):
raise TypeError("b must be a dict, but found %s" % b.__class__.__name__)
_a = cop... | [
"def",
"deep_merge_dict",
"(",
"a",
",",
"b",
")",
":",
"if",
"not",
"isinstance",
"(",
"a",
",",
"dict",
")",
":",
"raise",
"TypeError",
"(",
"\"a must be a dict, but found %s\"",
"%",
"a",
".",
"__class__",
".",
"__name__",
")",
"if",
"not",
"isinstance"... | Deep merges dictionary b into dictionary a. | [
"Deep",
"merges",
"dictionary",
"b",
"into",
"dictionary",
"a",
"."
] | 56b1b5a2cb05a97afa81f428bfcefc833e935b8d | https://github.com/thanethomson/statik/blob/56b1b5a2cb05a97afa81f428bfcefc833e935b8d/statik/utils.py#L102-L124 |
13,419 | thanethomson/statik | statik/utils.py | copy_file_if_modified | def copy_file_if_modified(src_path, dest_path):
"""Only copies the file from the source path to the destination path if it doesn't exist yet or it has
been modified. Intended to provide something of an optimisation when a project has large trees of assets."""
# if the destination path is a directory, delet... | python | def copy_file_if_modified(src_path, dest_path):
"""Only copies the file from the source path to the destination path if it doesn't exist yet or it has
been modified. Intended to provide something of an optimisation when a project has large trees of assets."""
# if the destination path is a directory, delet... | [
"def",
"copy_file_if_modified",
"(",
"src_path",
",",
"dest_path",
")",
":",
"# if the destination path is a directory, delete it completely - we assume here we are",
"# writing a file to the filesystem",
"if",
"os",
".",
"path",
".",
"isdir",
"(",
"dest_path",
")",
":",
"shu... | Only copies the file from the source path to the destination path if it doesn't exist yet or it has
been modified. Intended to provide something of an optimisation when a project has large trees of assets. | [
"Only",
"copies",
"the",
"file",
"from",
"the",
"source",
"path",
"to",
"the",
"destination",
"path",
"if",
"it",
"doesn",
"t",
"exist",
"yet",
"or",
"it",
"has",
"been",
"modified",
".",
"Intended",
"to",
"provide",
"something",
"of",
"an",
"optimisation"... | 56b1b5a2cb05a97afa81f428bfcefc833e935b8d | https://github.com/thanethomson/statik/blob/56b1b5a2cb05a97afa81f428bfcefc833e935b8d/statik/utils.py#L141-L163 |
13,420 | thanethomson/statik | statik/utils.py | get_url_file_ext | def get_url_file_ext(url):
"""Attempts to extract the file extension from the given URL."""
# get the last part of the path component
filename = url.split('/')[-1]
name, ext = os.path.splitext(filename)
# handle case of files with leading dot
if not ext and name and name[0] == '.':
ext ... | python | def get_url_file_ext(url):
"""Attempts to extract the file extension from the given URL."""
# get the last part of the path component
filename = url.split('/')[-1]
name, ext = os.path.splitext(filename)
# handle case of files with leading dot
if not ext and name and name[0] == '.':
ext ... | [
"def",
"get_url_file_ext",
"(",
"url",
")",
":",
"# get the last part of the path component",
"filename",
"=",
"url",
".",
"split",
"(",
"'/'",
")",
"[",
"-",
"1",
"]",
"name",
",",
"ext",
"=",
"os",
".",
"path",
".",
"splitext",
"(",
"filename",
")",
"#... | Attempts to extract the file extension from the given URL. | [
"Attempts",
"to",
"extract",
"the",
"file",
"extension",
"from",
"the",
"given",
"URL",
"."
] | 56b1b5a2cb05a97afa81f428bfcefc833e935b8d | https://github.com/thanethomson/statik/blob/56b1b5a2cb05a97afa81f428bfcefc833e935b8d/statik/utils.py#L195-L205 |
13,421 | thanethomson/statik | statik/utils.py | generate_quickstart | def generate_quickstart(project_path):
"""Generates all of the basic paths for a Statik project within the given project path. If the project path
doesn't exist, it will be created."""
ensure_path_exists(project_path)
ensure_file_exists(os.path.join(project_path, "config.yml"), DEFAULT_CONFIG_CONTENT)
... | python | def generate_quickstart(project_path):
"""Generates all of the basic paths for a Statik project within the given project path. If the project path
doesn't exist, it will be created."""
ensure_path_exists(project_path)
ensure_file_exists(os.path.join(project_path, "config.yml"), DEFAULT_CONFIG_CONTENT)
... | [
"def",
"generate_quickstart",
"(",
"project_path",
")",
":",
"ensure_path_exists",
"(",
"project_path",
")",
"ensure_file_exists",
"(",
"os",
".",
"path",
".",
"join",
"(",
"project_path",
",",
"\"config.yml\"",
")",
",",
"DEFAULT_CONFIG_CONTENT",
")",
"ensure_path_... | Generates all of the basic paths for a Statik project within the given project path. If the project path
doesn't exist, it will be created. | [
"Generates",
"all",
"of",
"the",
"basic",
"paths",
"for",
"a",
"Statik",
"project",
"within",
"the",
"given",
"project",
"path",
".",
"If",
"the",
"project",
"path",
"doesn",
"t",
"exist",
"it",
"will",
"be",
"created",
"."
] | 56b1b5a2cb05a97afa81f428bfcefc833e935b8d | https://github.com/thanethomson/statik/blob/56b1b5a2cb05a97afa81f428bfcefc833e935b8d/statik/utils.py#L208-L219 |
13,422 | thanethomson/statik | statik/utils.py | get_project_config_file | def get_project_config_file(path, default_config_file_name):
"""Attempts to extract the project config file's absolute path from the given path. If the path is a
directory, it automatically assumes a "config.yml" file will be in that directory. If the path is to
a .yml file, it assumes that that is the root... | python | def get_project_config_file(path, default_config_file_name):
"""Attempts to extract the project config file's absolute path from the given path. If the path is a
directory, it automatically assumes a "config.yml" file will be in that directory. If the path is to
a .yml file, it assumes that that is the root... | [
"def",
"get_project_config_file",
"(",
"path",
",",
"default_config_file_name",
")",
":",
"_path",
",",
"_config_file_path",
"=",
"None",
",",
"None",
"path",
"=",
"os",
".",
"path",
".",
"abspath",
"(",
"path",
")",
"if",
"os",
".",
"path",
".",
"isdir",
... | Attempts to extract the project config file's absolute path from the given path. If the path is a
directory, it automatically assumes a "config.yml" file will be in that directory. If the path is to
a .yml file, it assumes that that is the root configuration file for the project. | [
"Attempts",
"to",
"extract",
"the",
"project",
"config",
"file",
"s",
"absolute",
"path",
"from",
"the",
"given",
"path",
".",
"If",
"the",
"path",
"is",
"a",
"directory",
"it",
"automatically",
"assumes",
"a",
"config",
".",
"yml",
"file",
"will",
"be",
... | 56b1b5a2cb05a97afa81f428bfcefc833e935b8d | https://github.com/thanethomson/statik/blob/56b1b5a2cb05a97afa81f428bfcefc833e935b8d/statik/utils.py#L259-L276 |
13,423 | thanethomson/statik | statik/utils.py | strip_el_text | def strip_el_text(el, max_depth=0, cur_depth=0):
"""Recursively strips the plain text out of the given XML etree element up to the desired depth.
Args:
el: The etree element to scan.
max_depth: The depth to which to recursively strip text (default: 0).
cur_depth: The current recursive d... | python | def strip_el_text(el, max_depth=0, cur_depth=0):
"""Recursively strips the plain text out of the given XML etree element up to the desired depth.
Args:
el: The etree element to scan.
max_depth: The depth to which to recursively strip text (default: 0).
cur_depth: The current recursive d... | [
"def",
"strip_el_text",
"(",
"el",
",",
"max_depth",
"=",
"0",
",",
"cur_depth",
"=",
"0",
")",
":",
"# text in front of any child elements",
"el_text",
"=",
"strip_str",
"(",
"el",
".",
"text",
"if",
"el",
".",
"text",
"is",
"not",
"None",
"else",
"\"\"",... | Recursively strips the plain text out of the given XML etree element up to the desired depth.
Args:
el: The etree element to scan.
max_depth: The depth to which to recursively strip text (default: 0).
cur_depth: The current recursive depth to which we've scanned so far.
Returns:
... | [
"Recursively",
"strips",
"the",
"plain",
"text",
"out",
"of",
"the",
"given",
"XML",
"etree",
"element",
"up",
"to",
"the",
"desired",
"depth",
"."
] | 56b1b5a2cb05a97afa81f428bfcefc833e935b8d | https://github.com/thanethomson/statik/blob/56b1b5a2cb05a97afa81f428bfcefc833e935b8d/statik/utils.py#L303-L333 |
13,424 | thanethomson/statik | statik/utils.py | find_first_file_with_ext | def find_first_file_with_ext(base_paths, prefix, exts):
"""Runs through the given list of file extensions and returns the first file with the given base
path and extension combination that actually exists.
Args:
base_paths: The base paths in which to search for files.
prefix: The filename p... | python | def find_first_file_with_ext(base_paths, prefix, exts):
"""Runs through the given list of file extensions and returns the first file with the given base
path and extension combination that actually exists.
Args:
base_paths: The base paths in which to search for files.
prefix: The filename p... | [
"def",
"find_first_file_with_ext",
"(",
"base_paths",
",",
"prefix",
",",
"exts",
")",
":",
"for",
"base_path",
"in",
"base_paths",
":",
"for",
"ext",
"in",
"exts",
":",
"filename",
"=",
"os",
".",
"path",
".",
"join",
"(",
"base_path",
",",
"\"%s%s\"",
... | Runs through the given list of file extensions and returns the first file with the given base
path and extension combination that actually exists.
Args:
base_paths: The base paths in which to search for files.
prefix: The filename prefix of the file for which to search.
exts: An ordered... | [
"Runs",
"through",
"the",
"given",
"list",
"of",
"file",
"extensions",
"and",
"returns",
"the",
"first",
"file",
"with",
"the",
"given",
"base",
"path",
"and",
"extension",
"combination",
"that",
"actually",
"exists",
"."
] | 56b1b5a2cb05a97afa81f428bfcefc833e935b8d | https://github.com/thanethomson/statik/blob/56b1b5a2cb05a97afa81f428bfcefc833e935b8d/statik/utils.py#L336-L357 |
13,425 | thanethomson/statik | statik/utils.py | find_duplicates_in_array | def find_duplicates_in_array(array):
"""Runs through the array and returns the elements that contain
more than one duplicate
Args:
array: The array to check for duplicates.
Returns:
Array of the elements that are duplicates. Returns empty list if
there are no duplicates.
""... | python | def find_duplicates_in_array(array):
"""Runs through the array and returns the elements that contain
more than one duplicate
Args:
array: The array to check for duplicates.
Returns:
Array of the elements that are duplicates. Returns empty list if
there are no duplicates.
""... | [
"def",
"find_duplicates_in_array",
"(",
"array",
")",
":",
"duplicates",
"=",
"[",
"]",
"non_duplicates",
"=",
"[",
"]",
"if",
"len",
"(",
"array",
")",
"!=",
"len",
"(",
"set",
"(",
"array",
")",
")",
":",
"for",
"item",
"in",
"array",
":",
"if",
... | Runs through the array and returns the elements that contain
more than one duplicate
Args:
array: The array to check for duplicates.
Returns:
Array of the elements that are duplicates. Returns empty list if
there are no duplicates. | [
"Runs",
"through",
"the",
"array",
"and",
"returns",
"the",
"elements",
"that",
"contain",
"more",
"than",
"one",
"duplicate"
] | 56b1b5a2cb05a97afa81f428bfcefc833e935b8d | https://github.com/thanethomson/statik/blob/56b1b5a2cb05a97afa81f428bfcefc833e935b8d/statik/utils.py#L365-L386 |
13,426 | thanethomson/statik | setup.py | read_requirements | def read_requirements(filename):
"""
Parse a requirements file.
Accepts vcs+ links, and places the URL into
`DEPENDENCY_LINKS`.
:return: list of str for each package
"""
data = []
for line in read_file(filename):
line = line.strip()
if not line or line.startswith('#'):
... | python | def read_requirements(filename):
"""
Parse a requirements file.
Accepts vcs+ links, and places the URL into
`DEPENDENCY_LINKS`.
:return: list of str for each package
"""
data = []
for line in read_file(filename):
line = line.strip()
if not line or line.startswith('#'):
... | [
"def",
"read_requirements",
"(",
"filename",
")",
":",
"data",
"=",
"[",
"]",
"for",
"line",
"in",
"read_file",
"(",
"filename",
")",
":",
"line",
"=",
"line",
".",
"strip",
"(",
")",
"if",
"not",
"line",
"or",
"line",
".",
"startswith",
"(",
"'#'",
... | Parse a requirements file.
Accepts vcs+ links, and places the URL into
`DEPENDENCY_LINKS`.
:return: list of str for each package | [
"Parse",
"a",
"requirements",
"file",
"."
] | 56b1b5a2cb05a97afa81f428bfcefc833e935b8d | https://github.com/thanethomson/statik/blob/56b1b5a2cb05a97afa81f428bfcefc833e935b8d/setup.py#L22-L49 |
13,427 | thanethomson/statik | statik/models.py | StatikModel.find_additional_rels | def find_additional_rels(self, all_models):
"""Attempts to scan for additional relationship fields for this model based on all of the other models'
structures and relationships.
"""
for model_name, model in iteritems(all_models):
if model_name != self.name:
fo... | python | def find_additional_rels(self, all_models):
"""Attempts to scan for additional relationship fields for this model based on all of the other models'
structures and relationships.
"""
for model_name, model in iteritems(all_models):
if model_name != self.name:
fo... | [
"def",
"find_additional_rels",
"(",
"self",
",",
"all_models",
")",
":",
"for",
"model_name",
",",
"model",
"in",
"iteritems",
"(",
"all_models",
")",
":",
"if",
"model_name",
"!=",
"self",
".",
"name",
":",
"for",
"field_name",
"in",
"model",
".",
"field_... | Attempts to scan for additional relationship fields for this model based on all of the other models'
structures and relationships. | [
"Attempts",
"to",
"scan",
"for",
"additional",
"relationship",
"fields",
"for",
"this",
"model",
"based",
"on",
"all",
"of",
"the",
"other",
"models",
"structures",
"and",
"relationships",
"."
] | 56b1b5a2cb05a97afa81f428bfcefc833e935b8d | https://github.com/thanethomson/statik/blob/56b1b5a2cb05a97afa81f428bfcefc833e935b8d/statik/models.py#L73-L96 |
13,428 | thanethomson/statik | statik/database.py | StatikDatabase.create_db | def create_db(self, models):
"""Creates the in-memory SQLite database from the model
configuration."""
# first create the table definitions
self.tables = dict(
[
(model_name, self.create_model_table(model))
for model_name, model in iteritems(mo... | python | def create_db(self, models):
"""Creates the in-memory SQLite database from the model
configuration."""
# first create the table definitions
self.tables = dict(
[
(model_name, self.create_model_table(model))
for model_name, model in iteritems(mo... | [
"def",
"create_db",
"(",
"self",
",",
"models",
")",
":",
"# first create the table definitions",
"self",
".",
"tables",
"=",
"dict",
"(",
"[",
"(",
"model_name",
",",
"self",
".",
"create_model_table",
"(",
"model",
")",
")",
"for",
"model_name",
",",
"mode... | Creates the in-memory SQLite database from the model
configuration. | [
"Creates",
"the",
"in",
"-",
"memory",
"SQLite",
"database",
"from",
"the",
"model",
"configuration",
"."
] | 56b1b5a2cb05a97afa81f428bfcefc833e935b8d | https://github.com/thanethomson/statik/blob/56b1b5a2cb05a97afa81f428bfcefc833e935b8d/statik/database.py#L106-L125 |
13,429 | thanethomson/statik | statik/database.py | StatikDatabase.sort_models | def sort_models(self):
"""Sorts the database models appropriately based on their relationships so that we load our data
in the appropriate order.
Returns:
A sorted list containing the names of the models.
"""
model_names = [
table.name for table in self.B... | python | def sort_models(self):
"""Sorts the database models appropriately based on their relationships so that we load our data
in the appropriate order.
Returns:
A sorted list containing the names of the models.
"""
model_names = [
table.name for table in self.B... | [
"def",
"sort_models",
"(",
"self",
")",
":",
"model_names",
"=",
"[",
"table",
".",
"name",
"for",
"table",
"in",
"self",
".",
"Base",
".",
"metadata",
".",
"sorted_tables",
"if",
"table",
".",
"name",
"in",
"self",
".",
"models",
"]",
"logger",
".",
... | Sorts the database models appropriately based on their relationships so that we load our data
in the appropriate order.
Returns:
A sorted list containing the names of the models. | [
"Sorts",
"the",
"database",
"models",
"appropriately",
"based",
"on",
"their",
"relationships",
"so",
"that",
"we",
"load",
"our",
"data",
"in",
"the",
"appropriate",
"order",
"."
] | 56b1b5a2cb05a97afa81f428bfcefc833e935b8d | https://github.com/thanethomson/statik/blob/56b1b5a2cb05a97afa81f428bfcefc833e935b8d/statik/database.py#L141-L178 |
13,430 | thanethomson/statik | statik/database.py | StatikDatabase.create_model_table | def create_model_table(self, model):
"""Creates the table for the given model.
Args:
model: A StatikModel instance.
Returns:
A SQLAlchemy model instance for the table corresponding to this
particular model.
"""
try:
return db_mode... | python | def create_model_table(self, model):
"""Creates the table for the given model.
Args:
model: A StatikModel instance.
Returns:
A SQLAlchemy model instance for the table corresponding to this
particular model.
"""
try:
return db_mode... | [
"def",
"create_model_table",
"(",
"self",
",",
"model",
")",
":",
"try",
":",
"return",
"db_model_factory",
"(",
"self",
".",
"Base",
",",
"model",
",",
"self",
".",
"models",
")",
"except",
"Exception",
"as",
"exc",
":",
"raise",
"ModelError",
"(",
"mod... | Creates the table for the given model.
Args:
model: A StatikModel instance.
Returns:
A SQLAlchemy model instance for the table corresponding to this
particular model. | [
"Creates",
"the",
"table",
"for",
"the",
"given",
"model",
"."
] | 56b1b5a2cb05a97afa81f428bfcefc833e935b8d | https://github.com/thanethomson/statik/blob/56b1b5a2cb05a97afa81f428bfcefc833e935b8d/statik/database.py#L180-L198 |
13,431 | thanethomson/statik | statik/database.py | StatikDatabase.load_model_data | def load_model_data(self, path, model):
"""Loads the data for the specified model from the given path.
"""
if os.path.isdir(path):
# try find a model data collection
if os.path.isfile(os.path.join(path, '_all.yml')):
self.load_model_data_collection(path, m... | python | def load_model_data(self, path, model):
"""Loads the data for the specified model from the given path.
"""
if os.path.isdir(path):
# try find a model data collection
if os.path.isfile(os.path.join(path, '_all.yml')):
self.load_model_data_collection(path, m... | [
"def",
"load_model_data",
"(",
"self",
",",
"path",
",",
"model",
")",
":",
"if",
"os",
".",
"path",
".",
"isdir",
"(",
"path",
")",
":",
"# try find a model data collection",
"if",
"os",
".",
"path",
".",
"isfile",
"(",
"os",
".",
"path",
".",
"join",... | Loads the data for the specified model from the given path. | [
"Loads",
"the",
"data",
"for",
"the",
"specified",
"model",
"from",
"the",
"given",
"path",
"."
] | 56b1b5a2cb05a97afa81f428bfcefc833e935b8d | https://github.com/thanethomson/statik/blob/56b1b5a2cb05a97afa81f428bfcefc833e935b8d/statik/database.py#L200-L208 |
13,432 | thanethomson/statik | statik/database.py | StatikDatabase.query | def query(self, query, additional_locals=None, safe_mode=False):
"""Executes the given SQLAlchemy query string.
Args:
query: The SQLAlchemy ORM query (or Python code) to be executed.
additional_locals: Any additional local variables to inject into the execution context
... | python | def query(self, query, additional_locals=None, safe_mode=False):
"""Executes the given SQLAlchemy query string.
Args:
query: The SQLAlchemy ORM query (or Python code) to be executed.
additional_locals: Any additional local variables to inject into the execution context
... | [
"def",
"query",
"(",
"self",
",",
"query",
",",
"additional_locals",
"=",
"None",
",",
"safe_mode",
"=",
"False",
")",
":",
"logger",
".",
"debug",
"(",
"\"Attempting to execute database query: %s\"",
",",
"query",
")",
"if",
"safe_mode",
"and",
"not",
"isinst... | Executes the given SQLAlchemy query string.
Args:
query: The SQLAlchemy ORM query (or Python code) to be executed.
additional_locals: Any additional local variables to inject into the execution context
when executing the query.
safe_mode: Boolean value indica... | [
"Executes",
"the",
"given",
"SQLAlchemy",
"query",
"string",
"."
] | 56b1b5a2cb05a97afa81f428bfcefc833e935b8d | https://github.com/thanethomson/statik/blob/56b1b5a2cb05a97afa81f428bfcefc833e935b8d/statik/database.py#L328-L367 |
13,433 | thanethomson/statik | statik/generator.py | generate | def generate(input_path, output_path=None, in_memory=False, safe_mode=False, error_context=None):
"""Executes the Statik site generator using the given parameters.
"""
project = StatikProject(input_path, safe_mode=safe_mode, error_context=error_context)
return project.generate(output_path=output_path, i... | python | def generate(input_path, output_path=None, in_memory=False, safe_mode=False, error_context=None):
"""Executes the Statik site generator using the given parameters.
"""
project = StatikProject(input_path, safe_mode=safe_mode, error_context=error_context)
return project.generate(output_path=output_path, i... | [
"def",
"generate",
"(",
"input_path",
",",
"output_path",
"=",
"None",
",",
"in_memory",
"=",
"False",
",",
"safe_mode",
"=",
"False",
",",
"error_context",
"=",
"None",
")",
":",
"project",
"=",
"StatikProject",
"(",
"input_path",
",",
"safe_mode",
"=",
"... | Executes the Statik site generator using the given parameters. | [
"Executes",
"the",
"Statik",
"site",
"generator",
"using",
"the",
"given",
"parameters",
"."
] | 56b1b5a2cb05a97afa81f428bfcefc833e935b8d | https://github.com/thanethomson/statik/blob/56b1b5a2cb05a97afa81f428bfcefc833e935b8d/statik/generator.py#L11-L15 |
13,434 | thanethomson/statik | statik/project.py | StatikProject.generate | def generate(self, output_path=None, in_memory=False):
"""Executes the Statik project generator.
Args:
output_path: The path to which to write output files.
in_memory: Whether or not to generate the results in memory. If True, this will
generate the output result... | python | def generate(self, output_path=None, in_memory=False):
"""Executes the Statik project generator.
Args:
output_path: The path to which to write output files.
in_memory: Whether or not to generate the results in memory. If True, this will
generate the output result... | [
"def",
"generate",
"(",
"self",
",",
"output_path",
"=",
"None",
",",
"in_memory",
"=",
"False",
")",
":",
"result",
"=",
"dict",
"(",
")",
"if",
"in_memory",
"else",
"0",
"logger",
".",
"info",
"(",
"\"Generating Statik build...\"",
")",
"try",
":",
"if... | Executes the Statik project generator.
Args:
output_path: The path to which to write output files.
in_memory: Whether or not to generate the results in memory. If True, this will
generate the output result as a dictionary. If False, this will write the output
... | [
"Executes",
"the",
"Statik",
"project",
"generator",
"."
] | 56b1b5a2cb05a97afa81f428bfcefc833e935b8d | https://github.com/thanethomson/statik/blob/56b1b5a2cb05a97afa81f428bfcefc833e935b8d/statik/project.py#L71-L156 |
13,435 | thanethomson/statik | statik/project.py | StatikProject.load_views | def load_views(self):
"""Loads the views for this project from the project directory
structure."""
view_path = os.path.join(self.path, StatikProject.VIEWS_DIR)
logger.debug("Loading views from: %s", view_path)
if not os.path.isdir(view_path):
raise MissingProjectFolde... | python | def load_views(self):
"""Loads the views for this project from the project directory
structure."""
view_path = os.path.join(self.path, StatikProject.VIEWS_DIR)
logger.debug("Loading views from: %s", view_path)
if not os.path.isdir(view_path):
raise MissingProjectFolde... | [
"def",
"load_views",
"(",
"self",
")",
":",
"view_path",
"=",
"os",
".",
"path",
".",
"join",
"(",
"self",
".",
"path",
",",
"StatikProject",
".",
"VIEWS_DIR",
")",
"logger",
".",
"debug",
"(",
"\"Loading views from: %s\"",
",",
"view_path",
")",
"if",
"... | Loads the views for this project from the project directory
structure. | [
"Loads",
"the",
"views",
"for",
"this",
"project",
"from",
"the",
"project",
"directory",
"structure",
"."
] | 56b1b5a2cb05a97afa81f428bfcefc833e935b8d | https://github.com/thanethomson/statik/blob/56b1b5a2cb05a97afa81f428bfcefc833e935b8d/statik/project.py#L181-L203 |
13,436 | thanethomson/statik | statik/project.py | StatikProject.process_views | def process_views(self):
"""Processes the loaded views to generate the required output data."""
output = {}
logger.debug("Processing %d view(s)...", len(self.views))
for view_name, view in iteritems(self.views):
try:
output = deep_merge_dict(
... | python | def process_views(self):
"""Processes the loaded views to generate the required output data."""
output = {}
logger.debug("Processing %d view(s)...", len(self.views))
for view_name, view in iteritems(self.views):
try:
output = deep_merge_dict(
... | [
"def",
"process_views",
"(",
"self",
")",
":",
"output",
"=",
"{",
"}",
"logger",
".",
"debug",
"(",
"\"Processing %d view(s)...\"",
",",
"len",
"(",
"self",
".",
"views",
")",
")",
"for",
"view_name",
",",
"view",
"in",
"iteritems",
"(",
"self",
".",
... | Processes the loaded views to generate the required output data. | [
"Processes",
"the",
"loaded",
"views",
"to",
"generate",
"the",
"required",
"output",
"data",
"."
] | 56b1b5a2cb05a97afa81f428bfcefc833e935b8d | https://github.com/thanethomson/statik/blob/56b1b5a2cb05a97afa81f428bfcefc833e935b8d/statik/project.py#L243-L268 |
13,437 | thanethomson/statik | statik/project.py | StatikProject.dump_in_memory_result | def dump_in_memory_result(self, result, output_path):
"""Recursively dumps the result of our processing into files within the
given output path.
Args:
result: The in-memory result of our processing.
output_path: Full path to the folder into which to dump the files.
... | python | def dump_in_memory_result(self, result, output_path):
"""Recursively dumps the result of our processing into files within the
given output path.
Args:
result: The in-memory result of our processing.
output_path: Full path to the folder into which to dump the files.
... | [
"def",
"dump_in_memory_result",
"(",
"self",
",",
"result",
",",
"output_path",
")",
":",
"file_count",
"=",
"0",
"logger",
".",
"debug",
"(",
"\"Dumping in-memory processing results to output folder: %s\"",
",",
"output_path",
")",
"for",
"k",
",",
"v",
"in",
"it... | Recursively dumps the result of our processing into files within the
given output path.
Args:
result: The in-memory result of our processing.
output_path: Full path to the folder into which to dump the files.
Returns:
The number of files generated (integer). | [
"Recursively",
"dumps",
"the",
"result",
"of",
"our",
"processing",
"into",
"files",
"within",
"the",
"given",
"output",
"path",
"."
] | 56b1b5a2cb05a97afa81f428bfcefc833e935b8d | https://github.com/thanethomson/statik/blob/56b1b5a2cb05a97afa81f428bfcefc833e935b8d/statik/project.py#L270-L300 |
13,438 | thanethomson/statik | statik/project.py | StatikProject.copy_assets | def copy_assets(self, output_path):
"""Copies all asset files from the source path to the destination
path. If no such source path exists, no asset copying will be performed.
"""
src_paths = []
# if we have a theme
if self.config.theme is not None:
# assume i... | python | def copy_assets(self, output_path):
"""Copies all asset files from the source path to the destination
path. If no such source path exists, no asset copying will be performed.
"""
src_paths = []
# if we have a theme
if self.config.theme is not None:
# assume i... | [
"def",
"copy_assets",
"(",
"self",
",",
"output_path",
")",
":",
"src_paths",
"=",
"[",
"]",
"# if we have a theme",
"if",
"self",
".",
"config",
".",
"theme",
"is",
"not",
"None",
":",
"# assume it's in the folder: \"themes/theme_name/assets\"",
"src_paths",
".",
... | Copies all asset files from the source path to the destination
path. If no such source path exists, no asset copying will be performed. | [
"Copies",
"all",
"asset",
"files",
"from",
"the",
"source",
"path",
"to",
"the",
"destination",
"path",
".",
"If",
"no",
"such",
"source",
"path",
"exists",
"no",
"asset",
"copying",
"will",
"be",
"performed",
"."
] | 56b1b5a2cb05a97afa81f428bfcefc833e935b8d | https://github.com/thanethomson/statik/blob/56b1b5a2cb05a97afa81f428bfcefc833e935b8d/statik/project.py#L302-L340 |
13,439 | thanethomson/statik | statik/autogen.py | autogen | def autogen(project_path):
"""Autogenerates views and templates for all the models in the project."""
generate_quickstart(project_path)
project = StatikProject(project_path)
project.config = StatikConfig(project.config_file_path)
models = list(project.load_models().values())
logger.info('Crea... | python | def autogen(project_path):
"""Autogenerates views and templates for all the models in the project."""
generate_quickstart(project_path)
project = StatikProject(project_path)
project.config = StatikConfig(project.config_file_path)
models = list(project.load_models().values())
logger.info('Crea... | [
"def",
"autogen",
"(",
"project_path",
")",
":",
"generate_quickstart",
"(",
"project_path",
")",
"project",
"=",
"StatikProject",
"(",
"project_path",
")",
"project",
".",
"config",
"=",
"StatikConfig",
"(",
"project",
".",
"config_file_path",
")",
"models",
"=... | Autogenerates views and templates for all the models in the project. | [
"Autogenerates",
"views",
"and",
"templates",
"for",
"all",
"the",
"models",
"in",
"the",
"project",
"."
] | 56b1b5a2cb05a97afa81f428bfcefc833e935b8d | https://github.com/thanethomson/statik/blob/56b1b5a2cb05a97afa81f428bfcefc833e935b8d/statik/autogen.py#L17-L51 |
13,440 | thanethomson/statik | statik/autogen.py | generate_yaml_file | def generate_yaml_file(filename, contents):
"""Creates a yaml file with the given content."""
with open(filename, 'w') as file:
file.write(yaml.dump(contents, default_flow_style=False)) | python | def generate_yaml_file(filename, contents):
"""Creates a yaml file with the given content."""
with open(filename, 'w') as file:
file.write(yaml.dump(contents, default_flow_style=False)) | [
"def",
"generate_yaml_file",
"(",
"filename",
",",
"contents",
")",
":",
"with",
"open",
"(",
"filename",
",",
"'w'",
")",
"as",
"file",
":",
"file",
".",
"write",
"(",
"yaml",
".",
"dump",
"(",
"contents",
",",
"default_flow_style",
"=",
"False",
")",
... | Creates a yaml file with the given content. | [
"Creates",
"a",
"yaml",
"file",
"with",
"the",
"given",
"content",
"."
] | 56b1b5a2cb05a97afa81f428bfcefc833e935b8d | https://github.com/thanethomson/statik/blob/56b1b5a2cb05a97afa81f428bfcefc833e935b8d/statik/autogen.py#L54-L57 |
13,441 | thanethomson/statik | statik/autogen.py | generate_index_file | def generate_index_file(filename):
"""Constructs a default home page for the project."""
with open(filename, 'w') as file:
content = open(os.path.join(os.path.dirname(__file__), 'templates/index_page.html'), 'r').read()
file.write(content) | python | def generate_index_file(filename):
"""Constructs a default home page for the project."""
with open(filename, 'w') as file:
content = open(os.path.join(os.path.dirname(__file__), 'templates/index_page.html'), 'r').read()
file.write(content) | [
"def",
"generate_index_file",
"(",
"filename",
")",
":",
"with",
"open",
"(",
"filename",
",",
"'w'",
")",
"as",
"file",
":",
"content",
"=",
"open",
"(",
"os",
".",
"path",
".",
"join",
"(",
"os",
".",
"path",
".",
"dirname",
"(",
"__file__",
")",
... | Constructs a default home page for the project. | [
"Constructs",
"a",
"default",
"home",
"page",
"for",
"the",
"project",
"."
] | 56b1b5a2cb05a97afa81f428bfcefc833e935b8d | https://github.com/thanethomson/statik/blob/56b1b5a2cb05a97afa81f428bfcefc833e935b8d/statik/autogen.py#L60-L64 |
13,442 | thanethomson/statik | statik/autogen.py | generate_model_file | def generate_model_file(filename, project, model, fields):
"""Creates a webpage for a given instance of a model."""
for field in fields:
field.type = field.__class__.__name__
content = open(os.path.join(os.path.dirname(__file__), 'templates/model_page.html'), 'r').read()
engine = StatikTemplat... | python | def generate_model_file(filename, project, model, fields):
"""Creates a webpage for a given instance of a model."""
for field in fields:
field.type = field.__class__.__name__
content = open(os.path.join(os.path.dirname(__file__), 'templates/model_page.html'), 'r').read()
engine = StatikTemplat... | [
"def",
"generate_model_file",
"(",
"filename",
",",
"project",
",",
"model",
",",
"fields",
")",
":",
"for",
"field",
"in",
"fields",
":",
"field",
".",
"type",
"=",
"field",
".",
"__class__",
".",
"__name__",
"content",
"=",
"open",
"(",
"os",
".",
"p... | Creates a webpage for a given instance of a model. | [
"Creates",
"a",
"webpage",
"for",
"a",
"given",
"instance",
"of",
"a",
"model",
"."
] | 56b1b5a2cb05a97afa81f428bfcefc833e935b8d | https://github.com/thanethomson/statik/blob/56b1b5a2cb05a97afa81f428bfcefc833e935b8d/statik/autogen.py#L67-L84 |
13,443 | thanethomson/statik | statik/context.py | StatikContext.build_dynamic | def build_dynamic(self, db, extra=None, safe_mode=False):
"""Builds the dynamic context based on our current dynamic context entity and the given
database."""
result = dict()
for var, query in iteritems(self.dynamic):
result[var] = db.query(query, safe_mode=safe_mode, additio... | python | def build_dynamic(self, db, extra=None, safe_mode=False):
"""Builds the dynamic context based on our current dynamic context entity and the given
database."""
result = dict()
for var, query in iteritems(self.dynamic):
result[var] = db.query(query, safe_mode=safe_mode, additio... | [
"def",
"build_dynamic",
"(",
"self",
",",
"db",
",",
"extra",
"=",
"None",
",",
"safe_mode",
"=",
"False",
")",
":",
"result",
"=",
"dict",
"(",
")",
"for",
"var",
",",
"query",
"in",
"iteritems",
"(",
"self",
".",
"dynamic",
")",
":",
"result",
"[... | Builds the dynamic context based on our current dynamic context entity and the given
database. | [
"Builds",
"the",
"dynamic",
"context",
"based",
"on",
"our",
"current",
"dynamic",
"context",
"entity",
"and",
"the",
"given",
"database",
"."
] | 56b1b5a2cb05a97afa81f428bfcefc833e935b8d | https://github.com/thanethomson/statik/blob/56b1b5a2cb05a97afa81f428bfcefc833e935b8d/statik/context.py#L47-L53 |
13,444 | thanethomson/statik | statik/context.py | StatikContext.build_for_each | def build_for_each(self, db, safe_mode=False, extra=None):
"""Builds the for-each context."""
result = dict()
for var, query in iteritems(self.for_each):
result[var] = db.query(
query,
additional_locals=extra,
safe_mode=safe_mode
... | python | def build_for_each(self, db, safe_mode=False, extra=None):
"""Builds the for-each context."""
result = dict()
for var, query in iteritems(self.for_each):
result[var] = db.query(
query,
additional_locals=extra,
safe_mode=safe_mode
... | [
"def",
"build_for_each",
"(",
"self",
",",
"db",
",",
"safe_mode",
"=",
"False",
",",
"extra",
"=",
"None",
")",
":",
"result",
"=",
"dict",
"(",
")",
"for",
"var",
",",
"query",
"in",
"iteritems",
"(",
"self",
".",
"for_each",
")",
":",
"result",
... | Builds the for-each context. | [
"Builds",
"the",
"for",
"-",
"each",
"context",
"."
] | 56b1b5a2cb05a97afa81f428bfcefc833e935b8d | https://github.com/thanethomson/statik/blob/56b1b5a2cb05a97afa81f428bfcefc833e935b8d/statik/context.py#L55-L64 |
13,445 | thanethomson/statik | statik/context.py | StatikContext.build | def build(self, db=None, safe_mode=False, for_each_inst=None, extra=None):
"""Builds a dictionary that can be used as context for template rendering."""
result = copy(self.initial)
result.update(self.static)
if self.dynamic:
result.update(self.build_dynamic(db, extra=extra, s... | python | def build(self, db=None, safe_mode=False, for_each_inst=None, extra=None):
"""Builds a dictionary that can be used as context for template rendering."""
result = copy(self.initial)
result.update(self.static)
if self.dynamic:
result.update(self.build_dynamic(db, extra=extra, s... | [
"def",
"build",
"(",
"self",
",",
"db",
"=",
"None",
",",
"safe_mode",
"=",
"False",
",",
"for_each_inst",
"=",
"None",
",",
"extra",
"=",
"None",
")",
":",
"result",
"=",
"copy",
"(",
"self",
".",
"initial",
")",
"result",
".",
"update",
"(",
"sel... | Builds a dictionary that can be used as context for template rendering. | [
"Builds",
"a",
"dictionary",
"that",
"can",
"be",
"used",
"as",
"context",
"for",
"template",
"rendering",
"."
] | 56b1b5a2cb05a97afa81f428bfcefc833e935b8d | https://github.com/thanethomson/statik/blob/56b1b5a2cb05a97afa81f428bfcefc833e935b8d/statik/context.py#L66-L76 |
13,446 | thanethomson/statik | statik/templating.py | template_exception_handler | def template_exception_handler(fn, error_context, filename=None):
"""Calls the given function, attempting to catch any template-related errors, and
converts the error to a Statik TemplateError instance. Returns the result returned
by the function itself."""
error_message = None
if filename:
... | python | def template_exception_handler(fn, error_context, filename=None):
"""Calls the given function, attempting to catch any template-related errors, and
converts the error to a Statik TemplateError instance. Returns the result returned
by the function itself."""
error_message = None
if filename:
... | [
"def",
"template_exception_handler",
"(",
"fn",
",",
"error_context",
",",
"filename",
"=",
"None",
")",
":",
"error_message",
"=",
"None",
"if",
"filename",
":",
"error_context",
".",
"update",
"(",
"filename",
"=",
"filename",
")",
"try",
":",
"return",
"f... | Calls the given function, attempting to catch any template-related errors, and
converts the error to a Statik TemplateError instance. Returns the result returned
by the function itself. | [
"Calls",
"the",
"given",
"function",
"attempting",
"to",
"catch",
"any",
"template",
"-",
"related",
"errors",
"and",
"converts",
"the",
"error",
"to",
"a",
"Statik",
"TemplateError",
"instance",
".",
"Returns",
"the",
"result",
"returned",
"by",
"the",
"funct... | 56b1b5a2cb05a97afa81f428bfcefc833e935b8d | https://github.com/thanethomson/statik/blob/56b1b5a2cb05a97afa81f428bfcefc833e935b8d/statik/templating.py#L53-L70 |
13,447 | thanethomson/statik | statik/templating.py | StatikTemplateEngine.create_template | def create_template(self, s, provider_name=None):
"""Creates a template from the given string based on the specified provider or the provider with
highest precedence.
Args:
s: The string to convert to a template.
provider_name: The name of the provider to use to create t... | python | def create_template(self, s, provider_name=None):
"""Creates a template from the given string based on the specified provider or the provider with
highest precedence.
Args:
s: The string to convert to a template.
provider_name: The name of the provider to use to create t... | [
"def",
"create_template",
"(",
"self",
",",
"s",
",",
"provider_name",
"=",
"None",
")",
":",
"if",
"provider_name",
"is",
"None",
":",
"provider_name",
"=",
"self",
".",
"supported_providers",
"[",
"0",
"]",
"return",
"template_exception_handler",
"(",
"lambd... | Creates a template from the given string based on the specified provider or the provider with
highest precedence.
Args:
s: The string to convert to a template.
provider_name: The name of the provider to use to create the template. | [
"Creates",
"a",
"template",
"from",
"the",
"given",
"string",
"based",
"on",
"the",
"specified",
"provider",
"or",
"the",
"provider",
"with",
"highest",
"precedence",
"."
] | 56b1b5a2cb05a97afa81f428bfcefc833e935b8d | https://github.com/thanethomson/statik/blob/56b1b5a2cb05a97afa81f428bfcefc833e935b8d/statik/templating.py#L197-L210 |
13,448 | thanethomson/statik | statik/fields.py | construct_field | def construct_field(model_name, field_name, field_type, all_models, **kwargs):
"""Helper function to build a field from the given field name and
type.
Args:
model_name: The name of the model for which we're building this field.
field_name: The name of the field to build.
field_type:... | python | def construct_field(model_name, field_name, field_type, all_models, **kwargs):
"""Helper function to build a field from the given field name and
type.
Args:
model_name: The name of the model for which we're building this field.
field_name: The name of the field to build.
field_type:... | [
"def",
"construct_field",
"(",
"model_name",
",",
"field_name",
",",
"field_type",
",",
"all_models",
",",
"*",
"*",
"kwargs",
")",
":",
"field_type_parts",
"=",
"field_type",
".",
"split",
"(",
"'->'",
")",
"_field_type",
"=",
"field_type_parts",
"[",
"0",
... | Helper function to build a field from the given field name and
type.
Args:
model_name: The name of the model for which we're building this field.
field_name: The name of the field to build.
field_type: A string indicator as to which field type must be built.
all_models: A list c... | [
"Helper",
"function",
"to",
"build",
"a",
"field",
"from",
"the",
"given",
"field",
"name",
"and",
"type",
"."
] | 56b1b5a2cb05a97afa81f428bfcefc833e935b8d | https://github.com/thanethomson/statik/blob/56b1b5a2cb05a97afa81f428bfcefc833e935b8d/statik/fields.py#L90-L121 |
13,449 | thanethomson/statik | statik/pagination.py | paginate | def paginate(db_query, items_per_page, offset=0, start_page=1):
"""Instantiates a Paginator instance for database queries.
Args:
db_query: The SQLAlchemy database query to paginate.
items_per_page: The desired number of items per page.
offset: The number of items to skip when paginating... | python | def paginate(db_query, items_per_page, offset=0, start_page=1):
"""Instantiates a Paginator instance for database queries.
Args:
db_query: The SQLAlchemy database query to paginate.
items_per_page: The desired number of items per page.
offset: The number of items to skip when paginating... | [
"def",
"paginate",
"(",
"db_query",
",",
"items_per_page",
",",
"offset",
"=",
"0",
",",
"start_page",
"=",
"1",
")",
":",
"return",
"Paginator",
"(",
"db_query",
",",
"items_per_page",
",",
"offset",
"=",
"offset",
",",
"start_page",
"=",
"start_page",
")... | Instantiates a Paginator instance for database queries.
Args:
db_query: The SQLAlchemy database query to paginate.
items_per_page: The desired number of items per page.
offset: The number of items to skip when paginating.
start_page: The number of the first page when reporting on pa... | [
"Instantiates",
"a",
"Paginator",
"instance",
"for",
"database",
"queries",
"."
] | 56b1b5a2cb05a97afa81f428bfcefc833e935b8d | https://github.com/thanethomson/statik/blob/56b1b5a2cb05a97afa81f428bfcefc833e935b8d/statik/pagination.py#L132-L141 |
13,450 | thanethomson/statik | statik/views.py | StatikViewPath.render_reverse | def render_reverse(self, inst=None, context=None):
"""Renders the reverse URL for this path."""
rendered = self.render(inst=inst, context=context)
parts = rendered.split('/')
# we only prettify URLs for these files
if parts[-1] in ['index.html', 'index.htm']:
return (... | python | def render_reverse(self, inst=None, context=None):
"""Renders the reverse URL for this path."""
rendered = self.render(inst=inst, context=context)
parts = rendered.split('/')
# we only prettify URLs for these files
if parts[-1] in ['index.html', 'index.htm']:
return (... | [
"def",
"render_reverse",
"(",
"self",
",",
"inst",
"=",
"None",
",",
"context",
"=",
"None",
")",
":",
"rendered",
"=",
"self",
".",
"render",
"(",
"inst",
"=",
"inst",
",",
"context",
"=",
"context",
")",
"parts",
"=",
"rendered",
".",
"split",
"(",... | Renders the reverse URL for this path. | [
"Renders",
"the",
"reverse",
"URL",
"for",
"this",
"path",
"."
] | 56b1b5a2cb05a97afa81f428bfcefc833e935b8d | https://github.com/thanethomson/statik/blob/56b1b5a2cb05a97afa81f428bfcefc833e935b8d/statik/views.py#L61-L68 |
13,451 | thanethomson/statik | statik/views.py | StatikViewPath.create | def create(
cls,
path,
template_engine=None,
output_filename=None,
output_ext=None,
view_name=None
):
"""Create the relevant subclass of StatikView based on the given path variable and
parameters."""
# if it's a comp... | python | def create(
cls,
path,
template_engine=None,
output_filename=None,
output_ext=None,
view_name=None
):
"""Create the relevant subclass of StatikView based on the given path variable and
parameters."""
# if it's a comp... | [
"def",
"create",
"(",
"cls",
",",
"path",
",",
"template_engine",
"=",
"None",
",",
"output_filename",
"=",
"None",
",",
"output_ext",
"=",
"None",
",",
"view_name",
"=",
"None",
")",
":",
"# if it's a complex view",
"if",
"isinstance",
"(",
"path",
",",
"... | Create the relevant subclass of StatikView based on the given path variable and
parameters. | [
"Create",
"the",
"relevant",
"subclass",
"of",
"StatikView",
"based",
"on",
"the",
"given",
"path",
"variable",
"and",
"parameters",
"."
] | 56b1b5a2cb05a97afa81f428bfcefc833e935b8d | https://github.com/thanethomson/statik/blob/56b1b5a2cb05a97afa81f428bfcefc833e935b8d/statik/views.py#L71-L100 |
13,452 | thanethomson/statik | statik/views.py | StatikComplexViewRenderer.render | def render(self, context, db=None, safe_mode=False, extra_context=None):
"""Renders the given context using the specified database, returning a dictionary
containing path segments and rendered view contents."""
if not db:
raise MissingParameterError(
"db",
... | python | def render(self, context, db=None, safe_mode=False, extra_context=None):
"""Renders the given context using the specified database, returning a dictionary
containing path segments and rendered view contents."""
if not db:
raise MissingParameterError(
"db",
... | [
"def",
"render",
"(",
"self",
",",
"context",
",",
"db",
"=",
"None",
",",
"safe_mode",
"=",
"False",
",",
"extra_context",
"=",
"None",
")",
":",
"if",
"not",
"db",
":",
"raise",
"MissingParameterError",
"(",
"\"db\"",
",",
"context",
"=",
"self",
"."... | Renders the given context using the specified database, returning a dictionary
containing path segments and rendered view contents. | [
"Renders",
"the",
"given",
"context",
"using",
"the",
"specified",
"database",
"returning",
"a",
"dictionary",
"containing",
"path",
"segments",
"and",
"rendered",
"view",
"contents",
"."
] | 56b1b5a2cb05a97afa81f428bfcefc833e935b8d | https://github.com/thanethomson/statik/blob/56b1b5a2cb05a97afa81f428bfcefc833e935b8d/statik/views.py#L282-L310 |
13,453 | thanethomson/statik | statik/views.py | StatikView.render | def render(self, db, safe_mode=False, extra_context=None):
"""Renders this view, given the specified StatikDatabase instance."""
return self.renderer.render(
self.context,
db,
safe_mode=safe_mode,
extra_context=extra_context
) | python | def render(self, db, safe_mode=False, extra_context=None):
"""Renders this view, given the specified StatikDatabase instance."""
return self.renderer.render(
self.context,
db,
safe_mode=safe_mode,
extra_context=extra_context
) | [
"def",
"render",
"(",
"self",
",",
"db",
",",
"safe_mode",
"=",
"False",
",",
"extra_context",
"=",
"None",
")",
":",
"return",
"self",
".",
"renderer",
".",
"render",
"(",
"self",
".",
"context",
",",
"db",
",",
"safe_mode",
"=",
"safe_mode",
",",
"... | Renders this view, given the specified StatikDatabase instance. | [
"Renders",
"this",
"view",
"given",
"the",
"specified",
"StatikDatabase",
"instance",
"."
] | 56b1b5a2cb05a97afa81f428bfcefc833e935b8d | https://github.com/thanethomson/statik/blob/56b1b5a2cb05a97afa81f428bfcefc833e935b8d/statik/views.py#L399-L406 |
13,454 | goldmann/docker-squash | docker_squash/image.py | Image._validate_number_of_layers | def _validate_number_of_layers(self, number_of_layers):
"""
Makes sure that the specified number of layers to squash
is a valid number
"""
# Only positive numbers are correct
if number_of_layers <= 0:
raise SquashError(
"Number of layers to sq... | python | def _validate_number_of_layers(self, number_of_layers):
"""
Makes sure that the specified number of layers to squash
is a valid number
"""
# Only positive numbers are correct
if number_of_layers <= 0:
raise SquashError(
"Number of layers to sq... | [
"def",
"_validate_number_of_layers",
"(",
"self",
",",
"number_of_layers",
")",
":",
"# Only positive numbers are correct",
"if",
"number_of_layers",
"<=",
"0",
":",
"raise",
"SquashError",
"(",
"\"Number of layers to squash cannot be less or equal 0, provided: %s\"",
"%",
"num... | Makes sure that the specified number of layers to squash
is a valid number | [
"Makes",
"sure",
"that",
"the",
"specified",
"number",
"of",
"layers",
"to",
"squash",
"is",
"a",
"valid",
"number"
] | 89e0297942be268791aff2098b7ebfa50d82f8e8 | https://github.com/goldmann/docker-squash/blob/89e0297942be268791aff2098b7ebfa50d82f8e8/docker_squash/image.py#L125-L140 |
13,455 | goldmann/docker-squash | docker_squash/image.py | Image._files_in_layers | def _files_in_layers(self, layers, directory):
"""
Prepare a list of files in all layers
"""
files = {}
for layer in layers:
self.log.debug("Generating list of files in layer '%s'..." % layer)
tar_file = os.path.join(directory, layer, "layer.tar")
... | python | def _files_in_layers(self, layers, directory):
"""
Prepare a list of files in all layers
"""
files = {}
for layer in layers:
self.log.debug("Generating list of files in layer '%s'..." % layer)
tar_file = os.path.join(directory, layer, "layer.tar")
... | [
"def",
"_files_in_layers",
"(",
"self",
",",
"layers",
",",
"directory",
")",
":",
"files",
"=",
"{",
"}",
"for",
"layer",
"in",
"layers",
":",
"self",
".",
"log",
".",
"debug",
"(",
"\"Generating list of files in layer '%s'...\"",
"%",
"layer",
")",
"tar_fi... | Prepare a list of files in all layers | [
"Prepare",
"a",
"list",
"of",
"files",
"in",
"all",
"layers"
] | 89e0297942be268791aff2098b7ebfa50d82f8e8 | https://github.com/goldmann/docker-squash/blob/89e0297942be268791aff2098b7ebfa50d82f8e8/docker_squash/image.py#L260-L274 |
13,456 | goldmann/docker-squash | docker_squash/image.py | Image._prepare_tmp_directory | def _prepare_tmp_directory(self, tmp_dir):
""" Creates temporary directory that is used to work on layers """
if tmp_dir:
if os.path.exists(tmp_dir):
raise SquashError(
"The '%s' directory already exists, please remove it before you proceed" % tmp_dir)
... | python | def _prepare_tmp_directory(self, tmp_dir):
""" Creates temporary directory that is used to work on layers """
if tmp_dir:
if os.path.exists(tmp_dir):
raise SquashError(
"The '%s' directory already exists, please remove it before you proceed" % tmp_dir)
... | [
"def",
"_prepare_tmp_directory",
"(",
"self",
",",
"tmp_dir",
")",
":",
"if",
"tmp_dir",
":",
"if",
"os",
".",
"path",
".",
"exists",
"(",
"tmp_dir",
")",
":",
"raise",
"SquashError",
"(",
"\"The '%s' directory already exists, please remove it before you proceed\"",
... | Creates temporary directory that is used to work on layers | [
"Creates",
"temporary",
"directory",
"that",
"is",
"used",
"to",
"work",
"on",
"layers"
] | 89e0297942be268791aff2098b7ebfa50d82f8e8 | https://github.com/goldmann/docker-squash/blob/89e0297942be268791aff2098b7ebfa50d82f8e8/docker_squash/image.py#L276-L289 |
13,457 | goldmann/docker-squash | docker_squash/image.py | Image._layers_to_squash | def _layers_to_squash(self, layers, from_layer):
""" Prepares a list of layer IDs that should be squashed """
to_squash = []
to_leave = []
should_squash = True
for l in reversed(layers):
if l == from_layer:
should_squash = False
if should... | python | def _layers_to_squash(self, layers, from_layer):
""" Prepares a list of layer IDs that should be squashed """
to_squash = []
to_leave = []
should_squash = True
for l in reversed(layers):
if l == from_layer:
should_squash = False
if should... | [
"def",
"_layers_to_squash",
"(",
"self",
",",
"layers",
",",
"from_layer",
")",
":",
"to_squash",
"=",
"[",
"]",
"to_leave",
"=",
"[",
"]",
"should_squash",
"=",
"True",
"for",
"l",
"in",
"reversed",
"(",
"layers",
")",
":",
"if",
"l",
"==",
"from_laye... | Prepares a list of layer IDs that should be squashed | [
"Prepares",
"a",
"list",
"of",
"layer",
"IDs",
"that",
"should",
"be",
"squashed"
] | 89e0297942be268791aff2098b7ebfa50d82f8e8 | https://github.com/goldmann/docker-squash/blob/89e0297942be268791aff2098b7ebfa50d82f8e8/docker_squash/image.py#L319-L337 |
13,458 | goldmann/docker-squash | docker_squash/image.py | Image._save_image | def _save_image(self, image_id, directory):
""" Saves the image as a tar archive under specified name """
for x in [0, 1, 2]:
self.log.info("Saving image %s to %s directory..." %
(image_id, directory))
self.log.debug("Try #%s..." % (x + 1))
... | python | def _save_image(self, image_id, directory):
""" Saves the image as a tar archive under specified name """
for x in [0, 1, 2]:
self.log.info("Saving image %s to %s directory..." %
(image_id, directory))
self.log.debug("Try #%s..." % (x + 1))
... | [
"def",
"_save_image",
"(",
"self",
",",
"image_id",
",",
"directory",
")",
":",
"for",
"x",
"in",
"[",
"0",
",",
"1",
",",
"2",
"]",
":",
"self",
".",
"log",
".",
"info",
"(",
"\"Saving image %s to %s directory...\"",
"%",
"(",
"image_id",
",",
"direct... | Saves the image as a tar archive under specified name | [
"Saves",
"the",
"image",
"as",
"a",
"tar",
"archive",
"under",
"specified",
"name"
] | 89e0297942be268791aff2098b7ebfa50d82f8e8 | https://github.com/goldmann/docker-squash/blob/89e0297942be268791aff2098b7ebfa50d82f8e8/docker_squash/image.py#L343-L386 |
13,459 | goldmann/docker-squash | docker_squash/image.py | Image._unpack | def _unpack(self, tar_file, directory):
""" Unpacks tar archive to selected directory """
self.log.info("Unpacking %s tar file to %s directory" %
(tar_file, directory))
with tarfile.open(tar_file, 'r') as tar:
tar.extractall(path=directory)
self.log.i... | python | def _unpack(self, tar_file, directory):
""" Unpacks tar archive to selected directory """
self.log.info("Unpacking %s tar file to %s directory" %
(tar_file, directory))
with tarfile.open(tar_file, 'r') as tar:
tar.extractall(path=directory)
self.log.i... | [
"def",
"_unpack",
"(",
"self",
",",
"tar_file",
",",
"directory",
")",
":",
"self",
".",
"log",
".",
"info",
"(",
"\"Unpacking %s tar file to %s directory\"",
"%",
"(",
"tar_file",
",",
"directory",
")",
")",
"with",
"tarfile",
".",
"open",
"(",
"tar_file",
... | Unpacks tar archive to selected directory | [
"Unpacks",
"tar",
"archive",
"to",
"selected",
"directory"
] | 89e0297942be268791aff2098b7ebfa50d82f8e8 | https://github.com/goldmann/docker-squash/blob/89e0297942be268791aff2098b7ebfa50d82f8e8/docker_squash/image.py#L388-L397 |
13,460 | goldmann/docker-squash | docker_squash/image.py | Image._parse_image_name | def _parse_image_name(self, image):
"""
Parses the provided image name and splits it in the
name and tag part, if possible. If no tag is provided
'latest' is used.
"""
if ':' in image and '/' not in image.split(':')[-1]:
image_tag = image.split(':')[-1]
... | python | def _parse_image_name(self, image):
"""
Parses the provided image name and splits it in the
name and tag part, if possible. If no tag is provided
'latest' is used.
"""
if ':' in image and '/' not in image.split(':')[-1]:
image_tag = image.split(':')[-1]
... | [
"def",
"_parse_image_name",
"(",
"self",
",",
"image",
")",
":",
"if",
"':'",
"in",
"image",
"and",
"'/'",
"not",
"in",
"image",
".",
"split",
"(",
"':'",
")",
"[",
"-",
"1",
"]",
":",
"image_tag",
"=",
"image",
".",
"split",
"(",
"':'",
")",
"["... | Parses the provided image name and splits it in the
name and tag part, if possible. If no tag is provided
'latest' is used. | [
"Parses",
"the",
"provided",
"image",
"name",
"and",
"splits",
"it",
"in",
"the",
"name",
"and",
"tag",
"part",
"if",
"possible",
".",
"If",
"no",
"tag",
"is",
"provided",
"latest",
"is",
"used",
"."
] | 89e0297942be268791aff2098b7ebfa50d82f8e8 | https://github.com/goldmann/docker-squash/blob/89e0297942be268791aff2098b7ebfa50d82f8e8/docker_squash/image.py#L405-L418 |
13,461 | goldmann/docker-squash | docker_squash/image.py | Image._dump_json | def _dump_json(self, data, new_line=False):
"""
Helper function to marshal object into JSON string.
Additionally a sha256sum of the created JSON string is generated.
"""
# We do not want any spaces between keys and values in JSON
json_data = json.dumps(data, separators=(... | python | def _dump_json(self, data, new_line=False):
"""
Helper function to marshal object into JSON string.
Additionally a sha256sum of the created JSON string is generated.
"""
# We do not want any spaces between keys and values in JSON
json_data = json.dumps(data, separators=(... | [
"def",
"_dump_json",
"(",
"self",
",",
"data",
",",
"new_line",
"=",
"False",
")",
":",
"# We do not want any spaces between keys and values in JSON",
"json_data",
"=",
"json",
".",
"dumps",
"(",
"data",
",",
"separators",
"=",
"(",
"','",
",",
"':'",
")",
")"... | Helper function to marshal object into JSON string.
Additionally a sha256sum of the created JSON string is generated. | [
"Helper",
"function",
"to",
"marshal",
"object",
"into",
"JSON",
"string",
".",
"Additionally",
"a",
"sha256sum",
"of",
"the",
"created",
"JSON",
"string",
"is",
"generated",
"."
] | 89e0297942be268791aff2098b7ebfa50d82f8e8 | https://github.com/goldmann/docker-squash/blob/89e0297942be268791aff2098b7ebfa50d82f8e8/docker_squash/image.py#L420-L435 |
13,462 | goldmann/docker-squash | docker_squash/image.py | Image._move_layers | def _move_layers(self, layers, src, dest):
"""
This moves all the layers that should be copied as-is.
In other words - all layers that are not meant to be squashed will be
moved from the old image to the new image untouched.
"""
for layer in layers:
layer_id =... | python | def _move_layers(self, layers, src, dest):
"""
This moves all the layers that should be copied as-is.
In other words - all layers that are not meant to be squashed will be
moved from the old image to the new image untouched.
"""
for layer in layers:
layer_id =... | [
"def",
"_move_layers",
"(",
"self",
",",
"layers",
",",
"src",
",",
"dest",
")",
":",
"for",
"layer",
"in",
"layers",
":",
"layer_id",
"=",
"layer",
".",
"replace",
"(",
"'sha256:'",
",",
"''",
")",
"self",
".",
"log",
".",
"debug",
"(",
"\"Moving un... | This moves all the layers that should be copied as-is.
In other words - all layers that are not meant to be squashed will be
moved from the old image to the new image untouched. | [
"This",
"moves",
"all",
"the",
"layers",
"that",
"should",
"be",
"copied",
"as",
"-",
"is",
".",
"In",
"other",
"words",
"-",
"all",
"layers",
"that",
"are",
"not",
"meant",
"to",
"be",
"squashed",
"will",
"be",
"moved",
"from",
"the",
"old",
"image",
... | 89e0297942be268791aff2098b7ebfa50d82f8e8 | https://github.com/goldmann/docker-squash/blob/89e0297942be268791aff2098b7ebfa50d82f8e8/docker_squash/image.py#L475-L485 |
13,463 | goldmann/docker-squash | docker_squash/image.py | Image._marker_files | def _marker_files(self, tar, members):
"""
Searches for marker files in the specified archive.
Docker marker files are files taht have the .wh. prefix in the name.
These files mark the corresponding file to be removed (hidden) when
we start a container from the image.
""... | python | def _marker_files(self, tar, members):
"""
Searches for marker files in the specified archive.
Docker marker files are files taht have the .wh. prefix in the name.
These files mark the corresponding file to be removed (hidden) when
we start a container from the image.
""... | [
"def",
"_marker_files",
"(",
"self",
",",
"tar",
",",
"members",
")",
":",
"marker_files",
"=",
"{",
"}",
"self",
".",
"log",
".",
"debug",
"(",
"\"Searching for marker files in '%s' archive...\"",
"%",
"tar",
".",
"name",
")",
"for",
"member",
"in",
"member... | Searches for marker files in the specified archive.
Docker marker files are files taht have the .wh. prefix in the name.
These files mark the corresponding file to be removed (hidden) when
we start a container from the image. | [
"Searches",
"for",
"marker",
"files",
"in",
"the",
"specified",
"archive",
"."
] | 89e0297942be268791aff2098b7ebfa50d82f8e8 | https://github.com/goldmann/docker-squash/blob/89e0297942be268791aff2098b7ebfa50d82f8e8/docker_squash/image.py#L501-L521 |
13,464 | goldmann/docker-squash | docker_squash/image.py | Image._add_markers | def _add_markers(self, markers, tar, files_in_layers, added_symlinks):
"""
This method is responsible for adding back all markers that were not
added to the squashed layer AND files they refer to can be found in layers
we do not squash.
"""
if markers:
self.l... | python | def _add_markers(self, markers, tar, files_in_layers, added_symlinks):
"""
This method is responsible for adding back all markers that were not
added to the squashed layer AND files they refer to can be found in layers
we do not squash.
"""
if markers:
self.l... | [
"def",
"_add_markers",
"(",
"self",
",",
"markers",
",",
"tar",
",",
"files_in_layers",
",",
"added_symlinks",
")",
":",
"if",
"markers",
":",
"self",
".",
"log",
".",
"debug",
"(",
"\"Marker files to add: %s\"",
"%",
"[",
"o",
".",
"name",
"for",
"o",
"... | This method is responsible for adding back all markers that were not
added to the squashed layer AND files they refer to can be found in layers
we do not squash. | [
"This",
"method",
"is",
"responsible",
"for",
"adding",
"back",
"all",
"markers",
"that",
"were",
"not",
"added",
"to",
"the",
"squashed",
"layer",
"AND",
"files",
"they",
"refer",
"to",
"can",
"be",
"found",
"in",
"layers",
"we",
"do",
"not",
"squash",
... | 89e0297942be268791aff2098b7ebfa50d82f8e8 | https://github.com/goldmann/docker-squash/blob/89e0297942be268791aff2098b7ebfa50d82f8e8/docker_squash/image.py#L523-L582 |
13,465 | goldmann/docker-squash | docker_squash/lib/xtarfile.py | _proc_pax | def _proc_pax(self, filetar):
"""Process an extended or global header as described in POSIX.1-2001."""
# Read the header information.
buf = filetar.fileobj.read(self._block(self.size))
# A pax header stores supplemental information for either
# the following file (extended) or all following files
... | python | def _proc_pax(self, filetar):
"""Process an extended or global header as described in POSIX.1-2001."""
# Read the header information.
buf = filetar.fileobj.read(self._block(self.size))
# A pax header stores supplemental information for either
# the following file (extended) or all following files
... | [
"def",
"_proc_pax",
"(",
"self",
",",
"filetar",
")",
":",
"# Read the header information.",
"buf",
"=",
"filetar",
".",
"fileobj",
".",
"read",
"(",
"self",
".",
"_block",
"(",
"self",
".",
"size",
")",
")",
"# A pax header stores supplemental information for eit... | Process an extended or global header as described in POSIX.1-2001. | [
"Process",
"an",
"extended",
"or",
"global",
"header",
"as",
"described",
"in",
"POSIX",
".",
"1",
"-",
"2001",
"."
] | 89e0297942be268791aff2098b7ebfa50d82f8e8 | https://github.com/goldmann/docker-squash/blob/89e0297942be268791aff2098b7ebfa50d82f8e8/docker_squash/lib/xtarfile.py#L20-L81 |
13,466 | goldmann/docker-squash | docker_squash/lib/xtarfile.py | _create_pax_generic_header | def _create_pax_generic_header(cls, pax_headers, type=tarfile.XHDTYPE):
"""Return a POSIX.1-2001 extended or global header sequence
that contains a list of keyword, value pairs. The values
must be unicode objects.
"""
records = []
for keyword, value in pax_headers.iteritems():
try... | python | def _create_pax_generic_header(cls, pax_headers, type=tarfile.XHDTYPE):
"""Return a POSIX.1-2001 extended or global header sequence
that contains a list of keyword, value pairs. The values
must be unicode objects.
"""
records = []
for keyword, value in pax_headers.iteritems():
try... | [
"def",
"_create_pax_generic_header",
"(",
"cls",
",",
"pax_headers",
",",
"type",
"=",
"tarfile",
".",
"XHDTYPE",
")",
":",
"records",
"=",
"[",
"]",
"for",
"keyword",
",",
"value",
"in",
"pax_headers",
".",
"iteritems",
"(",
")",
":",
"try",
":",
"keywo... | Return a POSIX.1-2001 extended or global header sequence
that contains a list of keyword, value pairs. The values
must be unicode objects. | [
"Return",
"a",
"POSIX",
".",
"1",
"-",
"2001",
"extended",
"or",
"global",
"header",
"sequence",
"that",
"contains",
"a",
"list",
"of",
"keyword",
"value",
"pairs",
".",
"The",
"values",
"must",
"be",
"unicode",
"objects",
"."
] | 89e0297942be268791aff2098b7ebfa50d82f8e8 | https://github.com/goldmann/docker-squash/blob/89e0297942be268791aff2098b7ebfa50d82f8e8/docker_squash/lib/xtarfile.py#L84-L122 |
13,467 | goldmann/docker-squash | docker_squash/v2_image.py | V2Image._read_json_file | def _read_json_file(self, json_file):
""" Helper function to read JSON file as OrderedDict """
self.log.debug("Reading '%s' JSON file..." % json_file)
with open(json_file, 'r') as f:
return json.load(f, object_pairs_hook=OrderedDict) | python | def _read_json_file(self, json_file):
""" Helper function to read JSON file as OrderedDict """
self.log.debug("Reading '%s' JSON file..." % json_file)
with open(json_file, 'r') as f:
return json.load(f, object_pairs_hook=OrderedDict) | [
"def",
"_read_json_file",
"(",
"self",
",",
"json_file",
")",
":",
"self",
".",
"log",
".",
"debug",
"(",
"\"Reading '%s' JSON file...\"",
"%",
"json_file",
")",
"with",
"open",
"(",
"json_file",
",",
"'r'",
")",
"as",
"f",
":",
"return",
"json",
".",
"l... | Helper function to read JSON file as OrderedDict | [
"Helper",
"function",
"to",
"read",
"JSON",
"file",
"as",
"OrderedDict"
] | 89e0297942be268791aff2098b7ebfa50d82f8e8 | https://github.com/goldmann/docker-squash/blob/89e0297942be268791aff2098b7ebfa50d82f8e8/docker_squash/v2_image.py#L122-L128 |
13,468 | goldmann/docker-squash | docker_squash/v2_image.py | V2Image._read_layer_paths | def _read_layer_paths(self, old_image_config, old_image_manifest, layers_to_move):
"""
In case of v2 format, layer id's are not the same as the id's
used in the exported tar archive to name directories for layers.
These id's can be found in the configuration files saved with
the ... | python | def _read_layer_paths(self, old_image_config, old_image_manifest, layers_to_move):
"""
In case of v2 format, layer id's are not the same as the id's
used in the exported tar archive to name directories for layers.
These id's can be found in the configuration files saved with
the ... | [
"def",
"_read_layer_paths",
"(",
"self",
",",
"old_image_config",
",",
"old_image_manifest",
",",
"layers_to_move",
")",
":",
"# In manifest.json we do not have listed all layers",
"# but only layers that do contain some data.",
"current_manifest_layer",
"=",
"0",
"layer_paths_to_m... | In case of v2 format, layer id's are not the same as the id's
used in the exported tar archive to name directories for layers.
These id's can be found in the configuration files saved with
the image - we need to read them. | [
"In",
"case",
"of",
"v2",
"format",
"layer",
"id",
"s",
"are",
"not",
"the",
"same",
"as",
"the",
"id",
"s",
"used",
"in",
"the",
"exported",
"tar",
"archive",
"to",
"name",
"directories",
"for",
"layers",
".",
"These",
"id",
"s",
"can",
"be",
"found... | 89e0297942be268791aff2098b7ebfa50d82f8e8 | https://github.com/goldmann/docker-squash/blob/89e0297942be268791aff2098b7ebfa50d82f8e8/docker_squash/v2_image.py#L130-L163 |
13,469 | goldmann/docker-squash | docker_squash/v2_image.py | V2Image._generate_squashed_layer_path_id | def _generate_squashed_layer_path_id(self):
"""
This function generates the id used to name the directory to
store the squashed layer content in the archive.
This mimics what Docker does here: https://github.com/docker/docker/blob/v1.10.0-rc1/image/v1/imagev1.go#L42
To make it s... | python | def _generate_squashed_layer_path_id(self):
"""
This function generates the id used to name the directory to
store the squashed layer content in the archive.
This mimics what Docker does here: https://github.com/docker/docker/blob/v1.10.0-rc1/image/v1/imagev1.go#L42
To make it s... | [
"def",
"_generate_squashed_layer_path_id",
"(",
"self",
")",
":",
"# Using OrderedDict, because order of JSON elements is important",
"v1_metadata",
"=",
"OrderedDict",
"(",
"self",
".",
"old_image_config",
")",
"# Update image creation date",
"v1_metadata",
"[",
"'created'",
"... | This function generates the id used to name the directory to
store the squashed layer content in the archive.
This mimics what Docker does here: https://github.com/docker/docker/blob/v1.10.0-rc1/image/v1/imagev1.go#L42
To make it simpler we do reuse old image metadata and
modify it to w... | [
"This",
"function",
"generates",
"the",
"id",
"used",
"to",
"name",
"the",
"directory",
"to",
"store",
"the",
"squashed",
"layer",
"content",
"in",
"the",
"archive",
"."
] | 89e0297942be268791aff2098b7ebfa50d82f8e8 | https://github.com/goldmann/docker-squash/blob/89e0297942be268791aff2098b7ebfa50d82f8e8/docker_squash/v2_image.py#L215-L273 |
13,470 | django-dbbackup/django-dbbackup | dbbackup/management/commands/_base.py | BaseDbBackupCommand.write_local_file | def write_local_file(self, outputfile, path):
"""Write file to the desired path."""
self.logger.info("Writing file to %s", path)
outputfile.seek(0)
with open(path, 'wb') as fd:
copyfileobj(outputfile, fd) | python | def write_local_file(self, outputfile, path):
"""Write file to the desired path."""
self.logger.info("Writing file to %s", path)
outputfile.seek(0)
with open(path, 'wb') as fd:
copyfileobj(outputfile, fd) | [
"def",
"write_local_file",
"(",
"self",
",",
"outputfile",
",",
"path",
")",
":",
"self",
".",
"logger",
".",
"info",
"(",
"\"Writing file to %s\"",
",",
"path",
")",
"outputfile",
".",
"seek",
"(",
"0",
")",
"with",
"open",
"(",
"path",
",",
"'wb'",
"... | Write file to the desired path. | [
"Write",
"file",
"to",
"the",
"desired",
"path",
"."
] | 77de209e2d5317e51510d0f888e085ee0c400d66 | https://github.com/django-dbbackup/django-dbbackup/blob/77de209e2d5317e51510d0f888e085ee0c400d66/dbbackup/management/commands/_base.py#L94-L99 |
13,471 | django-dbbackup/django-dbbackup | dbbackup/management/commands/_base.py | BaseDbBackupCommand._cleanup_old_backups | def _cleanup_old_backups(self, database=None, servername=None):
"""
Cleanup old backups, keeping the number of backups specified by
DBBACKUP_CLEANUP_KEEP and any backups that occur on first of the month.
"""
self.storage.clean_old_backups(encrypted=self.encrypt,
... | python | def _cleanup_old_backups(self, database=None, servername=None):
"""
Cleanup old backups, keeping the number of backups specified by
DBBACKUP_CLEANUP_KEEP and any backups that occur on first of the month.
"""
self.storage.clean_old_backups(encrypted=self.encrypt,
... | [
"def",
"_cleanup_old_backups",
"(",
"self",
",",
"database",
"=",
"None",
",",
"servername",
"=",
"None",
")",
":",
"self",
".",
"storage",
".",
"clean_old_backups",
"(",
"encrypted",
"=",
"self",
".",
"encrypt",
",",
"compressed",
"=",
"self",
".",
"compr... | Cleanup old backups, keeping the number of backups specified by
DBBACKUP_CLEANUP_KEEP and any backups that occur on first of the month. | [
"Cleanup",
"old",
"backups",
"keeping",
"the",
"number",
"of",
"backups",
"specified",
"by",
"DBBACKUP_CLEANUP_KEEP",
"and",
"any",
"backups",
"that",
"occur",
"on",
"first",
"of",
"the",
"month",
"."
] | 77de209e2d5317e51510d0f888e085ee0c400d66 | https://github.com/django-dbbackup/django-dbbackup/blob/77de209e2d5317e51510d0f888e085ee0c400d66/dbbackup/management/commands/_base.py#L123-L132 |
13,472 | django-dbbackup/django-dbbackup | dbbackup/management/commands/dbbackup.py | Command._save_new_backup | def _save_new_backup(self, database):
"""
Save a new backup file.
"""
self.logger.info("Backing Up Database: %s", database['NAME'])
# Get backup and name
filename = self.connector.generate_filename(self.servername)
outputfile = self.connector.create_dump()
... | python | def _save_new_backup(self, database):
"""
Save a new backup file.
"""
self.logger.info("Backing Up Database: %s", database['NAME'])
# Get backup and name
filename = self.connector.generate_filename(self.servername)
outputfile = self.connector.create_dump()
... | [
"def",
"_save_new_backup",
"(",
"self",
",",
"database",
")",
":",
"self",
".",
"logger",
".",
"info",
"(",
"\"Backing Up Database: %s\"",
",",
"database",
"[",
"'NAME'",
"]",
")",
"# Get backup and name",
"filename",
"=",
"self",
".",
"connector",
".",
"gener... | Save a new backup file. | [
"Save",
"a",
"new",
"backup",
"file",
"."
] | 77de209e2d5317e51510d0f888e085ee0c400d66 | https://github.com/django-dbbackup/django-dbbackup/blob/77de209e2d5317e51510d0f888e085ee0c400d66/dbbackup/management/commands/dbbackup.py#L67-L90 |
13,473 | django-dbbackup/django-dbbackup | dbbackup/management/commands/mediabackup.py | Command._explore_storage | def _explore_storage(self):
"""Generator of all files contained in media storage."""
path = ''
dirs = [path]
while dirs:
path = dirs.pop()
subdirs, files = self.media_storage.listdir(path)
for media_filename in files:
yield os.path.join... | python | def _explore_storage(self):
"""Generator of all files contained in media storage."""
path = ''
dirs = [path]
while dirs:
path = dirs.pop()
subdirs, files = self.media_storage.listdir(path)
for media_filename in files:
yield os.path.join... | [
"def",
"_explore_storage",
"(",
"self",
")",
":",
"path",
"=",
"''",
"dirs",
"=",
"[",
"path",
"]",
"while",
"dirs",
":",
"path",
"=",
"dirs",
".",
"pop",
"(",
")",
"subdirs",
",",
"files",
"=",
"self",
".",
"media_storage",
".",
"listdir",
"(",
"p... | Generator of all files contained in media storage. | [
"Generator",
"of",
"all",
"files",
"contained",
"in",
"media",
"storage",
"."
] | 77de209e2d5317e51510d0f888e085ee0c400d66 | https://github.com/django-dbbackup/django-dbbackup/blob/77de209e2d5317e51510d0f888e085ee0c400d66/dbbackup/management/commands/mediabackup.py#L59-L68 |
13,474 | django-dbbackup/django-dbbackup | dbbackup/management/commands/mediabackup.py | Command._create_tar | def _create_tar(self, name):
"""Create TAR file."""
fileobj = utils.create_spooled_temporary_file()
mode = 'w:gz' if self.compress else 'w'
tar_file = tarfile.open(name=name, fileobj=fileobj, mode=mode)
for media_filename in self._explore_storage():
tarinfo = tarfile.... | python | def _create_tar(self, name):
"""Create TAR file."""
fileobj = utils.create_spooled_temporary_file()
mode = 'w:gz' if self.compress else 'w'
tar_file = tarfile.open(name=name, fileobj=fileobj, mode=mode)
for media_filename in self._explore_storage():
tarinfo = tarfile.... | [
"def",
"_create_tar",
"(",
"self",
",",
"name",
")",
":",
"fileobj",
"=",
"utils",
".",
"create_spooled_temporary_file",
"(",
")",
"mode",
"=",
"'w:gz'",
"if",
"self",
".",
"compress",
"else",
"'w'",
"tar_file",
"=",
"tarfile",
".",
"open",
"(",
"name",
... | Create TAR file. | [
"Create",
"TAR",
"file",
"."
] | 77de209e2d5317e51510d0f888e085ee0c400d66 | https://github.com/django-dbbackup/django-dbbackup/blob/77de209e2d5317e51510d0f888e085ee0c400d66/dbbackup/management/commands/mediabackup.py#L70-L82 |
13,475 | django-dbbackup/django-dbbackup | dbbackup/management/commands/mediabackup.py | Command.backup_mediafiles | def backup_mediafiles(self):
"""
Create backup file and write it to storage.
"""
# Create file name
extension = "tar%s" % ('.gz' if self.compress else '')
filename = utils.filename_generate(extension,
servername=self.servername,
... | python | def backup_mediafiles(self):
"""
Create backup file and write it to storage.
"""
# Create file name
extension = "tar%s" % ('.gz' if self.compress else '')
filename = utils.filename_generate(extension,
servername=self.servername,
... | [
"def",
"backup_mediafiles",
"(",
"self",
")",
":",
"# Create file name",
"extension",
"=",
"\"tar%s\"",
"%",
"(",
"'.gz'",
"if",
"self",
".",
"compress",
"else",
"''",
")",
"filename",
"=",
"utils",
".",
"filename_generate",
"(",
"extension",
",",
"servername"... | Create backup file and write it to storage. | [
"Create",
"backup",
"file",
"and",
"write",
"it",
"to",
"storage",
"."
] | 77de209e2d5317e51510d0f888e085ee0c400d66 | https://github.com/django-dbbackup/django-dbbackup/blob/77de209e2d5317e51510d0f888e085ee0c400d66/dbbackup/management/commands/mediabackup.py#L84-L105 |
13,476 | django-dbbackup/django-dbbackup | dbbackup/utils.py | bytes_to_str | def bytes_to_str(byteVal, decimals=1):
"""
Convert bytes to a human readable string.
:param byteVal: Value to convert in bytes
:type byteVal: int or float
:param decimal: Number of decimal to display
:type decimal: int
:returns: Number of byte with the best unit of measure
:rtype: str... | python | def bytes_to_str(byteVal, decimals=1):
"""
Convert bytes to a human readable string.
:param byteVal: Value to convert in bytes
:type byteVal: int or float
:param decimal: Number of decimal to display
:type decimal: int
:returns: Number of byte with the best unit of measure
:rtype: str... | [
"def",
"bytes_to_str",
"(",
"byteVal",
",",
"decimals",
"=",
"1",
")",
":",
"for",
"unit",
",",
"byte",
"in",
"BYTES",
":",
"if",
"(",
"byteVal",
">=",
"byte",
")",
":",
"if",
"decimals",
"==",
"0",
":",
"return",
"'%s %s'",
"%",
"(",
"int",
"(",
... | Convert bytes to a human readable string.
:param byteVal: Value to convert in bytes
:type byteVal: int or float
:param decimal: Number of decimal to display
:type decimal: int
:returns: Number of byte with the best unit of measure
:rtype: str | [
"Convert",
"bytes",
"to",
"a",
"human",
"readable",
"string",
"."
] | 77de209e2d5317e51510d0f888e085ee0c400d66 | https://github.com/django-dbbackup/django-dbbackup/blob/77de209e2d5317e51510d0f888e085ee0c400d66/dbbackup/utils.py#L58-L76 |
13,477 | django-dbbackup/django-dbbackup | dbbackup/utils.py | mail_admins | def mail_admins(subject, message, fail_silently=False, connection=None,
html_message=None):
"""Sends a message to the admins, as defined by the DBBACKUP_ADMINS setting."""
if not settings.ADMINS:
return
mail = EmailMultiAlternatives('%s%s' % (settings.EMAIL_SUBJECT_PREFIX, subject),
... | python | def mail_admins(subject, message, fail_silently=False, connection=None,
html_message=None):
"""Sends a message to the admins, as defined by the DBBACKUP_ADMINS setting."""
if not settings.ADMINS:
return
mail = EmailMultiAlternatives('%s%s' % (settings.EMAIL_SUBJECT_PREFIX, subject),
... | [
"def",
"mail_admins",
"(",
"subject",
",",
"message",
",",
"fail_silently",
"=",
"False",
",",
"connection",
"=",
"None",
",",
"html_message",
"=",
"None",
")",
":",
"if",
"not",
"settings",
".",
"ADMINS",
":",
"return",
"mail",
"=",
"EmailMultiAlternatives"... | Sends a message to the admins, as defined by the DBBACKUP_ADMINS setting. | [
"Sends",
"a",
"message",
"to",
"the",
"admins",
"as",
"defined",
"by",
"the",
"DBBACKUP_ADMINS",
"setting",
"."
] | 77de209e2d5317e51510d0f888e085ee0c400d66 | https://github.com/django-dbbackup/django-dbbackup/blob/77de209e2d5317e51510d0f888e085ee0c400d66/dbbackup/utils.py#L93-L103 |
13,478 | django-dbbackup/django-dbbackup | dbbackup/utils.py | create_spooled_temporary_file | def create_spooled_temporary_file(filepath=None, fileobj=None):
"""
Create a spooled temporary file. if ``filepath`` or ``fileobj`` is
defined its content will be copied into temporary file.
:param filepath: Path of input file
:type filepath: str
:param fileobj: Input file object
:type fil... | python | def create_spooled_temporary_file(filepath=None, fileobj=None):
"""
Create a spooled temporary file. if ``filepath`` or ``fileobj`` is
defined its content will be copied into temporary file.
:param filepath: Path of input file
:type filepath: str
:param fileobj: Input file object
:type fil... | [
"def",
"create_spooled_temporary_file",
"(",
"filepath",
"=",
"None",
",",
"fileobj",
"=",
"None",
")",
":",
"spooled_file",
"=",
"tempfile",
".",
"SpooledTemporaryFile",
"(",
"max_size",
"=",
"settings",
".",
"TMP_FILE_MAX_SIZE",
",",
"dir",
"=",
"settings",
".... | Create a spooled temporary file. if ``filepath`` or ``fileobj`` is
defined its content will be copied into temporary file.
:param filepath: Path of input file
:type filepath: str
:param fileobj: Input file object
:type fileobj: file
:returns: Spooled temporary file
:rtype: :class:`tempfil... | [
"Create",
"a",
"spooled",
"temporary",
"file",
".",
"if",
"filepath",
"or",
"fileobj",
"is",
"defined",
"its",
"content",
"will",
"be",
"copied",
"into",
"temporary",
"file",
"."
] | 77de209e2d5317e51510d0f888e085ee0c400d66 | https://github.com/django-dbbackup/django-dbbackup/blob/77de209e2d5317e51510d0f888e085ee0c400d66/dbbackup/utils.py#L129-L151 |
13,479 | django-dbbackup/django-dbbackup | dbbackup/utils.py | compress_file | def compress_file(inputfile, filename):
"""
Compress input file using gzip and change its name.
:param inputfile: File to compress
:type inputfile: ``file`` like object
:param filename: File's name
:type filename: ``str``
:returns: Tuple with compressed file and new file's name
:rtype... | python | def compress_file(inputfile, filename):
"""
Compress input file using gzip and change its name.
:param inputfile: File to compress
:type inputfile: ``file`` like object
:param filename: File's name
:type filename: ``str``
:returns: Tuple with compressed file and new file's name
:rtype... | [
"def",
"compress_file",
"(",
"inputfile",
",",
"filename",
")",
":",
"outputfile",
"=",
"create_spooled_temporary_file",
"(",
")",
"new_filename",
"=",
"filename",
"+",
"'.gz'",
"zipfile",
"=",
"gzip",
".",
"GzipFile",
"(",
"filename",
"=",
"filename",
",",
"f... | Compress input file using gzip and change its name.
:param inputfile: File to compress
:type inputfile: ``file`` like object
:param filename: File's name
:type filename: ``str``
:returns: Tuple with compressed file and new file's name
:rtype: :class:`tempfile.SpooledTemporaryFile`, ``str`` | [
"Compress",
"input",
"file",
"using",
"gzip",
"and",
"change",
"its",
"name",
"."
] | 77de209e2d5317e51510d0f888e085ee0c400d66 | https://github.com/django-dbbackup/django-dbbackup/blob/77de209e2d5317e51510d0f888e085ee0c400d66/dbbackup/utils.py#L234-L255 |
13,480 | django-dbbackup/django-dbbackup | dbbackup/utils.py | uncompress_file | def uncompress_file(inputfile, filename):
"""
Uncompress this file using gzip and change its name.
:param inputfile: File to compress
:type inputfile: ``file`` like object
:param filename: File's name
:type filename: ``str``
:returns: Tuple with file and new file's name
:rtype: :class... | python | def uncompress_file(inputfile, filename):
"""
Uncompress this file using gzip and change its name.
:param inputfile: File to compress
:type inputfile: ``file`` like object
:param filename: File's name
:type filename: ``str``
:returns: Tuple with file and new file's name
:rtype: :class... | [
"def",
"uncompress_file",
"(",
"inputfile",
",",
"filename",
")",
":",
"zipfile",
"=",
"gzip",
".",
"GzipFile",
"(",
"fileobj",
"=",
"inputfile",
",",
"mode",
"=",
"\"rb\"",
")",
"try",
":",
"outputfile",
"=",
"create_spooled_temporary_file",
"(",
"fileobj",
... | Uncompress this file using gzip and change its name.
:param inputfile: File to compress
:type inputfile: ``file`` like object
:param filename: File's name
:type filename: ``str``
:returns: Tuple with file and new file's name
:rtype: :class:`tempfile.SpooledTemporaryFile`, ``str`` | [
"Uncompress",
"this",
"file",
"using",
"gzip",
"and",
"change",
"its",
"name",
"."
] | 77de209e2d5317e51510d0f888e085ee0c400d66 | https://github.com/django-dbbackup/django-dbbackup/blob/77de209e2d5317e51510d0f888e085ee0c400d66/dbbackup/utils.py#L258-L277 |
13,481 | django-dbbackup/django-dbbackup | dbbackup/utils.py | timestamp | def timestamp(value):
"""
Return the timestamp of a datetime.datetime object.
:param value: a datetime object
:type value: datetime.datetime
:return: the timestamp
:rtype: str
"""
value = value if timezone.is_naive(value) else timezone.localtime(value)
return value.strftime(setting... | python | def timestamp(value):
"""
Return the timestamp of a datetime.datetime object.
:param value: a datetime object
:type value: datetime.datetime
:return: the timestamp
:rtype: str
"""
value = value if timezone.is_naive(value) else timezone.localtime(value)
return value.strftime(setting... | [
"def",
"timestamp",
"(",
"value",
")",
":",
"value",
"=",
"value",
"if",
"timezone",
".",
"is_naive",
"(",
"value",
")",
"else",
"timezone",
".",
"localtime",
"(",
"value",
")",
"return",
"value",
".",
"strftime",
"(",
"settings",
".",
"DATE_FORMAT",
")"... | Return the timestamp of a datetime.datetime object.
:param value: a datetime object
:type value: datetime.datetime
:return: the timestamp
:rtype: str | [
"Return",
"the",
"timestamp",
"of",
"a",
"datetime",
".",
"datetime",
"object",
"."
] | 77de209e2d5317e51510d0f888e085ee0c400d66 | https://github.com/django-dbbackup/django-dbbackup/blob/77de209e2d5317e51510d0f888e085ee0c400d66/dbbackup/utils.py#L280-L291 |
13,482 | django-dbbackup/django-dbbackup | dbbackup/utils.py | datefmt_to_regex | def datefmt_to_regex(datefmt):
"""
Convert a strftime format string to a regex.
:param datefmt: strftime format string
:type datefmt: ``str``
:returns: Equivalent regex
:rtype: ``re.compite``
"""
new_string = datefmt
for pat, reg in PATTERN_MATCHNG:
new_string = new_string.... | python | def datefmt_to_regex(datefmt):
"""
Convert a strftime format string to a regex.
:param datefmt: strftime format string
:type datefmt: ``str``
:returns: Equivalent regex
:rtype: ``re.compite``
"""
new_string = datefmt
for pat, reg in PATTERN_MATCHNG:
new_string = new_string.... | [
"def",
"datefmt_to_regex",
"(",
"datefmt",
")",
":",
"new_string",
"=",
"datefmt",
"for",
"pat",
",",
"reg",
"in",
"PATTERN_MATCHNG",
":",
"new_string",
"=",
"new_string",
".",
"replace",
"(",
"pat",
",",
"reg",
")",
"return",
"re",
".",
"compile",
"(",
... | Convert a strftime format string to a regex.
:param datefmt: strftime format string
:type datefmt: ``str``
:returns: Equivalent regex
:rtype: ``re.compite`` | [
"Convert",
"a",
"strftime",
"format",
"string",
"to",
"a",
"regex",
"."
] | 77de209e2d5317e51510d0f888e085ee0c400d66 | https://github.com/django-dbbackup/django-dbbackup/blob/77de209e2d5317e51510d0f888e085ee0c400d66/dbbackup/utils.py#L327-L340 |
13,483 | django-dbbackup/django-dbbackup | dbbackup/utils.py | filename_to_date | def filename_to_date(filename, datefmt=None):
"""
Return a datetime from a file name.
:param datefmt: strftime format string, ``settings.DATE_FORMAT`` is used
if is ``None``
:type datefmt: ``str`` or ``NoneType``
:returns: Date guessed or nothing if no date found
:rtype: ``... | python | def filename_to_date(filename, datefmt=None):
"""
Return a datetime from a file name.
:param datefmt: strftime format string, ``settings.DATE_FORMAT`` is used
if is ``None``
:type datefmt: ``str`` or ``NoneType``
:returns: Date guessed or nothing if no date found
:rtype: ``... | [
"def",
"filename_to_date",
"(",
"filename",
",",
"datefmt",
"=",
"None",
")",
":",
"datefmt",
"=",
"datefmt",
"or",
"settings",
".",
"DATE_FORMAT",
"datestring",
"=",
"filename_to_datestring",
"(",
"filename",
",",
"datefmt",
")",
"if",
"datestring",
"is",
"no... | Return a datetime from a file name.
:param datefmt: strftime format string, ``settings.DATE_FORMAT`` is used
if is ``None``
:type datefmt: ``str`` or ``NoneType``
:returns: Date guessed or nothing if no date found
:rtype: ``datetime.datetime`` or ``NoneType`` | [
"Return",
"a",
"datetime",
"from",
"a",
"file",
"name",
"."
] | 77de209e2d5317e51510d0f888e085ee0c400d66 | https://github.com/django-dbbackup/django-dbbackup/blob/77de209e2d5317e51510d0f888e085ee0c400d66/dbbackup/utils.py#L361-L375 |
13,484 | django-dbbackup/django-dbbackup | dbbackup/utils.py | filename_generate | def filename_generate(extension, database_name='', servername=None, content_type='db', wildcard=None):
"""
Create a new backup filename.
:param extension: Extension of backup file
:type extension: ``str``
:param database_name: If it is database backup specify its name
:type database_name: ``st... | python | def filename_generate(extension, database_name='', servername=None, content_type='db', wildcard=None):
"""
Create a new backup filename.
:param extension: Extension of backup file
:type extension: ``str``
:param database_name: If it is database backup specify its name
:type database_name: ``st... | [
"def",
"filename_generate",
"(",
"extension",
",",
"database_name",
"=",
"''",
",",
"servername",
"=",
"None",
",",
"content_type",
"=",
"'db'",
",",
"wildcard",
"=",
"None",
")",
":",
"if",
"content_type",
"==",
"'db'",
":",
"if",
"'/'",
"in",
"database_n... | Create a new backup filename.
:param extension: Extension of backup file
:type extension: ``str``
:param database_name: If it is database backup specify its name
:type database_name: ``str``
:param servername: Specify server name or by default ``settings.DBBACKUP_HOSTNAME``
:type servername: ... | [
"Create",
"a",
"new",
"backup",
"filename",
"."
] | 77de209e2d5317e51510d0f888e085ee0c400d66 | https://github.com/django-dbbackup/django-dbbackup/blob/77de209e2d5317e51510d0f888e085ee0c400d66/dbbackup/utils.py#L378-L424 |
13,485 | django-dbbackup/django-dbbackup | dbbackup/storage.py | get_storage | def get_storage(path=None, options=None):
"""
Get the specified storage configured with options.
:param path: Path in Python dot style to module containing the storage
class. If empty settings.DBBACKUP_STORAGE will be used.
:type path: ``str``
:param options: Parameters for config... | python | def get_storage(path=None, options=None):
"""
Get the specified storage configured with options.
:param path: Path in Python dot style to module containing the storage
class. If empty settings.DBBACKUP_STORAGE will be used.
:type path: ``str``
:param options: Parameters for config... | [
"def",
"get_storage",
"(",
"path",
"=",
"None",
",",
"options",
"=",
"None",
")",
":",
"path",
"=",
"path",
"or",
"settings",
".",
"STORAGE",
"options",
"=",
"options",
"or",
"settings",
".",
"STORAGE_OPTIONS",
"if",
"not",
"path",
":",
"raise",
"Imprope... | Get the specified storage configured with options.
:param path: Path in Python dot style to module containing the storage
class. If empty settings.DBBACKUP_STORAGE will be used.
:type path: ``str``
:param options: Parameters for configure the storage, if empty
settings... | [
"Get",
"the",
"specified",
"storage",
"configured",
"with",
"options",
"."
] | 77de209e2d5317e51510d0f888e085ee0c400d66 | https://github.com/django-dbbackup/django-dbbackup/blob/77de209e2d5317e51510d0f888e085ee0c400d66/dbbackup/storage.py#L10-L30 |
13,486 | django-dbbackup/django-dbbackup | dbbackup/storage.py | Storage.list_backups | def list_backups(self, encrypted=None, compressed=None, content_type=None,
database=None, servername=None):
"""
List stored files except given filter. If filter is None, it won't be
used. ``content_type`` must be ``'db'`` for database backups or
``'media'`` for media... | python | def list_backups(self, encrypted=None, compressed=None, content_type=None,
database=None, servername=None):
"""
List stored files except given filter. If filter is None, it won't be
used. ``content_type`` must be ``'db'`` for database backups or
``'media'`` for media... | [
"def",
"list_backups",
"(",
"self",
",",
"encrypted",
"=",
"None",
",",
"compressed",
"=",
"None",
",",
"content_type",
"=",
"None",
",",
"database",
"=",
"None",
",",
"servername",
"=",
"None",
")",
":",
"if",
"content_type",
"not",
"in",
"(",
"'db'",
... | List stored files except given filter. If filter is None, it won't be
used. ``content_type`` must be ``'db'`` for database backups or
``'media'`` for media backups.
:param encrypted: Filter by encrypted or not
:type encrypted: ``bool`` or ``None``
:param compressed: Filter by c... | [
"List",
"stored",
"files",
"except",
"given",
"filter",
".",
"If",
"filter",
"is",
"None",
"it",
"won",
"t",
"be",
"used",
".",
"content_type",
"must",
"be",
"db",
"for",
"database",
"backups",
"or",
"media",
"for",
"media",
"backups",
"."
] | 77de209e2d5317e51510d0f888e085ee0c400d66 | https://github.com/django-dbbackup/django-dbbackup/blob/77de209e2d5317e51510d0f888e085ee0c400d66/dbbackup/storage.py#L91-L136 |
13,487 | django-dbbackup/django-dbbackup | dbbackup/storage.py | Storage.get_older_backup | def get_older_backup(self, encrypted=None, compressed=None,
content_type=None, database=None, servername=None):
"""
Return the older backup's file name.
:param encrypted: Filter by encrypted or not
:type encrypted: ``bool`` or ``None``
:param compressed... | python | def get_older_backup(self, encrypted=None, compressed=None,
content_type=None, database=None, servername=None):
"""
Return the older backup's file name.
:param encrypted: Filter by encrypted or not
:type encrypted: ``bool`` or ``None``
:param compressed... | [
"def",
"get_older_backup",
"(",
"self",
",",
"encrypted",
"=",
"None",
",",
"compressed",
"=",
"None",
",",
"content_type",
"=",
"None",
",",
"database",
"=",
"None",
",",
"servername",
"=",
"None",
")",
":",
"files",
"=",
"self",
".",
"list_backups",
"(... | Return the older backup's file name.
:param encrypted: Filter by encrypted or not
:type encrypted: ``bool`` or ``None``
:param compressed: Filter by compressed or not
:type compressed: ``bool`` or ``None``
:param content_type: Filter by media or database backup, must be
... | [
"Return",
"the",
"older",
"backup",
"s",
"file",
"name",
"."
] | 77de209e2d5317e51510d0f888e085ee0c400d66 | https://github.com/django-dbbackup/django-dbbackup/blob/77de209e2d5317e51510d0f888e085ee0c400d66/dbbackup/storage.py#L172-L204 |
13,488 | django-dbbackup/django-dbbackup | dbbackup/storage.py | Storage.clean_old_backups | def clean_old_backups(self, encrypted=None, compressed=None,
content_type=None, database=None, servername=None,
keep_number=None):
"""
Delete olders backups and hold the number defined.
:param encrypted: Filter by encrypted or not
:typ... | python | def clean_old_backups(self, encrypted=None, compressed=None,
content_type=None, database=None, servername=None,
keep_number=None):
"""
Delete olders backups and hold the number defined.
:param encrypted: Filter by encrypted or not
:typ... | [
"def",
"clean_old_backups",
"(",
"self",
",",
"encrypted",
"=",
"None",
",",
"compressed",
"=",
"None",
",",
"content_type",
"=",
"None",
",",
"database",
"=",
"None",
",",
"servername",
"=",
"None",
",",
"keep_number",
"=",
"None",
")",
":",
"if",
"keep... | Delete olders backups and hold the number defined.
:param encrypted: Filter by encrypted or not
:type encrypted: ``bool`` or ``None``
:param compressed: Filter by compressed or not
:type compressed: ``bool`` or ``None``
:param content_type: Filter by media or database backup, ... | [
"Delete",
"olders",
"backups",
"and",
"hold",
"the",
"number",
"defined",
"."
] | 77de209e2d5317e51510d0f888e085ee0c400d66 | https://github.com/django-dbbackup/django-dbbackup/blob/77de209e2d5317e51510d0f888e085ee0c400d66/dbbackup/storage.py#L206-L244 |
13,489 | django-dbbackup/django-dbbackup | dbbackup/management/commands/dbrestore.py | Command._get_database | def _get_database(self, options):
"""Get the database to restore."""
database_name = options.get('database')
if not database_name:
if len(settings.DATABASES) > 1:
errmsg = "Because this project contains more than one database, you"\
" must specify ... | python | def _get_database(self, options):
"""Get the database to restore."""
database_name = options.get('database')
if not database_name:
if len(settings.DATABASES) > 1:
errmsg = "Because this project contains more than one database, you"\
" must specify ... | [
"def",
"_get_database",
"(",
"self",
",",
"options",
")",
":",
"database_name",
"=",
"options",
".",
"get",
"(",
"'database'",
")",
"if",
"not",
"database_name",
":",
"if",
"len",
"(",
"settings",
".",
"DATABASES",
")",
">",
"1",
":",
"errmsg",
"=",
"\... | Get the database to restore. | [
"Get",
"the",
"database",
"to",
"restore",
"."
] | 77de209e2d5317e51510d0f888e085ee0c400d66 | https://github.com/django-dbbackup/django-dbbackup/blob/77de209e2d5317e51510d0f888e085ee0c400d66/dbbackup/management/commands/dbrestore.py#L57-L68 |
13,490 | django-dbbackup/django-dbbackup | dbbackup/management/commands/dbrestore.py | Command._restore_backup | def _restore_backup(self):
"""Restore the specified database."""
input_filename, input_file = self._get_backup_file(database=self.database_name,
servername=self.servername)
self.logger.info("Restoring backup for database '%s' and server ... | python | def _restore_backup(self):
"""Restore the specified database."""
input_filename, input_file = self._get_backup_file(database=self.database_name,
servername=self.servername)
self.logger.info("Restoring backup for database '%s' and server ... | [
"def",
"_restore_backup",
"(",
"self",
")",
":",
"input_filename",
",",
"input_file",
"=",
"self",
".",
"_get_backup_file",
"(",
"database",
"=",
"self",
".",
"database_name",
",",
"servername",
"=",
"self",
".",
"servername",
")",
"self",
".",
"logger",
"."... | Restore the specified database. | [
"Restore",
"the",
"specified",
"database",
"."
] | 77de209e2d5317e51510d0f888e085ee0c400d66 | https://github.com/django-dbbackup/django-dbbackup/blob/77de209e2d5317e51510d0f888e085ee0c400d66/dbbackup/management/commands/dbrestore.py#L70-L94 |
13,491 | django-dbbackup/django-dbbackup | dbbackup/db/base.py | get_connector | def get_connector(database_name=None):
"""
Get a connector from its database key in setttings.
"""
from django.db import connections, DEFAULT_DB_ALIAS
# Get DB
database_name = database_name or DEFAULT_DB_ALIAS
connection = connections[database_name]
engine = connection.settings_dict['ENG... | python | def get_connector(database_name=None):
"""
Get a connector from its database key in setttings.
"""
from django.db import connections, DEFAULT_DB_ALIAS
# Get DB
database_name = database_name or DEFAULT_DB_ALIAS
connection = connections[database_name]
engine = connection.settings_dict['ENG... | [
"def",
"get_connector",
"(",
"database_name",
"=",
"None",
")",
":",
"from",
"django",
".",
"db",
"import",
"connections",
",",
"DEFAULT_DB_ALIAS",
"# Get DB",
"database_name",
"=",
"database_name",
"or",
"DEFAULT_DB_ALIAS",
"connection",
"=",
"connections",
"[",
... | Get a connector from its database key in setttings. | [
"Get",
"a",
"connector",
"from",
"its",
"database",
"key",
"in",
"setttings",
"."
] | 77de209e2d5317e51510d0f888e085ee0c400d66 | https://github.com/django-dbbackup/django-dbbackup/blob/77de209e2d5317e51510d0f888e085ee0c400d66/dbbackup/db/base.py#L31-L46 |
13,492 | django-dbbackup/django-dbbackup | dbbackup/db/base.py | BaseDBConnector.settings | def settings(self):
"""Mix of database and connector settings."""
if not hasattr(self, '_settings'):
sett = self.connection.settings_dict.copy()
sett.update(settings.CONNECTORS.get(self.database_name, {}))
self._settings = sett
return self._settings | python | def settings(self):
"""Mix of database and connector settings."""
if not hasattr(self, '_settings'):
sett = self.connection.settings_dict.copy()
sett.update(settings.CONNECTORS.get(self.database_name, {}))
self._settings = sett
return self._settings | [
"def",
"settings",
"(",
"self",
")",
":",
"if",
"not",
"hasattr",
"(",
"self",
",",
"'_settings'",
")",
":",
"sett",
"=",
"self",
".",
"connection",
".",
"settings_dict",
".",
"copy",
"(",
")",
"sett",
".",
"update",
"(",
"settings",
".",
"CONNECTORS",... | Mix of database and connector settings. | [
"Mix",
"of",
"database",
"and",
"connector",
"settings",
"."
] | 77de209e2d5317e51510d0f888e085ee0c400d66 | https://github.com/django-dbbackup/django-dbbackup/blob/77de209e2d5317e51510d0f888e085ee0c400d66/dbbackup/db/base.py#L65-L71 |
13,493 | django-dbbackup/django-dbbackup | dbbackup/db/base.py | BaseCommandDBConnector.run_command | def run_command(self, command, stdin=None, env=None):
"""
Launch a shell command line.
:param command: Command line to launch
:type command: str
:param stdin: Standard input of command
:type stdin: file
:param env: Environment variable used in command
:ty... | python | def run_command(self, command, stdin=None, env=None):
"""
Launch a shell command line.
:param command: Command line to launch
:type command: str
:param stdin: Standard input of command
:type stdin: file
:param env: Environment variable used in command
:ty... | [
"def",
"run_command",
"(",
"self",
",",
"command",
",",
"stdin",
"=",
"None",
",",
"env",
"=",
"None",
")",
":",
"cmd",
"=",
"shlex",
".",
"split",
"(",
"command",
")",
"stdout",
"=",
"SpooledTemporaryFile",
"(",
"max_size",
"=",
"settings",
".",
"TMP_... | Launch a shell command line.
:param command: Command line to launch
:type command: str
:param stdin: Standard input of command
:type stdin: file
:param env: Environment variable used in command
:type env: dict
:return: Standard output of command
:rtype: f... | [
"Launch",
"a",
"shell",
"command",
"line",
"."
] | 77de209e2d5317e51510d0f888e085ee0c400d66 | https://github.com/django-dbbackup/django-dbbackup/blob/77de209e2d5317e51510d0f888e085ee0c400d66/dbbackup/db/base.py#L118-L155 |
13,494 | tchellomello/raincloudy | raincloudy/faucet.py | RainCloudyFaucetCore._assign_zones | def _assign_zones(self):
"""Assign all RainCloudyFaucetZone managed by faucet."""
for zone_id in range(1, 5):
zone = \
RainCloudyFaucetZone(
parent=self._parent,
controller=self._controller,
faucet=self,
... | python | def _assign_zones(self):
"""Assign all RainCloudyFaucetZone managed by faucet."""
for zone_id in range(1, 5):
zone = \
RainCloudyFaucetZone(
parent=self._parent,
controller=self._controller,
faucet=self,
... | [
"def",
"_assign_zones",
"(",
"self",
")",
":",
"for",
"zone_id",
"in",
"range",
"(",
"1",
",",
"5",
")",
":",
"zone",
"=",
"RainCloudyFaucetZone",
"(",
"parent",
"=",
"self",
".",
"_parent",
",",
"controller",
"=",
"self",
".",
"_controller",
",",
"fau... | Assign all RainCloudyFaucetZone managed by faucet. | [
"Assign",
"all",
"RainCloudyFaucetZone",
"managed",
"by",
"faucet",
"."
] | 1847fa913e5ba79645d51bf23637860d68c67dbf | https://github.com/tchellomello/raincloudy/blob/1847fa913e5ba79645d51bf23637860d68c67dbf/raincloudy/faucet.py#L38-L49 |
13,495 | tchellomello/raincloudy | raincloudy/faucet.py | RainCloudyFaucetCore._find_zone_by_id | def _find_zone_by_id(self, zone_id):
"""Return zone by id."""
if not self.zones:
return None
zone = list(filter(
lambda zone: zone.id == zone_id, self.zones))
return zone[0] if zone else None | python | def _find_zone_by_id(self, zone_id):
"""Return zone by id."""
if not self.zones:
return None
zone = list(filter(
lambda zone: zone.id == zone_id, self.zones))
return zone[0] if zone else None | [
"def",
"_find_zone_by_id",
"(",
"self",
",",
"zone_id",
")",
":",
"if",
"not",
"self",
".",
"zones",
":",
"return",
"None",
"zone",
"=",
"list",
"(",
"filter",
"(",
"lambda",
"zone",
":",
"zone",
".",
"id",
"==",
"zone_id",
",",
"self",
".",
"zones",... | Return zone by id. | [
"Return",
"zone",
"by",
"id",
"."
] | 1847fa913e5ba79645d51bf23637860d68c67dbf | https://github.com/tchellomello/raincloudy/blob/1847fa913e5ba79645d51bf23637860d68c67dbf/raincloudy/faucet.py#L114-L122 |
13,496 | tchellomello/raincloudy | raincloudy/faucet.py | RainCloudyFaucetZone._set_zone_name | def _set_zone_name(self, zoneid, name):
"""Private method to override zone name."""
# zone starts with index 0
zoneid -= 1
data = {
'_set_zone_name': 'Set Name',
'select_zone': str(zoneid),
'zone_name': name,
}
self._controller.post(dat... | python | def _set_zone_name(self, zoneid, name):
"""Private method to override zone name."""
# zone starts with index 0
zoneid -= 1
data = {
'_set_zone_name': 'Set Name',
'select_zone': str(zoneid),
'zone_name': name,
}
self._controller.post(dat... | [
"def",
"_set_zone_name",
"(",
"self",
",",
"zoneid",
",",
"name",
")",
":",
"# zone starts with index 0",
"zoneid",
"-=",
"1",
"data",
"=",
"{",
"'_set_zone_name'",
":",
"'Set Name'",
",",
"'select_zone'",
":",
"str",
"(",
"zoneid",
")",
",",
"'zone_name'",
... | Private method to override zone name. | [
"Private",
"method",
"to",
"override",
"zone",
"name",
"."
] | 1847fa913e5ba79645d51bf23637860d68c67dbf | https://github.com/tchellomello/raincloudy/blob/1847fa913e5ba79645d51bf23637860d68c67dbf/raincloudy/faucet.py#L181-L190 |
13,497 | tchellomello/raincloudy | raincloudy/faucet.py | RainCloudyFaucetZone._set_watering_time | def _set_watering_time(self, zoneid, value):
"""Private method to set watering_time per zone."""
if value not in MANUAL_WATERING_ALLOWED:
raise ValueError(
'Valid options are: {}'.format(
', '.join(map(str, MANUAL_WATERING_ALLOWED)))
)
... | python | def _set_watering_time(self, zoneid, value):
"""Private method to set watering_time per zone."""
if value not in MANUAL_WATERING_ALLOWED:
raise ValueError(
'Valid options are: {}'.format(
', '.join(map(str, MANUAL_WATERING_ALLOWED)))
)
... | [
"def",
"_set_watering_time",
"(",
"self",
",",
"zoneid",
",",
"value",
")",
":",
"if",
"value",
"not",
"in",
"MANUAL_WATERING_ALLOWED",
":",
"raise",
"ValueError",
"(",
"'Valid options are: {}'",
".",
"format",
"(",
"', '",
".",
"join",
"(",
"map",
"(",
"str... | Private method to set watering_time per zone. | [
"Private",
"method",
"to",
"set",
"watering_time",
"per",
"zone",
"."
] | 1847fa913e5ba79645d51bf23637860d68c67dbf | https://github.com/tchellomello/raincloudy/blob/1847fa913e5ba79645d51bf23637860d68c67dbf/raincloudy/faucet.py#L202-L220 |
13,498 | tchellomello/raincloudy | raincloudy/faucet.py | RainCloudyFaucetZone.watering_time | def watering_time(self):
"""Return watering_time from zone."""
# zone starts with index 0
index = self.id - 1
auto_watering_time =\
self._attributes['rain_delay_mode'][index]['auto_watering_time']
manual_watering_time =\
self._attributes['rain_delay_mode'... | python | def watering_time(self):
"""Return watering_time from zone."""
# zone starts with index 0
index = self.id - 1
auto_watering_time =\
self._attributes['rain_delay_mode'][index]['auto_watering_time']
manual_watering_time =\
self._attributes['rain_delay_mode'... | [
"def",
"watering_time",
"(",
"self",
")",
":",
"# zone starts with index 0",
"index",
"=",
"self",
".",
"id",
"-",
"1",
"auto_watering_time",
"=",
"self",
".",
"_attributes",
"[",
"'rain_delay_mode'",
"]",
"[",
"index",
"]",
"[",
"'auto_watering_time'",
"]",
"... | Return watering_time from zone. | [
"Return",
"watering_time",
"from",
"zone",
"."
] | 1847fa913e5ba79645d51bf23637860d68c67dbf | https://github.com/tchellomello/raincloudy/blob/1847fa913e5ba79645d51bf23637860d68c67dbf/raincloudy/faucet.py#L224-L239 |
13,499 | tchellomello/raincloudy | raincloudy/faucet.py | RainCloudyFaucetZone._set_rain_delay | def _set_rain_delay(self, zoneid, value):
"""Generic method to set auto_watering program."""
# current index for rain_delay starts in 0
zoneid -= 1
if isinstance(value, int):
if value > MAX_RAIN_DELAY_DAYS or value < 0:
return None
elif value == 0... | python | def _set_rain_delay(self, zoneid, value):
"""Generic method to set auto_watering program."""
# current index for rain_delay starts in 0
zoneid -= 1
if isinstance(value, int):
if value > MAX_RAIN_DELAY_DAYS or value < 0:
return None
elif value == 0... | [
"def",
"_set_rain_delay",
"(",
"self",
",",
"zoneid",
",",
"value",
")",
":",
"# current index for rain_delay starts in 0",
"zoneid",
"-=",
"1",
"if",
"isinstance",
"(",
"value",
",",
"int",
")",
":",
"if",
"value",
">",
"MAX_RAIN_DELAY_DAYS",
"or",
"value",
"... | Generic method to set auto_watering program. | [
"Generic",
"method",
"to",
"set",
"auto_watering",
"program",
"."
] | 1847fa913e5ba79645d51bf23637860d68c67dbf | https://github.com/tchellomello/raincloudy/blob/1847fa913e5ba79645d51bf23637860d68c67dbf/raincloudy/faucet.py#L250-L272 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.