repo stringlengths 7 55 | path stringlengths 4 127 | func_name stringlengths 1 88 | original_string stringlengths 75 19.8k | language stringclasses 1
value | code stringlengths 75 19.8k | code_tokens list | docstring stringlengths 3 17.3k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 87 242 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
tchellomello/raincloudy | raincloudy/faucet.py | RainCloudyFaucetZone._set_auto_watering | def _set_auto_watering(self, zoneid, value):
"""Private method to set auto_watering program."""
if not isinstance(value, bool):
return None
ddata = self.preupdate()
attr = 'zone{}_program_toggle'.format(zoneid)
try:
if not value:
ddata.pop... | python | def _set_auto_watering(self, zoneid, value):
"""Private method to set auto_watering program."""
if not isinstance(value, bool):
return None
ddata = self.preupdate()
attr = 'zone{}_program_toggle'.format(zoneid)
try:
if not value:
ddata.pop... | [
"def",
"_set_auto_watering",
"(",
"self",
",",
"zoneid",
",",
"value",
")",
":",
"if",
"not",
"isinstance",
"(",
"value",
",",
"bool",
")",
":",
"return",
"None",
"ddata",
"=",
"self",
".",
"preupdate",
"(",
")",
"attr",
"=",
"'zone{}_program_toggle'",
"... | Private method to set auto_watering program. | [
"Private",
"method",
"to",
"set",
"auto_watering",
"program",
"."
] | 1847fa913e5ba79645d51bf23637860d68c67dbf | https://github.com/tchellomello/raincloudy/blob/1847fa913e5ba79645d51bf23637860d68c67dbf/raincloudy/faucet.py#L291-L306 | train |
tchellomello/raincloudy | raincloudy/faucet.py | RainCloudyFaucetZone.auto_watering | def auto_watering(self):
"""Return if zone is configured to automatic watering."""
value = "zone{}".format(self.id)
return find_program_status(self._parent.html['home'], value) | python | def auto_watering(self):
"""Return if zone is configured to automatic watering."""
value = "zone{}".format(self.id)
return find_program_status(self._parent.html['home'], value) | [
"def",
"auto_watering",
"(",
"self",
")",
":",
"value",
"=",
"\"zone{}\"",
".",
"format",
"(",
"self",
".",
"id",
")",
"return",
"find_program_status",
"(",
"self",
".",
"_parent",
".",
"html",
"[",
"'home'",
"]",
",",
"value",
")"
] | Return if zone is configured to automatic watering. | [
"Return",
"if",
"zone",
"is",
"configured",
"to",
"automatic",
"watering",
"."
] | 1847fa913e5ba79645d51bf23637860d68c67dbf | https://github.com/tchellomello/raincloudy/blob/1847fa913e5ba79645d51bf23637860d68c67dbf/raincloudy/faucet.py#L309-L312 | train |
tchellomello/raincloudy | raincloudy/faucet.py | RainCloudyFaucetZone._to_dict | def _to_dict(self):
"""Method to build zone dict."""
return {
'auto_watering':
getattr(self, "auto_watering"),
'droplet':
getattr(self, "droplet"),
'is_watering':
getattr(self, "is_watering"),
'name':
... | python | def _to_dict(self):
"""Method to build zone dict."""
return {
'auto_watering':
getattr(self, "auto_watering"),
'droplet':
getattr(self, "droplet"),
'is_watering':
getattr(self, "is_watering"),
'name':
... | [
"def",
"_to_dict",
"(",
"self",
")",
":",
"return",
"{",
"'auto_watering'",
":",
"getattr",
"(",
"self",
",",
"\"auto_watering\"",
")",
",",
"'droplet'",
":",
"getattr",
"(",
"self",
",",
"\"droplet\"",
")",
",",
"'is_watering'",
":",
"getattr",
"(",
"self... | Method to build zone dict. | [
"Method",
"to",
"build",
"zone",
"dict",
"."
] | 1847fa913e5ba79645d51bf23637860d68c67dbf | https://github.com/tchellomello/raincloudy/blob/1847fa913e5ba79645d51bf23637860d68c67dbf/raincloudy/faucet.py#L324-L341 | train |
tchellomello/raincloudy | raincloudy/faucet.py | RainCloudyFaucetZone.preupdate | def preupdate(self, force_refresh=True):
"""Return a dict with all current options prior submitting request."""
ddata = MANUAL_OP_DATA.copy()
# force update to make sure status is accurate
if force_refresh:
self.update()
# select current controller and faucet
... | python | def preupdate(self, force_refresh=True):
"""Return a dict with all current options prior submitting request."""
ddata = MANUAL_OP_DATA.copy()
# force update to make sure status is accurate
if force_refresh:
self.update()
# select current controller and faucet
... | [
"def",
"preupdate",
"(",
"self",
",",
"force_refresh",
"=",
"True",
")",
":",
"ddata",
"=",
"MANUAL_OP_DATA",
".",
"copy",
"(",
")",
"# force update to make sure status is accurate",
"if",
"force_refresh",
":",
"self",
".",
"update",
"(",
")",
"# select current co... | Return a dict with all current options prior submitting request. | [
"Return",
"a",
"dict",
"with",
"all",
"current",
"options",
"prior",
"submitting",
"request",
"."
] | 1847fa913e5ba79645d51bf23637860d68c67dbf | https://github.com/tchellomello/raincloudy/blob/1847fa913e5ba79645d51bf23637860d68c67dbf/raincloudy/faucet.py#L347-L386 | train |
tchellomello/raincloudy | raincloudy/faucet.py | RainCloudyFaucetZone.submit_action | def submit_action(self, ddata):
"""Post data."""
self._controller.post(ddata,
url=HOME_ENDPOINT,
referer=HOME_ENDPOINT) | python | def submit_action(self, ddata):
"""Post data."""
self._controller.post(ddata,
url=HOME_ENDPOINT,
referer=HOME_ENDPOINT) | [
"def",
"submit_action",
"(",
"self",
",",
"ddata",
")",
":",
"self",
".",
"_controller",
".",
"post",
"(",
"ddata",
",",
"url",
"=",
"HOME_ENDPOINT",
",",
"referer",
"=",
"HOME_ENDPOINT",
")"
] | Post data. | [
"Post",
"data",
"."
] | 1847fa913e5ba79645d51bf23637860d68c67dbf | https://github.com/tchellomello/raincloudy/blob/1847fa913e5ba79645d51bf23637860d68c67dbf/raincloudy/faucet.py#L388-L392 | train |
tchellomello/raincloudy | raincloudy/core.py | RainCloudy.controller | def controller(self):
"""Show current linked controllers."""
if hasattr(self, 'controllers'):
if len(self.controllers) > 1:
# in the future, we should support more controllers
raise TypeError("Only one controller per account.")
return self.controll... | python | def controller(self):
"""Show current linked controllers."""
if hasattr(self, 'controllers'):
if len(self.controllers) > 1:
# in the future, we should support more controllers
raise TypeError("Only one controller per account.")
return self.controll... | [
"def",
"controller",
"(",
"self",
")",
":",
"if",
"hasattr",
"(",
"self",
",",
"'controllers'",
")",
":",
"if",
"len",
"(",
"self",
".",
"controllers",
")",
">",
"1",
":",
"# in the future, we should support more controllers",
"raise",
"TypeError",
"(",
"\"Onl... | Show current linked controllers. | [
"Show",
"current",
"linked",
"controllers",
"."
] | 1847fa913e5ba79645d51bf23637860d68c67dbf | https://github.com/tchellomello/raincloudy/blob/1847fa913e5ba79645d51bf23637860d68c67dbf/raincloudy/core.py#L123-L130 | train |
tchellomello/raincloudy | raincloudy/controller.py | RainCloudyController._assign_faucets | def _assign_faucets(self, faucets):
"""Assign RainCloudyFaucet objects to self.faucets."""
if not faucets:
raise TypeError("Controller does not have a faucet assigned.")
for faucet_id in faucets:
self.faucets.append(
RainCloudyFaucet(self._parent, self, f... | python | def _assign_faucets(self, faucets):
"""Assign RainCloudyFaucet objects to self.faucets."""
if not faucets:
raise TypeError("Controller does not have a faucet assigned.")
for faucet_id in faucets:
self.faucets.append(
RainCloudyFaucet(self._parent, self, f... | [
"def",
"_assign_faucets",
"(",
"self",
",",
"faucets",
")",
":",
"if",
"not",
"faucets",
":",
"raise",
"TypeError",
"(",
"\"Controller does not have a faucet assigned.\"",
")",
"for",
"faucet_id",
"in",
"faucets",
":",
"self",
".",
"faucets",
".",
"append",
"(",... | Assign RainCloudyFaucet objects to self.faucets. | [
"Assign",
"RainCloudyFaucet",
"objects",
"to",
"self",
".",
"faucets",
"."
] | 1847fa913e5ba79645d51bf23637860d68c67dbf | https://github.com/tchellomello/raincloudy/blob/1847fa913e5ba79645d51bf23637860d68c67dbf/raincloudy/controller.py#L48-L55 | train |
tchellomello/raincloudy | raincloudy/controller.py | RainCloudyController.post | def post(self, ddata, url=SETUP_ENDPOINT, referer=SETUP_ENDPOINT):
"""Method to update some attributes on namespace."""
headers = HEADERS.copy()
if referer is None:
headers.pop('Referer')
else:
headers['Referer'] = referer
# append csrftoken
if 'c... | python | def post(self, ddata, url=SETUP_ENDPOINT, referer=SETUP_ENDPOINT):
"""Method to update some attributes on namespace."""
headers = HEADERS.copy()
if referer is None:
headers.pop('Referer')
else:
headers['Referer'] = referer
# append csrftoken
if 'c... | [
"def",
"post",
"(",
"self",
",",
"ddata",
",",
"url",
"=",
"SETUP_ENDPOINT",
",",
"referer",
"=",
"SETUP_ENDPOINT",
")",
":",
"headers",
"=",
"HEADERS",
".",
"copy",
"(",
")",
"if",
"referer",
"is",
"None",
":",
"headers",
".",
"pop",
"(",
"'Referer'",... | Method to update some attributes on namespace. | [
"Method",
"to",
"update",
"some",
"attributes",
"on",
"namespace",
"."
] | 1847fa913e5ba79645d51bf23637860d68c67dbf | https://github.com/tchellomello/raincloudy/blob/1847fa913e5ba79645d51bf23637860d68c67dbf/raincloudy/controller.py#L64-L78 | train |
tchellomello/raincloudy | raincloudy/controller.py | RainCloudyController._get_cu_and_fu_status | def _get_cu_and_fu_status(self):
"""Submit GET request to update information."""
# adjust headers
headers = HEADERS.copy()
headers['Accept'] = '*/*'
headers['X-Requested-With'] = 'XMLHttpRequest'
headers['X-CSRFToken'] = self._parent.csrftoken
args = '?controller... | python | def _get_cu_and_fu_status(self):
"""Submit GET request to update information."""
# adjust headers
headers = HEADERS.copy()
headers['Accept'] = '*/*'
headers['X-Requested-With'] = 'XMLHttpRequest'
headers['X-CSRFToken'] = self._parent.csrftoken
args = '?controller... | [
"def",
"_get_cu_and_fu_status",
"(",
"self",
")",
":",
"# adjust headers",
"headers",
"=",
"HEADERS",
".",
"copy",
"(",
")",
"headers",
"[",
"'Accept'",
"]",
"=",
"'*/*'",
"headers",
"[",
"'X-Requested-With'",
"]",
"=",
"'XMLHttpRequest'",
"headers",
"[",
"'X-... | Submit GET request to update information. | [
"Submit",
"GET",
"request",
"to",
"update",
"information",
"."
] | 1847fa913e5ba79645d51bf23637860d68c67dbf | https://github.com/tchellomello/raincloudy/blob/1847fa913e5ba79645d51bf23637860d68c67dbf/raincloudy/controller.py#L80-L101 | train |
tchellomello/raincloudy | raincloudy/controller.py | RainCloudyController.name | def name(self, value):
"""Set a new name to controller."""
data = {
'_set_controller_name': 'Set Name',
'controller_name': value,
}
self.post(data, url=SETUP_ENDPOINT, referer=SETUP_ENDPOINT) | python | def name(self, value):
"""Set a new name to controller."""
data = {
'_set_controller_name': 'Set Name',
'controller_name': value,
}
self.post(data, url=SETUP_ENDPOINT, referer=SETUP_ENDPOINT) | [
"def",
"name",
"(",
"self",
",",
"value",
")",
":",
"data",
"=",
"{",
"'_set_controller_name'",
":",
"'Set Name'",
",",
"'controller_name'",
":",
"value",
",",
"}",
"self",
".",
"post",
"(",
"data",
",",
"url",
"=",
"SETUP_ENDPOINT",
",",
"referer",
"=",... | Set a new name to controller. | [
"Set",
"a",
"new",
"name",
"to",
"controller",
"."
] | 1847fa913e5ba79645d51bf23637860d68c67dbf | https://github.com/tchellomello/raincloudy/blob/1847fa913e5ba79645d51bf23637860d68c67dbf/raincloudy/controller.py#L148-L154 | train |
tchellomello/raincloudy | raincloudy/controller.py | RainCloudyController.faucet | def faucet(self):
"""Show current linked faucet."""
if hasattr(self, 'faucets'):
if len(self.faucets) > 1:
# in the future, we should support more faucets
raise TypeError("Only one faucet per account.")
return self.faucets[0]
raise Attribut... | python | def faucet(self):
"""Show current linked faucet."""
if hasattr(self, 'faucets'):
if len(self.faucets) > 1:
# in the future, we should support more faucets
raise TypeError("Only one faucet per account.")
return self.faucets[0]
raise Attribut... | [
"def",
"faucet",
"(",
"self",
")",
":",
"if",
"hasattr",
"(",
"self",
",",
"'faucets'",
")",
":",
"if",
"len",
"(",
"self",
".",
"faucets",
")",
">",
"1",
":",
"# in the future, we should support more faucets",
"raise",
"TypeError",
"(",
"\"Only one faucet per... | Show current linked faucet. | [
"Show",
"current",
"linked",
"faucet",
"."
] | 1847fa913e5ba79645d51bf23637860d68c67dbf | https://github.com/tchellomello/raincloudy/blob/1847fa913e5ba79645d51bf23637860d68c67dbf/raincloudy/controller.py#L167-L174 | train |
tchellomello/raincloudy | raincloudy/helpers.py | serial_finder | def serial_finder(data):
"""
Find controller serial and faucet_serial from the setup page.
<select id="id_select_controller2" name="select_controller" >
<option value='0' selected='selected'>1 - Controller001</option>
</select>
:param data: text to be parsed
:type data: BeautilSoup obj... | python | def serial_finder(data):
"""
Find controller serial and faucet_serial from the setup page.
<select id="id_select_controller2" name="select_controller" >
<option value='0' selected='selected'>1 - Controller001</option>
</select>
:param data: text to be parsed
:type data: BeautilSoup obj... | [
"def",
"serial_finder",
"(",
"data",
")",
":",
"if",
"not",
"isinstance",
"(",
"data",
",",
"BeautifulSoup",
")",
":",
"raise",
"TypeError",
"(",
"\"Function requires BeautifulSoup HTML element.\"",
")",
"try",
":",
"# The setup page contains a select box for each control... | Find controller serial and faucet_serial from the setup page.
<select id="id_select_controller2" name="select_controller" >
<option value='0' selected='selected'>1 - Controller001</option>
</select>
:param data: text to be parsed
:type data: BeautilSoup object
:return: a dict with controll... | [
"Find",
"controller",
"serial",
"and",
"faucet_serial",
"from",
"the",
"setup",
"page",
"."
] | 1847fa913e5ba79645d51bf23637860d68c67dbf | https://github.com/tchellomello/raincloudy/blob/1847fa913e5ba79645d51bf23637860d68c67dbf/raincloudy/helpers.py#L15-L54 | train |
tchellomello/raincloudy | raincloudy/helpers.py | find_controller_or_faucet_name | def find_controller_or_faucet_name(data, p_type):
"""
Find on the HTML document the controller name.
# expected result
<label for="select_controller">
<span class="more_info" id="#styling-type-light" data-hasqtip="26" \
title="Select Control Unit to display." >Control Unit:</span></label><br/... | python | def find_controller_or_faucet_name(data, p_type):
"""
Find on the HTML document the controller name.
# expected result
<label for="select_controller">
<span class="more_info" id="#styling-type-light" data-hasqtip="26" \
title="Select Control Unit to display." >Control Unit:</span></label><br/... | [
"def",
"find_controller_or_faucet_name",
"(",
"data",
",",
"p_type",
")",
":",
"if",
"not",
"isinstance",
"(",
"data",
",",
"BeautifulSoup",
")",
":",
"raise",
"TypeError",
"(",
"\"Function requires BeautilSoup HTML element.\"",
")",
"if",
"not",
"(",
"p_type",
"=... | Find on the HTML document the controller name.
# expected result
<label for="select_controller">
<span class="more_info" id="#styling-type-light" data-hasqtip="26" \
title="Select Control Unit to display." >Control Unit:</span></label><br/>
<select class="simpleselect" id="id_select_controller" ... | [
"Find",
"on",
"the",
"HTML",
"document",
"the",
"controller",
"name",
"."
] | 1847fa913e5ba79645d51bf23637860d68c67dbf | https://github.com/tchellomello/raincloudy/blob/1847fa913e5ba79645d51bf23637860d68c67dbf/raincloudy/helpers.py#L93-L123 | train |
tchellomello/raincloudy | raincloudy/helpers.py | find_zone_name | def find_zone_name(data, zone_id):
"""
Find on the HTML document the zone name.
# expected result
<span class="more_info" \
title="Zone can be renamed on Setup tab">1 - zone1</span>,
:param data: BeautifulSoup object
:param zone: zone id
:return: zone name
:rtype: string
:r... | python | def find_zone_name(data, zone_id):
"""
Find on the HTML document the zone name.
# expected result
<span class="more_info" \
title="Zone can be renamed on Setup tab">1 - zone1</span>,
:param data: BeautifulSoup object
:param zone: zone id
:return: zone name
:rtype: string
:r... | [
"def",
"find_zone_name",
"(",
"data",
",",
"zone_id",
")",
":",
"if",
"not",
"isinstance",
"(",
"data",
",",
"BeautifulSoup",
")",
":",
"raise",
"TypeError",
"(",
"\"Function requires BeautilSoup HTML element.\"",
")",
"table",
"=",
"data",
".",
"find",
"(",
"... | Find on the HTML document the zone name.
# expected result
<span class="more_info" \
title="Zone can be renamed on Setup tab">1 - zone1</span>,
:param data: BeautifulSoup object
:param zone: zone id
:return: zone name
:rtype: string
:raises TypeError: if data is not a BeautifulSoup... | [
"Find",
"on",
"the",
"HTML",
"document",
"the",
"zone",
"name",
"."
] | 1847fa913e5ba79645d51bf23637860d68c67dbf | https://github.com/tchellomello/raincloudy/blob/1847fa913e5ba79645d51bf23637860d68c67dbf/raincloudy/helpers.py#L126-L150 | train |
django-getpaid/django-getpaid | example/orders/listeners.py | new_payment_query_listener | def new_payment_query_listener(sender, order=None, payment=None, **kwargs):
"""
Here we fill only two obligatory fields of payment, and leave signal handler
"""
payment.amount = order.total
payment.currency = order.currency
logger.debug("new_payment_query_listener, amount=%s, currency=%s",
... | python | def new_payment_query_listener(sender, order=None, payment=None, **kwargs):
"""
Here we fill only two obligatory fields of payment, and leave signal handler
"""
payment.amount = order.total
payment.currency = order.currency
logger.debug("new_payment_query_listener, amount=%s, currency=%s",
... | [
"def",
"new_payment_query_listener",
"(",
"sender",
",",
"order",
"=",
"None",
",",
"payment",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"payment",
".",
"amount",
"=",
"order",
".",
"total",
"payment",
".",
"currency",
"=",
"order",
".",
"currency"... | Here we fill only two obligatory fields of payment, and leave signal handler | [
"Here",
"we",
"fill",
"only",
"two",
"obligatory",
"fields",
"of",
"payment",
"and",
"leave",
"signal",
"handler"
] | f32badcd0ebc28d24adceb4f649c0c2b84c03987 | https://github.com/django-getpaid/django-getpaid/blob/f32badcd0ebc28d24adceb4f649c0c2b84c03987/example/orders/listeners.py#L6-L14 | train |
django-getpaid/django-getpaid | example/orders/listeners.py | payment_status_changed_listener | def payment_status_changed_listener(sender, instance, old_status, new_status, **kwargs):
"""
Here we will actually do something, when payment is accepted.
E.g. lets change an order status.
"""
logger.debug("payment_status_changed_listener, old=%s, new=%s", old_status,
new_status)
... | python | def payment_status_changed_listener(sender, instance, old_status, new_status, **kwargs):
"""
Here we will actually do something, when payment is accepted.
E.g. lets change an order status.
"""
logger.debug("payment_status_changed_listener, old=%s, new=%s", old_status,
new_status)
... | [
"def",
"payment_status_changed_listener",
"(",
"sender",
",",
"instance",
",",
"old_status",
",",
"new_status",
",",
"*",
"*",
"kwargs",
")",
":",
"logger",
".",
"debug",
"(",
"\"payment_status_changed_listener, old=%s, new=%s\"",
",",
"old_status",
",",
"new_status",... | Here we will actually do something, when payment is accepted.
E.g. lets change an order status. | [
"Here",
"we",
"will",
"actually",
"do",
"something",
"when",
"payment",
"is",
"accepted",
".",
"E",
".",
"g",
".",
"lets",
"change",
"an",
"order",
"status",
"."
] | f32badcd0ebc28d24adceb4f649c0c2b84c03987 | https://github.com/django-getpaid/django-getpaid/blob/f32badcd0ebc28d24adceb4f649c0c2b84c03987/example/orders/listeners.py#L17-L27 | train |
django-getpaid/django-getpaid | getpaid/models.py | register_to_payment | def register_to_payment(order_class, **kwargs):
"""
A function for registering unaware order class to ``getpaid``. This will
generate a ``Payment`` model class that will store payments with
ForeignKey to original order class
This also will build a model class for every enabled backend.
"""
... | python | def register_to_payment(order_class, **kwargs):
"""
A function for registering unaware order class to ``getpaid``. This will
generate a ``Payment`` model class that will store payments with
ForeignKey to original order class
This also will build a model class for every enabled backend.
"""
... | [
"def",
"register_to_payment",
"(",
"order_class",
",",
"*",
"*",
"kwargs",
")",
":",
"global",
"Payment",
"global",
"Order",
"class",
"Payment",
"(",
"PaymentFactory",
".",
"construct",
"(",
"order",
"=",
"order_class",
",",
"*",
"*",
"kwargs",
")",
")",
"... | A function for registering unaware order class to ``getpaid``. This will
generate a ``Payment`` model class that will store payments with
ForeignKey to original order class
This also will build a model class for every enabled backend. | [
"A",
"function",
"for",
"registering",
"unaware",
"order",
"class",
"to",
"getpaid",
".",
"This",
"will",
"generate",
"a",
"Payment",
"model",
"class",
"that",
"will",
"store",
"payments",
"with",
"ForeignKey",
"to",
"original",
"order",
"class"
] | f32badcd0ebc28d24adceb4f649c0c2b84c03987 | https://github.com/django-getpaid/django-getpaid/blob/f32badcd0ebc28d24adceb4f649c0c2b84c03987/getpaid/models.py#L128-L155 | train |
django-getpaid/django-getpaid | getpaid/utils.py | get_backend_choices | def get_backend_choices(currency=None):
"""
Get active backends modules. Backend list can be filtered by
supporting given currency.
"""
choices = []
backends_names = getattr(settings, 'GETPAID_BACKENDS', [])
for backend_name in backends_names:
backend = import_module(backend_name)
... | python | def get_backend_choices(currency=None):
"""
Get active backends modules. Backend list can be filtered by
supporting given currency.
"""
choices = []
backends_names = getattr(settings, 'GETPAID_BACKENDS', [])
for backend_name in backends_names:
backend = import_module(backend_name)
... | [
"def",
"get_backend_choices",
"(",
"currency",
"=",
"None",
")",
":",
"choices",
"=",
"[",
"]",
"backends_names",
"=",
"getattr",
"(",
"settings",
",",
"'GETPAID_BACKENDS'",
",",
"[",
"]",
")",
"for",
"backend_name",
"in",
"backends_names",
":",
"backend",
"... | Get active backends modules. Backend list can be filtered by
supporting given currency. | [
"Get",
"active",
"backends",
"modules",
".",
"Backend",
"list",
"can",
"be",
"filtered",
"by",
"supporting",
"given",
"currency",
"."
] | f32badcd0ebc28d24adceb4f649c0c2b84c03987 | https://github.com/django-getpaid/django-getpaid/blob/f32badcd0ebc28d24adceb4f649c0c2b84c03987/getpaid/utils.py#L29-L48 | train |
django-getpaid/django-getpaid | getpaid/backends/payu_rest/__init__.py | PaymentProcessor.online | def online(cls, payload, ip, req_sig):
"""
Receive and analyze request from payment service with information on payment status change.
"""
from getpaid.models import Payment
params = json.loads(payload)
order_data = params.get('order', {})
pos_id = order_data.ge... | python | def online(cls, payload, ip, req_sig):
"""
Receive and analyze request from payment service with information on payment status change.
"""
from getpaid.models import Payment
params = json.loads(payload)
order_data = params.get('order', {})
pos_id = order_data.ge... | [
"def",
"online",
"(",
"cls",
",",
"payload",
",",
"ip",
",",
"req_sig",
")",
":",
"from",
"getpaid",
".",
"models",
"import",
"Payment",
"params",
"=",
"json",
".",
"loads",
"(",
"payload",
")",
"order_data",
"=",
"params",
".",
"get",
"(",
"'order'",
... | Receive and analyze request from payment service with information on payment status change. | [
"Receive",
"and",
"analyze",
"request",
"from",
"payment",
"service",
"with",
"information",
"on",
"payment",
"status",
"change",
"."
] | f32badcd0ebc28d24adceb4f649c0c2b84c03987 | https://github.com/django-getpaid/django-getpaid/blob/f32badcd0ebc28d24adceb4f649c0c2b84c03987/getpaid/backends/payu_rest/__init__.py#L87-L132 | train |
django-getpaid/django-getpaid | getpaid/backends/__init__.py | PaymentProcessorBase.get_order_description | def get_order_description(self, payment, order):
"""
Renders order description using django template provided in ``settings.GETPAID_ORDER_DESCRIPTION``
or if not provided return unicode representation of ``Order object``.
"""
template = getattr(settings, 'GETPAID_ORDER_DESCRIPTIO... | python | def get_order_description(self, payment, order):
"""
Renders order description using django template provided in ``settings.GETPAID_ORDER_DESCRIPTION``
or if not provided return unicode representation of ``Order object``.
"""
template = getattr(settings, 'GETPAID_ORDER_DESCRIPTIO... | [
"def",
"get_order_description",
"(",
"self",
",",
"payment",
",",
"order",
")",
":",
"template",
"=",
"getattr",
"(",
"settings",
",",
"'GETPAID_ORDER_DESCRIPTION'",
",",
"None",
")",
"if",
"template",
":",
"return",
"Template",
"(",
"template",
")",
".",
"r... | Renders order description using django template provided in ``settings.GETPAID_ORDER_DESCRIPTION``
or if not provided return unicode representation of ``Order object``. | [
"Renders",
"order",
"description",
"using",
"django",
"template",
"provided",
"in",
"settings",
".",
"GETPAID_ORDER_DESCRIPTION",
"or",
"if",
"not",
"provided",
"return",
"unicode",
"representation",
"of",
"Order",
"object",
"."
] | f32badcd0ebc28d24adceb4f649c0c2b84c03987 | https://github.com/django-getpaid/django-getpaid/blob/f32badcd0ebc28d24adceb4f649c0c2b84c03987/getpaid/backends/__init__.py#L54-L63 | train |
django-getpaid/django-getpaid | getpaid/backends/__init__.py | PaymentProcessorBase.get_backend_setting | def get_backend_setting(cls, name, default=None):
"""
Reads ``name`` setting from backend settings dictionary.
If `default` value is omitted, raises ``ImproperlyConfigured`` when
setting ``name`` is not available.
"""
backend_settings = get_backend_settings(cls.BACKEND)
... | python | def get_backend_setting(cls, name, default=None):
"""
Reads ``name`` setting from backend settings dictionary.
If `default` value is omitted, raises ``ImproperlyConfigured`` when
setting ``name`` is not available.
"""
backend_settings = get_backend_settings(cls.BACKEND)
... | [
"def",
"get_backend_setting",
"(",
"cls",
",",
"name",
",",
"default",
"=",
"None",
")",
":",
"backend_settings",
"=",
"get_backend_settings",
"(",
"cls",
".",
"BACKEND",
")",
"if",
"default",
"is",
"not",
"None",
":",
"return",
"backend_settings",
".",
"get... | Reads ``name`` setting from backend settings dictionary.
If `default` value is omitted, raises ``ImproperlyConfigured`` when
setting ``name`` is not available. | [
"Reads",
"name",
"setting",
"from",
"backend",
"settings",
"dictionary",
"."
] | f32badcd0ebc28d24adceb4f649c0c2b84c03987 | https://github.com/django-getpaid/django-getpaid/blob/f32badcd0ebc28d24adceb4f649c0c2b84c03987/getpaid/backends/__init__.py#L83-L97 | train |
django-getpaid/django-getpaid | getpaid/backends/dotpay/__init__.py | PaymentProcessor.get_gateway_url | def get_gateway_url(self, request):
"""
Routes a payment to Gateway, should return URL for redirection.
"""
params = {
'id': self.get_backend_setting('id'),
'description': self.get_order_description(self.payment, self.payment.order),
'amount': self.pay... | python | def get_gateway_url(self, request):
"""
Routes a payment to Gateway, should return URL for redirection.
"""
params = {
'id': self.get_backend_setting('id'),
'description': self.get_order_description(self.payment, self.payment.order),
'amount': self.pay... | [
"def",
"get_gateway_url",
"(",
"self",
",",
"request",
")",
":",
"params",
"=",
"{",
"'id'",
":",
"self",
".",
"get_backend_setting",
"(",
"'id'",
")",
",",
"'description'",
":",
"self",
".",
"get_order_description",
"(",
"self",
".",
"payment",
",",
"self... | Routes a payment to Gateway, should return URL for redirection. | [
"Routes",
"a",
"payment",
"to",
"Gateway",
"should",
"return",
"URL",
"for",
"redirection",
"."
] | f32badcd0ebc28d24adceb4f649c0c2b84c03987 | https://github.com/django-getpaid/django-getpaid/blob/f32badcd0ebc28d24adceb4f649c0c2b84c03987/getpaid/backends/dotpay/__init__.py#L114-L163 | train |
hubo1016/aiogrpc | aiogrpc/channel.py | channel_ready_future | def channel_ready_future(channel):
"""Creates a Future that tracks when a Channel is ready.
Cancelling the Future does not affect the channel's state machine.
It merely decouples the Future from channel state machine.
Args:
channel: A Channel object.
Returns:
A Future object that matures when the... | python | def channel_ready_future(channel):
"""Creates a Future that tracks when a Channel is ready.
Cancelling the Future does not affect the channel's state machine.
It merely decouples the Future from channel state machine.
Args:
channel: A Channel object.
Returns:
A Future object that matures when the... | [
"def",
"channel_ready_future",
"(",
"channel",
")",
":",
"fut",
"=",
"channel",
".",
"_loop",
".",
"create_future",
"(",
")",
"def",
"_set_result",
"(",
"state",
")",
":",
"if",
"not",
"fut",
".",
"done",
"(",
")",
"and",
"state",
"is",
"_grpc",
".",
... | Creates a Future that tracks when a Channel is ready.
Cancelling the Future does not affect the channel's state machine.
It merely decouples the Future from channel state machine.
Args:
channel: A Channel object.
Returns:
A Future object that matures when the channel connectivity is
ChannelConnec... | [
"Creates",
"a",
"Future",
"that",
"tracks",
"when",
"a",
"Channel",
"is",
"ready",
"."
] | 5bc98bfbe9f2e11dd0eab8e93b8aeefbcc2ccd4b | https://github.com/hubo1016/aiogrpc/blob/5bc98bfbe9f2e11dd0eab8e93b8aeefbcc2ccd4b/aiogrpc/channel.py#L395-L414 | train |
hubo1016/aiogrpc | aiogrpc/channel.py | insecure_channel | def insecure_channel(target, options=None, *, loop=None, executor=None,
standalone_pool_for_streaming=False):
"""Creates an insecure Channel to a server.
Args:
target: The server address
options: An optional list of key-value pairs (channel args in gRPC runtime)
to configure the c... | python | def insecure_channel(target, options=None, *, loop=None, executor=None,
standalone_pool_for_streaming=False):
"""Creates an insecure Channel to a server.
Args:
target: The server address
options: An optional list of key-value pairs (channel args in gRPC runtime)
to configure the c... | [
"def",
"insecure_channel",
"(",
"target",
",",
"options",
"=",
"None",
",",
"*",
",",
"loop",
"=",
"None",
",",
"executor",
"=",
"None",
",",
"standalone_pool_for_streaming",
"=",
"False",
")",
":",
"return",
"Channel",
"(",
"_grpc",
".",
"insecure_channel",... | Creates an insecure Channel to a server.
Args:
target: The server address
options: An optional list of key-value pairs (channel args in gRPC runtime)
to configure the channel.
Returns:
A Channel object. | [
"Creates",
"an",
"insecure",
"Channel",
"to",
"a",
"server",
"."
] | 5bc98bfbe9f2e11dd0eab8e93b8aeefbcc2ccd4b | https://github.com/hubo1016/aiogrpc/blob/5bc98bfbe9f2e11dd0eab8e93b8aeefbcc2ccd4b/aiogrpc/channel.py#L417-L429 | train |
hubo1016/aiogrpc | aiogrpc/channel.py | secure_channel | def secure_channel(target, credentials, options=None, *, loop=None, executor=None,
standalone_pool_for_streaming=False):
"""Creates a secure Channel to a server.
Args:
target: The server address.
credentials: A ChannelCredentials instance.
options: An optional list of key-value pai... | python | def secure_channel(target, credentials, options=None, *, loop=None, executor=None,
standalone_pool_for_streaming=False):
"""Creates a secure Channel to a server.
Args:
target: The server address.
credentials: A ChannelCredentials instance.
options: An optional list of key-value pai... | [
"def",
"secure_channel",
"(",
"target",
",",
"credentials",
",",
"options",
"=",
"None",
",",
"*",
",",
"loop",
"=",
"None",
",",
"executor",
"=",
"None",
",",
"standalone_pool_for_streaming",
"=",
"False",
")",
":",
"return",
"Channel",
"(",
"_grpc",
".",... | Creates a secure Channel to a server.
Args:
target: The server address.
credentials: A ChannelCredentials instance.
options: An optional list of key-value pairs (channel args in gRPC runtime)
to configure the channel.
Returns:
A Channel object. | [
"Creates",
"a",
"secure",
"Channel",
"to",
"a",
"server",
"."
] | 5bc98bfbe9f2e11dd0eab8e93b8aeefbcc2ccd4b | https://github.com/hubo1016/aiogrpc/blob/5bc98bfbe9f2e11dd0eab8e93b8aeefbcc2ccd4b/aiogrpc/channel.py#L432-L446 | train |
hubo1016/aiogrpc | aiogrpc/channel.py | _UnaryUnaryMultiCallable.future | def future(self, request, timeout=None, metadata=None, credentials=None):
"""Asynchronously invokes the underlying RPC.
Args:
request: The request value for the RPC.
timeout: An optional duration of time in seconds to allow for the RPC.
metadata: Optional :term:`metadata` to be transmitte... | python | def future(self, request, timeout=None, metadata=None, credentials=None):
"""Asynchronously invokes the underlying RPC.
Args:
request: The request value for the RPC.
timeout: An optional duration of time in seconds to allow for the RPC.
metadata: Optional :term:`metadata` to be transmitte... | [
"def",
"future",
"(",
"self",
",",
"request",
",",
"timeout",
"=",
"None",
",",
"metadata",
"=",
"None",
",",
"credentials",
"=",
"None",
")",
":",
"return",
"_utils",
".",
"wrap_future_call",
"(",
"self",
".",
"_inner",
".",
"future",
"(",
"request",
... | Asynchronously invokes the underlying RPC.
Args:
request: The request value for the RPC.
timeout: An optional duration of time in seconds to allow for the RPC.
metadata: Optional :term:`metadata` to be transmitted to the
service-side of the RPC.
credentials: An optional CallCredenti... | [
"Asynchronously",
"invokes",
"the",
"underlying",
"RPC",
"."
] | 5bc98bfbe9f2e11dd0eab8e93b8aeefbcc2ccd4b | https://github.com/hubo1016/aiogrpc/blob/5bc98bfbe9f2e11dd0eab8e93b8aeefbcc2ccd4b/aiogrpc/channel.py#L72-L89 | train |
hubo1016/aiogrpc | aiogrpc/channel.py | _StreamUnaryMultiCallable.with_call | async def with_call(self,
request_iterator,
timeout=None,
metadata=None,
credentials=None):
"""Synchronously invokes the underlying RPC on the client.
Args:
request_iterator: An ASYNC iterator that yields request values for the R... | python | async def with_call(self,
request_iterator,
timeout=None,
metadata=None,
credentials=None):
"""Synchronously invokes the underlying RPC on the client.
Args:
request_iterator: An ASYNC iterator that yields request values for the R... | [
"async",
"def",
"with_call",
"(",
"self",
",",
"request_iterator",
",",
"timeout",
"=",
"None",
",",
"metadata",
"=",
"None",
",",
"credentials",
"=",
"None",
")",
":",
"fut",
"=",
"self",
".",
"future",
"(",
"request_iterator",
",",
"timeout",
",",
"met... | Synchronously invokes the underlying RPC on the client.
Args:
request_iterator: An ASYNC iterator that yields request values for the RPC.
timeout: An optional duration of time in seconds to allow for the RPC.
If None, the timeout is considered infinite.
metadata: Optional :term:`me... | [
"Synchronously",
"invokes",
"the",
"underlying",
"RPC",
"on",
"the",
"client",
"."
] | 5bc98bfbe9f2e11dd0eab8e93b8aeefbcc2ccd4b | https://github.com/hubo1016/aiogrpc/blob/5bc98bfbe9f2e11dd0eab8e93b8aeefbcc2ccd4b/aiogrpc/channel.py#L177-L206 | train |
hubo1016/aiogrpc | aiogrpc/channel.py | _StreamUnaryMultiCallable.future | def future(self,
request_iterator,
timeout=None,
metadata=None,
credentials=None):
"""Asynchronously invokes the underlying RPC on the client.
Args:
request_iterator: An ASYNC iterator that yields request values for the RPC.
timeout: A... | python | def future(self,
request_iterator,
timeout=None,
metadata=None,
credentials=None):
"""Asynchronously invokes the underlying RPC on the client.
Args:
request_iterator: An ASYNC iterator that yields request values for the RPC.
timeout: A... | [
"def",
"future",
"(",
"self",
",",
"request_iterator",
",",
"timeout",
"=",
"None",
",",
"metadata",
"=",
"None",
",",
"credentials",
"=",
"None",
")",
":",
"return",
"_utils",
".",
"wrap_future_call",
"(",
"self",
".",
"_inner",
".",
"future",
"(",
"_ut... | Asynchronously invokes the underlying RPC on the client.
Args:
request_iterator: An ASYNC iterator that yields request values for the RPC.
timeout: An optional duration of time in seconds to allow for the RPC.
If None, the timeout is considered infinite.
metadata: Optional :term:`m... | [
"Asynchronously",
"invokes",
"the",
"underlying",
"RPC",
"on",
"the",
"client",
"."
] | 5bc98bfbe9f2e11dd0eab8e93b8aeefbcc2ccd4b | https://github.com/hubo1016/aiogrpc/blob/5bc98bfbe9f2e11dd0eab8e93b8aeefbcc2ccd4b/aiogrpc/channel.py#L208-L237 | train |
Cymmetria/honeycomb | honeycomb/utils/config_utils.py | config_field_type | def config_field_type(field, cls):
"""Validate a config field against a type.
Similar functionality to :func:`validate_field_matches_type` but returns :obj:`honeycomb.defs.ConfigField`
"""
return defs.ConfigField(lambda _: isinstance(_, cls),
lambda: CONFIG_FIELD_TYPE_ERROR.... | python | def config_field_type(field, cls):
"""Validate a config field against a type.
Similar functionality to :func:`validate_field_matches_type` but returns :obj:`honeycomb.defs.ConfigField`
"""
return defs.ConfigField(lambda _: isinstance(_, cls),
lambda: CONFIG_FIELD_TYPE_ERROR.... | [
"def",
"config_field_type",
"(",
"field",
",",
"cls",
")",
":",
"return",
"defs",
".",
"ConfigField",
"(",
"lambda",
"_",
":",
"isinstance",
"(",
"_",
",",
"cls",
")",
",",
"lambda",
":",
"CONFIG_FIELD_TYPE_ERROR",
".",
"format",
"(",
"field",
",",
"cls"... | Validate a config field against a type.
Similar functionality to :func:`validate_field_matches_type` but returns :obj:`honeycomb.defs.ConfigField` | [
"Validate",
"a",
"config",
"field",
"against",
"a",
"type",
"."
] | 33ea91b5cf675000e4e85dd02efe580ea6e95c86 | https://github.com/Cymmetria/honeycomb/blob/33ea91b5cf675000e4e85dd02efe580ea6e95c86/honeycomb/utils/config_utils.py#L21-L27 | train |
Cymmetria/honeycomb | honeycomb/utils/config_utils.py | get_config_parameters | def get_config_parameters(plugin_path):
"""Return the parameters section from config.json."""
json_config_path = os.path.join(plugin_path, defs.CONFIG_FILE_NAME)
with open(json_config_path, "r") as f:
config = json.load(f)
return config.get(defs.PARAMETERS, []) | python | def get_config_parameters(plugin_path):
"""Return the parameters section from config.json."""
json_config_path = os.path.join(plugin_path, defs.CONFIG_FILE_NAME)
with open(json_config_path, "r") as f:
config = json.load(f)
return config.get(defs.PARAMETERS, []) | [
"def",
"get_config_parameters",
"(",
"plugin_path",
")",
":",
"json_config_path",
"=",
"os",
".",
"path",
".",
"join",
"(",
"plugin_path",
",",
"defs",
".",
"CONFIG_FILE_NAME",
")",
"with",
"open",
"(",
"json_config_path",
",",
"\"r\"",
")",
"as",
"f",
":",
... | Return the parameters section from config.json. | [
"Return",
"the",
"parameters",
"section",
"from",
"config",
".",
"json",
"."
] | 33ea91b5cf675000e4e85dd02efe580ea6e95c86 | https://github.com/Cymmetria/honeycomb/blob/33ea91b5cf675000e4e85dd02efe580ea6e95c86/honeycomb/utils/config_utils.py#L41-L46 | train |
Cymmetria/honeycomb | honeycomb/utils/config_utils.py | validate_config_parameters | def validate_config_parameters(config_json, allowed_keys, allowed_types):
"""Validate parameters in config file."""
custom_fields = config_json.get(defs.PARAMETERS, [])
for field in custom_fields:
validate_field(field, allowed_keys, allowed_types)
default = field.get(defs.DEFAULT)
fi... | python | def validate_config_parameters(config_json, allowed_keys, allowed_types):
"""Validate parameters in config file."""
custom_fields = config_json.get(defs.PARAMETERS, [])
for field in custom_fields:
validate_field(field, allowed_keys, allowed_types)
default = field.get(defs.DEFAULT)
fi... | [
"def",
"validate_config_parameters",
"(",
"config_json",
",",
"allowed_keys",
",",
"allowed_types",
")",
":",
"custom_fields",
"=",
"config_json",
".",
"get",
"(",
"defs",
".",
"PARAMETERS",
",",
"[",
"]",
")",
"for",
"field",
"in",
"custom_fields",
":",
"vali... | Validate parameters in config file. | [
"Validate",
"parameters",
"in",
"config",
"file",
"."
] | 33ea91b5cf675000e4e85dd02efe580ea6e95c86 | https://github.com/Cymmetria/honeycomb/blob/33ea91b5cf675000e4e85dd02efe580ea6e95c86/honeycomb/utils/config_utils.py#L49-L57 | train |
Cymmetria/honeycomb | honeycomb/utils/config_utils.py | validate_field_matches_type | def validate_field_matches_type(field, value, field_type, select_items=None, _min=None, _max=None):
"""Validate a config field against a specific type."""
if (field_type == defs.TEXT_TYPE and not isinstance(value, six.string_types)) or \
(field_type == defs.STRING_TYPE and not isinstance(value, six.strin... | python | def validate_field_matches_type(field, value, field_type, select_items=None, _min=None, _max=None):
"""Validate a config field against a specific type."""
if (field_type == defs.TEXT_TYPE and not isinstance(value, six.string_types)) or \
(field_type == defs.STRING_TYPE and not isinstance(value, six.strin... | [
"def",
"validate_field_matches_type",
"(",
"field",
",",
"value",
",",
"field_type",
",",
"select_items",
"=",
"None",
",",
"_min",
"=",
"None",
",",
"_max",
"=",
"None",
")",
":",
"if",
"(",
"field_type",
"==",
"defs",
".",
"TEXT_TYPE",
"and",
"not",
"i... | Validate a config field against a specific type. | [
"Validate",
"a",
"config",
"field",
"against",
"a",
"specific",
"type",
"."
] | 33ea91b5cf675000e4e85dd02efe580ea6e95c86 | https://github.com/Cymmetria/honeycomb/blob/33ea91b5cf675000e4e85dd02efe580ea6e95c86/honeycomb/utils/config_utils.py#L60-L78 | train |
Cymmetria/honeycomb | honeycomb/utils/config_utils.py | get_truetype | def get_truetype(value):
"""Convert a string to a pythonized parameter."""
if value in ["true", "True", "y", "Y", "yes"]:
return True
if value in ["false", "False", "n", "N", "no"]:
return False
if value.isdigit():
return int(value)
return str(value) | python | def get_truetype(value):
"""Convert a string to a pythonized parameter."""
if value in ["true", "True", "y", "Y", "yes"]:
return True
if value in ["false", "False", "n", "N", "no"]:
return False
if value.isdigit():
return int(value)
return str(value) | [
"def",
"get_truetype",
"(",
"value",
")",
":",
"if",
"value",
"in",
"[",
"\"true\"",
",",
"\"True\"",
",",
"\"y\"",
",",
"\"Y\"",
",",
"\"yes\"",
"]",
":",
"return",
"True",
"if",
"value",
"in",
"[",
"\"false\"",
",",
"\"False\"",
",",
"\"n\"",
",",
... | Convert a string to a pythonized parameter. | [
"Convert",
"a",
"string",
"to",
"a",
"pythonized",
"parameter",
"."
] | 33ea91b5cf675000e4e85dd02efe580ea6e95c86 | https://github.com/Cymmetria/honeycomb/blob/33ea91b5cf675000e4e85dd02efe580ea6e95c86/honeycomb/utils/config_utils.py#L81-L89 | train |
Cymmetria/honeycomb | honeycomb/utils/config_utils.py | validate_field | def validate_field(field, allowed_keys, allowed_types):
"""Validate field is allowed and valid."""
for key, value in field.items():
if key not in allowed_keys:
raise exceptions.ParametersFieldError(key, "property")
if key == defs.TYPE:
if value not in allowed_types:
... | python | def validate_field(field, allowed_keys, allowed_types):
"""Validate field is allowed and valid."""
for key, value in field.items():
if key not in allowed_keys:
raise exceptions.ParametersFieldError(key, "property")
if key == defs.TYPE:
if value not in allowed_types:
... | [
"def",
"validate_field",
"(",
"field",
",",
"allowed_keys",
",",
"allowed_types",
")",
":",
"for",
"key",
",",
"value",
"in",
"field",
".",
"items",
"(",
")",
":",
"if",
"key",
"not",
"in",
"allowed_keys",
":",
"raise",
"exceptions",
".",
"ParametersFieldE... | Validate field is allowed and valid. | [
"Validate",
"field",
"is",
"allowed",
"and",
"valid",
"."
] | 33ea91b5cf675000e4e85dd02efe580ea6e95c86 | https://github.com/Cymmetria/honeycomb/blob/33ea91b5cf675000e4e85dd02efe580ea6e95c86/honeycomb/utils/config_utils.py#L92-L102 | train |
Cymmetria/honeycomb | honeycomb/utils/config_utils.py | is_valid_field_name | def is_valid_field_name(value):
"""Ensure field name is valid."""
leftovers = re.sub(r"\w", "", value)
leftovers = re.sub(r"-", "", leftovers)
if leftovers != "" or value[0].isdigit() or value[0] in ["-", "_"] or " " in value:
return False
return True | python | def is_valid_field_name(value):
"""Ensure field name is valid."""
leftovers = re.sub(r"\w", "", value)
leftovers = re.sub(r"-", "", leftovers)
if leftovers != "" or value[0].isdigit() or value[0] in ["-", "_"] or " " in value:
return False
return True | [
"def",
"is_valid_field_name",
"(",
"value",
")",
":",
"leftovers",
"=",
"re",
".",
"sub",
"(",
"r\"\\w\"",
",",
"\"\"",
",",
"value",
")",
"leftovers",
"=",
"re",
".",
"sub",
"(",
"r\"-\"",
",",
"\"\"",
",",
"leftovers",
")",
"if",
"leftovers",
"!=",
... | Ensure field name is valid. | [
"Ensure",
"field",
"name",
"is",
"valid",
"."
] | 33ea91b5cf675000e4e85dd02efe580ea6e95c86 | https://github.com/Cymmetria/honeycomb/blob/33ea91b5cf675000e4e85dd02efe580ea6e95c86/honeycomb/utils/config_utils.py#L105-L111 | train |
Cymmetria/honeycomb | honeycomb/utils/config_utils.py | process_config | def process_config(ctx, configfile):
"""Process a yaml config with instructions.
This is a heavy method that loads lots of content, so we only run the imports if its called.
"""
from honeycomb.commands.service.run import run as service_run
# from honeycomb.commands.service.logs import logs as servi... | python | def process_config(ctx, configfile):
"""Process a yaml config with instructions.
This is a heavy method that loads lots of content, so we only run the imports if its called.
"""
from honeycomb.commands.service.run import run as service_run
# from honeycomb.commands.service.logs import logs as servi... | [
"def",
"process_config",
"(",
"ctx",
",",
"configfile",
")",
":",
"from",
"honeycomb",
".",
"commands",
".",
"service",
".",
"run",
"import",
"run",
"as",
"service_run",
"# from honeycomb.commands.service.logs import logs as service_logs",
"from",
"honeycomb",
".",
"c... | Process a yaml config with instructions.
This is a heavy method that loads lots of content, so we only run the imports if its called. | [
"Process",
"a",
"yaml",
"config",
"with",
"instructions",
"."
] | 33ea91b5cf675000e4e85dd02efe580ea6e95c86 | https://github.com/Cymmetria/honeycomb/blob/33ea91b5cf675000e4e85dd02efe580ea6e95c86/honeycomb/utils/config_utils.py#L114-L178 | train |
Cymmetria/honeycomb | honeycomb/utils/plugin_utils.py | get_plugin_path | def get_plugin_path(home, plugin_type, plugin_name, editable=False):
"""Return path to plugin.
:param home: Path to honeycomb home
:param plugin_type: Type of plugin (:obj:`honeycomb.defs.SERVICES` pr :obj:`honeycomb.defs.INTEGRATIONS`)
:param plugin_name: Name of plugin
:param editable: Use plugin... | python | def get_plugin_path(home, plugin_type, plugin_name, editable=False):
"""Return path to plugin.
:param home: Path to honeycomb home
:param plugin_type: Type of plugin (:obj:`honeycomb.defs.SERVICES` pr :obj:`honeycomb.defs.INTEGRATIONS`)
:param plugin_name: Name of plugin
:param editable: Use plugin... | [
"def",
"get_plugin_path",
"(",
"home",
",",
"plugin_type",
",",
"plugin_name",
",",
"editable",
"=",
"False",
")",
":",
"if",
"editable",
":",
"plugin_path",
"=",
"plugin_name",
"else",
":",
"plugin_path",
"=",
"os",
".",
"path",
".",
"join",
"(",
"home",
... | Return path to plugin.
:param home: Path to honeycomb home
:param plugin_type: Type of plugin (:obj:`honeycomb.defs.SERVICES` pr :obj:`honeycomb.defs.INTEGRATIONS`)
:param plugin_name: Name of plugin
:param editable: Use plugin_name as direct path instead of loading from honeycomb home folder | [
"Return",
"path",
"to",
"plugin",
"."
] | 33ea91b5cf675000e4e85dd02efe580ea6e95c86 | https://github.com/Cymmetria/honeycomb/blob/33ea91b5cf675000e4e85dd02efe580ea6e95c86/honeycomb/utils/plugin_utils.py#L44-L57 | train |
Cymmetria/honeycomb | honeycomb/utils/plugin_utils.py | install_plugin | def install_plugin(pkgpath, plugin_type, install_path, register_func):
"""Install specified plugin.
:param pkgpath: Name of plugin to be downloaded from online repo or path to plugin folder or zip file.
:param install_path: Path where plugin will be installed.
:param register_func: Method used to regis... | python | def install_plugin(pkgpath, plugin_type, install_path, register_func):
"""Install specified plugin.
:param pkgpath: Name of plugin to be downloaded from online repo or path to plugin folder or zip file.
:param install_path: Path where plugin will be installed.
:param register_func: Method used to regis... | [
"def",
"install_plugin",
"(",
"pkgpath",
",",
"plugin_type",
",",
"install_path",
",",
"register_func",
")",
":",
"service_name",
"=",
"os",
".",
"path",
".",
"basename",
"(",
"pkgpath",
")",
"if",
"os",
".",
"path",
".",
"exists",
"(",
"os",
".",
"path"... | Install specified plugin.
:param pkgpath: Name of plugin to be downloaded from online repo or path to plugin folder or zip file.
:param install_path: Path where plugin will be installed.
:param register_func: Method used to register and validate plugin. | [
"Install",
"specified",
"plugin",
"."
] | 33ea91b5cf675000e4e85dd02efe580ea6e95c86 | https://github.com/Cymmetria/honeycomb/blob/33ea91b5cf675000e4e85dd02efe580ea6e95c86/honeycomb/utils/plugin_utils.py#L60-L86 | train |
Cymmetria/honeycomb | honeycomb/utils/plugin_utils.py | install_deps | def install_deps(pkgpath):
"""Install plugin dependencies using pip.
We import pip here to reduce load time for when its not needed.
"""
if os.path.exists(os.path.join(pkgpath, "requirements.txt")):
logger.debug("installing dependencies")
click.secho("[*] Installing dependencies")
... | python | def install_deps(pkgpath):
"""Install plugin dependencies using pip.
We import pip here to reduce load time for when its not needed.
"""
if os.path.exists(os.path.join(pkgpath, "requirements.txt")):
logger.debug("installing dependencies")
click.secho("[*] Installing dependencies")
... | [
"def",
"install_deps",
"(",
"pkgpath",
")",
":",
"if",
"os",
".",
"path",
".",
"exists",
"(",
"os",
".",
"path",
".",
"join",
"(",
"pkgpath",
",",
"\"requirements.txt\"",
")",
")",
":",
"logger",
".",
"debug",
"(",
"\"installing dependencies\"",
")",
"cl... | Install plugin dependencies using pip.
We import pip here to reduce load time for when its not needed. | [
"Install",
"plugin",
"dependencies",
"using",
"pip",
"."
] | 33ea91b5cf675000e4e85dd02efe580ea6e95c86 | https://github.com/Cymmetria/honeycomb/blob/33ea91b5cf675000e4e85dd02efe580ea6e95c86/honeycomb/utils/plugin_utils.py#L89-L101 | train |
Cymmetria/honeycomb | honeycomb/utils/plugin_utils.py | copy_file | def copy_file(src, dst):
"""Copy a single file.
:param src: Source name
:param dst: Destination name
"""
try:
fin = os.open(src, READ_FLAGS)
stat = os.fstat(fin)
fout = os.open(dst, WRITE_FLAGS, stat.st_mode)
for x in iter(lambda: os.read(fin, BUFFER_SIZE), b""):
... | python | def copy_file(src, dst):
"""Copy a single file.
:param src: Source name
:param dst: Destination name
"""
try:
fin = os.open(src, READ_FLAGS)
stat = os.fstat(fin)
fout = os.open(dst, WRITE_FLAGS, stat.st_mode)
for x in iter(lambda: os.read(fin, BUFFER_SIZE), b""):
... | [
"def",
"copy_file",
"(",
"src",
",",
"dst",
")",
":",
"try",
":",
"fin",
"=",
"os",
".",
"open",
"(",
"src",
",",
"READ_FLAGS",
")",
"stat",
"=",
"os",
".",
"fstat",
"(",
"fin",
")",
"fout",
"=",
"os",
".",
"open",
"(",
"dst",
",",
"WRITE_FLAGS... | Copy a single file.
:param src: Source name
:param dst: Destination name | [
"Copy",
"a",
"single",
"file",
"."
] | 33ea91b5cf675000e4e85dd02efe580ea6e95c86 | https://github.com/Cymmetria/honeycomb/blob/33ea91b5cf675000e4e85dd02efe580ea6e95c86/honeycomb/utils/plugin_utils.py#L104-L124 | train |
Cymmetria/honeycomb | honeycomb/utils/plugin_utils.py | copy_tree | def copy_tree(src, dst, symlinks=False, ignore=[]):
"""Copy a full directory structure.
:param src: Source path
:param dst: Destination path
:param symlinks: Copy symlinks
:param ignore: Subdirs/filenames to ignore
"""
names = os.listdir(src)
if not os.path.exists(dst):
os.make... | python | def copy_tree(src, dst, symlinks=False, ignore=[]):
"""Copy a full directory structure.
:param src: Source path
:param dst: Destination path
:param symlinks: Copy symlinks
:param ignore: Subdirs/filenames to ignore
"""
names = os.listdir(src)
if not os.path.exists(dst):
os.make... | [
"def",
"copy_tree",
"(",
"src",
",",
"dst",
",",
"symlinks",
"=",
"False",
",",
"ignore",
"=",
"[",
"]",
")",
":",
"names",
"=",
"os",
".",
"listdir",
"(",
"src",
")",
"if",
"not",
"os",
".",
"path",
".",
"exists",
"(",
"dst",
")",
":",
"os",
... | Copy a full directory structure.
:param src: Source path
:param dst: Destination path
:param symlinks: Copy symlinks
:param ignore: Subdirs/filenames to ignore | [
"Copy",
"a",
"full",
"directory",
"structure",
"."
] | 33ea91b5cf675000e4e85dd02efe580ea6e95c86 | https://github.com/Cymmetria/honeycomb/blob/33ea91b5cf675000e4e85dd02efe580ea6e95c86/honeycomb/utils/plugin_utils.py#L130-L161 | train |
Cymmetria/honeycomb | honeycomb/utils/plugin_utils.py | install_dir | def install_dir(pkgpath, install_path, register_func, delete_after_install=False):
"""Install plugin from specified directory.
install_path and register_func are same as :func:`install_plugin`.
:param delete_after_install: Delete pkgpath after install (used in :func:`install_from_zip`).
"""
logger.... | python | def install_dir(pkgpath, install_path, register_func, delete_after_install=False):
"""Install plugin from specified directory.
install_path and register_func are same as :func:`install_plugin`.
:param delete_after_install: Delete pkgpath after install (used in :func:`install_from_zip`).
"""
logger.... | [
"def",
"install_dir",
"(",
"pkgpath",
",",
"install_path",
",",
"register_func",
",",
"delete_after_install",
"=",
"False",
")",
":",
"logger",
".",
"debug",
"(",
"\"%s is a directory, attempting to validate\"",
",",
"pkgpath",
")",
"plugin",
"=",
"register_func",
"... | Install plugin from specified directory.
install_path and register_func are same as :func:`install_plugin`.
:param delete_after_install: Delete pkgpath after install (used in :func:`install_from_zip`). | [
"Install",
"plugin",
"from",
"specified",
"directory",
"."
] | 33ea91b5cf675000e4e85dd02efe580ea6e95c86 | https://github.com/Cymmetria/honeycomb/blob/33ea91b5cf675000e4e85dd02efe580ea6e95c86/honeycomb/utils/plugin_utils.py#L164-L184 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.