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
opendatateam/udata
udata/commands/__init__.py
error
def error(msg, details=None): '''Display an error message with optional details''' msg = '{0} {1}'.format(red(KO), white(safe_unicode(msg))) msg = safe_unicode(msg) if details: msg = b'\n'.join((msg, safe_unicode(details))) echo(format_multiline(msg))
python
def error(msg, details=None): '''Display an error message with optional details''' msg = '{0} {1}'.format(red(KO), white(safe_unicode(msg))) msg = safe_unicode(msg) if details: msg = b'\n'.join((msg, safe_unicode(details))) echo(format_multiline(msg))
[ "def", "error", "(", "msg", ",", "details", "=", "None", ")", ":", "msg", "=", "'{0} {1}'", ".", "format", "(", "red", "(", "KO", ")", ",", "white", "(", "safe_unicode", "(", "msg", ")", ")", ")", "msg", "=", "safe_unicode", "(", "msg", ")", "if"...
Display an error message with optional details
[ "Display", "an", "error", "message", "with", "optional", "details" ]
f016585af94b0ff6bd73738c700324adc8ba7f8f
https://github.com/opendatateam/udata/blob/f016585af94b0ff6bd73738c700324adc8ba7f8f/udata/commands/__init__.py#L62-L68
train
opendatateam/udata
udata/commands/__init__.py
UdataGroup.main
def main(self, *args, **kwargs): ''' Instanciate ScriptInfo before parent does to ensure the `settings` parameters is available to `create_app ''' obj = kwargs.get('obj') if obj is None: obj = ScriptInfo(create_app=self.create_app) # This is the import...
python
def main(self, *args, **kwargs): ''' Instanciate ScriptInfo before parent does to ensure the `settings` parameters is available to `create_app ''' obj = kwargs.get('obj') if obj is None: obj = ScriptInfo(create_app=self.create_app) # This is the import...
[ "def", "main", "(", "self", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "obj", "=", "kwargs", ".", "get", "(", "'obj'", ")", "if", "obj", "is", "None", ":", "obj", "=", "ScriptInfo", "(", "create_app", "=", "self", ".", "create_app", ")"...
Instanciate ScriptInfo before parent does to ensure the `settings` parameters is available to `create_app
[ "Instanciate", "ScriptInfo", "before", "parent", "does", "to", "ensure", "the", "settings", "parameters", "is", "available", "to", "create_app" ]
f016585af94b0ff6bd73738c700324adc8ba7f8f
https://github.com/opendatateam/udata/blob/f016585af94b0ff6bd73738c700324adc8ba7f8f/udata/commands/__init__.py#L240-L251
train
opendatateam/udata
udata/entrypoints.py
get_plugins_dists
def get_plugins_dists(app, name=None): '''Return a list of Distributions with enabled udata plugins''' if name: plugins = set(e.name for e in iter_all(name) if e.name in app.config['PLUGINS']) else: plugins = set(app.config['PLUGINS']) return [ d for d in known_dists() if...
python
def get_plugins_dists(app, name=None): '''Return a list of Distributions with enabled udata plugins''' if name: plugins = set(e.name for e in iter_all(name) if e.name in app.config['PLUGINS']) else: plugins = set(app.config['PLUGINS']) return [ d for d in known_dists() if...
[ "def", "get_plugins_dists", "(", "app", ",", "name", "=", "None", ")", ":", "if", "name", ":", "plugins", "=", "set", "(", "e", ".", "name", "for", "e", "in", "iter_all", "(", "name", ")", "if", "e", ".", "name", "in", "app", ".", "config", "[", ...
Return a list of Distributions with enabled udata plugins
[ "Return", "a", "list", "of", "Distributions", "with", "enabled", "udata", "plugins" ]
f016585af94b0ff6bd73738c700324adc8ba7f8f
https://github.com/opendatateam/udata/blob/f016585af94b0ff6bd73738c700324adc8ba7f8f/udata/entrypoints.py#L64-L73
train
opendatateam/udata
udata/routing.py
lazy_raise_or_redirect
def lazy_raise_or_redirect(): ''' Raise exception lazily to ensure request.endpoint is set Also perform redirect if needed ''' if not request.view_args: return for name, value in request.view_args.items(): if isinstance(value, NotFound): request.routing_exception = va...
python
def lazy_raise_or_redirect(): ''' Raise exception lazily to ensure request.endpoint is set Also perform redirect if needed ''' if not request.view_args: return for name, value in request.view_args.items(): if isinstance(value, NotFound): request.routing_exception = va...
[ "def", "lazy_raise_or_redirect", "(", ")", ":", "if", "not", "request", ".", "view_args", ":", "return", "for", "name", ",", "value", "in", "request", ".", "view_args", ".", "items", "(", ")", ":", "if", "isinstance", "(", "value", ",", "NotFound", ")", ...
Raise exception lazily to ensure request.endpoint is set Also perform redirect if needed
[ "Raise", "exception", "lazily", "to", "ensure", "request", ".", "endpoint", "is", "set", "Also", "perform", "redirect", "if", "needed" ]
f016585af94b0ff6bd73738c700324adc8ba7f8f
https://github.com/opendatateam/udata/blob/f016585af94b0ff6bd73738c700324adc8ba7f8f/udata/routing.py#L199-L214
train
opendatateam/udata
udata/routing.py
TerritoryConverter.to_python
def to_python(self, value): """ `value` has slashs in it, that's why we inherit from `PathConverter`. E.g.: `commune/13200@latest/`, `departement/13@1860-07-01/` or `region/76@2016-01-01/Auvergne-Rhone-Alpes/`. Note that the slug is not significative but cannot be omitted. ...
python
def to_python(self, value): """ `value` has slashs in it, that's why we inherit from `PathConverter`. E.g.: `commune/13200@latest/`, `departement/13@1860-07-01/` or `region/76@2016-01-01/Auvergne-Rhone-Alpes/`. Note that the slug is not significative but cannot be omitted. ...
[ "def", "to_python", "(", "self", ",", "value", ")", ":", "if", "'/'", "not", "in", "value", ":", "return", "level", ",", "code", "=", "value", ".", "split", "(", "'/'", ")", "[", ":", "2", "]", "# Ignore optional slug", "geoid", "=", "GeoZone", ".", ...
`value` has slashs in it, that's why we inherit from `PathConverter`. E.g.: `commune/13200@latest/`, `departement/13@1860-07-01/` or `region/76@2016-01-01/Auvergne-Rhone-Alpes/`. Note that the slug is not significative but cannot be omitted.
[ "value", "has", "slashs", "in", "it", "that", "s", "why", "we", "inherit", "from", "PathConverter", "." ]
f016585af94b0ff6bd73738c700324adc8ba7f8f
https://github.com/opendatateam/udata/blob/f016585af94b0ff6bd73738c700324adc8ba7f8f/udata/routing.py#L152-L175
train
opendatateam/udata
udata/routing.py
TerritoryConverter.to_url
def to_url(self, obj): """ Reconstruct the URL from level name, code or datagouv id and slug. """ level_name = getattr(obj, 'level_name', None) if not level_name: raise ValueError('Unable to serialize "%s" to url' % obj) code = getattr(obj, 'code', None) ...
python
def to_url(self, obj): """ Reconstruct the URL from level name, code or datagouv id and slug. """ level_name = getattr(obj, 'level_name', None) if not level_name: raise ValueError('Unable to serialize "%s" to url' % obj) code = getattr(obj, 'code', None) ...
[ "def", "to_url", "(", "self", ",", "obj", ")", ":", "level_name", "=", "getattr", "(", "obj", ",", "'level_name'", ",", "None", ")", "if", "not", "level_name", ":", "raise", "ValueError", "(", "'Unable to serialize \"%s\" to url'", "%", "obj", ")", "code", ...
Reconstruct the URL from level name, code or datagouv id and slug.
[ "Reconstruct", "the", "URL", "from", "level", "name", "code", "or", "datagouv", "id", "and", "slug", "." ]
f016585af94b0ff6bd73738c700324adc8ba7f8f
https://github.com/opendatateam/udata/blob/f016585af94b0ff6bd73738c700324adc8ba7f8f/udata/routing.py#L177-L196
train
opendatateam/udata
udata/tasks.py
job
def job(name, **kwargs): '''A shortcut decorator for declaring jobs''' return task(name=name, schedulable=True, base=JobTask, bind=True, **kwargs)
python
def job(name, **kwargs): '''A shortcut decorator for declaring jobs''' return task(name=name, schedulable=True, base=JobTask, bind=True, **kwargs)
[ "def", "job", "(", "name", ",", "*", "*", "kwargs", ")", ":", "return", "task", "(", "name", "=", "name", ",", "schedulable", "=", "True", ",", "base", "=", "JobTask", ",", "bind", "=", "True", ",", "*", "*", "kwargs", ")" ]
A shortcut decorator for declaring jobs
[ "A", "shortcut", "decorator", "for", "declaring", "jobs" ]
f016585af94b0ff6bd73738c700324adc8ba7f8f
https://github.com/opendatateam/udata/blob/f016585af94b0ff6bd73738c700324adc8ba7f8f/udata/tasks.py#L80-L83
train
opendatateam/udata
udata/tasks.py
Scheduler.apply_async
def apply_async(self, entry, **kwargs): '''A MongoScheduler storing the last task_id''' result = super(Scheduler, self).apply_async(entry, **kwargs) entry._task.last_run_id = result.id return result
python
def apply_async(self, entry, **kwargs): '''A MongoScheduler storing the last task_id''' result = super(Scheduler, self).apply_async(entry, **kwargs) entry._task.last_run_id = result.id return result
[ "def", "apply_async", "(", "self", ",", "entry", ",", "*", "*", "kwargs", ")", ":", "result", "=", "super", "(", "Scheduler", ",", "self", ")", ".", "apply_async", "(", "entry", ",", "*", "*", "kwargs", ")", "entry", ".", "_task", ".", "last_run_id",...
A MongoScheduler storing the last task_id
[ "A", "MongoScheduler", "storing", "the", "last", "task_id" ]
f016585af94b0ff6bd73738c700324adc8ba7f8f
https://github.com/opendatateam/udata/blob/f016585af94b0ff6bd73738c700324adc8ba7f8f/udata/tasks.py#L40-L44
train
opendatateam/udata
udata/commands/info.py
config
def config(): '''Display some details about the local configuration''' if hasattr(current_app, 'settings_file'): log.info('Loaded configuration from %s', current_app.settings_file) log.info(white('Current configuration')) for key in sorted(current_app.config): if key.startswith('__') or...
python
def config(): '''Display some details about the local configuration''' if hasattr(current_app, 'settings_file'): log.info('Loaded configuration from %s', current_app.settings_file) log.info(white('Current configuration')) for key in sorted(current_app.config): if key.startswith('__') or...
[ "def", "config", "(", ")", ":", "if", "hasattr", "(", "current_app", ",", "'settings_file'", ")", ":", "log", ".", "info", "(", "'Loaded configuration from %s'", ",", "current_app", ".", "settings_file", ")", "log", ".", "info", "(", "white", "(", "'Current ...
Display some details about the local configuration
[ "Display", "some", "details", "about", "the", "local", "configuration" ]
f016585af94b0ff6bd73738c700324adc8ba7f8f
https://github.com/opendatateam/udata/blob/f016585af94b0ff6bd73738c700324adc8ba7f8f/udata/commands/info.py#L34-L43
train
opendatateam/udata
udata/commands/info.py
plugins
def plugins(): '''Display some details about the local plugins''' plugins = current_app.config['PLUGINS'] for name, description in entrypoints.ENTRYPOINTS.items(): echo('{0} ({1})'.format(white(description), name)) if name == 'udata.themes': actives = [current_app.config['THEME']...
python
def plugins(): '''Display some details about the local plugins''' plugins = current_app.config['PLUGINS'] for name, description in entrypoints.ENTRYPOINTS.items(): echo('{0} ({1})'.format(white(description), name)) if name == 'udata.themes': actives = [current_app.config['THEME']...
[ "def", "plugins", "(", ")", ":", "plugins", "=", "current_app", ".", "config", "[", "'PLUGINS'", "]", "for", "name", ",", "description", "in", "entrypoints", ".", "ENTRYPOINTS", ".", "items", "(", ")", ":", "echo", "(", "'{0} ({1})'", ".", "format", "(",...
Display some details about the local plugins
[ "Display", "some", "details", "about", "the", "local", "plugins" ]
f016585af94b0ff6bd73738c700324adc8ba7f8f
https://github.com/opendatateam/udata/blob/f016585af94b0ff6bd73738c700324adc8ba7f8f/udata/commands/info.py#L47-L59
train
opendatateam/udata
udata/frontend/views.py
BaseView.can
def can(self, *args, **kwargs): '''Overwrite this method to implement custom contextual permissions''' if isinstance(self.require, auth.Permission): return self.require.can() elif callable(self.require): return self.require() elif isinstance(self.require, bool): ...
python
def can(self, *args, **kwargs): '''Overwrite this method to implement custom contextual permissions''' if isinstance(self.require, auth.Permission): return self.require.can() elif callable(self.require): return self.require() elif isinstance(self.require, bool): ...
[ "def", "can", "(", "self", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "if", "isinstance", "(", "self", ".", "require", ",", "auth", ".", "Permission", ")", ":", "return", "self", ".", "require", ".", "can", "(", ")", "elif", "callable", ...
Overwrite this method to implement custom contextual permissions
[ "Overwrite", "this", "method", "to", "implement", "custom", "contextual", "permissions" ]
f016585af94b0ff6bd73738c700324adc8ba7f8f
https://github.com/opendatateam/udata/blob/f016585af94b0ff6bd73738c700324adc8ba7f8f/udata/frontend/views.py#L36-L45
train
opendatateam/udata
udata/core/storages/utils.py
extension
def extension(filename): '''Properly extract the extension from filename''' filename = os.path.basename(filename) extension = None while '.' in filename: filename, ext = os.path.splitext(filename) if ext.startswith('.'): ext = ext[1:] extension = ext if not extension...
python
def extension(filename): '''Properly extract the extension from filename''' filename = os.path.basename(filename) extension = None while '.' in filename: filename, ext = os.path.splitext(filename) if ext.startswith('.'): ext = ext[1:] extension = ext if not extension...
[ "def", "extension", "(", "filename", ")", ":", "filename", "=", "os", ".", "path", ".", "basename", "(", "filename", ")", "extension", "=", "None", "while", "'.'", "in", "filename", ":", "filename", ",", "ext", "=", "os", ".", "path", ".", "splitext", ...
Properly extract the extension from filename
[ "Properly", "extract", "the", "extension", "from", "filename" ]
f016585af94b0ff6bd73738c700324adc8ba7f8f
https://github.com/opendatateam/udata/blob/f016585af94b0ff6bd73738c700324adc8ba7f8f/udata/core/storages/utils.py#L48-L59
train
opendatateam/udata
udata/theme/__init__.py
theme_static_with_version
def theme_static_with_version(ctx, filename, external=False): '''Override the default theme static to add cache burst''' if current_app.theme_manager.static_folder: url = assets.cdn_for('_themes.static', filename=current.identifier + '/' + filename, ...
python
def theme_static_with_version(ctx, filename, external=False): '''Override the default theme static to add cache burst''' if current_app.theme_manager.static_folder: url = assets.cdn_for('_themes.static', filename=current.identifier + '/' + filename, ...
[ "def", "theme_static_with_version", "(", "ctx", ",", "filename", ",", "external", "=", "False", ")", ":", "if", "current_app", ".", "theme_manager", ".", "static_folder", ":", "url", "=", "assets", ".", "cdn_for", "(", "'_themes.static'", ",", "filename", "=",...
Override the default theme static to add cache burst
[ "Override", "the", "default", "theme", "static", "to", "add", "cache", "burst" ]
f016585af94b0ff6bd73738c700324adc8ba7f8f
https://github.com/opendatateam/udata/blob/f016585af94b0ff6bd73738c700324adc8ba7f8f/udata/theme/__init__.py#L48-L65
train
opendatateam/udata
udata/theme/__init__.py
render
def render(template, **context): ''' Render a template with uData frontend specifics * Theme ''' theme = current_app.config['THEME'] return render_theme_template(get_theme(theme), template, **context)
python
def render(template, **context): ''' Render a template with uData frontend specifics * Theme ''' theme = current_app.config['THEME'] return render_theme_template(get_theme(theme), template, **context)
[ "def", "render", "(", "template", ",", "*", "*", "context", ")", ":", "theme", "=", "current_app", ".", "config", "[", "'THEME'", "]", "return", "render_theme_template", "(", "get_theme", "(", "theme", ")", ",", "template", ",", "*", "*", "context", ")" ...
Render a template with uData frontend specifics * Theme
[ "Render", "a", "template", "with", "uData", "frontend", "specifics" ]
f016585af94b0ff6bd73738c700324adc8ba7f8f
https://github.com/opendatateam/udata/blob/f016585af94b0ff6bd73738c700324adc8ba7f8f/udata/theme/__init__.py#L141-L148
train
opendatateam/udata
udata/theme/__init__.py
context
def context(name): '''A decorator for theme context processors''' def wrapper(func): g.theme.context_processors[name] = func return func return wrapper
python
def context(name): '''A decorator for theme context processors''' def wrapper(func): g.theme.context_processors[name] = func return func return wrapper
[ "def", "context", "(", "name", ")", ":", "def", "wrapper", "(", "func", ")", ":", "g", ".", "theme", ".", "context_processors", "[", "name", "]", "=", "func", "return", "func", "return", "wrapper" ]
A decorator for theme context processors
[ "A", "decorator", "for", "theme", "context", "processors" ]
f016585af94b0ff6bd73738c700324adc8ba7f8f
https://github.com/opendatateam/udata/blob/f016585af94b0ff6bd73738c700324adc8ba7f8f/udata/theme/__init__.py#L159-L164
train
opendatateam/udata
udata/theme/__init__.py
ConfigurableTheme.variant
def variant(self): '''Get the current theme variant''' variant = current_app.config['THEME_VARIANT'] if variant not in self.variants: log.warning('Unkown theme variant: %s', variant) return 'default' else: return variant
python
def variant(self): '''Get the current theme variant''' variant = current_app.config['THEME_VARIANT'] if variant not in self.variants: log.warning('Unkown theme variant: %s', variant) return 'default' else: return variant
[ "def", "variant", "(", "self", ")", ":", "variant", "=", "current_app", ".", "config", "[", "'THEME_VARIANT'", "]", "if", "variant", "not", "in", "self", ".", "variants", ":", "log", ".", "warning", "(", "'Unkown theme variant: %s'", ",", "variant", ")", "...
Get the current theme variant
[ "Get", "the", "current", "theme", "variant" ]
f016585af94b0ff6bd73738c700324adc8ba7f8f
https://github.com/opendatateam/udata/blob/f016585af94b0ff6bd73738c700324adc8ba7f8f/udata/theme/__init__.py#L110-L117
train
opendatateam/udata
udata/core/dataset/views.py
resource_redirect
def resource_redirect(id): ''' Redirect to the latest version of a resource given its identifier. ''' resource = get_resource(id) return redirect(resource.url.strip()) if resource else abort(404)
python
def resource_redirect(id): ''' Redirect to the latest version of a resource given its identifier. ''' resource = get_resource(id) return redirect(resource.url.strip()) if resource else abort(404)
[ "def", "resource_redirect", "(", "id", ")", ":", "resource", "=", "get_resource", "(", "id", ")", "return", "redirect", "(", "resource", ".", "url", ".", "strip", "(", ")", ")", "if", "resource", "else", "abort", "(", "404", ")" ]
Redirect to the latest version of a resource given its identifier.
[ "Redirect", "to", "the", "latest", "version", "of", "a", "resource", "given", "its", "identifier", "." ]
f016585af94b0ff6bd73738c700324adc8ba7f8f
https://github.com/opendatateam/udata/blob/f016585af94b0ff6bd73738c700324adc8ba7f8f/udata/core/dataset/views.py#L130-L135
train
opendatateam/udata
udata/core/dataset/views.py
group_resources_by_type
def group_resources_by_type(resources): """Group a list of `resources` by `type` with order""" groups = defaultdict(list) for resource in resources: groups[getattr(resource, 'type')].append(resource) ordered = OrderedDict() for rtype, rtype_label in RESOURCE_TYPES.items(): if groups[...
python
def group_resources_by_type(resources): """Group a list of `resources` by `type` with order""" groups = defaultdict(list) for resource in resources: groups[getattr(resource, 'type')].append(resource) ordered = OrderedDict() for rtype, rtype_label in RESOURCE_TYPES.items(): if groups[...
[ "def", "group_resources_by_type", "(", "resources", ")", ":", "groups", "=", "defaultdict", "(", "list", ")", "for", "resource", "in", "resources", ":", "groups", "[", "getattr", "(", "resource", ",", "'type'", ")", "]", ".", "append", "(", "resource", ")"...
Group a list of `resources` by `type` with order
[ "Group", "a", "list", "of", "resources", "by", "type", "with", "order" ]
f016585af94b0ff6bd73738c700324adc8ba7f8f
https://github.com/opendatateam/udata/blob/f016585af94b0ff6bd73738c700324adc8ba7f8f/udata/core/dataset/views.py#L166-L175
train
opendatateam/udata
udata/core/metrics/__init__.py
Metric.aggregate
def aggregate(self, start, end): ''' This method encpsualte the metric aggregation logic. Override this method when you inherit this class. By default, it takes the last value. ''' last = self.objects( level='daily', date__lte=self.iso(end), date__...
python
def aggregate(self, start, end): ''' This method encpsualte the metric aggregation logic. Override this method when you inherit this class. By default, it takes the last value. ''' last = self.objects( level='daily', date__lte=self.iso(end), date__...
[ "def", "aggregate", "(", "self", ",", "start", ",", "end", ")", ":", "last", "=", "self", ".", "objects", "(", "level", "=", "'daily'", ",", "date__lte", "=", "self", ".", "iso", "(", "end", ")", ",", "date__gte", "=", "self", ".", "iso", "(", "s...
This method encpsualte the metric aggregation logic. Override this method when you inherit this class. By default, it takes the last value.
[ "This", "method", "encpsualte", "the", "metric", "aggregation", "logic", ".", "Override", "this", "method", "when", "you", "inherit", "this", "class", ".", "By", "default", "it", "takes", "the", "last", "value", "." ]
f016585af94b0ff6bd73738c700324adc8ba7f8f
https://github.com/opendatateam/udata/blob/f016585af94b0ff6bd73738c700324adc8ba7f8f/udata/core/metrics/__init__.py#L92-L101
train
opendatateam/udata
udata/harvest/actions.py
paginate_sources
def paginate_sources(owner=None, page=1, page_size=DEFAULT_PAGE_SIZE): '''Paginate harvest sources''' sources = _sources_queryset(owner=owner) page = max(page or 1, 1) return sources.paginate(page, page_size)
python
def paginate_sources(owner=None, page=1, page_size=DEFAULT_PAGE_SIZE): '''Paginate harvest sources''' sources = _sources_queryset(owner=owner) page = max(page or 1, 1) return sources.paginate(page, page_size)
[ "def", "paginate_sources", "(", "owner", "=", "None", ",", "page", "=", "1", ",", "page_size", "=", "DEFAULT_PAGE_SIZE", ")", ":", "sources", "=", "_sources_queryset", "(", "owner", "=", "owner", ")", "page", "=", "max", "(", "page", "or", "1", ",", "1...
Paginate harvest sources
[ "Paginate", "harvest", "sources" ]
f016585af94b0ff6bd73738c700324adc8ba7f8f
https://github.com/opendatateam/udata/blob/f016585af94b0ff6bd73738c700324adc8ba7f8f/udata/harvest/actions.py#L45-L49
train
opendatateam/udata
udata/harvest/actions.py
update_source
def update_source(ident, data): '''Update an harvest source''' source = get_source(ident) source.modify(**data) signals.harvest_source_updated.send(source) return source
python
def update_source(ident, data): '''Update an harvest source''' source = get_source(ident) source.modify(**data) signals.harvest_source_updated.send(source) return source
[ "def", "update_source", "(", "ident", ",", "data", ")", ":", "source", "=", "get_source", "(", "ident", ")", "source", ".", "modify", "(", "*", "*", "data", ")", "signals", ".", "harvest_source_updated", ".", "send", "(", "source", ")", "return", "source...
Update an harvest source
[ "Update", "an", "harvest", "source" ]
f016585af94b0ff6bd73738c700324adc8ba7f8f
https://github.com/opendatateam/udata/blob/f016585af94b0ff6bd73738c700324adc8ba7f8f/udata/harvest/actions.py#L90-L95
train
opendatateam/udata
udata/harvest/actions.py
validate_source
def validate_source(ident, comment=None): '''Validate a source for automatic harvesting''' source = get_source(ident) source.validation.on = datetime.now() source.validation.comment = comment source.validation.state = VALIDATION_ACCEPTED if current_user.is_authenticated: source.validatio...
python
def validate_source(ident, comment=None): '''Validate a source for automatic harvesting''' source = get_source(ident) source.validation.on = datetime.now() source.validation.comment = comment source.validation.state = VALIDATION_ACCEPTED if current_user.is_authenticated: source.validatio...
[ "def", "validate_source", "(", "ident", ",", "comment", "=", "None", ")", ":", "source", "=", "get_source", "(", "ident", ")", "source", ".", "validation", ".", "on", "=", "datetime", ".", "now", "(", ")", "source", ".", "validation", ".", "comment", "...
Validate a source for automatic harvesting
[ "Validate", "a", "source", "for", "automatic", "harvesting" ]
f016585af94b0ff6bd73738c700324adc8ba7f8f
https://github.com/opendatateam/udata/blob/f016585af94b0ff6bd73738c700324adc8ba7f8f/udata/harvest/actions.py#L98-L109
train
opendatateam/udata
udata/harvest/actions.py
reject_source
def reject_source(ident, comment): '''Reject a source for automatic harvesting''' source = get_source(ident) source.validation.on = datetime.now() source.validation.comment = comment source.validation.state = VALIDATION_REFUSED if current_user.is_authenticated: source.validation.by = cur...
python
def reject_source(ident, comment): '''Reject a source for automatic harvesting''' source = get_source(ident) source.validation.on = datetime.now() source.validation.comment = comment source.validation.state = VALIDATION_REFUSED if current_user.is_authenticated: source.validation.by = cur...
[ "def", "reject_source", "(", "ident", ",", "comment", ")", ":", "source", "=", "get_source", "(", "ident", ")", "source", ".", "validation", ".", "on", "=", "datetime", ".", "now", "(", ")", "source", ".", "validation", ".", "comment", "=", "comment", ...
Reject a source for automatic harvesting
[ "Reject", "a", "source", "for", "automatic", "harvesting" ]
f016585af94b0ff6bd73738c700324adc8ba7f8f
https://github.com/opendatateam/udata/blob/f016585af94b0ff6bd73738c700324adc8ba7f8f/udata/harvest/actions.py#L112-L121
train
opendatateam/udata
udata/harvest/actions.py
delete_source
def delete_source(ident): '''Delete an harvest source''' source = get_source(ident) source.deleted = datetime.now() source.save() signals.harvest_source_deleted.send(source) return source
python
def delete_source(ident): '''Delete an harvest source''' source = get_source(ident) source.deleted = datetime.now() source.save() signals.harvest_source_deleted.send(source) return source
[ "def", "delete_source", "(", "ident", ")", ":", "source", "=", "get_source", "(", "ident", ")", "source", ".", "deleted", "=", "datetime", ".", "now", "(", ")", "source", ".", "save", "(", ")", "signals", ".", "harvest_source_deleted", ".", "send", "(", ...
Delete an harvest source
[ "Delete", "an", "harvest", "source" ]
f016585af94b0ff6bd73738c700324adc8ba7f8f
https://github.com/opendatateam/udata/blob/f016585af94b0ff6bd73738c700324adc8ba7f8f/udata/harvest/actions.py#L124-L130
train
opendatateam/udata
udata/harvest/actions.py
run
def run(ident): '''Launch or resume an harvesting for a given source if none is running''' source = get_source(ident) cls = backends.get(current_app, source.backend) backend = cls(source) backend.harvest()
python
def run(ident): '''Launch or resume an harvesting for a given source if none is running''' source = get_source(ident) cls = backends.get(current_app, source.backend) backend = cls(source) backend.harvest()
[ "def", "run", "(", "ident", ")", ":", "source", "=", "get_source", "(", "ident", ")", "cls", "=", "backends", ".", "get", "(", "current_app", ",", "source", ".", "backend", ")", "backend", "=", "cls", "(", "source", ")", "backend", ".", "harvest", "(...
Launch or resume an harvesting for a given source if none is running
[ "Launch", "or", "resume", "an", "harvesting", "for", "a", "given", "source", "if", "none", "is", "running" ]
f016585af94b0ff6bd73738c700324adc8ba7f8f
https://github.com/opendatateam/udata/blob/f016585af94b0ff6bd73738c700324adc8ba7f8f/udata/harvest/actions.py#L138-L143
train
opendatateam/udata
udata/harvest/actions.py
preview
def preview(ident): '''Preview an harvesting for a given source''' source = get_source(ident) cls = backends.get(current_app, source.backend) max_items = current_app.config['HARVEST_PREVIEW_MAX_ITEMS'] backend = cls(source, dryrun=True, max_items=max_items) return backend.harvest()
python
def preview(ident): '''Preview an harvesting for a given source''' source = get_source(ident) cls = backends.get(current_app, source.backend) max_items = current_app.config['HARVEST_PREVIEW_MAX_ITEMS'] backend = cls(source, dryrun=True, max_items=max_items) return backend.harvest()
[ "def", "preview", "(", "ident", ")", ":", "source", "=", "get_source", "(", "ident", ")", "cls", "=", "backends", ".", "get", "(", "current_app", ",", "source", ".", "backend", ")", "max_items", "=", "current_app", ".", "config", "[", "'HARVEST_PREVIEW_MAX...
Preview an harvesting for a given source
[ "Preview", "an", "harvesting", "for", "a", "given", "source" ]
f016585af94b0ff6bd73738c700324adc8ba7f8f
https://github.com/opendatateam/udata/blob/f016585af94b0ff6bd73738c700324adc8ba7f8f/udata/harvest/actions.py#L151-L157
train
opendatateam/udata
udata/harvest/actions.py
preview_from_config
def preview_from_config(name, url, backend, description=None, frequency=DEFAULT_HARVEST_FREQUENCY, owner=None, organization=None, config=None, ): '''Preview an harvesting f...
python
def preview_from_config(name, url, backend, description=None, frequency=DEFAULT_HARVEST_FREQUENCY, owner=None, organization=None, config=None, ): '''Preview an harvesting f...
[ "def", "preview_from_config", "(", "name", ",", "url", ",", "backend", ",", "description", "=", "None", ",", "frequency", "=", "DEFAULT_HARVEST_FREQUENCY", ",", "owner", "=", "None", ",", "organization", "=", "None", ",", "config", "=", "None", ",", ")", "...
Preview an harvesting from a source created with the given parameters
[ "Preview", "an", "harvesting", "from", "a", "source", "created", "with", "the", "given", "parameters" ]
f016585af94b0ff6bd73738c700324adc8ba7f8f
https://github.com/opendatateam/udata/blob/f016585af94b0ff6bd73738c700324adc8ba7f8f/udata/harvest/actions.py#L160-L187
train
opendatateam/udata
udata/harvest/actions.py
schedule
def schedule(ident, cron=None, minute='*', hour='*', day_of_week='*', day_of_month='*', month_of_year='*'): '''Schedule an harvesting on a source given a crontab''' source = get_source(ident) if cron: minute, hour, day_of_month, month_of_year, day_of_week = cron.split() crontab = ...
python
def schedule(ident, cron=None, minute='*', hour='*', day_of_week='*', day_of_month='*', month_of_year='*'): '''Schedule an harvesting on a source given a crontab''' source = get_source(ident) if cron: minute, hour, day_of_month, month_of_year, day_of_week = cron.split() crontab = ...
[ "def", "schedule", "(", "ident", ",", "cron", "=", "None", ",", "minute", "=", "'*'", ",", "hour", "=", "'*'", ",", "day_of_week", "=", "'*'", ",", "day_of_month", "=", "'*'", ",", "month_of_year", "=", "'*'", ")", ":", "source", "=", "get_source", "...
Schedule an harvesting on a source given a crontab
[ "Schedule", "an", "harvesting", "on", "a", "source", "given", "a", "crontab" ]
f016585af94b0ff6bd73738c700324adc8ba7f8f
https://github.com/opendatateam/udata/blob/f016585af94b0ff6bd73738c700324adc8ba7f8f/udata/harvest/actions.py#L190-L218
train
opendatateam/udata
udata/harvest/actions.py
unschedule
def unschedule(ident): '''Unschedule an harvesting on a source''' source = get_source(ident) if not source.periodic_task: msg = 'Harvesting on source {0} is ot scheduled'.format(source.name) raise ValueError(msg) source.periodic_task.delete() signals.harvest_source_unscheduled.send(...
python
def unschedule(ident): '''Unschedule an harvesting on a source''' source = get_source(ident) if not source.periodic_task: msg = 'Harvesting on source {0} is ot scheduled'.format(source.name) raise ValueError(msg) source.periodic_task.delete() signals.harvest_source_unscheduled.send(...
[ "def", "unschedule", "(", "ident", ")", ":", "source", "=", "get_source", "(", "ident", ")", "if", "not", "source", ".", "periodic_task", ":", "msg", "=", "'Harvesting on source {0} is ot scheduled'", ".", "format", "(", "source", ".", "name", ")", "raise", ...
Unschedule an harvesting on a source
[ "Unschedule", "an", "harvesting", "on", "a", "source" ]
f016585af94b0ff6bd73738c700324adc8ba7f8f
https://github.com/opendatateam/udata/blob/f016585af94b0ff6bd73738c700324adc8ba7f8f/udata/harvest/actions.py#L221-L230
train
opendatateam/udata
udata/harvest/actions.py
attach
def attach(domain, filename): '''Attach existing dataset to their harvest remote id before harvesting. The expected csv file format is the following: - a column with header "local" and the local IDs or slugs - a column with header "remote" and the remote IDs The delimiter should be ";". columns o...
python
def attach(domain, filename): '''Attach existing dataset to their harvest remote id before harvesting. The expected csv file format is the following: - a column with header "local" and the local IDs or slugs - a column with header "remote" and the remote IDs The delimiter should be ";". columns o...
[ "def", "attach", "(", "domain", ",", "filename", ")", ":", "count", "=", "0", "errors", "=", "0", "with", "open", "(", "filename", ")", "as", "csvfile", ":", "reader", "=", "csv", ".", "DictReader", "(", "csvfile", ",", "delimiter", "=", "b';'", ",",...
Attach existing dataset to their harvest remote id before harvesting. The expected csv file format is the following: - a column with header "local" and the local IDs or slugs - a column with header "remote" and the remote IDs The delimiter should be ";". columns order and extras columns does not ...
[ "Attach", "existing", "dataset", "to", "their", "harvest", "remote", "id", "before", "harvesting", "." ]
f016585af94b0ff6bd73738c700324adc8ba7f8f
https://github.com/opendatateam/udata/blob/f016585af94b0ff6bd73738c700324adc8ba7f8f/udata/harvest/actions.py#L236-L276
train
opendatateam/udata
udata/models/extras_fields.py
ExtrasField.register
def register(self, key, dbtype): '''Register a DB type to add constraint on a given extra key''' if not issubclass(dbtype, (BaseField, EmbeddedDocument)): msg = 'ExtrasField can only register MongoEngine fields' raise TypeError(msg) self.registered[key] = dbtype
python
def register(self, key, dbtype): '''Register a DB type to add constraint on a given extra key''' if not issubclass(dbtype, (BaseField, EmbeddedDocument)): msg = 'ExtrasField can only register MongoEngine fields' raise TypeError(msg) self.registered[key] = dbtype
[ "def", "register", "(", "self", ",", "key", ",", "dbtype", ")", ":", "if", "not", "issubclass", "(", "dbtype", ",", "(", "BaseField", ",", "EmbeddedDocument", ")", ")", ":", "msg", "=", "'ExtrasField can only register MongoEngine fields'", "raise", "TypeError", ...
Register a DB type to add constraint on a given extra key
[ "Register", "a", "DB", "type", "to", "add", "constraint", "on", "a", "given", "extra", "key" ]
f016585af94b0ff6bd73738c700324adc8ba7f8f
https://github.com/opendatateam/udata/blob/f016585af94b0ff6bd73738c700324adc8ba7f8f/udata/models/extras_fields.py#L22-L27
train
opendatateam/udata
udata/core/user/commands.py
delete
def delete(): '''Delete an existing user''' email = click.prompt('Email') user = User.objects(email=email).first() if not user: exit_with_error('Invalid user') user.delete() success('User deleted successfully')
python
def delete(): '''Delete an existing user''' email = click.prompt('Email') user = User.objects(email=email).first() if not user: exit_with_error('Invalid user') user.delete() success('User deleted successfully')
[ "def", "delete", "(", ")", ":", "email", "=", "click", ".", "prompt", "(", "'Email'", ")", "user", "=", "User", ".", "objects", "(", "email", "=", "email", ")", ".", "first", "(", ")", "if", "not", "user", ":", "exit_with_error", "(", "'Invalid user'...
Delete an existing user
[ "Delete", "an", "existing", "user" ]
f016585af94b0ff6bd73738c700324adc8ba7f8f
https://github.com/opendatateam/udata/blob/f016585af94b0ff6bd73738c700324adc8ba7f8f/udata/core/user/commands.py#L66-L73
train
opendatateam/udata
udata/core/user/commands.py
set_admin
def set_admin(email): '''Set an user as administrator''' user = datastore.get_user(email) log.info('Adding admin role to user %s (%s)', user.fullname, user.email) role = datastore.find_or_create_role('admin') datastore.add_role_to_user(user, role) success('User %s (%s) is now administrator' % (u...
python
def set_admin(email): '''Set an user as administrator''' user = datastore.get_user(email) log.info('Adding admin role to user %s (%s)', user.fullname, user.email) role = datastore.find_or_create_role('admin') datastore.add_role_to_user(user, role) success('User %s (%s) is now administrator' % (u...
[ "def", "set_admin", "(", "email", ")", ":", "user", "=", "datastore", ".", "get_user", "(", "email", ")", "log", ".", "info", "(", "'Adding admin role to user %s (%s)'", ",", "user", ".", "fullname", ",", "user", ".", "email", ")", "role", "=", "datastore"...
Set an user as administrator
[ "Set", "an", "user", "as", "administrator" ]
f016585af94b0ff6bd73738c700324adc8ba7f8f
https://github.com/opendatateam/udata/blob/f016585af94b0ff6bd73738c700324adc8ba7f8f/udata/core/user/commands.py#L78-L84
train
opendatateam/udata
udata/core/storages/api.py
combine_chunks
def combine_chunks(storage, args, prefix=None): ''' Combine a chunked file into a whole file again. Goes through each part, in order, and appends that part's bytes to another destination file. Chunks are stored in the chunks storage. ''' uuid = args['uuid'] # Normalize filename including...
python
def combine_chunks(storage, args, prefix=None): ''' Combine a chunked file into a whole file again. Goes through each part, in order, and appends that part's bytes to another destination file. Chunks are stored in the chunks storage. ''' uuid = args['uuid'] # Normalize filename including...
[ "def", "combine_chunks", "(", "storage", ",", "args", ",", "prefix", "=", "None", ")", ":", "uuid", "=", "args", "[", "'uuid'", "]", "# Normalize filename including extension", "target", "=", "utils", ".", "normalize", "(", "args", "[", "'filename'", "]", ")...
Combine a chunked file into a whole file again. Goes through each part, in order, and appends that part's bytes to another destination file. Chunks are stored in the chunks storage.
[ "Combine", "a", "chunked", "file", "into", "a", "whole", "file", "again", ".", "Goes", "through", "each", "part", "in", "order", "and", "appends", "that", "part", "s", "bytes", "to", "another", "destination", "file", ".", "Chunks", "are", "stored", "in", ...
f016585af94b0ff6bd73738c700324adc8ba7f8f
https://github.com/opendatateam/udata/blob/f016585af94b0ff6bd73738c700324adc8ba7f8f/udata/core/storages/api.py#L111-L129
train
opendatateam/udata
udata/models/__init__.py
UDataMongoEngine.resolve_model
def resolve_model(self, model): ''' Resolve a model given a name or dict with `class` entry. :raises ValueError: model specification is wrong or does not exists ''' if not model: raise ValueError('Unsupported model specifications') if isinstance(model, basest...
python
def resolve_model(self, model): ''' Resolve a model given a name or dict with `class` entry. :raises ValueError: model specification is wrong or does not exists ''' if not model: raise ValueError('Unsupported model specifications') if isinstance(model, basest...
[ "def", "resolve_model", "(", "self", ",", "model", ")", ":", "if", "not", "model", ":", "raise", "ValueError", "(", "'Unsupported model specifications'", ")", "if", "isinstance", "(", "model", ",", "basestring", ")", ":", "classname", "=", "model", "elif", "...
Resolve a model given a name or dict with `class` entry. :raises ValueError: model specification is wrong or does not exists
[ "Resolve", "a", "model", "given", "a", "name", "or", "dict", "with", "class", "entry", "." ]
f016585af94b0ff6bd73738c700324adc8ba7f8f
https://github.com/opendatateam/udata/blob/f016585af94b0ff6bd73738c700324adc8ba7f8f/udata/models/__init__.py#L60-L79
train
opendatateam/udata
udata/frontend/helpers.py
tooltip_ellipsis
def tooltip_ellipsis(source, length=0): ''' return the plain text representation of markdown encoded text. That is the texted without any html tags. If ``length`` is 0 then it will not be truncated.''' try: length = int(length) except ValueError: # invalid literal for int() return...
python
def tooltip_ellipsis(source, length=0): ''' return the plain text representation of markdown encoded text. That is the texted without any html tags. If ``length`` is 0 then it will not be truncated.''' try: length = int(length) except ValueError: # invalid literal for int() return...
[ "def", "tooltip_ellipsis", "(", "source", ",", "length", "=", "0", ")", ":", "try", ":", "length", "=", "int", "(", "length", ")", "except", "ValueError", ":", "# invalid literal for int()", "return", "source", "# Fail silently.", "ellipsis", "=", "'<a href v-to...
return the plain text representation of markdown encoded text. That is the texted without any html tags. If ``length`` is 0 then it will not be truncated.
[ "return", "the", "plain", "text", "representation", "of", "markdown", "encoded", "text", ".", "That", "is", "the", "texted", "without", "any", "html", "tags", ".", "If", "length", "is", "0", "then", "it", "will", "not", "be", "truncated", "." ]
f016585af94b0ff6bd73738c700324adc8ba7f8f
https://github.com/opendatateam/udata/blob/f016585af94b0ff6bd73738c700324adc8ba7f8f/udata/frontend/helpers.py#L254-L264
train
opendatateam/udata
udata/frontend/helpers.py
filesize
def filesize(value): '''Display a human readable filesize''' suffix = 'o' for unit in '', 'K', 'M', 'G', 'T', 'P', 'E', 'Z': if abs(value) < 1024.0: return "%3.1f%s%s" % (value, unit, suffix) value /= 1024.0 return "%.1f%s%s" % (value, 'Y', suffix)
python
def filesize(value): '''Display a human readable filesize''' suffix = 'o' for unit in '', 'K', 'M', 'G', 'T', 'P', 'E', 'Z': if abs(value) < 1024.0: return "%3.1f%s%s" % (value, unit, suffix) value /= 1024.0 return "%.1f%s%s" % (value, 'Y', suffix)
[ "def", "filesize", "(", "value", ")", ":", "suffix", "=", "'o'", "for", "unit", "in", "''", ",", "'K'", ",", "'M'", ",", "'G'", ",", "'T'", ",", "'P'", ",", "'E'", ",", "'Z'", ":", "if", "abs", "(", "value", ")", "<", "1024.0", ":", "return", ...
Display a human readable filesize
[ "Display", "a", "human", "readable", "filesize" ]
f016585af94b0ff6bd73738c700324adc8ba7f8f
https://github.com/opendatateam/udata/blob/f016585af94b0ff6bd73738c700324adc8ba7f8f/udata/frontend/helpers.py#L399-L406
train
opendatateam/udata
udata/rdf.py
negociate_content
def negociate_content(default='json-ld'): '''Perform a content negociation on the format given the Accept header''' mimetype = request.accept_mimetypes.best_match(ACCEPTED_MIME_TYPES.keys()) return ACCEPTED_MIME_TYPES.get(mimetype, default)
python
def negociate_content(default='json-ld'): '''Perform a content negociation on the format given the Accept header''' mimetype = request.accept_mimetypes.best_match(ACCEPTED_MIME_TYPES.keys()) return ACCEPTED_MIME_TYPES.get(mimetype, default)
[ "def", "negociate_content", "(", "default", "=", "'json-ld'", ")", ":", "mimetype", "=", "request", ".", "accept_mimetypes", ".", "best_match", "(", "ACCEPTED_MIME_TYPES", ".", "keys", "(", ")", ")", "return", "ACCEPTED_MIME_TYPES", ".", "get", "(", "mimetype", ...
Perform a content negociation on the format given the Accept header
[ "Perform", "a", "content", "negociation", "on", "the", "format", "given", "the", "Accept", "header" ]
f016585af94b0ff6bd73738c700324adc8ba7f8f
https://github.com/opendatateam/udata/blob/f016585af94b0ff6bd73738c700324adc8ba7f8f/udata/rdf.py#L97-L100
train
opendatateam/udata
udata/rdf.py
url_from_rdf
def url_from_rdf(rdf, prop): ''' Try to extract An URL from a resource property. It can be expressed in many forms as a URIRef or a Literal ''' value = rdf.value(prop) if isinstance(value, (URIRef, Literal)): return value.toPython() elif isinstance(value, RdfResource): return...
python
def url_from_rdf(rdf, prop): ''' Try to extract An URL from a resource property. It can be expressed in many forms as a URIRef or a Literal ''' value = rdf.value(prop) if isinstance(value, (URIRef, Literal)): return value.toPython() elif isinstance(value, RdfResource): return...
[ "def", "url_from_rdf", "(", "rdf", ",", "prop", ")", ":", "value", "=", "rdf", ".", "value", "(", "prop", ")", "if", "isinstance", "(", "value", ",", "(", "URIRef", ",", "Literal", ")", ")", ":", "return", "value", ".", "toPython", "(", ")", "elif"...
Try to extract An URL from a resource property. It can be expressed in many forms as a URIRef or a Literal
[ "Try", "to", "extract", "An", "URL", "from", "a", "resource", "property", ".", "It", "can", "be", "expressed", "in", "many", "forms", "as", "a", "URIRef", "or", "a", "Literal" ]
f016585af94b0ff6bd73738c700324adc8ba7f8f
https://github.com/opendatateam/udata/blob/f016585af94b0ff6bd73738c700324adc8ba7f8f/udata/rdf.py#L224-L233
train
opendatateam/udata
udata/rdf.py
graph_response
def graph_response(graph, format): ''' Return a proper flask response for a RDF resource given an expected format. ''' fmt = guess_format(format) if not fmt: abort(404) headers = { 'Content-Type': RDF_MIME_TYPES[fmt] } kwargs = {} if fmt == 'json-ld': kwargs['...
python
def graph_response(graph, format): ''' Return a proper flask response for a RDF resource given an expected format. ''' fmt = guess_format(format) if not fmt: abort(404) headers = { 'Content-Type': RDF_MIME_TYPES[fmt] } kwargs = {} if fmt == 'json-ld': kwargs['...
[ "def", "graph_response", "(", "graph", ",", "format", ")", ":", "fmt", "=", "guess_format", "(", "format", ")", "if", "not", "fmt", ":", "abort", "(", "404", ")", "headers", "=", "{", "'Content-Type'", ":", "RDF_MIME_TYPES", "[", "fmt", "]", "}", "kwar...
Return a proper flask response for a RDF resource given an expected format.
[ "Return", "a", "proper", "flask", "response", "for", "a", "RDF", "resource", "given", "an", "expected", "format", "." ]
f016585af94b0ff6bd73738c700324adc8ba7f8f
https://github.com/opendatateam/udata/blob/f016585af94b0ff6bd73738c700324adc8ba7f8f/udata/rdf.py#L236-L251
train
opendatateam/udata
udata/core/spatial/models.py
GeoZoneQuerySet.valid_at
def valid_at(self, valid_date): '''Limit current QuerySet to zone valid at a given date''' is_valid = db.Q(validity__end__gt=valid_date, validity__start__lte=valid_date) no_validity = db.Q(validity=None) return self(is_valid | no_validity)
python
def valid_at(self, valid_date): '''Limit current QuerySet to zone valid at a given date''' is_valid = db.Q(validity__end__gt=valid_date, validity__start__lte=valid_date) no_validity = db.Q(validity=None) return self(is_valid | no_validity)
[ "def", "valid_at", "(", "self", ",", "valid_date", ")", ":", "is_valid", "=", "db", ".", "Q", "(", "validity__end__gt", "=", "valid_date", ",", "validity__start__lte", "=", "valid_date", ")", "no_validity", "=", "db", ".", "Q", "(", "validity", "=", "None"...
Limit current QuerySet to zone valid at a given date
[ "Limit", "current", "QuerySet", "to", "zone", "valid", "at", "a", "given", "date" ]
f016585af94b0ff6bd73738c700324adc8ba7f8f
https://github.com/opendatateam/udata/blob/f016585af94b0ff6bd73738c700324adc8ba7f8f/udata/core/spatial/models.py#L44-L49
train
opendatateam/udata
udata/core/spatial/models.py
GeoZoneQuerySet.resolve
def resolve(self, geoid, id_only=False): ''' Resolve a GeoZone given a GeoID. The start date is resolved from the given GeoID, ie. it find there is a zone valid a the geoid validity, resolve the `latest` alias or use `latest` when no validity is given. If `id_on...
python
def resolve(self, geoid, id_only=False): ''' Resolve a GeoZone given a GeoID. The start date is resolved from the given GeoID, ie. it find there is a zone valid a the geoid validity, resolve the `latest` alias or use `latest` when no validity is given. If `id_on...
[ "def", "resolve", "(", "self", ",", "geoid", ",", "id_only", "=", "False", ")", ":", "level", ",", "code", ",", "validity", "=", "geoids", ".", "parse", "(", "geoid", ")", "qs", "=", "self", "(", "level", "=", "level", ",", "code", "=", "code", "...
Resolve a GeoZone given a GeoID. The start date is resolved from the given GeoID, ie. it find there is a zone valid a the geoid validity, resolve the `latest` alias or use `latest` when no validity is given. If `id_only` is True, the result will be the resolved GeoID ...
[ "Resolve", "a", "GeoZone", "given", "a", "GeoID", "." ]
f016585af94b0ff6bd73738c700324adc8ba7f8f
https://github.com/opendatateam/udata/blob/f016585af94b0ff6bd73738c700324adc8ba7f8f/udata/core/spatial/models.py#L60-L81
train
opendatateam/udata
udata/core/spatial/models.py
GeoZone.keys_values
def keys_values(self): """Key values might be a list or not, always return a list.""" keys_values = [] for value in self.keys.values(): if isinstance(value, list): keys_values += value elif isinstance(value, basestring) and not value.startswith('-'): ...
python
def keys_values(self): """Key values might be a list or not, always return a list.""" keys_values = [] for value in self.keys.values(): if isinstance(value, list): keys_values += value elif isinstance(value, basestring) and not value.startswith('-'): ...
[ "def", "keys_values", "(", "self", ")", ":", "keys_values", "=", "[", "]", "for", "value", "in", "self", ".", "keys", ".", "values", "(", ")", ":", "if", "isinstance", "(", "value", ",", "list", ")", ":", "keys_values", "+=", "value", "elif", "isinst...
Key values might be a list or not, always return a list.
[ "Key", "values", "might", "be", "a", "list", "or", "not", "always", "return", "a", "list", "." ]
f016585af94b0ff6bd73738c700324adc8ba7f8f
https://github.com/opendatateam/udata/blob/f016585af94b0ff6bd73738c700324adc8ba7f8f/udata/core/spatial/models.py#L134-L146
train
opendatateam/udata
udata/core/spatial/models.py
GeoZone.level_i18n_name
def level_i18n_name(self): """In use within templates for dynamic translations.""" for level, name in spatial_granularities: if self.level == level: return name return self.level_name
python
def level_i18n_name(self): """In use within templates for dynamic translations.""" for level, name in spatial_granularities: if self.level == level: return name return self.level_name
[ "def", "level_i18n_name", "(", "self", ")", ":", "for", "level", ",", "name", "in", "spatial_granularities", ":", "if", "self", ".", "level", "==", "level", ":", "return", "name", "return", "self", ".", "level_name" ]
In use within templates for dynamic translations.
[ "In", "use", "within", "templates", "for", "dynamic", "translations", "." ]
f016585af94b0ff6bd73738c700324adc8ba7f8f
https://github.com/opendatateam/udata/blob/f016585af94b0ff6bd73738c700324adc8ba7f8f/udata/core/spatial/models.py#L164-L169
train
opendatateam/udata
udata/core/spatial/models.py
GeoZone.ancestors_objects
def ancestors_objects(self): """Ancestors objects sorted by name.""" ancestors_objects = [] for ancestor in self.ancestors: try: ancestor_object = GeoZone.objects.get(id=ancestor) except GeoZone.DoesNotExist: continue ancestors_...
python
def ancestors_objects(self): """Ancestors objects sorted by name.""" ancestors_objects = [] for ancestor in self.ancestors: try: ancestor_object = GeoZone.objects.get(id=ancestor) except GeoZone.DoesNotExist: continue ancestors_...
[ "def", "ancestors_objects", "(", "self", ")", ":", "ancestors_objects", "=", "[", "]", "for", "ancestor", "in", "self", ".", "ancestors", ":", "try", ":", "ancestor_object", "=", "GeoZone", ".", "objects", ".", "get", "(", "id", "=", "ancestor", ")", "ex...
Ancestors objects sorted by name.
[ "Ancestors", "objects", "sorted", "by", "name", "." ]
f016585af94b0ff6bd73738c700324adc8ba7f8f
https://github.com/opendatateam/udata/blob/f016585af94b0ff6bd73738c700324adc8ba7f8f/udata/core/spatial/models.py#L172-L182
train
opendatateam/udata
udata/core/spatial/models.py
GeoZone.child_level
def child_level(self): """Return the child level given handled levels.""" HANDLED_LEVELS = current_app.config.get('HANDLED_LEVELS') try: return HANDLED_LEVELS[HANDLED_LEVELS.index(self.level) - 1] except (IndexError, ValueError): return None
python
def child_level(self): """Return the child level given handled levels.""" HANDLED_LEVELS = current_app.config.get('HANDLED_LEVELS') try: return HANDLED_LEVELS[HANDLED_LEVELS.index(self.level) - 1] except (IndexError, ValueError): return None
[ "def", "child_level", "(", "self", ")", ":", "HANDLED_LEVELS", "=", "current_app", ".", "config", ".", "get", "(", "'HANDLED_LEVELS'", ")", "try", ":", "return", "HANDLED_LEVELS", "[", "HANDLED_LEVELS", ".", "index", "(", "self", ".", "level", ")", "-", "1...
Return the child level given handled levels.
[ "Return", "the", "child", "level", "given", "handled", "levels", "." ]
f016585af94b0ff6bd73738c700324adc8ba7f8f
https://github.com/opendatateam/udata/blob/f016585af94b0ff6bd73738c700324adc8ba7f8f/udata/core/spatial/models.py#L185-L191
train
opendatateam/udata
udata/harvest/backends/base.py
BaseBackend.harvest
def harvest(self): '''Start the harvesting process''' if self.perform_initialization() is not None: self.process_items() self.finalize() return self.job
python
def harvest(self): '''Start the harvesting process''' if self.perform_initialization() is not None: self.process_items() self.finalize() return self.job
[ "def", "harvest", "(", "self", ")", ":", "if", "self", ".", "perform_initialization", "(", ")", "is", "not", "None", ":", "self", ".", "process_items", "(", ")", "self", ".", "finalize", "(", ")", "return", "self", ".", "job" ]
Start the harvesting process
[ "Start", "the", "harvesting", "process" ]
f016585af94b0ff6bd73738c700324adc8ba7f8f
https://github.com/opendatateam/udata/blob/f016585af94b0ff6bd73738c700324adc8ba7f8f/udata/harvest/backends/base.py#L127-L132
train
opendatateam/udata
udata/harvest/backends/base.py
BaseBackend.perform_initialization
def perform_initialization(self): '''Initialize the harvesting for a given job''' log.debug('Initializing backend') factory = HarvestJob if self.dryrun else HarvestJob.objects.create self.job = factory(status='initializing', started=datetime.now(), ...
python
def perform_initialization(self): '''Initialize the harvesting for a given job''' log.debug('Initializing backend') factory = HarvestJob if self.dryrun else HarvestJob.objects.create self.job = factory(status='initializing', started=datetime.now(), ...
[ "def", "perform_initialization", "(", "self", ")", ":", "log", ".", "debug", "(", "'Initializing backend'", ")", "factory", "=", "HarvestJob", "if", "self", ".", "dryrun", "else", "HarvestJob", ".", "objects", ".", "create", "self", ".", "job", "=", "factory...
Initialize the harvesting for a given job
[ "Initialize", "the", "harvesting", "for", "a", "given", "job" ]
f016585af94b0ff6bd73738c700324adc8ba7f8f
https://github.com/opendatateam/udata/blob/f016585af94b0ff6bd73738c700324adc8ba7f8f/udata/harvest/backends/base.py#L134-L172
train
opendatateam/udata
udata/harvest/backends/base.py
BaseBackend.validate
def validate(self, data, schema): '''Perform a data validation against a given schema. :param data: an object to validate :param schema: a Voluptous schema to validate against ''' try: return schema(data) except MultipleInvalid as ie: errors = [] ...
python
def validate(self, data, schema): '''Perform a data validation against a given schema. :param data: an object to validate :param schema: a Voluptous schema to validate against ''' try: return schema(data) except MultipleInvalid as ie: errors = [] ...
[ "def", "validate", "(", "self", ",", "data", ",", "schema", ")", ":", "try", ":", "return", "schema", "(", "data", ")", "except", "MultipleInvalid", "as", "ie", ":", "errors", "=", "[", "]", "for", "error", "in", "ie", ".", "errors", ":", "if", "er...
Perform a data validation against a given schema. :param data: an object to validate :param schema: a Voluptous schema to validate against
[ "Perform", "a", "data", "validation", "against", "a", "given", "schema", "." ]
f016585af94b0ff6bd73738c700324adc8ba7f8f
https://github.com/opendatateam/udata/blob/f016585af94b0ff6bd73738c700324adc8ba7f8f/udata/harvest/backends/base.py#L265-L304
train
opendatateam/udata
udata/core/badges/api.py
add
def add(obj): ''' Handle a badge add API. - Expecting badge_fieds as payload - Return the badge as payload - Return 200 if the badge is already - Return 201 if the badge is added ''' Form = badge_form(obj.__class__) form = api.validate(Form) kind = form.kind.data badge = obj...
python
def add(obj): ''' Handle a badge add API. - Expecting badge_fieds as payload - Return the badge as payload - Return 200 if the badge is already - Return 201 if the badge is added ''' Form = badge_form(obj.__class__) form = api.validate(Form) kind = form.kind.data badge = obj...
[ "def", "add", "(", "obj", ")", ":", "Form", "=", "badge_form", "(", "obj", ".", "__class__", ")", "form", "=", "api", ".", "validate", "(", "Form", ")", "kind", "=", "form", ".", "kind", ".", "data", "badge", "=", "obj", ".", "get_badge", "(", "k...
Handle a badge add API. - Expecting badge_fieds as payload - Return the badge as payload - Return 200 if the badge is already - Return 201 if the badge is added
[ "Handle", "a", "badge", "add", "API", "." ]
f016585af94b0ff6bd73738c700324adc8ba7f8f
https://github.com/opendatateam/udata/blob/f016585af94b0ff6bd73738c700324adc8ba7f8f/udata/core/badges/api.py#L16-L32
train
opendatateam/udata
udata/core/badges/api.py
remove
def remove(obj, kind): ''' Handle badge removal API - Returns 404 if the badge for this kind is absent - Returns 204 on success ''' if not obj.get_badge(kind): api.abort(404, 'Badge does not exists') obj.remove_badge(kind) return '', 204
python
def remove(obj, kind): ''' Handle badge removal API - Returns 404 if the badge for this kind is absent - Returns 204 on success ''' if not obj.get_badge(kind): api.abort(404, 'Badge does not exists') obj.remove_badge(kind) return '', 204
[ "def", "remove", "(", "obj", ",", "kind", ")", ":", "if", "not", "obj", ".", "get_badge", "(", "kind", ")", ":", "api", ".", "abort", "(", "404", ",", "'Badge does not exists'", ")", "obj", ".", "remove_badge", "(", "kind", ")", "return", "''", ",", ...
Handle badge removal API - Returns 404 if the badge for this kind is absent - Returns 204 on success
[ "Handle", "badge", "removal", "API" ]
f016585af94b0ff6bd73738c700324adc8ba7f8f
https://github.com/opendatateam/udata/blob/f016585af94b0ff6bd73738c700324adc8ba7f8f/udata/core/badges/api.py#L35-L45
train
opendatateam/udata
udata/features/territories/__init__.py
check_for_territories
def check_for_territories(query): """ Return a geozone queryset of territories given the `query`. Results are sorted by population and area (biggest first). """ if not query or not current_app.config.get('ACTIVATE_TERRITORIES'): return [] dbqs = db.Q() query = query.lower() is_...
python
def check_for_territories(query): """ Return a geozone queryset of territories given the `query`. Results are sorted by population and area (biggest first). """ if not query or not current_app.config.get('ACTIVATE_TERRITORIES'): return [] dbqs = db.Q() query = query.lower() is_...
[ "def", "check_for_territories", "(", "query", ")", ":", "if", "not", "query", "or", "not", "current_app", ".", "config", ".", "get", "(", "'ACTIVATE_TERRITORIES'", ")", ":", "return", "[", "]", "dbqs", "=", "db", ".", "Q", "(", ")", "query", "=", "quer...
Return a geozone queryset of territories given the `query`. Results are sorted by population and area (biggest first).
[ "Return", "a", "geozone", "queryset", "of", "territories", "given", "the", "query", "." ]
f016585af94b0ff6bd73738c700324adc8ba7f8f
https://github.com/opendatateam/udata/blob/f016585af94b0ff6bd73738c700324adc8ba7f8f/udata/features/territories/__init__.py#L9-L50
train
opendatateam/udata
udata/core/spatial/geoids.py
build
def build(level, code, validity=None): '''Serialize a GeoID from its parts''' spatial = ':'.join((level, code)) if not validity: return spatial elif isinstance(validity, basestring): return '@'.join((spatial, validity)) elif isinstance(validity, datetime): return '@'.join((sp...
python
def build(level, code, validity=None): '''Serialize a GeoID from its parts''' spatial = ':'.join((level, code)) if not validity: return spatial elif isinstance(validity, basestring): return '@'.join((spatial, validity)) elif isinstance(validity, datetime): return '@'.join((sp...
[ "def", "build", "(", "level", ",", "code", ",", "validity", "=", "None", ")", ":", "spatial", "=", "':'", ".", "join", "(", "(", "level", ",", "code", ")", ")", "if", "not", "validity", ":", "return", "spatial", "elif", "isinstance", "(", "validity",...
Serialize a GeoID from its parts
[ "Serialize", "a", "GeoID", "from", "its", "parts" ]
f016585af94b0ff6bd73738c700324adc8ba7f8f
https://github.com/opendatateam/udata/blob/f016585af94b0ff6bd73738c700324adc8ba7f8f/udata/core/spatial/geoids.py#L41-L54
train
opendatateam/udata
udata/core/spatial/geoids.py
from_zone
def from_zone(zone): '''Build a GeoID from a given zone''' validity = zone.validity.start if zone.validity else None return build(zone.level, zone.code, validity)
python
def from_zone(zone): '''Build a GeoID from a given zone''' validity = zone.validity.start if zone.validity else None return build(zone.level, zone.code, validity)
[ "def", "from_zone", "(", "zone", ")", ":", "validity", "=", "zone", ".", "validity", ".", "start", "if", "zone", ".", "validity", "else", "None", "return", "build", "(", "zone", ".", "level", ",", "zone", ".", "code", ",", "validity", ")" ]
Build a GeoID from a given zone
[ "Build", "a", "GeoID", "from", "a", "given", "zone" ]
f016585af94b0ff6bd73738c700324adc8ba7f8f
https://github.com/opendatateam/udata/blob/f016585af94b0ff6bd73738c700324adc8ba7f8f/udata/core/spatial/geoids.py#L57-L60
train
opendatateam/udata
udata/core/dataset/rdf.py
temporal_from_rdf
def temporal_from_rdf(period_of_time): '''Failsafe parsing of a temporal coverage''' try: if isinstance(period_of_time, Literal): return temporal_from_literal(str(period_of_time)) elif isinstance(period_of_time, RdfResource): return temporal_from_resource(period_of_time) ...
python
def temporal_from_rdf(period_of_time): '''Failsafe parsing of a temporal coverage''' try: if isinstance(period_of_time, Literal): return temporal_from_literal(str(period_of_time)) elif isinstance(period_of_time, RdfResource): return temporal_from_resource(period_of_time) ...
[ "def", "temporal_from_rdf", "(", "period_of_time", ")", ":", "try", ":", "if", "isinstance", "(", "period_of_time", ",", "Literal", ")", ":", "return", "temporal_from_literal", "(", "str", "(", "period_of_time", ")", ")", "elif", "isinstance", "(", "period_of_ti...
Failsafe parsing of a temporal coverage
[ "Failsafe", "parsing", "of", "a", "temporal", "coverage" ]
f016585af94b0ff6bd73738c700324adc8ba7f8f
https://github.com/opendatateam/udata/blob/f016585af94b0ff6bd73738c700324adc8ba7f8f/udata/core/dataset/rdf.py#L284-L295
train
opendatateam/udata
udata/core/dataset/rdf.py
title_from_rdf
def title_from_rdf(rdf, url): ''' Try to extract a distribution title from a property. As it's not a mandatory property, it fallback on building a title from the URL then the format and in last ressort a generic resource name. ''' title = rdf_value(rdf, DCT.title) if title: retur...
python
def title_from_rdf(rdf, url): ''' Try to extract a distribution title from a property. As it's not a mandatory property, it fallback on building a title from the URL then the format and in last ressort a generic resource name. ''' title = rdf_value(rdf, DCT.title) if title: retur...
[ "def", "title_from_rdf", "(", "rdf", ",", "url", ")", ":", "title", "=", "rdf_value", "(", "rdf", ",", "DCT", ".", "title", ")", "if", "title", ":", "return", "title", "if", "url", ":", "last_part", "=", "url", ".", "split", "(", "'/'", ")", "[", ...
Try to extract a distribution title from a property. As it's not a mandatory property, it fallback on building a title from the URL then the format and in last ressort a generic resource name.
[ "Try", "to", "extract", "a", "distribution", "title", "from", "a", "property", ".", "As", "it", "s", "not", "a", "mandatory", "property", "it", "fallback", "on", "building", "a", "title", "from", "the", "URL", "then", "the", "format", "and", "in", "last"...
f016585af94b0ff6bd73738c700324adc8ba7f8f
https://github.com/opendatateam/udata/blob/f016585af94b0ff6bd73738c700324adc8ba7f8f/udata/core/dataset/rdf.py#L313-L333
train
opendatateam/udata
udata/core/reuse/forms.py
check_url_does_not_exists
def check_url_does_not_exists(form, field): '''Ensure a reuse URL is not yet registered''' if field.data != field.object_data and Reuse.url_exists(field.data): raise validators.ValidationError(_('This URL is already registered'))
python
def check_url_does_not_exists(form, field): '''Ensure a reuse URL is not yet registered''' if field.data != field.object_data and Reuse.url_exists(field.data): raise validators.ValidationError(_('This URL is already registered'))
[ "def", "check_url_does_not_exists", "(", "form", ",", "field", ")", ":", "if", "field", ".", "data", "!=", "field", ".", "object_data", "and", "Reuse", ".", "url_exists", "(", "field", ".", "data", ")", ":", "raise", "validators", ".", "ValidationError", "...
Ensure a reuse URL is not yet registered
[ "Ensure", "a", "reuse", "URL", "is", "not", "yet", "registered" ]
f016585af94b0ff6bd73738c700324adc8ba7f8f
https://github.com/opendatateam/udata/blob/f016585af94b0ff6bd73738c700324adc8ba7f8f/udata/core/reuse/forms.py#L13-L16
train
opendatateam/udata
udata/search/fields.py
obj_to_string
def obj_to_string(obj): '''Render an object into a unicode string if possible''' if not obj: return None elif isinstance(obj, bytes): return obj.decode('utf-8') elif isinstance(obj, basestring): return obj elif is_lazy_string(obj): return obj.value elif hasattr(ob...
python
def obj_to_string(obj): '''Render an object into a unicode string if possible''' if not obj: return None elif isinstance(obj, bytes): return obj.decode('utf-8') elif isinstance(obj, basestring): return obj elif is_lazy_string(obj): return obj.value elif hasattr(ob...
[ "def", "obj_to_string", "(", "obj", ")", ":", "if", "not", "obj", ":", "return", "None", "elif", "isinstance", "(", "obj", ",", "bytes", ")", ":", "return", "obj", ".", "decode", "(", "'utf-8'", ")", "elif", "isinstance", "(", "obj", ",", "basestring",...
Render an object into a unicode string if possible
[ "Render", "an", "object", "into", "a", "unicode", "string", "if", "possible" ]
f016585af94b0ff6bd73738c700324adc8ba7f8f
https://github.com/opendatateam/udata/blob/f016585af94b0ff6bd73738c700324adc8ba7f8f/udata/search/fields.py#L41-L54
train
opendatateam/udata
udata/search/fields.py
TermsFacet.add_filter
def add_filter(self, filter_values): """Improve the original one to deal with OR cases.""" field = self._params['field'] # Build a `AND` query on values wihtout the OR operator. # and a `OR` query for each value containing the OR operator. filters = [ Q('bool', should...
python
def add_filter(self, filter_values): """Improve the original one to deal with OR cases.""" field = self._params['field'] # Build a `AND` query on values wihtout the OR operator. # and a `OR` query for each value containing the OR operator. filters = [ Q('bool', should...
[ "def", "add_filter", "(", "self", ",", "filter_values", ")", ":", "field", "=", "self", ".", "_params", "[", "'field'", "]", "# Build a `AND` query on values wihtout the OR operator.", "# and a `OR` query for each value containing the OR operator.", "filters", "=", "[", "Q"...
Improve the original one to deal with OR cases.
[ "Improve", "the", "original", "one", "to", "deal", "with", "OR", "cases", "." ]
f016585af94b0ff6bd73738c700324adc8ba7f8f
https://github.com/opendatateam/udata/blob/f016585af94b0ff6bd73738c700324adc8ba7f8f/udata/search/fields.py#L87-L100
train
opendatateam/udata
udata/search/fields.py
ModelTermsFacet.get_values
def get_values(self, data, filter_values): """ Turn the raw bucket data into a list of tuples containing the object, number of documents and a flag indicating whether this value has been selected or not. """ values = super(ModelTermsFacet, self).get_values(data, filter_va...
python
def get_values(self, data, filter_values): """ Turn the raw bucket data into a list of tuples containing the object, number of documents and a flag indicating whether this value has been selected or not. """ values = super(ModelTermsFacet, self).get_values(data, filter_va...
[ "def", "get_values", "(", "self", ",", "data", ",", "filter_values", ")", ":", "values", "=", "super", "(", "ModelTermsFacet", ",", "self", ")", ".", "get_values", "(", "data", ",", "filter_values", ")", "ids", "=", "[", "key", "for", "(", "key", ",", ...
Turn the raw bucket data into a list of tuples containing the object, number of documents and a flag indicating whether this value has been selected or not.
[ "Turn", "the", "raw", "bucket", "data", "into", "a", "list", "of", "tuples", "containing", "the", "object", "number", "of", "documents", "and", "a", "flag", "indicating", "whether", "this", "value", "has", "been", "selected", "or", "not", "." ]
f016585af94b0ff6bd73738c700324adc8ba7f8f
https://github.com/opendatateam/udata/blob/f016585af94b0ff6bd73738c700324adc8ba7f8f/udata/search/fields.py#L135-L151
train
opendatateam/udata
udata/core/organization/forms.py
OrganizationForm.save
def save(self, commit=True, **kwargs): '''Register the current user as admin on creation''' org = super(OrganizationForm, self).save(commit=False, **kwargs) if not org.id: user = current_user._get_current_object() member = Member(user=user, role='admin') org....
python
def save(self, commit=True, **kwargs): '''Register the current user as admin on creation''' org = super(OrganizationForm, self).save(commit=False, **kwargs) if not org.id: user = current_user._get_current_object() member = Member(user=user, role='admin') org....
[ "def", "save", "(", "self", ",", "commit", "=", "True", ",", "*", "*", "kwargs", ")", ":", "org", "=", "super", "(", "OrganizationForm", ",", "self", ")", ".", "save", "(", "commit", "=", "False", ",", "*", "*", "kwargs", ")", "if", "not", "org",...
Register the current user as admin on creation
[ "Register", "the", "current", "user", "as", "admin", "on", "creation" ]
f016585af94b0ff6bd73738c700324adc8ba7f8f
https://github.com/opendatateam/udata/blob/f016585af94b0ff6bd73738c700324adc8ba7f8f/udata/core/organization/forms.py#L36-L48
train
antonagestam/collectfast
collectfast/etag.py
get_cache_key
def get_cache_key(path): """ Create a cache key by concatenating the prefix with a hash of the path. """ # Python 2/3 support for path hashing try: path_hash = hashlib.md5(path).hexdigest() except TypeError: path_hash = hashlib.md5(path.encode('utf-8')).hexdigest() return set...
python
def get_cache_key(path): """ Create a cache key by concatenating the prefix with a hash of the path. """ # Python 2/3 support for path hashing try: path_hash = hashlib.md5(path).hexdigest() except TypeError: path_hash = hashlib.md5(path.encode('utf-8')).hexdigest() return set...
[ "def", "get_cache_key", "(", "path", ")", ":", "# Python 2/3 support for path hashing", "try", ":", "path_hash", "=", "hashlib", ".", "md5", "(", "path", ")", ".", "hexdigest", "(", ")", "except", "TypeError", ":", "path_hash", "=", "hashlib", ".", "md5", "(...
Create a cache key by concatenating the prefix with a hash of the path.
[ "Create", "a", "cache", "key", "by", "concatenating", "the", "prefix", "with", "a", "hash", "of", "the", "path", "." ]
fb9d7976da2a2578528fa6f3bbd053ee87475ecb
https://github.com/antonagestam/collectfast/blob/fb9d7976da2a2578528fa6f3bbd053ee87475ecb/collectfast/etag.py#L28-L37
train
antonagestam/collectfast
collectfast/etag.py
get_remote_etag
def get_remote_etag(storage, prefixed_path): """ Get etag of path from S3 using boto or boto3. """ normalized_path = safe_join(storage.location, prefixed_path).replace( '\\', '/') try: return storage.bucket.get_key(normalized_path).etag except AttributeError: pass try...
python
def get_remote_etag(storage, prefixed_path): """ Get etag of path from S3 using boto or boto3. """ normalized_path = safe_join(storage.location, prefixed_path).replace( '\\', '/') try: return storage.bucket.get_key(normalized_path).etag except AttributeError: pass try...
[ "def", "get_remote_etag", "(", "storage", ",", "prefixed_path", ")", ":", "normalized_path", "=", "safe_join", "(", "storage", ".", "location", ",", "prefixed_path", ")", ".", "replace", "(", "'\\\\'", ",", "'/'", ")", "try", ":", "return", "storage", ".", ...
Get etag of path from S3 using boto or boto3.
[ "Get", "etag", "of", "path", "from", "S3", "using", "boto", "or", "boto3", "." ]
fb9d7976da2a2578528fa6f3bbd053ee87475ecb
https://github.com/antonagestam/collectfast/blob/fb9d7976da2a2578528fa6f3bbd053ee87475ecb/collectfast/etag.py#L40-L54
train
antonagestam/collectfast
collectfast/etag.py
get_etag
def get_etag(storage, path, prefixed_path): """ Get etag of path from cache or S3 - in that order. """ cache_key = get_cache_key(path) etag = cache.get(cache_key, False) if etag is False: etag = get_remote_etag(storage, prefixed_path) cache.set(cache_key, etag) return etag
python
def get_etag(storage, path, prefixed_path): """ Get etag of path from cache or S3 - in that order. """ cache_key = get_cache_key(path) etag = cache.get(cache_key, False) if etag is False: etag = get_remote_etag(storage, prefixed_path) cache.set(cache_key, etag) return etag
[ "def", "get_etag", "(", "storage", ",", "path", ",", "prefixed_path", ")", ":", "cache_key", "=", "get_cache_key", "(", "path", ")", "etag", "=", "cache", ".", "get", "(", "cache_key", ",", "False", ")", "if", "etag", "is", "False", ":", "etag", "=", ...
Get etag of path from cache or S3 - in that order.
[ "Get", "etag", "of", "path", "from", "cache", "or", "S3", "-", "in", "that", "order", "." ]
fb9d7976da2a2578528fa6f3bbd053ee87475ecb
https://github.com/antonagestam/collectfast/blob/fb9d7976da2a2578528fa6f3bbd053ee87475ecb/collectfast/etag.py#L57-L66
train
antonagestam/collectfast
collectfast/etag.py
get_file_hash
def get_file_hash(storage, path): """ Create md5 hash from file contents. """ contents = storage.open(path).read() file_hash = hashlib.md5(contents).hexdigest() # Check if content should be gzipped and hash gzipped content content_type = mimetypes.guess_type(path)[0] or 'application/octet-s...
python
def get_file_hash(storage, path): """ Create md5 hash from file contents. """ contents = storage.open(path).read() file_hash = hashlib.md5(contents).hexdigest() # Check if content should be gzipped and hash gzipped content content_type = mimetypes.guess_type(path)[0] or 'application/octet-s...
[ "def", "get_file_hash", "(", "storage", ",", "path", ")", ":", "contents", "=", "storage", ".", "open", "(", "path", ")", ".", "read", "(", ")", "file_hash", "=", "hashlib", ".", "md5", "(", "contents", ")", ".", "hexdigest", "(", ")", "# Check if cont...
Create md5 hash from file contents.
[ "Create", "md5", "hash", "from", "file", "contents", "." ]
fb9d7976da2a2578528fa6f3bbd053ee87475ecb
https://github.com/antonagestam/collectfast/blob/fb9d7976da2a2578528fa6f3bbd053ee87475ecb/collectfast/etag.py#L76-L97
train
antonagestam/collectfast
collectfast/etag.py
has_matching_etag
def has_matching_etag(remote_storage, source_storage, path, prefixed_path): """ Compare etag of path in source storage with remote. """ storage_etag = get_etag(remote_storage, path, prefixed_path) local_etag = get_file_hash(source_storage, path) return storage_etag == local_etag
python
def has_matching_etag(remote_storage, source_storage, path, prefixed_path): """ Compare etag of path in source storage with remote. """ storage_etag = get_etag(remote_storage, path, prefixed_path) local_etag = get_file_hash(source_storage, path) return storage_etag == local_etag
[ "def", "has_matching_etag", "(", "remote_storage", ",", "source_storage", ",", "path", ",", "prefixed_path", ")", ":", "storage_etag", "=", "get_etag", "(", "remote_storage", ",", "path", ",", "prefixed_path", ")", "local_etag", "=", "get_file_hash", "(", "source_...
Compare etag of path in source storage with remote.
[ "Compare", "etag", "of", "path", "in", "source", "storage", "with", "remote", "." ]
fb9d7976da2a2578528fa6f3bbd053ee87475ecb
https://github.com/antonagestam/collectfast/blob/fb9d7976da2a2578528fa6f3bbd053ee87475ecb/collectfast/etag.py#L100-L106
train
antonagestam/collectfast
collectfast/etag.py
should_copy_file
def should_copy_file(remote_storage, path, prefixed_path, source_storage): """ Returns True if the file should be copied, otherwise False. """ if has_matching_etag( remote_storage, source_storage, path, prefixed_path): logger.info("%s: Skipping based on matching file hashes" % path) ...
python
def should_copy_file(remote_storage, path, prefixed_path, source_storage): """ Returns True if the file should be copied, otherwise False. """ if has_matching_etag( remote_storage, source_storage, path, prefixed_path): logger.info("%s: Skipping based on matching file hashes" % path) ...
[ "def", "should_copy_file", "(", "remote_storage", ",", "path", ",", "prefixed_path", ",", "source_storage", ")", ":", "if", "has_matching_etag", "(", "remote_storage", ",", "source_storage", ",", "path", ",", "prefixed_path", ")", ":", "logger", ".", "info", "("...
Returns True if the file should be copied, otherwise False.
[ "Returns", "True", "if", "the", "file", "should", "be", "copied", "otherwise", "False", "." ]
fb9d7976da2a2578528fa6f3bbd053ee87475ecb
https://github.com/antonagestam/collectfast/blob/fb9d7976da2a2578528fa6f3bbd053ee87475ecb/collectfast/etag.py#L109-L121
train
antonagestam/collectfast
collectfast/management/commands/collectstatic.py
Command.set_options
def set_options(self, **options): """ Set options and handle deprecation. """ ignore_etag = options.pop('ignore_etag', False) disable = options.pop('disable_collectfast', False) if ignore_etag: warnings.warn( "--ignore-etag is deprecated since ...
python
def set_options(self, **options): """ Set options and handle deprecation. """ ignore_etag = options.pop('ignore_etag', False) disable = options.pop('disable_collectfast', False) if ignore_etag: warnings.warn( "--ignore-etag is deprecated since ...
[ "def", "set_options", "(", "self", ",", "*", "*", "options", ")", ":", "ignore_etag", "=", "options", ".", "pop", "(", "'ignore_etag'", ",", "False", ")", "disable", "=", "options", ".", "pop", "(", "'disable_collectfast'", ",", "False", ")", "if", "igno...
Set options and handle deprecation.
[ "Set", "options", "and", "handle", "deprecation", "." ]
fb9d7976da2a2578528fa6f3bbd053ee87475ecb
https://github.com/antonagestam/collectfast/blob/fb9d7976da2a2578528fa6f3bbd053ee87475ecb/collectfast/management/commands/collectstatic.py#L44-L56
train
antonagestam/collectfast
collectfast/management/commands/collectstatic.py
Command.handle
def handle(self, **options): """ Override handle to supress summary output """ super(Command, self).handle(**options) return "{} static file{} copied.".format( self.num_copied_files, '' if self.num_copied_files == 1 else 's')
python
def handle(self, **options): """ Override handle to supress summary output """ super(Command, self).handle(**options) return "{} static file{} copied.".format( self.num_copied_files, '' if self.num_copied_files == 1 else 's')
[ "def", "handle", "(", "self", ",", "*", "*", "options", ")", ":", "super", "(", "Command", ",", "self", ")", ".", "handle", "(", "*", "*", "options", ")", "return", "\"{} static file{} copied.\"", ".", "format", "(", "self", ".", "num_copied_files", ",",...
Override handle to supress summary output
[ "Override", "handle", "to", "supress", "summary", "output" ]
fb9d7976da2a2578528fa6f3bbd053ee87475ecb
https://github.com/antonagestam/collectfast/blob/fb9d7976da2a2578528fa6f3bbd053ee87475ecb/collectfast/management/commands/collectstatic.py#L68-L75
train
antonagestam/collectfast
collectfast/management/commands/collectstatic.py
Command.do_copy_file
def do_copy_file(self, args): """ Determine if file should be copied or not and handle exceptions. """ path, prefixed_path, source_storage = args reset_connection(self.storage) if self.collectfast_enabled and not self.dry_run: try: if not sho...
python
def do_copy_file(self, args): """ Determine if file should be copied or not and handle exceptions. """ path, prefixed_path, source_storage = args reset_connection(self.storage) if self.collectfast_enabled and not self.dry_run: try: if not sho...
[ "def", "do_copy_file", "(", "self", ",", "args", ")", ":", "path", ",", "prefixed_path", ",", "source_storage", "=", "args", "reset_connection", "(", "self", ".", "storage", ")", "if", "self", ".", "collectfast_enabled", "and", "not", "self", ".", "dry_run",...
Determine if file should be copied or not and handle exceptions.
[ "Determine", "if", "file", "should", "be", "copied", "or", "not", "and", "handle", "exceptions", "." ]
fb9d7976da2a2578528fa6f3bbd053ee87475ecb
https://github.com/antonagestam/collectfast/blob/fb9d7976da2a2578528fa6f3bbd053ee87475ecb/collectfast/management/commands/collectstatic.py#L77-L100
train
antonagestam/collectfast
collectfast/management/commands/collectstatic.py
Command.copy_file
def copy_file(self, path, prefixed_path, source_storage): """ Appends path to task queue if threads are enabled, otherwise copies the file with a blocking call. """ args = (path, prefixed_path, source_storage) if settings.threads: self.tasks.append(args) ...
python
def copy_file(self, path, prefixed_path, source_storage): """ Appends path to task queue if threads are enabled, otherwise copies the file with a blocking call. """ args = (path, prefixed_path, source_storage) if settings.threads: self.tasks.append(args) ...
[ "def", "copy_file", "(", "self", ",", "path", ",", "prefixed_path", ",", "source_storage", ")", ":", "args", "=", "(", "path", ",", "prefixed_path", ",", "source_storage", ")", "if", "settings", ".", "threads", ":", "self", ".", "tasks", ".", "append", "...
Appends path to task queue if threads are enabled, otherwise copies the file with a blocking call.
[ "Appends", "path", "to", "task", "queue", "if", "threads", "are", "enabled", "otherwise", "copies", "the", "file", "with", "a", "blocking", "call", "." ]
fb9d7976da2a2578528fa6f3bbd053ee87475ecb
https://github.com/antonagestam/collectfast/blob/fb9d7976da2a2578528fa6f3bbd053ee87475ecb/collectfast/management/commands/collectstatic.py#L102-L111
train
antonagestam/collectfast
collectfast/management/commands/collectstatic.py
Command.delete_file
def delete_file(self, path, prefixed_path, source_storage): """ Override delete_file to skip modified time and exists lookups. """ if not self.collectfast_enabled: return super(Command, self).delete_file( path, prefixed_path, source_storage) if not sel...
python
def delete_file(self, path, prefixed_path, source_storage): """ Override delete_file to skip modified time and exists lookups. """ if not self.collectfast_enabled: return super(Command, self).delete_file( path, prefixed_path, source_storage) if not sel...
[ "def", "delete_file", "(", "self", ",", "path", ",", "prefixed_path", ",", "source_storage", ")", ":", "if", "not", "self", ".", "collectfast_enabled", ":", "return", "super", "(", "Command", ",", "self", ")", ".", "delete_file", "(", "path", ",", "prefixe...
Override delete_file to skip modified time and exists lookups.
[ "Override", "delete_file", "to", "skip", "modified", "time", "and", "exists", "lookups", "." ]
fb9d7976da2a2578528fa6f3bbd053ee87475ecb
https://github.com/antonagestam/collectfast/blob/fb9d7976da2a2578528fa6f3bbd053ee87475ecb/collectfast/management/commands/collectstatic.py#L113-L125
train
satellogic/telluric
telluric/georaster.py
join
def join(rasters): """ This method takes a list of rasters and returns a raster that is constructed of all of them """ raster = rasters[0] # using the first raster to understand what is the type of data we have mask_band = None nodata = None with raster._raster_opener(raster.source_file) a...
python
def join(rasters): """ This method takes a list of rasters and returns a raster that is constructed of all of them """ raster = rasters[0] # using the first raster to understand what is the type of data we have mask_band = None nodata = None with raster._raster_opener(raster.source_file) a...
[ "def", "join", "(", "rasters", ")", ":", "raster", "=", "rasters", "[", "0", "]", "# using the first raster to understand what is the type of data we have", "mask_band", "=", "None", "nodata", "=", "None", "with", "raster", ".", "_raster_opener", "(", "raster", ".",...
This method takes a list of rasters and returns a raster that is constructed of all of them
[ "This", "method", "takes", "a", "list", "of", "rasters", "and", "returns", "a", "raster", "that", "is", "constructed", "of", "all", "of", "them" ]
e752cd3ee71e339f79717e526fde362e80055d9e
https://github.com/satellogic/telluric/blob/e752cd3ee71e339f79717e526fde362e80055d9e/telluric/georaster.py#L95-L109
train
satellogic/telluric
telluric/georaster.py
merge_all
def merge_all(rasters, roi=None, dest_resolution=None, merge_strategy=MergeStrategy.UNION, shape=None, ul_corner=None, crs=None, pixel_strategy=PixelStrategy.FIRST, resampling=Resampling.nearest): """Merge a list of rasters, cropping by a region of interest. There are cases that t...
python
def merge_all(rasters, roi=None, dest_resolution=None, merge_strategy=MergeStrategy.UNION, shape=None, ul_corner=None, crs=None, pixel_strategy=PixelStrategy.FIRST, resampling=Resampling.nearest): """Merge a list of rasters, cropping by a region of interest. There are cases that t...
[ "def", "merge_all", "(", "rasters", ",", "roi", "=", "None", ",", "dest_resolution", "=", "None", ",", "merge_strategy", "=", "MergeStrategy", ".", "UNION", ",", "shape", "=", "None", ",", "ul_corner", "=", "None", ",", "crs", "=", "None", ",", "pixel_st...
Merge a list of rasters, cropping by a region of interest. There are cases that the roi is not precise enough for this cases one can use, the upper left corner the shape and crs to precisely define the roi. When roi is provided the ul_corner, shape and crs are ignored
[ "Merge", "a", "list", "of", "rasters", "cropping", "by", "a", "region", "of", "interest", ".", "There", "are", "cases", "that", "the", "roi", "is", "not", "precise", "enough", "for", "this", "cases", "one", "can", "use", "the", "upper", "left", "corner",...
e752cd3ee71e339f79717e526fde362e80055d9e
https://github.com/satellogic/telluric/blob/e752cd3ee71e339f79717e526fde362e80055d9e/telluric/georaster.py#L120-L161
train
satellogic/telluric
telluric/georaster.py
_merge_common_bands
def _merge_common_bands(rasters): # type: (List[_Raster]) -> List[_Raster] """Combine the common bands. """ # Compute band order all_bands = IndexedSet([rs.band_names[0] for rs in rasters]) def key(rs): return all_bands.index(rs.band_names[0]) rasters_final = [] # type: List[_Ras...
python
def _merge_common_bands(rasters): # type: (List[_Raster]) -> List[_Raster] """Combine the common bands. """ # Compute band order all_bands = IndexedSet([rs.band_names[0] for rs in rasters]) def key(rs): return all_bands.index(rs.band_names[0]) rasters_final = [] # type: List[_Ras...
[ "def", "_merge_common_bands", "(", "rasters", ")", ":", "# type: (List[_Raster]) -> List[_Raster]", "# Compute band order", "all_bands", "=", "IndexedSet", "(", "[", "rs", ".", "band_names", "[", "0", "]", "for", "rs", "in", "rasters", "]", ")", "def", "key", "(...
Combine the common bands.
[ "Combine", "the", "common", "bands", "." ]
e752cd3ee71e339f79717e526fde362e80055d9e
https://github.com/satellogic/telluric/blob/e752cd3ee71e339f79717e526fde362e80055d9e/telluric/georaster.py#L197-L212
train
satellogic/telluric
telluric/georaster.py
_explode_raster
def _explode_raster(raster, band_names=[]): # type: (_Raster, Iterable[str]) -> List[_Raster] """Splits a raster into multiband rasters. """ # Using band_names=[] does no harm because we are not mutating it in place # and it makes MyPy happy if not band_names: band_names = raster.band_n...
python
def _explode_raster(raster, band_names=[]): # type: (_Raster, Iterable[str]) -> List[_Raster] """Splits a raster into multiband rasters. """ # Using band_names=[] does no harm because we are not mutating it in place # and it makes MyPy happy if not band_names: band_names = raster.band_n...
[ "def", "_explode_raster", "(", "raster", ",", "band_names", "=", "[", "]", ")", ":", "# type: (_Raster, Iterable[str]) -> List[_Raster]", "# Using band_names=[] does no harm because we are not mutating it in place", "# and it makes MyPy happy", "if", "not", "band_names", ":", "ba...
Splits a raster into multiband rasters.
[ "Splits", "a", "raster", "into", "multiband", "rasters", "." ]
e752cd3ee71e339f79717e526fde362e80055d9e
https://github.com/satellogic/telluric/blob/e752cd3ee71e339f79717e526fde362e80055d9e/telluric/georaster.py#L244-L256
train
satellogic/telluric
telluric/georaster.py
_fill_pixels
def _fill_pixels(one, other): # type: (_Raster, _Raster) -> _Raster """Merges two single band rasters with the same band by filling the pixels according to depth. """ assert len(one.band_names) == len(other.band_names) == 1, "Rasters are not single band" # We raise an error in the intersection is ...
python
def _fill_pixels(one, other): # type: (_Raster, _Raster) -> _Raster """Merges two single band rasters with the same band by filling the pixels according to depth. """ assert len(one.band_names) == len(other.band_names) == 1, "Rasters are not single band" # We raise an error in the intersection is ...
[ "def", "_fill_pixels", "(", "one", ",", "other", ")", ":", "# type: (_Raster, _Raster) -> _Raster", "assert", "len", "(", "one", ".", "band_names", ")", "==", "len", "(", "other", ".", "band_names", ")", "==", "1", ",", "\"Rasters are not single band\"", "# We r...
Merges two single band rasters with the same band by filling the pixels according to depth.
[ "Merges", "two", "single", "band", "rasters", "with", "the", "same", "band", "by", "filling", "the", "pixels", "according", "to", "depth", "." ]
e752cd3ee71e339f79717e526fde362e80055d9e
https://github.com/satellogic/telluric/blob/e752cd3ee71e339f79717e526fde362e80055d9e/telluric/georaster.py#L286-L329
train
satellogic/telluric
telluric/georaster.py
_stack_bands
def _stack_bands(one, other): # type: (_Raster, _Raster) -> _Raster """Merges two rasters with non overlapping bands by stacking the bands. """ assert set(one.band_names).intersection(set(other.band_names)) == set() # We raise an error in the bands are the same. See above. if one.band_names ==...
python
def _stack_bands(one, other): # type: (_Raster, _Raster) -> _Raster """Merges two rasters with non overlapping bands by stacking the bands. """ assert set(one.band_names).intersection(set(other.band_names)) == set() # We raise an error in the bands are the same. See above. if one.band_names ==...
[ "def", "_stack_bands", "(", "one", ",", "other", ")", ":", "# type: (_Raster, _Raster) -> _Raster", "assert", "set", "(", "one", ".", "band_names", ")", ".", "intersection", "(", "set", "(", "other", ".", "band_names", ")", ")", "==", "set", "(", ")", "# W...
Merges two rasters with non overlapping bands by stacking the bands.
[ "Merges", "two", "rasters", "with", "non", "overlapping", "bands", "by", "stacking", "the", "bands", "." ]
e752cd3ee71e339f79717e526fde362e80055d9e
https://github.com/satellogic/telluric/blob/e752cd3ee71e339f79717e526fde362e80055d9e/telluric/georaster.py#L332-L362
train
satellogic/telluric
telluric/georaster.py
merge_two
def merge_two(one, other, merge_strategy=MergeStrategy.UNION, silent=False, pixel_strategy=PixelStrategy.FIRST): # type: (GeoRaster2, GeoRaster2, MergeStrategy, bool, PixelStrategy) -> GeoRaster2 """Merge two rasters into one. Parameters ---------- one : GeoRaster2 Left raster to merge. ...
python
def merge_two(one, other, merge_strategy=MergeStrategy.UNION, silent=False, pixel_strategy=PixelStrategy.FIRST): # type: (GeoRaster2, GeoRaster2, MergeStrategy, bool, PixelStrategy) -> GeoRaster2 """Merge two rasters into one. Parameters ---------- one : GeoRaster2 Left raster to merge. ...
[ "def", "merge_two", "(", "one", ",", "other", ",", "merge_strategy", "=", "MergeStrategy", ".", "UNION", ",", "silent", "=", "False", ",", "pixel_strategy", "=", "PixelStrategy", ".", "FIRST", ")", ":", "# type: (GeoRaster2, GeoRaster2, MergeStrategy, bool, PixelStrat...
Merge two rasters into one. Parameters ---------- one : GeoRaster2 Left raster to merge. other : GeoRaster2 Right raster to merge. merge_strategy : MergeStrategy, optional Merge strategy, from :py:data:`telluric.georaster.MergeStrategy` (default to "union"). silent : boo...
[ "Merge", "two", "rasters", "into", "one", "." ]
e752cd3ee71e339f79717e526fde362e80055d9e
https://github.com/satellogic/telluric/blob/e752cd3ee71e339f79717e526fde362e80055d9e/telluric/georaster.py#L365-L414
train
satellogic/telluric
telluric/georaster.py
_Raster._set_image
def _set_image(self, image, nodata=None): """ Set self._image. :param image: supported: np.ma.array, np.array, TODO: PIL image :param nodata: if provided image is array (not masked array), treat pixels with value=nodata as nodata :return: """ # convert to masked ...
python
def _set_image(self, image, nodata=None): """ Set self._image. :param image: supported: np.ma.array, np.array, TODO: PIL image :param nodata: if provided image is array (not masked array), treat pixels with value=nodata as nodata :return: """ # convert to masked ...
[ "def", "_set_image", "(", "self", ",", "image", ",", "nodata", "=", "None", ")", ":", "# convert to masked array:", "if", "isinstance", "(", "image", ",", "np", ".", "ma", ".", "core", ".", "MaskedArray", ")", ":", "masked", "=", "image", "elif", "isinst...
Set self._image. :param image: supported: np.ma.array, np.array, TODO: PIL image :param nodata: if provided image is array (not masked array), treat pixels with value=nodata as nodata :return:
[ "Set", "self", ".", "_image", "." ]
e752cd3ee71e339f79717e526fde362e80055d9e
https://github.com/satellogic/telluric/blob/e752cd3ee71e339f79717e526fde362e80055d9e/telluric/georaster.py#L467-L497
train
satellogic/telluric
telluric/georaster.py
GeoRaster2.from_wms
def from_wms(cls, filename, vector, resolution, destination_file=None): """Create georaster from the web service definition file.""" doc = wms_vrt(filename, bounds=vector, resolution=resolution).tostring() filename = cls._save_to_destination_file(doc, ...
python
def from_wms(cls, filename, vector, resolution, destination_file=None): """Create georaster from the web service definition file.""" doc = wms_vrt(filename, bounds=vector, resolution=resolution).tostring() filename = cls._save_to_destination_file(doc, ...
[ "def", "from_wms", "(", "cls", ",", "filename", ",", "vector", ",", "resolution", ",", "destination_file", "=", "None", ")", ":", "doc", "=", "wms_vrt", "(", "filename", ",", "bounds", "=", "vector", ",", "resolution", "=", "resolution", ")", ".", "tostr...
Create georaster from the web service definition file.
[ "Create", "georaster", "from", "the", "web", "service", "definition", "file", "." ]
e752cd3ee71e339f79717e526fde362e80055d9e
https://github.com/satellogic/telluric/blob/e752cd3ee71e339f79717e526fde362e80055d9e/telluric/georaster.py#L626-L632
train
satellogic/telluric
telluric/georaster.py
GeoRaster2.from_rasters
def from_rasters(cls, rasters, relative_to_vrt=True, destination_file=None, nodata=None, mask_band=None): """Create georaster out of a list of rasters.""" if isinstance(rasters, list): doc = raster_list_vrt(rasters, relative_to_vrt, nodata, mask_band).tostring() else: doc...
python
def from_rasters(cls, rasters, relative_to_vrt=True, destination_file=None, nodata=None, mask_band=None): """Create georaster out of a list of rasters.""" if isinstance(rasters, list): doc = raster_list_vrt(rasters, relative_to_vrt, nodata, mask_band).tostring() else: doc...
[ "def", "from_rasters", "(", "cls", ",", "rasters", ",", "relative_to_vrt", "=", "True", ",", "destination_file", "=", "None", ",", "nodata", "=", "None", ",", "mask_band", "=", "None", ")", ":", "if", "isinstance", "(", "rasters", ",", "list", ")", ":", ...
Create georaster out of a list of rasters.
[ "Create", "georaster", "out", "of", "a", "list", "of", "rasters", "." ]
e752cd3ee71e339f79717e526fde362e80055d9e
https://github.com/satellogic/telluric/blob/e752cd3ee71e339f79717e526fde362e80055d9e/telluric/georaster.py#L635-L642
train
satellogic/telluric
telluric/georaster.py
GeoRaster2.open
def open(cls, filename, band_names=None, lazy_load=True, mutable=False, **kwargs): """ Read a georaster from a file. :param filename: url :param band_names: list of strings, or string. if None - will try to read from image, otherwise - these will be ['0', ..]...
python
def open(cls, filename, band_names=None, lazy_load=True, mutable=False, **kwargs): """ Read a georaster from a file. :param filename: url :param band_names: list of strings, or string. if None - will try to read from image, otherwise - these will be ['0', ..]...
[ "def", "open", "(", "cls", ",", "filename", ",", "band_names", "=", "None", ",", "lazy_load", "=", "True", ",", "mutable", "=", "False", ",", "*", "*", "kwargs", ")", ":", "if", "mutable", ":", "geo_raster", "=", "MutableGeoRaster", "(", "filename", "=...
Read a georaster from a file. :param filename: url :param band_names: list of strings, or string. if None - will try to read from image, otherwise - these will be ['0', ..] :param lazy_load: if True - do not load anything :return: GeoRaster2
[ "Read", "a", "georaster", "from", "a", "file", "." ]
e752cd3ee71e339f79717e526fde362e80055d9e
https://github.com/satellogic/telluric/blob/e752cd3ee71e339f79717e526fde362e80055d9e/telluric/georaster.py#L645-L661
train
satellogic/telluric
telluric/georaster.py
GeoRaster2.tags
def tags(cls, filename, namespace=None): """Extract tags from file.""" return cls._raster_opener(filename).tags(ns=namespace)
python
def tags(cls, filename, namespace=None): """Extract tags from file.""" return cls._raster_opener(filename).tags(ns=namespace)
[ "def", "tags", "(", "cls", ",", "filename", ",", "namespace", "=", "None", ")", ":", "return", "cls", ".", "_raster_opener", "(", "filename", ")", ".", "tags", "(", "ns", "=", "namespace", ")" ]
Extract tags from file.
[ "Extract", "tags", "from", "file", "." ]
e752cd3ee71e339f79717e526fde362e80055d9e
https://github.com/satellogic/telluric/blob/e752cd3ee71e339f79717e526fde362e80055d9e/telluric/georaster.py#L724-L726
train
satellogic/telluric
telluric/georaster.py
GeoRaster2.image
def image(self): """Raster bitmap in numpy array.""" if self._image is None: self._populate_from_rasterio_object(read_image=True) return self._image
python
def image(self): """Raster bitmap in numpy array.""" if self._image is None: self._populate_from_rasterio_object(read_image=True) return self._image
[ "def", "image", "(", "self", ")", ":", "if", "self", ".", "_image", "is", "None", ":", "self", ".", "_populate_from_rasterio_object", "(", "read_image", "=", "True", ")", "return", "self", ".", "_image" ]
Raster bitmap in numpy array.
[ "Raster", "bitmap", "in", "numpy", "array", "." ]
e752cd3ee71e339f79717e526fde362e80055d9e
https://github.com/satellogic/telluric/blob/e752cd3ee71e339f79717e526fde362e80055d9e/telluric/georaster.py#L729-L733
train
satellogic/telluric
telluric/georaster.py
GeoRaster2.crs
def crs(self): # type: () -> CRS """Raster crs.""" if self._crs is None: self._populate_from_rasterio_object(read_image=False) return self._crs
python
def crs(self): # type: () -> CRS """Raster crs.""" if self._crs is None: self._populate_from_rasterio_object(read_image=False) return self._crs
[ "def", "crs", "(", "self", ")", ":", "# type: () -> CRS", "if", "self", ".", "_crs", "is", "None", ":", "self", ".", "_populate_from_rasterio_object", "(", "read_image", "=", "False", ")", "return", "self", ".", "_crs" ]
Raster crs.
[ "Raster", "crs", "." ]
e752cd3ee71e339f79717e526fde362e80055d9e
https://github.com/satellogic/telluric/blob/e752cd3ee71e339f79717e526fde362e80055d9e/telluric/georaster.py#L758-L762
train
satellogic/telluric
telluric/georaster.py
GeoRaster2.shape
def shape(self): """Raster shape.""" if self._shape is None: self._populate_from_rasterio_object(read_image=False) return self._shape
python
def shape(self): """Raster shape.""" if self._shape is None: self._populate_from_rasterio_object(read_image=False) return self._shape
[ "def", "shape", "(", "self", ")", ":", "if", "self", ".", "_shape", "is", "None", ":", "self", ".", "_populate_from_rasterio_object", "(", "read_image", "=", "False", ")", "return", "self", ".", "_shape" ]
Raster shape.
[ "Raster", "shape", "." ]
e752cd3ee71e339f79717e526fde362e80055d9e
https://github.com/satellogic/telluric/blob/e752cd3ee71e339f79717e526fde362e80055d9e/telluric/georaster.py#L765-L769
train
satellogic/telluric
telluric/georaster.py
GeoRaster2.source_file
def source_file(self): """ When using open, returns the filename used """ if self._filename is None: self._filename = self._as_in_memory_geotiff()._filename return self._filename
python
def source_file(self): """ When using open, returns the filename used """ if self._filename is None: self._filename = self._as_in_memory_geotiff()._filename return self._filename
[ "def", "source_file", "(", "self", ")", ":", "if", "self", ".", "_filename", "is", "None", ":", "self", ".", "_filename", "=", "self", ".", "_as_in_memory_geotiff", "(", ")", ".", "_filename", "return", "self", ".", "_filename" ]
When using open, returns the filename used
[ "When", "using", "open", "returns", "the", "filename", "used" ]
e752cd3ee71e339f79717e526fde362e80055d9e
https://github.com/satellogic/telluric/blob/e752cd3ee71e339f79717e526fde362e80055d9e/telluric/georaster.py#L788-L793
train
satellogic/telluric
telluric/georaster.py
GeoRaster2.blockshapes
def blockshapes(self): """Raster all bands block shape.""" if self._blockshapes is None: if self._filename: self._populate_from_rasterio_object(read_image=False) else: # if no file is attached to the raster set the shape of each band to be the data...
python
def blockshapes(self): """Raster all bands block shape.""" if self._blockshapes is None: if self._filename: self._populate_from_rasterio_object(read_image=False) else: # if no file is attached to the raster set the shape of each band to be the data...
[ "def", "blockshapes", "(", "self", ")", ":", "if", "self", ".", "_blockshapes", "is", "None", ":", "if", "self", ".", "_filename", ":", "self", ".", "_populate_from_rasterio_object", "(", "read_image", "=", "False", ")", "else", ":", "# if no file is attached ...
Raster all bands block shape.
[ "Raster", "all", "bands", "block", "shape", "." ]
e752cd3ee71e339f79717e526fde362e80055d9e
https://github.com/satellogic/telluric/blob/e752cd3ee71e339f79717e526fde362e80055d9e/telluric/georaster.py#L822-L830
train
satellogic/telluric
telluric/georaster.py
GeoRaster2.get
def get(self, point): """ Get the pixel values at the requested point. :param point: A GeoVector(POINT) with the coordinates of the values to get :return: numpy array of values """ if not (isinstance(point, GeoVector) and point.type == 'Point'): raise TypeErr...
python
def get(self, point): """ Get the pixel values at the requested point. :param point: A GeoVector(POINT) with the coordinates of the values to get :return: numpy array of values """ if not (isinstance(point, GeoVector) and point.type == 'Point'): raise TypeErr...
[ "def", "get", "(", "self", ",", "point", ")", ":", "if", "not", "(", "isinstance", "(", "point", ",", "GeoVector", ")", "and", "point", ".", "type", "==", "'Point'", ")", ":", "raise", "TypeError", "(", "'expect GeoVector(Point), got %s'", "%", "(", "poi...
Get the pixel values at the requested point. :param point: A GeoVector(POINT) with the coordinates of the values to get :return: numpy array of values
[ "Get", "the", "pixel", "values", "at", "the", "requested", "point", "." ]
e752cd3ee71e339f79717e526fde362e80055d9e
https://github.com/satellogic/telluric/blob/e752cd3ee71e339f79717e526fde362e80055d9e/telluric/georaster.py#L978-L989
train
satellogic/telluric
telluric/georaster.py
GeoRaster2.copy
def copy(self, mutable=False): """Return a copy of this GeoRaster with no modifications. Can be use to create a Mutable copy of the GeoRaster""" if self.not_loaded(): _cls = self.__class__ if mutable: _cls = MutableGeoRaster return _cls.open(...
python
def copy(self, mutable=False): """Return a copy of this GeoRaster with no modifications. Can be use to create a Mutable copy of the GeoRaster""" if self.not_loaded(): _cls = self.__class__ if mutable: _cls = MutableGeoRaster return _cls.open(...
[ "def", "copy", "(", "self", ",", "mutable", "=", "False", ")", ":", "if", "self", ".", "not_loaded", "(", ")", ":", "_cls", "=", "self", ".", "__class__", "if", "mutable", ":", "_cls", "=", "MutableGeoRaster", "return", "_cls", ".", "open", "(", "sel...
Return a copy of this GeoRaster with no modifications. Can be use to create a Mutable copy of the GeoRaster
[ "Return", "a", "copy", "of", "this", "GeoRaster", "with", "no", "modifications", "." ]
e752cd3ee71e339f79717e526fde362e80055d9e
https://github.com/satellogic/telluric/blob/e752cd3ee71e339f79717e526fde362e80055d9e/telluric/georaster.py#L1198-L1209
train
satellogic/telluric
telluric/georaster.py
GeoRaster2._resize
def _resize(self, ratio_x, ratio_y, resampling): """Return raster resized by ratio.""" new_width = int(np.ceil(self.width * ratio_x)) new_height = int(np.ceil(self.height * ratio_y)) dest_affine = self.affine * Affine.scale(1 / ratio_x, 1 / ratio_y) if self.not_loaded(): ...
python
def _resize(self, ratio_x, ratio_y, resampling): """Return raster resized by ratio.""" new_width = int(np.ceil(self.width * ratio_x)) new_height = int(np.ceil(self.height * ratio_y)) dest_affine = self.affine * Affine.scale(1 / ratio_x, 1 / ratio_y) if self.not_loaded(): ...
[ "def", "_resize", "(", "self", ",", "ratio_x", ",", "ratio_y", ",", "resampling", ")", ":", "new_width", "=", "int", "(", "np", ".", "ceil", "(", "self", ".", "width", "*", "ratio_x", ")", ")", "new_height", "=", "int", "(", "np", ".", "ceil", "(",...
Return raster resized by ratio.
[ "Return", "raster", "resized", "by", "ratio", "." ]
e752cd3ee71e339f79717e526fde362e80055d9e
https://github.com/satellogic/telluric/blob/e752cd3ee71e339f79717e526fde362e80055d9e/telluric/georaster.py#L1277-L1288
train
satellogic/telluric
telluric/georaster.py
GeoRaster2.to_pillow_image
def to_pillow_image(self, return_mask=False): """Return Pillow. Image, and optionally also mask.""" img = np.rollaxis(np.rollaxis(self.image.data, 2), 2) img = Image.fromarray(img[:, :, 0]) if img.shape[2] == 1 else Image.fromarray(img) if return_mask: mask = np.ma.getmaskarr...
python
def to_pillow_image(self, return_mask=False): """Return Pillow. Image, and optionally also mask.""" img = np.rollaxis(np.rollaxis(self.image.data, 2), 2) img = Image.fromarray(img[:, :, 0]) if img.shape[2] == 1 else Image.fromarray(img) if return_mask: mask = np.ma.getmaskarr...
[ "def", "to_pillow_image", "(", "self", ",", "return_mask", "=", "False", ")", ":", "img", "=", "np", ".", "rollaxis", "(", "np", ".", "rollaxis", "(", "self", ".", "image", ".", "data", ",", "2", ")", ",", "2", ")", "img", "=", "Image", ".", "fro...
Return Pillow. Image, and optionally also mask.
[ "Return", "Pillow", ".", "Image", "and", "optionally", "also", "mask", "." ]
e752cd3ee71e339f79717e526fde362e80055d9e
https://github.com/satellogic/telluric/blob/e752cd3ee71e339f79717e526fde362e80055d9e/telluric/georaster.py#L1290-L1299
train
satellogic/telluric
telluric/georaster.py
GeoRaster2.from_bytes
def from_bytes(cls, image_bytes, affine, crs, band_names=None): """Create GeoRaster from image BytesIo object. :param image_bytes: io.BytesIO object :param affine: rasters affine :param crs: rasters crs :param band_names: e.g. ['red', 'blue'] or 'red' """ b = io....
python
def from_bytes(cls, image_bytes, affine, crs, band_names=None): """Create GeoRaster from image BytesIo object. :param image_bytes: io.BytesIO object :param affine: rasters affine :param crs: rasters crs :param band_names: e.g. ['red', 'blue'] or 'red' """ b = io....
[ "def", "from_bytes", "(", "cls", ",", "image_bytes", ",", "affine", ",", "crs", ",", "band_names", "=", "None", ")", ":", "b", "=", "io", ".", "BytesIO", "(", "image_bytes", ")", "image", "=", "imageio", ".", "imread", "(", "b", ")", "roll", "=", "...
Create GeoRaster from image BytesIo object. :param image_bytes: io.BytesIO object :param affine: rasters affine :param crs: rasters crs :param band_names: e.g. ['red', 'blue'] or 'red'
[ "Create", "GeoRaster", "from", "image", "BytesIo", "object", "." ]
e752cd3ee71e339f79717e526fde362e80055d9e
https://github.com/satellogic/telluric/blob/e752cd3ee71e339f79717e526fde362e80055d9e/telluric/georaster.py#L1506-L1522
train
satellogic/telluric
telluric/georaster.py
GeoRaster2._repr_html_
def _repr_html_(self): """Required for jupyter notebook to show raster as an interactive map.""" TileServer.run_tileserver(self, self.footprint()) capture = "raster: %s" % self._filename mp = TileServer.folium_client(self, self.footprint(), capture=capture) return mp._repr_html_(...
python
def _repr_html_(self): """Required for jupyter notebook to show raster as an interactive map.""" TileServer.run_tileserver(self, self.footprint()) capture = "raster: %s" % self._filename mp = TileServer.folium_client(self, self.footprint(), capture=capture) return mp._repr_html_(...
[ "def", "_repr_html_", "(", "self", ")", ":", "TileServer", ".", "run_tileserver", "(", "self", ",", "self", ".", "footprint", "(", ")", ")", "capture", "=", "\"raster: %s\"", "%", "self", ".", "_filename", "mp", "=", "TileServer", ".", "folium_client", "("...
Required for jupyter notebook to show raster as an interactive map.
[ "Required", "for", "jupyter", "notebook", "to", "show", "raster", "as", "an", "interactive", "map", "." ]
e752cd3ee71e339f79717e526fde362e80055d9e
https://github.com/satellogic/telluric/blob/e752cd3ee71e339f79717e526fde362e80055d9e/telluric/georaster.py#L1524-L1529
train
satellogic/telluric
telluric/georaster.py
GeoRaster2.image_corner
def image_corner(self, corner): """Return image corner in pixels, as shapely.Point.""" if corner not in self.corner_types(): raise GeoRaster2Error('corner %s invalid, expected: %s' % (corner, self.corner_types())) x = 0 if corner[1] == 'l' else self.width y = 0 if corner[0] ...
python
def image_corner(self, corner): """Return image corner in pixels, as shapely.Point.""" if corner not in self.corner_types(): raise GeoRaster2Error('corner %s invalid, expected: %s' % (corner, self.corner_types())) x = 0 if corner[1] == 'l' else self.width y = 0 if corner[0] ...
[ "def", "image_corner", "(", "self", ",", "corner", ")", ":", "if", "corner", "not", "in", "self", ".", "corner_types", "(", ")", ":", "raise", "GeoRaster2Error", "(", "'corner %s invalid, expected: %s'", "%", "(", "corner", ",", "self", ".", "corner_types", ...
Return image corner in pixels, as shapely.Point.
[ "Return", "image", "corner", "in", "pixels", "as", "shapely", ".", "Point", "." ]
e752cd3ee71e339f79717e526fde362e80055d9e
https://github.com/satellogic/telluric/blob/e752cd3ee71e339f79717e526fde362e80055d9e/telluric/georaster.py#L1555-L1562
train
satellogic/telluric
telluric/georaster.py
GeoRaster2.center
def center(self): """Return footprint center in world coordinates, as GeoVector.""" image_center = Point(self.width / 2, self.height / 2) return self.to_world(image_center)
python
def center(self): """Return footprint center in world coordinates, as GeoVector.""" image_center = Point(self.width / 2, self.height / 2) return self.to_world(image_center)
[ "def", "center", "(", "self", ")", ":", "image_center", "=", "Point", "(", "self", ".", "width", "/", "2", ",", "self", ".", "height", "/", "2", ")", "return", "self", ".", "to_world", "(", "image_center", ")" ]
Return footprint center in world coordinates, as GeoVector.
[ "Return", "footprint", "center", "in", "world", "coordinates", "as", "GeoVector", "." ]
e752cd3ee71e339f79717e526fde362e80055d9e
https://github.com/satellogic/telluric/blob/e752cd3ee71e339f79717e526fde362e80055d9e/telluric/georaster.py#L1576-L1579
train
satellogic/telluric
telluric/georaster.py
GeoRaster2.bounds
def bounds(self): """Return image rectangle in pixels, as shapely.Polygon.""" corners = [self.image_corner(corner) for corner in self.corner_types()] return Polygon([[corner.x, corner.y] for corner in corners])
python
def bounds(self): """Return image rectangle in pixels, as shapely.Polygon.""" corners = [self.image_corner(corner) for corner in self.corner_types()] return Polygon([[corner.x, corner.y] for corner in corners])
[ "def", "bounds", "(", "self", ")", ":", "corners", "=", "[", "self", ".", "image_corner", "(", "corner", ")", "for", "corner", "in", "self", ".", "corner_types", "(", ")", "]", "return", "Polygon", "(", "[", "[", "corner", ".", "x", ",", "corner", ...
Return image rectangle in pixels, as shapely.Polygon.
[ "Return", "image", "rectangle", "in", "pixels", "as", "shapely", ".", "Polygon", "." ]
e752cd3ee71e339f79717e526fde362e80055d9e
https://github.com/satellogic/telluric/blob/e752cd3ee71e339f79717e526fde362e80055d9e/telluric/georaster.py#L1581-L1584
train
satellogic/telluric
telluric/georaster.py
GeoRaster2._calc_footprint
def _calc_footprint(self): """Return rectangle in world coordinates, as GeoVector.""" corners = [self.corner(corner) for corner in self.corner_types()] coords = [] for corner in corners: shape = corner.get_shape(corner.crs) coords.append([shape.x, shape.y]) ...
python
def _calc_footprint(self): """Return rectangle in world coordinates, as GeoVector.""" corners = [self.corner(corner) for corner in self.corner_types()] coords = [] for corner in corners: shape = corner.get_shape(corner.crs) coords.append([shape.x, shape.y]) ...
[ "def", "_calc_footprint", "(", "self", ")", ":", "corners", "=", "[", "self", ".", "corner", "(", "corner", ")", "for", "corner", "in", "self", ".", "corner_types", "(", ")", "]", "coords", "=", "[", "]", "for", "corner", "in", "corners", ":", "shape...
Return rectangle in world coordinates, as GeoVector.
[ "Return", "rectangle", "in", "world", "coordinates", "as", "GeoVector", "." ]
e752cd3ee71e339f79717e526fde362e80055d9e
https://github.com/satellogic/telluric/blob/e752cd3ee71e339f79717e526fde362e80055d9e/telluric/georaster.py#L1586-L1597
train
satellogic/telluric
telluric/georaster.py
GeoRaster2.to_raster
def to_raster(self, vector): """Return the vector in pixel coordinates, as shapely.Geometry.""" return transform(vector.get_shape(vector.crs), vector.crs, self.crs, dst_affine=~self.affine)
python
def to_raster(self, vector): """Return the vector in pixel coordinates, as shapely.Geometry.""" return transform(vector.get_shape(vector.crs), vector.crs, self.crs, dst_affine=~self.affine)
[ "def", "to_raster", "(", "self", ",", "vector", ")", ":", "return", "transform", "(", "vector", ".", "get_shape", "(", "vector", ".", "crs", ")", ",", "vector", ".", "crs", ",", "self", ".", "crs", ",", "dst_affine", "=", "~", "self", ".", "affine", ...
Return the vector in pixel coordinates, as shapely.Geometry.
[ "Return", "the", "vector", "in", "pixel", "coordinates", "as", "shapely", ".", "Geometry", "." ]
e752cd3ee71e339f79717e526fde362e80055d9e
https://github.com/satellogic/telluric/blob/e752cd3ee71e339f79717e526fde362e80055d9e/telluric/georaster.py#L1611-L1613
train