nwo
stringlengths 10
28
| sha
stringlengths 40
40
| path
stringlengths 11
97
| identifier
stringlengths 1
64
| parameters
stringlengths 2
2.24k
| return_statement
stringlengths 0
2.17k
| docstring
stringlengths 0
5.45k
| docstring_summary
stringlengths 0
3.83k
| func_begin
int64 1
13.4k
| func_end
int64 2
13.4k
| function
stringlengths 28
56.4k
| url
stringlengths 106
209
| project
int64 1
48
| executed_lines
list | executed_lines_pc
float64 0
153
| missing_lines
list | missing_lines_pc
float64 0
100
| covered
bool 2
classes | filecoverage
float64 2.53
100
| function_lines
int64 2
1.46k
| mccabe
int64 1
253
| coverage
float64 0
100
| docstring_lines
int64 0
112
| function_nodoc
stringlengths 9
56.4k
| id
int64 0
29.8k
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/builder.py
|
Builder.connect_to_database
|
(self)
|
return con
| 1,102 | 1,114 |
def connect_to_database(self):
con = sqlite3.connect(
self.buildstate_database_filename,
isolation_level=None,
timeout=10,
check_same_thread=False,
)
cur = con.cursor()
cur.execute("pragma journal_mode=WAL")
cur.execute("pragma synchronous=NORMAL")
con.commit()
cur.close()
return con
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/builder.py#L1102-L1114
| 40 |
[
0,
1,
7,
8,
9,
10,
11,
12
] | 61.538462 |
[] | 0 | false | 85.756677 | 13 | 1 | 100 | 0 |
def connect_to_database(self):
con = sqlite3.connect(
self.buildstate_database_filename,
isolation_level=None,
timeout=10,
check_same_thread=False,
)
cur = con.cursor()
cur.execute("pragma journal_mode=WAL")
cur.execute("pragma synchronous=NORMAL")
con.commit()
cur.close()
return con
| 26,514 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/builder.py
|
Builder.touch_site_config
|
(self)
|
Touches the site config which typically will trigger a rebuild.
|
Touches the site config which typically will trigger a rebuild.
| 1,116 | 1,121 |
def touch_site_config(self):
"""Touches the site config which typically will trigger a rebuild."""
try:
os.utime(os.path.join(self.env.root_path, "site.ini"), None)
except OSError:
pass
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/builder.py#L1116-L1121
| 40 |
[
0,
1
] | 33.333333 |
[
2,
3,
4,
5
] | 66.666667 | false | 85.756677 | 6 | 2 | 33.333333 | 1 |
def touch_site_config(self):
try:
os.utime(os.path.join(self.env.root_path, "site.ini"), None)
except OSError:
pass
| 26,515 |
|
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/builder.py
|
Builder.find_files
|
(self, query, alt=PRIMARY_ALT, lang=None, limit=50, types=None)
|
return find_files(self, query, alt, lang, limit, types)
|
Returns a list of files that match the query. This requires that
the source info is up to date and is primarily used by the admin to
show files that exist.
|
Returns a list of files that match the query. This requires that
the source info is up to date and is primarily used by the admin to
show files that exist.
| 1,123 | 1,128 |
def find_files(self, query, alt=PRIMARY_ALT, lang=None, limit=50, types=None):
"""Returns a list of files that match the query. This requires that
the source info is up to date and is primarily used by the admin to
show files that exist.
"""
return find_files(self, query, alt, lang, limit, types)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/builder.py#L1123-L1128
| 40 |
[
0,
1,
2,
3,
4,
5
] | 100 |
[] | 0 | true | 85.756677 | 6 | 1 | 100 | 3 |
def find_files(self, query, alt=PRIMARY_ALT, lang=None, limit=50, types=None):
return find_files(self, query, alt, lang, limit, types)
| 26,516 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/builder.py
|
Builder.new_build_state
|
(self, path_cache=None)
|
return BuildState(self, path_cache)
|
Creates a new build state.
|
Creates a new build state.
| 1,130 | 1,134 |
def new_build_state(self, path_cache=None):
"""Creates a new build state."""
if path_cache is None:
path_cache = PathCache(self.env)
return BuildState(self, path_cache)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/builder.py#L1130-L1134
| 40 |
[
0,
1,
2,
3,
4
] | 100 |
[] | 0 | true | 85.756677 | 5 | 2 | 100 | 1 |
def new_build_state(self, path_cache=None):
if path_cache is None:
path_cache = PathCache(self.env)
return BuildState(self, path_cache)
| 26,517 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/builder.py
|
Builder.get_build_program
|
(self, source, build_state)
|
Finds the right build function for the given source file.
|
Finds the right build function for the given source file.
| 1,136 | 1,143 |
def get_build_program(self, source, build_state):
"""Finds the right build function for the given source file."""
for cls, builder in chain(
reversed(self.env.build_programs), reversed(builtin_build_programs)
):
if isinstance(source, cls):
return builder(source, build_state)
raise RuntimeError("I do not know how to build %r" % source)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/builder.py#L1136-L1143
| 40 |
[
0,
1,
2,
3,
4,
5,
6
] | 87.5 |
[
7
] | 12.5 | false | 85.756677 | 8 | 3 | 87.5 | 1 |
def get_build_program(self, source, build_state):
for cls, builder in chain(
reversed(self.env.build_programs), reversed(builtin_build_programs)
):
if isinstance(source, cls):
return builder(source, build_state)
raise RuntimeError("I do not know how to build %r" % source)
| 26,518 |
|
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/builder.py
|
Builder.build_artifact
|
(self, artifact, build_func)
|
return None
|
Various parts of the system once they have an artifact and a
function to build it, will invoke this function. This ultimately
is what builds.
The return value is the ctx that was used to build this thing
if it was built, or `None` otherwise.
|
Various parts of the system once they have an artifact and a
function to build it, will invoke this function. This ultimately
is what builds.
| 1,145 | 1,166 |
def build_artifact(self, artifact, build_func):
"""Various parts of the system once they have an artifact and a
function to build it, will invoke this function. This ultimately
is what builds.
The return value is the ctx that was used to build this thing
if it was built, or `None` otherwise.
"""
is_current = artifact.is_current
with reporter.build_artifact(artifact, build_func, is_current):
if not is_current:
with artifact.update() as ctx:
# Upon builing anything we record a dependency to the
# project file. This is not ideal but for the moment
# it will ensure that if the file changes we will
# rebuild.
project_file = self.env.project.project_file
if project_file:
ctx.record_dependency(project_file)
build_func(artifact)
return ctx
return None
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/builder.py#L1145-L1166
| 40 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21
] | 100 |
[] | 0 | true | 85.756677 | 22 | 5 | 100 | 6 |
def build_artifact(self, artifact, build_func):
is_current = artifact.is_current
with reporter.build_artifact(artifact, build_func, is_current):
if not is_current:
with artifact.update() as ctx:
# Upon builing anything we record a dependency to the
# project file. This is not ideal but for the moment
# it will ensure that if the file changes we will
# rebuild.
project_file = self.env.project.project_file
if project_file:
ctx.record_dependency(project_file)
build_func(artifact)
return ctx
return None
| 26,519 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/builder.py
|
Builder.update_source_info
|
(prog, build_state)
|
Updates a single source info based on a program. This is done
automatically as part of a build.
|
Updates a single source info based on a program. This is done
automatically as part of a build.
| 1,169 | 1,175 |
def update_source_info(prog, build_state):
"""Updates a single source info based on a program. This is done
automatically as part of a build.
"""
info = prog.describe_source_record()
if info is not None:
build_state.write_source_info(info)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/builder.py#L1169-L1175
| 40 |
[
0,
1,
2,
3,
4,
5,
6
] | 100 |
[] | 0 | true | 85.756677 | 7 | 2 | 100 | 2 |
def update_source_info(prog, build_state):
info = prog.describe_source_record()
if info is not None:
build_state.write_source_info(info)
| 26,520 |
|
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/builder.py
|
Builder.prune
|
(self, all=False)
|
This cleans up data left in the build folder that does not
correspond to known artifacts.
|
This cleans up data left in the build folder that does not
correspond to known artifacts.
| 1,177 | 1,194 |
def prune(self, all=False):
"""This cleans up data left in the build folder that does not
correspond to known artifacts.
"""
path_cache = PathCache(self.env)
with reporter.build(all and "clean" or "prune", self):
self.env.plugin_controller.emit("before-prune", builder=self, all=all)
with self.new_build_state(path_cache=path_cache) as build_state:
for aft in build_state.iter_unreferenced_artifacts(all=all):
reporter.report_pruned_artifact(aft)
filename = build_state.get_destination_filename(aft)
prune_file_and_folder(filename, self.destination_path)
build_state.remove_artifact(aft)
build_state.prune_source_infos()
if all:
build_state.vacuum()
self.env.plugin_controller.emit("after-prune", builder=self, all=all)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/builder.py#L1177-L1194
| 40 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17
] | 100 |
[] | 0 | true | 85.756677 | 18 | 7 | 100 | 2 |
def prune(self, all=False):
path_cache = PathCache(self.env)
with reporter.build(all and "clean" or "prune", self):
self.env.plugin_controller.emit("before-prune", builder=self, all=all)
with self.new_build_state(path_cache=path_cache) as build_state:
for aft in build_state.iter_unreferenced_artifacts(all=all):
reporter.report_pruned_artifact(aft)
filename = build_state.get_destination_filename(aft)
prune_file_and_folder(filename, self.destination_path)
build_state.remove_artifact(aft)
build_state.prune_source_infos()
if all:
build_state.vacuum()
self.env.plugin_controller.emit("after-prune", builder=self, all=all)
| 26,521 |
|
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/builder.py
|
Builder.build
|
(self, source, path_cache=None)
|
Given a source object, builds it.
|
Given a source object, builds it.
| 1,196 | 1,218 |
def build(self, source, path_cache=None):
"""Given a source object, builds it."""
with self.new_build_state(path_cache=path_cache) as build_state:
with reporter.process_source(source):
prog = self.get_build_program(source, build_state)
self.env.plugin_controller.emit(
"before-build",
builder=self,
build_state=build_state,
source=source,
prog=prog,
)
prog.build()
if build_state.updated_artifacts:
self.update_source_info(prog, build_state)
self.env.plugin_controller.emit(
"after-build",
builder=self,
build_state=build_state,
source=source,
prog=prog,
)
return prog, build_state
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/builder.py#L1196-L1218
| 40 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22
] | 100 |
[] | 0 | true | 85.756677 | 23 | 4 | 100 | 1 |
def build(self, source, path_cache=None):
with self.new_build_state(path_cache=path_cache) as build_state:
with reporter.process_source(source):
prog = self.get_build_program(source, build_state)
self.env.plugin_controller.emit(
"before-build",
builder=self,
build_state=build_state,
source=source,
prog=prog,
)
prog.build()
if build_state.updated_artifacts:
self.update_source_info(prog, build_state)
self.env.plugin_controller.emit(
"after-build",
builder=self,
build_state=build_state,
source=source,
prog=prog,
)
return prog, build_state
| 26,522 |
|
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/builder.py
|
Builder.get_initial_build_queue
|
(self)
|
return deque(self.pad.get_all_roots())
|
Returns the initial build queue as deque.
|
Returns the initial build queue as deque.
| 1,220 | 1,222 |
def get_initial_build_queue(self):
"""Returns the initial build queue as deque."""
return deque(self.pad.get_all_roots())
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/builder.py#L1220-L1222
| 40 |
[
0,
1,
2
] | 100 |
[] | 0 | true | 85.756677 | 3 | 1 | 100 | 1 |
def get_initial_build_queue(self):
return deque(self.pad.get_all_roots())
| 26,523 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/builder.py
|
Builder.extend_build_queue
|
(self, queue, prog)
| 1,224 | 1,227 |
def extend_build_queue(self, queue, prog):
queue.extend(prog.iter_child_sources())
for func in self.env.custom_generators:
queue.extend(func(prog.source) or ())
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/builder.py#L1224-L1227
| 40 |
[
0,
1,
2
] | 75 |
[
3
] | 25 | false | 85.756677 | 4 | 3 | 75 | 0 |
def extend_build_queue(self, queue, prog):
queue.extend(prog.iter_child_sources())
for func in self.env.custom_generators:
queue.extend(func(prog.source) or ())
| 26,524 |
|||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/builder.py
|
Builder.build_all
|
(self)
|
Builds the entire tree. Returns the number of failures.
|
Builds the entire tree. Returns the number of failures.
| 1,229 | 1,250 |
def build_all(self):
"""Builds the entire tree. Returns the number of failures."""
failures = 0
path_cache = PathCache(self.env)
# We keep a dummy connection here that does not do anything which
# helps us with the WAL handling. See #144
con = self.connect_to_database()
try:
with reporter.build("build", self):
self.env.plugin_controller.emit("before-build-all", builder=self)
to_build = self.get_initial_build_queue()
while to_build:
source = to_build.popleft()
prog, build_state = self.build(source, path_cache=path_cache)
self.extend_build_queue(to_build, prog)
failures += len(build_state.failed_artifacts)
self.env.plugin_controller.emit("after-build-all", builder=self)
if failures:
reporter.report_build_all_failure(failures)
return failures
finally:
con.close()
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/builder.py#L1229-L1250
| 40 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21
] | 100 |
[] | 0 | true | 85.756677 | 22 | 4 | 100 | 1 |
def build_all(self):
failures = 0
path_cache = PathCache(self.env)
# We keep a dummy connection here that does not do anything which
# helps us with the WAL handling. See #144
con = self.connect_to_database()
try:
with reporter.build("build", self):
self.env.plugin_controller.emit("before-build-all", builder=self)
to_build = self.get_initial_build_queue()
while to_build:
source = to_build.popleft()
prog, build_state = self.build(source, path_cache=path_cache)
self.extend_build_queue(to_build, prog)
failures += len(build_state.failed_artifacts)
self.env.plugin_controller.emit("after-build-all", builder=self)
if failures:
reporter.report_build_all_failure(failures)
return failures
finally:
con.close()
| 26,525 |
|
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/builder.py
|
Builder.update_all_source_infos
|
(self)
|
Fast way to update all source infos without having to build
everything.
|
Fast way to update all source infos without having to build
everything.
| 1,252 | 1,271 |
def update_all_source_infos(self):
"""Fast way to update all source infos without having to build
everything.
"""
# We keep a dummy connection here that does not do anything which
# helps us with the WAL handling. See #144
con = self.connect_to_database()
try:
with reporter.build("source info update", self):
with self.new_build_state() as build_state:
to_build = self.get_initial_build_queue()
while to_build:
source = to_build.popleft()
with reporter.process_source(source):
prog = self.get_build_program(source, build_state)
self.update_source_info(prog, build_state)
self.extend_build_queue(to_build, prog)
build_state.prune_source_infos()
finally:
con.close()
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/builder.py#L1252-L1271
| 40 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19
] | 100 |
[] | 0 | true | 85.756677 | 20 | 5 | 100 | 2 |
def update_all_source_infos(self):
# We keep a dummy connection here that does not do anything which
# helps us with the WAL handling. See #144
con = self.connect_to_database()
try:
with reporter.build("source info update", self):
with self.new_build_state() as build_state:
to_build = self.get_initial_build_queue()
while to_build:
source = to_build.popleft()
with reporter.process_source(source):
prog = self.get_build_program(source, build_state)
self.update_source_info(prog, build_state)
self.extend_build_queue(to_build, prog)
build_state.prune_source_infos()
finally:
con.close()
| 26,526 |
|
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/pluginsystem.py
|
get_plugin
|
(plugin_id_or_class, env=None)
|
Looks up the plugin instance by id or class.
|
Looks up the plugin instance by id or class.
| 17 | 31 |
def get_plugin(plugin_id_or_class, env=None):
"""Looks up the plugin instance by id or class."""
if env is None:
ctx = get_ctx()
if ctx is None:
raise RuntimeError(
"Context is unavailable and no environment "
"was passed to the function."
)
env = ctx.env
plugin_id = env.plugin_ids_by_class.get(plugin_id_or_class, plugin_id_or_class)
try:
return env.plugins[plugin_id]
except KeyError as error:
raise LookupError("Plugin %r not found" % plugin_id) from error
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/pluginsystem.py#L17-L31
| 40 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14
] | 100 |
[] | 0 | true | 100 | 15 | 4 | 100 | 1 |
def get_plugin(plugin_id_or_class, env=None):
if env is None:
ctx = get_ctx()
if ctx is None:
raise RuntimeError(
"Context is unavailable and no environment "
"was passed to the function."
)
env = ctx.env
plugin_id = env.plugin_ids_by_class.get(plugin_id_or_class, plugin_id_or_class)
try:
return env.plugins[plugin_id]
except KeyError as error:
raise LookupError("Plugin %r not found" % plugin_id) from error
| 26,527 |
|
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/pluginsystem.py
|
_find_plugins
|
()
|
Find all available plugins.
Returns an interator of (distribution, entry_point) pairs.
|
Find all available plugins.
| 117 | 126 |
def _find_plugins():
"""Find all available plugins.
Returns an interator of (distribution, entry_point) pairs.
"""
for dist in metadata.distributions():
for ep in dist.entry_points:
if ep.group == "lektor.plugins":
_check_dist_name(dist.metadata["Name"], ep.name)
yield dist, ep
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/pluginsystem.py#L117-L126
| 40 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9
] | 100 |
[] | 0 | true | 100 | 10 | 4 | 100 | 3 |
def _find_plugins():
for dist in metadata.distributions():
for ep in dist.entry_points:
if ep.group == "lektor.plugins":
_check_dist_name(dist.metadata["Name"], ep.name)
yield dist, ep
| 26,528 |
|
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/pluginsystem.py
|
_check_dist_name
|
(dist_name, plugin_id)
|
Check that plugin comes from a validly named distribution.
Raises RuntimeError if distribution name is not of the form
``lektor-``*<plugin_id>*.
|
Check that plugin comes from a validly named distribution.
| 129 | 141 |
def _check_dist_name(dist_name, plugin_id):
"""Check that plugin comes from a validly named distribution.
Raises RuntimeError if distribution name is not of the form
``lektor-``*<plugin_id>*.
"""
# XXX: do we really need to be so strict about distribution names?
match_name = "lektor-" + plugin_id.lower()
if match_name != dist_name.lower():
raise RuntimeError(
"Disallowed distribution name: distribution name for "
f"plugin {plugin_id!r} must be {match_name!r} (not {dist_name!r})."
)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/pluginsystem.py#L129-L141
| 40 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12
] | 100 |
[] | 0 | true | 100 | 13 | 2 | 100 | 4 |
def _check_dist_name(dist_name, plugin_id):
# XXX: do we really need to be so strict about distribution names?
match_name = "lektor-" + plugin_id.lower()
if match_name != dist_name.lower():
raise RuntimeError(
"Disallowed distribution name: distribution name for "
f"plugin {plugin_id!r} must be {match_name!r} (not {dist_name!r})."
)
| 26,529 |
|
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/pluginsystem.py
|
initialize_plugins
|
(env)
|
Initializes the plugins for the environment.
|
Initializes the plugins for the environment.
| 144 | 150 |
def initialize_plugins(env):
"""Initializes the plugins for the environment."""
for dist, ep in _find_plugins():
plugin_id = ep.name
plugin_cls = ep.load()
env.plugin_controller.instanciate_plugin(plugin_id, plugin_cls, dist)
env.plugin_controller.emit("setup-env")
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/pluginsystem.py#L144-L150
| 40 |
[
0,
1,
2,
3,
4,
5,
6
] | 100 |
[] | 0 | true | 100 | 7 | 2 | 100 | 1 |
def initialize_plugins(env):
for dist, ep in _find_plugins():
plugin_id = ep.name
plugin_cls = ep.load()
env.plugin_controller.instanciate_plugin(plugin_id, plugin_cls, dist)
env.plugin_controller.emit("setup-env")
| 26,530 |
|
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/pluginsystem.py
|
Plugin.__init__
|
(self, env, id)
| 42 | 44 |
def __init__(self, env, id):
self._env = weakref(env)
self.id = id
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/pluginsystem.py#L42-L44
| 40 |
[
0,
1,
2
] | 100 |
[] | 0 | true | 100 | 3 | 1 | 100 | 0 |
def __init__(self, env, id):
self._env = weakref(env)
self.id = id
| 26,531 |
|||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/pluginsystem.py
|
Plugin.env
|
(self)
|
return rv
| 47 | 51 |
def env(self):
rv = self._env()
if rv is None:
raise RuntimeError("Environment went away")
return rv
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/pluginsystem.py#L47-L51
| 40 |
[
0,
1,
2,
3,
4
] | 100 |
[] | 0 | true | 100 | 5 | 2 | 100 | 0 |
def env(self):
rv = self._env()
if rv is None:
raise RuntimeError("Environment went away")
return rv
| 26,532 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/pluginsystem.py
|
Plugin.version
|
(self)
|
return None
| 54 | 57 |
def version(self):
if self.__dist is not None:
return self.__dist.version
return None
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/pluginsystem.py#L54-L57
| 40 |
[
0,
1,
2,
3
] | 100 |
[] | 0 | true | 100 | 4 | 2 | 100 | 0 |
def version(self):
if self.__dist is not None:
return self.__dist.version
return None
| 26,533 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/pluginsystem.py
|
Plugin.path
|
(self)
|
return None
| 60 | 65 |
def path(self):
mod = sys.modules[self.__class__.__module__.split(".", maxsplit=1)[0]]
path = os.path.abspath(os.path.dirname(mod.__file__))
if not path.startswith(self.env.project.get_package_cache_path()):
return path
return None
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/pluginsystem.py#L60-L65
| 40 |
[
0,
1,
2,
3,
4,
5
] | 100 |
[] | 0 | true | 100 | 6 | 2 | 100 | 0 |
def path(self):
mod = sys.modules[self.__class__.__module__.split(".", maxsplit=1)[0]]
path = os.path.abspath(os.path.dirname(mod.__file__))
if not path.startswith(self.env.project.get_package_cache_path()):
return path
return None
| 26,534 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/pluginsystem.py
|
Plugin.import_name
|
(self)
|
return self.__class__.__module__ + ":" + self.__class__.__name__
| 68 | 69 |
def import_name(self):
return self.__class__.__module__ + ":" + self.__class__.__name__
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/pluginsystem.py#L68-L69
| 40 |
[
0,
1
] | 100 |
[] | 0 | true | 100 | 2 | 1 | 100 | 0 |
def import_name(self):
return self.__class__.__module__ + ":" + self.__class__.__name__
| 26,535 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/pluginsystem.py
|
Plugin.get_lektor_config
|
(self)
|
return cfg
|
Returns the global config.
|
Returns the global config.
| 71 | 78 |
def get_lektor_config(self):
"""Returns the global config."""
ctx = get_ctx()
if ctx is not None:
cfg = ctx.pad.db.config
else:
cfg = self.env.load_config()
return cfg
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/pluginsystem.py#L71-L78
| 40 |
[
0,
1,
2,
3,
4,
5,
6,
7
] | 100 |
[] | 0 | true | 100 | 8 | 2 | 100 | 1 |
def get_lektor_config(self):
ctx = get_ctx()
if ctx is not None:
cfg = ctx.pad.db.config
else:
cfg = self.env.load_config()
return cfg
| 26,536 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/pluginsystem.py
|
Plugin.config_filename
|
(self)
|
return os.path.join(self.env.root_path, "configs", self.id + ".ini")
|
The filename of the plugin specific config file.
|
The filename of the plugin specific config file.
| 81 | 83 |
def config_filename(self):
"""The filename of the plugin specific config file."""
return os.path.join(self.env.root_path, "configs", self.id + ".ini")
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/pluginsystem.py#L81-L83
| 40 |
[
0,
1,
2
] | 100 |
[] | 0 | true | 100 | 3 | 1 | 100 | 1 |
def config_filename(self):
return os.path.join(self.env.root_path, "configs", self.id + ".ini")
| 26,537 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/pluginsystem.py
|
Plugin.get_config
|
(self, fresh=False)
|
return cfg
|
Returns the config specific for this plugin. By default this
will be cached for the current build context but this can be
disabled by passing ``fresh=True``.
|
Returns the config specific for this plugin. By default this
will be cached for the current build context but this can be
disabled by passing ``fresh=True``.
| 85 | 101 |
def get_config(self, fresh=False):
"""Returns the config specific for this plugin. By default this
will be cached for the current build context but this can be
disabled by passing ``fresh=True``.
"""
ctx = get_ctx()
if ctx is not None and not fresh:
cache = ctx.cache.setdefault(__name__ + ":configs", {})
cfg = cache.get(self.id)
if cfg is None:
cfg = IniFile(self.config_filename)
cache[self.id] = cfg
else:
cfg = IniFile(self.config_filename)
if ctx is not None:
ctx.record_dependency(self.config_filename)
return cfg
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/pluginsystem.py#L85-L101
| 40 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16
] | 100 |
[] | 0 | true | 100 | 17 | 5 | 100 | 3 |
def get_config(self, fresh=False):
ctx = get_ctx()
if ctx is not None and not fresh:
cache = ctx.cache.setdefault(__name__ + ":configs", {})
cfg = cache.get(self.id)
if cfg is None:
cfg = IniFile(self.config_filename)
cache[self.id] = cfg
else:
cfg = IniFile(self.config_filename)
if ctx is not None:
ctx.record_dependency(self.config_filename)
return cfg
| 26,538 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/pluginsystem.py
|
Plugin.emit
|
(self, event, **kwargs)
|
return self.env.plugin_controller.emit(self.id + "-" + event, **kwargs)
| 103 | 104 |
def emit(self, event, **kwargs):
return self.env.plugin_controller.emit(self.id + "-" + event, **kwargs)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/pluginsystem.py#L103-L104
| 40 |
[
0,
1
] | 100 |
[] | 0 | true | 100 | 2 | 1 | 100 | 0 |
def emit(self, event, **kwargs):
return self.env.plugin_controller.emit(self.id + "-" + event, **kwargs)
| 26,539 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/pluginsystem.py
|
Plugin.to_json
|
(self)
|
return {
"id": self.id,
"name": self.name,
"version": self.version,
"description": self.description,
"path": self.path,
"import_name": self.import_name,
}
| 106 | 114 |
def to_json(self):
return {
"id": self.id,
"name": self.name,
"version": self.version,
"description": self.description,
"path": self.path,
"import_name": self.import_name,
}
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/pluginsystem.py#L106-L114
| 40 |
[
0,
1
] | 22.222222 |
[] | 0 | false | 100 | 9 | 1 | 100 | 0 |
def to_json(self):
return {
"id": self.id,
"name": self.name,
"version": self.version,
"description": self.description,
"path": self.path,
"import_name": self.import_name,
}
| 26,540 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/pluginsystem.py
|
PluginController.__init__
|
(self, env, extra_flags=None)
| 158 | 160 |
def __init__(self, env, extra_flags=None):
self._env = weakref(env)
self.extra_flags = extra_flags
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/pluginsystem.py#L158-L160
| 40 |
[
0,
1,
2
] | 100 |
[] | 0 | true | 100 | 3 | 1 | 100 | 0 |
def __init__(self, env, extra_flags=None):
self._env = weakref(env)
self.extra_flags = extra_flags
| 26,541 |
|||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/pluginsystem.py
|
PluginController.env
|
(self)
|
return rv
| 163 | 167 |
def env(self):
rv = self._env()
if rv is None:
raise RuntimeError("Environment went away")
return rv
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/pluginsystem.py#L163-L167
| 40 |
[
0,
1,
2,
3,
4
] | 100 |
[] | 0 | true | 100 | 5 | 2 | 100 | 0 |
def env(self):
rv = self._env()
if rv is None:
raise RuntimeError("Environment went away")
return rv
| 26,542 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/pluginsystem.py
|
PluginController.instanciate_plugin
|
(
self,
plugin_id: str,
plugin_cls: Type[Plugin],
dist: metadata.Distribution | None = None,
)
| 169 | 185 |
def instanciate_plugin(
self,
plugin_id: str,
plugin_cls: Type[Plugin],
dist: metadata.Distribution | None = None,
) -> None:
env = self.env
if plugin_id in env.plugins:
raise RuntimeError('Plugin "%s" is already registered' % plugin_id)
plugin = plugin_cls(env, plugin_id)
# Plugin.version needs the source distribution to be able to cleanly determine
# the plugin version. For reasons of backward compatibility, we don't want to
# change the signature of the constructor, so we stick it in a private attribute
# here.
plugin._Plugin__dist = dist
env.plugins[plugin_id] = plugin
env.plugin_ids_by_class[plugin_cls] = plugin_id
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/pluginsystem.py#L169-L185
| 40 |
[
0,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16
] | 70.588235 |
[] | 0 | false | 100 | 17 | 2 | 100 | 0 |
def instanciate_plugin(
self,
plugin_id: str,
plugin_cls: Type[Plugin],
dist: metadata.Distribution | None = None,
) -> None:
env = self.env
if plugin_id in env.plugins:
raise RuntimeError('Plugin "%s" is already registered' % plugin_id)
plugin = plugin_cls(env, plugin_id)
# Plugin.version needs the source distribution to be able to cleanly determine
# the plugin version. For reasons of backward compatibility, we don't want to
# change the signature of the constructor, so we stick it in a private attribute
# here.
plugin._Plugin__dist = dist
env.plugins[plugin_id] = plugin
env.plugin_ids_by_class[plugin_cls] = plugin_id
| 26,543 |
|||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/pluginsystem.py
|
PluginController.iter_plugins
|
(self)
|
return self.env.plugins.values()
| 187 | 189 |
def iter_plugins(self):
# XXX: sort?
return self.env.plugins.values()
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/pluginsystem.py#L187-L189
| 40 |
[
0,
1,
2
] | 100 |
[] | 0 | true | 100 | 3 | 1 | 100 | 0 |
def iter_plugins(self):
# XXX: sort?
return self.env.plugins.values()
| 26,544 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/pluginsystem.py
|
PluginController.emit
|
(self, event, **kwargs)
|
return rv
|
Invoke event hook for all plugins that support it.
Any ``kwargs`` are passed to the hook methods.
Returns a dict mapping plugin ids to hook method return values.
|
Invoke event hook for all plugins that support it.
| 191 | 219 |
def emit(self, event, **kwargs):
"""Invoke event hook for all plugins that support it.
Any ``kwargs`` are passed to the hook methods.
Returns a dict mapping plugin ids to hook method return values.
"""
rv = {}
extra_flags = process_extra_flags(self.extra_flags)
funcname = "on_" + event.replace("-", "_")
for plugin in self.iter_plugins():
handler = getattr(plugin, funcname, None)
if handler is not None:
kw = {**kwargs, "extra_flags": extra_flags}
try:
inspect.signature(handler).bind(**kw)
except TypeError:
del kw["extra_flags"]
rv[plugin.id] = handler(**kw)
if "extra_flags" not in kw:
warnings.warn(
f"The plugin {plugin.id!r} function {funcname!r} does not "
"accept extra_flags. "
"It should be updated to accept `**extra` so that it will "
"not break if new parameters are passed to it by newer "
"versions of Lektor.",
DeprecationWarning,
)
return rv
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/pluginsystem.py#L191-L219
| 40 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
25,
26,
27,
28
] | 100 |
[] | 0 | true | 100 | 29 | 5 | 100 | 5 |
def emit(self, event, **kwargs):
rv = {}
extra_flags = process_extra_flags(self.extra_flags)
funcname = "on_" + event.replace("-", "_")
for plugin in self.iter_plugins():
handler = getattr(plugin, funcname, None)
if handler is not None:
kw = {**kwargs, "extra_flags": extra_flags}
try:
inspect.signature(handler).bind(**kw)
except TypeError:
del kw["extra_flags"]
rv[plugin.id] = handler(**kw)
if "extra_flags" not in kw:
warnings.warn(
f"The plugin {plugin.id!r} function {funcname!r} does not "
"accept extra_flags. "
"It should be updated to accept `**extra` so that it will "
"not break if new parameters are passed to it by newer "
"versions of Lektor.",
DeprecationWarning,
)
return rv
| 26,545 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/cli.py
|
cli
|
(ctx, project=None, language=None)
|
The lektor management application.
This command can invoke lektor locally and serve up the website. It's
intended for local development of websites.
|
The lektor management application.
| 36 | 46 |
def cli(ctx, project=None, language=None):
"""The lektor management application.
This command can invoke lektor locally and serve up the website. It's
intended for local development of websites.
"""
warnings.simplefilter("default")
if language is not None:
ctx.ui_lang = language
if project is not None:
ctx.set_project_path(project)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/cli.py#L36-L46
| 40 |
[
0,
1,
2,
3,
4,
5
] | 54.545455 |
[
6,
7,
8,
9,
10
] | 45.454545 | false | 37.681159 | 11 | 3 | 54.545455 | 4 |
def cli(ctx, project=None, language=None):
warnings.simplefilter("default")
if language is not None:
ctx.ui_lang = language
if project is not None:
ctx.set_project_path(project)
| 26,546 |
|
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/cli.py
|
build_cmd
|
(
ctx,
output_path,
watch,
prune,
verbosity,
source_info_only,
buildstate_path,
profile,
extra_flags,
)
|
Builds the entire project into the final artifacts.
The default behavior is to build the project into the default build
output path which can be discovered with the `project-info` command
but an alternative output folder can be provided with the `--output-path`
option.
The default behavior is to perform a build followed by a pruning step
which removes no longer referenced artifacts from the output folder.
Lektor will only build the files that require rebuilding if the output
folder is reused.
To enforce a clean build you have to issue a `clean` command first.
If the build fails the exit code will be `1` otherwise `0`. This can be
used by external scripts to only deploy on successful build for instance.
|
Builds the entire project into the final artifacts.
| 87 | 157 |
def build_cmd(
ctx,
output_path,
watch,
prune,
verbosity,
source_info_only,
buildstate_path,
profile,
extra_flags,
):
"""Builds the entire project into the final artifacts.
The default behavior is to build the project into the default build
output path which can be discovered with the `project-info` command
but an alternative output folder can be provided with the `--output-path`
option.
The default behavior is to perform a build followed by a pruning step
which removes no longer referenced artifacts from the output folder.
Lektor will only build the files that require rebuilding if the output
folder is reused.
To enforce a clean build you have to issue a `clean` command first.
If the build fails the exit code will be `1` otherwise `0`. This can be
used by external scripts to only deploy on successful build for instance.
"""
from lektor.builder import Builder
from lektor.reporter import CliReporter
if output_path is None:
output_path = ctx.get_default_output_path()
ctx.load_plugins(extra_flags=extra_flags)
env = ctx.get_env()
def _build():
builder = Builder(
env.new_pad(),
output_path,
buildstate_path=buildstate_path,
extra_flags=extra_flags,
)
if source_info_only:
builder.update_all_source_infos()
return True
if profile:
failures = profile_func(builder.build_all)
else:
failures = builder.build_all()
if prune:
builder.prune()
return failures == 0
reporter = CliReporter(env, verbosity=verbosity)
with reporter:
success = _build()
if not watch:
return sys.exit(0 if success else 1)
from lektor.watcher import watch
click.secho("Watching for file system changes", fg="cyan")
last_build = time.time()
for ts, _, _ in watch(env):
if ts > last_build:
_build()
last_build = time.time()
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/cli.py#L87-L157
| 40 |
[
0
] | 1.408451 |
[
28,
29,
31,
32,
34,
36,
38,
39,
45,
46,
47,
49,
50,
52,
53,
54,
55,
57,
58,
59,
60,
61,
63,
65,
66,
67,
68,
69,
70
] | 40.84507 | false | 37.681159 | 71 | 10 | 59.15493 | 16 |
def build_cmd(
ctx,
output_path,
watch,
prune,
verbosity,
source_info_only,
buildstate_path,
profile,
extra_flags,
):
from lektor.builder import Builder
from lektor.reporter import CliReporter
if output_path is None:
output_path = ctx.get_default_output_path()
ctx.load_plugins(extra_flags=extra_flags)
env = ctx.get_env()
def _build():
builder = Builder(
env.new_pad(),
output_path,
buildstate_path=buildstate_path,
extra_flags=extra_flags,
)
if source_info_only:
builder.update_all_source_infos()
return True
if profile:
failures = profile_func(builder.build_all)
else:
failures = builder.build_all()
if prune:
builder.prune()
return failures == 0
reporter = CliReporter(env, verbosity=verbosity)
with reporter:
success = _build()
if not watch:
return sys.exit(0 if success else 1)
from lektor.watcher import watch
click.secho("Watching for file system changes", fg="cyan")
last_build = time.time()
for ts, _, _ in watch(env):
if ts > last_build:
_build()
last_build = time.time()
| 26,547 |
|
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/cli.py
|
clean_cmd
|
(ctx, output_path, verbosity, extra_flags)
|
Cleans the entire build folder.
If not build folder is provided, the default build folder of the project
in the Lektor cache is used.
|
Cleans the entire build folder.
| 174 | 192 |
def clean_cmd(ctx, output_path, verbosity, extra_flags):
"""Cleans the entire build folder.
If not build folder is provided, the default build folder of the project
in the Lektor cache is used.
"""
from lektor.builder import Builder
from lektor.reporter import CliReporter
if output_path is None:
output_path = ctx.get_default_output_path()
ctx.load_plugins(extra_flags=extra_flags)
env = ctx.get_env()
reporter = CliReporter(env, verbosity=verbosity)
with reporter:
builder = Builder(env.new_pad(), output_path)
builder.prune(all=True)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/cli.py#L174-L192
| 40 |
[
0,
1,
2,
3,
4,
5
] | 31.578947 |
[
6,
7,
9,
10,
12,
13,
15,
16,
17,
18
] | 52.631579 | false | 37.681159 | 19 | 3 | 47.368421 | 4 |
def clean_cmd(ctx, output_path, verbosity, extra_flags):
from lektor.builder import Builder
from lektor.reporter import CliReporter
if output_path is None:
output_path = ctx.get_default_output_path()
ctx.load_plugins(extra_flags=extra_flags)
env = ctx.get_env()
reporter = CliReporter(env, verbosity=verbosity)
with reporter:
builder = Builder(env.new_pad(), output_path)
builder.prune(all=True)
| 26,548 |
|
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/cli.py
|
deploy_cmd
|
(ctx, server, output_path, extra_flags, **credentials)
|
This command deploys the entire contents of the build folder
(`--output-path`) onto a configured remote server. The name of the
server must fit the name from a target in the project configuration.
If no server is supplied then the default server from the config is
used.
The deployment credentials are typically contained in the project config
file but it's also possible to supply them here explicitly. In this
case the `--username` and `--password` parameters (as well as the
`LEKTOR_DEPLOY_USERNAME` and `LEKTOR_DEPLOY_PASSWORD` environment
variables) can override what's in the URL.
For more information see the deployment chapter in the documentation.
|
This command deploys the entire contents of the build folder
(`--output-path`) onto a configured remote server. The name of the
server must fit the name from a target in the project configuration.
If no server is supplied then the default server from the config is
used.
| 224 | 285 |
def deploy_cmd(ctx, server, output_path, extra_flags, **credentials):
"""This command deploys the entire contents of the build folder
(`--output-path`) onto a configured remote server. The name of the
server must fit the name from a target in the project configuration.
If no server is supplied then the default server from the config is
used.
The deployment credentials are typically contained in the project config
file but it's also possible to supply them here explicitly. In this
case the `--username` and `--password` parameters (as well as the
`LEKTOR_DEPLOY_USERNAME` and `LEKTOR_DEPLOY_PASSWORD` environment
variables) can override what's in the URL.
For more information see the deployment chapter in the documentation.
"""
from lektor.publisher import publish, PublishError
if output_path is None:
output_path = ctx.get_default_output_path()
ctx.load_plugins(extra_flags=extra_flags)
env = ctx.get_env()
config = env.load_config()
if server is None:
server_info = config.get_default_server()
if server_info is None:
raise click.BadParameter(
"No default server configured.", param_hint="server"
)
else:
server_info = config.get_server(server)
if server_info is None:
raise click.BadParameter(
'Server "%s" does not exist.' % server, param_hint="server"
)
try:
event_iter = publish(
env,
server_info.target,
output_path,
credentials=credentials,
server_info=server_info,
extra_flags=extra_flags,
)
except PublishError as e:
raise click.UsageError(
'Server "%s" is not configured for a valid '
"publishing method: %s" % (server, e)
)
click.echo("Deploying to %s" % server_info.name)
click.echo(" Build cache: %s" % output_path)
click.echo(" Target: %s" % secure_url(server_info.target))
try:
for line in event_iter:
click.echo(" %s" % click.style(line, fg="cyan"))
except PublishError as e:
click.secho("Error: %s" % e, fg="red")
else:
click.echo("Done!")
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/cli.py#L224-L285
| 40 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14
] | 24.193548 |
[
15,
17,
18,
20,
21,
22,
24,
25,
26,
27,
31,
32,
33,
37,
38,
46,
47,
52,
53,
54,
55,
56,
57,
58,
59,
61
] | 41.935484 | false | 37.681159 | 62 | 8 | 58.064516 | 13 |
def deploy_cmd(ctx, server, output_path, extra_flags, **credentials):
from lektor.publisher import publish, PublishError
if output_path is None:
output_path = ctx.get_default_output_path()
ctx.load_plugins(extra_flags=extra_flags)
env = ctx.get_env()
config = env.load_config()
if server is None:
server_info = config.get_default_server()
if server_info is None:
raise click.BadParameter(
"No default server configured.", param_hint="server"
)
else:
server_info = config.get_server(server)
if server_info is None:
raise click.BadParameter(
'Server "%s" does not exist.' % server, param_hint="server"
)
try:
event_iter = publish(
env,
server_info.target,
output_path,
credentials=credentials,
server_info=server_info,
extra_flags=extra_flags,
)
except PublishError as e:
raise click.UsageError(
'Server "%s" is not configured for a valid '
"publishing method: %s" % (server, e)
)
click.echo("Deploying to %s" % server_info.name)
click.echo(" Build cache: %s" % output_path)
click.echo(" Target: %s" % secure_url(server_info.target))
try:
for line in event_iter:
click.echo(" %s" % click.style(line, fg="cyan"))
except PublishError as e:
click.secho("Error: %s" % e, fg="red")
else:
click.echo("Done!")
| 26,549 |
|
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/cli.py
|
server_cmd
|
(
ctx, host, port, output_path, prune, verbosity, extra_flags, browse, reload
)
|
The server command will launch a local server for development.
Lektor's development server will automatically build all files into
pages similar to how the build command with the `--watch` switch
works, but also at the same time serve up the website on a local
HTTP server.
|
The server command will launch a local server for development.
| 327 | 355 |
def server_cmd(
ctx, host, port, output_path, prune, verbosity, extra_flags, browse, reload
):
"""The server command will launch a local server for development.
Lektor's development server will automatically build all files into
pages similar to how the build command with the `--watch` switch
works, but also at the same time serve up the website on a local
HTTP server.
"""
from lektor.devserver import run_server
if output_path is None:
output_path = ctx.get_default_output_path()
ctx.load_plugins(extra_flags=extra_flags)
click.echo(" * Project path: %s" % ctx.get_project().project_path)
click.echo(" * Output path: %s" % output_path)
run_server(
(host, port),
env=ctx.get_env(),
output_path=output_path,
prune=prune,
verbosity=verbosity,
ui_lang=ctx.ui_lang,
extra_flags=extra_flags,
lektor_dev=os.environ.get("LEKTOR_DEV") == "1",
browse=browse,
reload=reload,
)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/cli.py#L327-L355
| 40 |
[
0
] | 3.448276 |
[
10,
12,
13,
14,
15,
16,
17
] | 24.137931 | false | 37.681159 | 29 | 2 | 75.862069 | 6 |
def server_cmd(
ctx, host, port, output_path, prune, verbosity, extra_flags, browse, reload
):
from lektor.devserver import run_server
if output_path is None:
output_path = ctx.get_default_output_path()
ctx.load_plugins(extra_flags=extra_flags)
click.echo(" * Project path: %s" % ctx.get_project().project_path)
click.echo(" * Output path: %s" % output_path)
run_server(
(host, port),
env=ctx.get_env(),
output_path=output_path,
prune=prune,
verbosity=verbosity,
ui_lang=ctx.ui_lang,
extra_flags=extra_flags,
lektor_dev=os.environ.get("LEKTOR_DEV") == "1",
browse=browse,
reload=reload,
)
| 26,550 |
|
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/cli.py
|
project_info_cmd
|
(ctx, as_json, **opts)
|
Prints out information about the project. This is particular
useful for script usage or for discovering information about a
Lektor project that is not immediately obvious (like the paths
to the default output folder).
|
Prints out information about the project. This is particular
useful for script usage or for discovering information about a
Lektor project that is not immediately obvious (like the paths
to the default output folder).
| 382 | 402 |
def project_info_cmd(ctx, as_json, **opts):
"""Prints out information about the project. This is particular
useful for script usage or for discovering information about a
Lektor project that is not immediately obvious (like the paths
to the default output folder).
"""
project = ctx.get_project()
if as_json:
echo_json(project.to_json())
return
ops = [k for k, v in opts.items() if v]
if ops:
data = project.to_json()
for op in ops:
click.echo(data.get(op, ""))
else:
click.echo("Name: %s" % project.name)
click.echo("File: %s" % project.project_file)
click.echo("Tree: %s" % project.tree)
click.echo("Output: %s" % project.get_output_path())
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/cli.py#L382-L402
| 40 |
[
0,
1,
2,
3,
4,
5
] | 28.571429 |
[
6,
7,
8,
9,
11,
12,
13,
14,
15,
17,
18,
19,
20
] | 61.904762 | false | 37.681159 | 21 | 5 | 38.095238 | 4 |
def project_info_cmd(ctx, as_json, **opts):
project = ctx.get_project()
if as_json:
echo_json(project.to_json())
return
ops = [k for k, v in opts.items() if v]
if ops:
data = project.to_json()
for op in ops:
click.echo(data.get(op, ""))
else:
click.echo("Name: %s" % project.name)
click.echo("File: %s" % project.project_file)
click.echo("Tree: %s" % project.tree)
click.echo("Output: %s" % project.get_output_path())
| 26,551 |
|
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/cli.py
|
content_file_info_cmd
|
(ctx, files, as_json)
|
Given a list of files this returns the information for those files
in the context of a project. If the files are from different projects
an error is generated.
|
Given a list of files this returns the information for those files
in the context of a project. If the files are from different projects
an error is generated.
| 411 | 460 |
def content_file_info_cmd(ctx, files, as_json):
"""Given a list of files this returns the information for those files
in the context of a project. If the files are from different projects
an error is generated.
"""
project = None
def fail(msg):
if as_json:
echo_json({"success": False, "error": msg})
sys.exit(1)
raise click.UsageError("Could not find content file info: %s" % msg)
for filename in files:
this_project = Project.discover(filename)
if this_project is None:
fail("no project found")
if project is None:
project = this_project
elif project.project_path != this_project.project_path:
fail("multiple projects")
if project is None:
fail("no file indicated a project")
project_files = []
for filename in files:
content_path = project.content_path_from_filename(filename)
if content_path is not None:
project_files.append(content_path)
if not project_files:
fail("no files resolve in project")
if as_json:
echo_json(
{
"success": True,
"project": project.to_json(),
"paths": project_files,
}
)
else:
click.echo("Project:")
click.echo(" Name: %s" % project.name)
click.echo(" File: %s" % project.project_file)
click.echo(" Tree: %s" % project.tree)
click.echo("Paths:")
for project_file in project_files:
click.echo(" - %s" % project_file)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/cli.py#L411-L460
| 40 |
[
0,
1,
2,
3,
4
] | 10 |
[
5,
7,
8,
9,
10,
11,
13,
14,
15,
16,
17,
18,
19,
20,
22,
23,
25,
26,
27,
28,
29,
31,
32,
34,
35,
43,
44,
45,
46,
47,
48,
49
] | 64 | false | 37.681159 | 50 | 13 | 36 | 3 |
def content_file_info_cmd(ctx, files, as_json):
project = None
def fail(msg):
if as_json:
echo_json({"success": False, "error": msg})
sys.exit(1)
raise click.UsageError("Could not find content file info: %s" % msg)
for filename in files:
this_project = Project.discover(filename)
if this_project is None:
fail("no project found")
if project is None:
project = this_project
elif project.project_path != this_project.project_path:
fail("multiple projects")
if project is None:
fail("no file indicated a project")
project_files = []
for filename in files:
content_path = project.content_path_from_filename(filename)
if content_path is not None:
project_files.append(content_path)
if not project_files:
fail("no files resolve in project")
if as_json:
echo_json(
{
"success": True,
"project": project.to_json(),
"paths": project_files,
}
)
else:
click.echo("Project:")
click.echo(" Name: %s" % project.name)
click.echo(" File: %s" % project.project_file)
click.echo(" Tree: %s" % project.tree)
click.echo("Paths:")
for project_file in project_files:
click.echo(" - %s" % project_file)
| 26,552 |
|
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/cli.py
|
plugins_cmd
|
()
|
This command group provides various helpers to manages plugins
in a Lektor project.
|
This command group provides various helpers to manages plugins
in a Lektor project.
| 464 | 467 |
def plugins_cmd():
"""This command group provides various helpers to manages plugins
in a Lektor project.
"""
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/cli.py#L464-L467
| 40 |
[
0,
1,
2,
3
] | 100 |
[] | 0 | true | 37.681159 | 4 | 1 | 100 | 2 |
def plugins_cmd():
| 26,553 |
|
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/cli.py
|
plugins_add_cmd
|
(ctx, name)
|
This command can add a new plugin to the project. If just given
the name of the plugin the latest version of that plugin is added to
the project.
The argument is either the name of the plugin or the name of the plugin
suffixed with `@version` with the version. For instance to install
the version 0.1 of the plugin demo you would do `demo@0.1`.
|
This command can add a new plugin to the project. If just given
the name of the plugin the latest version of that plugin is added to
the project.
| 473 | 496 |
def plugins_add_cmd(ctx, name):
"""This command can add a new plugin to the project. If just given
the name of the plugin the latest version of that plugin is added to
the project.
The argument is either the name of the plugin or the name of the plugin
suffixed with `@version` with the version. For instance to install
the version 0.1 of the plugin demo you would do `demo@0.1`.
"""
project = ctx.get_project()
from .packages import add_package_to_project
try:
info = add_package_to_project(project, name)
except RuntimeError as e:
click.echo("Error: %s" % e, err=True)
else:
click.echo(
"Package %s (%s) was added to the project"
% (
info["name"],
info["version"],
)
)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/cli.py#L473-L496
| 40 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8
] | 37.5 |
[
9,
10,
12,
13,
14,
15,
17
] | 29.166667 | false | 37.681159 | 24 | 2 | 70.833333 | 7 |
def plugins_add_cmd(ctx, name):
project = ctx.get_project()
from .packages import add_package_to_project
try:
info = add_package_to_project(project, name)
except RuntimeError as e:
click.echo("Error: %s" % e, err=True)
else:
click.echo(
"Package %s (%s) was added to the project"
% (
info["name"],
info["version"],
)
)
| 26,554 |
|
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/cli.py
|
plugins_remove_cmd
|
(ctx, name)
|
This command can remove a plugin to the project again. The name
of the plugin is the only argument to the function.
|
This command can remove a plugin to the project again. The name
of the plugin is the only argument to the function.
| 502 | 525 |
def plugins_remove_cmd(ctx, name):
"""This command can remove a plugin to the project again. The name
of the plugin is the only argument to the function.
"""
project = ctx.get_project()
from .packages import remove_package_from_project
try:
old_info = remove_package_from_project(project, name)
except RuntimeError as e:
click.echo("Error: %s" % e, err=True)
else:
if old_info is None:
click.echo(
"Package was not registered with the project. Nothing was removed."
)
else:
click.echo(
"Removed package %s (%s)"
% (
old_info["name"],
old_info["version"],
)
)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/cli.py#L502-L525
| 40 |
[
0,
1,
2,
3
] | 16.666667 |
[
4,
5,
7,
8,
9,
10,
12,
13,
17
] | 37.5 | false | 37.681159 | 24 | 3 | 62.5 | 2 |
def plugins_remove_cmd(ctx, name):
project = ctx.get_project()
from .packages import remove_package_from_project
try:
old_info = remove_package_from_project(project, name)
except RuntimeError as e:
click.echo("Error: %s" % e, err=True)
else:
if old_info is None:
click.echo(
"Package was not registered with the project. Nothing was removed."
)
else:
click.echo(
"Removed package %s (%s)"
% (
old_info["name"],
old_info["version"],
)
)
| 26,555 |
|
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/cli.py
|
plugins_list_cmd
|
(ctx, as_json, verbosity)
|
This returns a list of all currently actively installed plugins
in the project. By default it only prints out the plugin IDs and
version numbers but the entire information can be returned by
increasing verbosity with `-v`. Additionally JSON output can be
requested with `--json`.
|
This returns a list of all currently actively installed plugins
in the project. By default it only prints out the plugin IDs and
version numbers but the entire information can be returned by
increasing verbosity with `-v`. Additionally JSON output can be
requested with `--json`.
| 538 | 567 |
def plugins_list_cmd(ctx, as_json, verbosity):
"""This returns a list of all currently actively installed plugins
in the project. By default it only prints out the plugin IDs and
version numbers but the entire information can be returned by
increasing verbosity with `-v`. Additionally JSON output can be
requested with `--json`.
"""
ctx.load_plugins()
env = ctx.get_env()
plugins = sorted(env.plugins.values(), key=lambda x: x.id.lower())
if as_json:
echo_json({"plugins": [x.to_json() for x in plugins]})
return
if verbosity == 0:
for plugin in plugins:
click.echo("%s (version %s)" % (plugin.id, plugin.version))
return
for idx, plugin in enumerate(plugins):
if idx:
click.echo()
click.echo("%s (%s)" % (plugin.name, plugin.id))
for line in plugin.description.splitlines():
click.echo(" %s" % line)
if plugin.path is not None:
click.echo(" path: %s" % plugin.path)
click.echo(" version: %s" % plugin.version)
click.echo(" import-name: %s" % plugin.import_name)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/cli.py#L538-L567
| 40 |
[
0,
1,
2,
3,
4,
5,
6
] | 23.333333 |
[
7,
8,
9,
11,
12,
13,
15,
16,
17,
18,
20,
21,
22,
23,
24,
25,
26,
27,
28,
29
] | 66.666667 | false | 37.681159 | 30 | 9 | 33.333333 | 5 |
def plugins_list_cmd(ctx, as_json, verbosity):
ctx.load_plugins()
env = ctx.get_env()
plugins = sorted(env.plugins.values(), key=lambda x: x.id.lower())
if as_json:
echo_json({"plugins": [x.to_json() for x in plugins]})
return
if verbosity == 0:
for plugin in plugins:
click.echo("%s (version %s)" % (plugin.id, plugin.version))
return
for idx, plugin in enumerate(plugins):
if idx:
click.echo()
click.echo("%s (%s)" % (plugin.name, plugin.id))
for line in plugin.description.splitlines():
click.echo(" %s" % line)
if plugin.path is not None:
click.echo(" path: %s" % plugin.path)
click.echo(" version: %s" % plugin.version)
click.echo(" import-name: %s" % plugin.import_name)
| 26,556 |
|
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/cli.py
|
plugins_flush_cache_cmd
|
(ctx)
|
This uninstalls all plugins in the cache. On next usage the plugins
will be reinstalled automatically. This is mostly just useful during
plugin development when the cache got corrupted.
|
This uninstalls all plugins in the cache. On next usage the plugins
will be reinstalled automatically. This is mostly just useful during
plugin development when the cache got corrupted.
| 574 | 583 |
def plugins_flush_cache_cmd(ctx):
"""This uninstalls all plugins in the cache. On next usage the plugins
will be reinstalled automatically. This is mostly just useful during
plugin development when the cache got corrupted.
"""
click.echo("Flushing plugin cache ...")
from .packages import wipe_package_cache
wipe_package_cache(ctx.get_env())
click.echo("All done!")
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/cli.py#L574-L583
| 40 |
[
0,
1,
2,
3,
4
] | 50 |
[
5,
6,
8,
9
] | 40 | false | 37.681159 | 10 | 1 | 60 | 3 |
def plugins_flush_cache_cmd(ctx):
click.echo("Flushing plugin cache ...")
from .packages import wipe_package_cache
wipe_package_cache(ctx.get_env())
click.echo("All done!")
| 26,557 |
|
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/cli.py
|
plugins_reinstall_cmd
|
(ctx)
|
Forces a re-installation of all plugins. This will download the
requested versions of the plugins and install them into the plugin
cache folder. Alternatively one can just use `flush-cache` to
flush the cache and on next build Lektor will automatically download
the plugins again.
|
Forces a re-installation of all plugins. This will download the
requested versions of the plugins and install them into the plugin
cache folder. Alternatively one can just use `flush-cache` to
flush the cache and on next build Lektor will automatically download
the plugins again.
| 588 | 595 |
def plugins_reinstall_cmd(ctx):
"""Forces a re-installation of all plugins. This will download the
requested versions of the plugins and install them into the plugin
cache folder. Alternatively one can just use `flush-cache` to
flush the cache and on next build Lektor will automatically download
the plugins again.
"""
ctx.load_plugins(reinstall=True)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/cli.py#L588-L595
| 40 |
[
0,
1,
2,
3,
4,
5,
6
] | 87.5 |
[
7
] | 12.5 | false | 37.681159 | 8 | 1 | 87.5 | 5 |
def plugins_reinstall_cmd(ctx):
ctx.load_plugins(reinstall=True)
| 26,558 |
|
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/cli.py
|
quickstart_cmd
|
(ctx, **options)
|
Starts a new empty project with a minimum boilerplate.
|
Starts a new empty project with a minimum boilerplate.
| 602 | 606 |
def quickstart_cmd(ctx, **options):
"""Starts a new empty project with a minimum boilerplate."""
from lektor.quickstart import project_quickstart
project_quickstart(options)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/cli.py#L602-L606
| 40 |
[
0,
1
] | 40 |
[
2,
4
] | 40 | false | 37.681159 | 5 | 1 | 60 | 1 |
def quickstart_cmd(ctx, **options):
from lektor.quickstart import project_quickstart
project_quickstart(options)
| 26,559 |
|
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/cli.py
|
main
|
(as_module=False)
| 614 | 622 |
def main(as_module=False):
args = sys.argv[1:]
name = None
if as_module:
name = "python -m lektor"
sys.argv = ["-m", "lektor"] + args
cli.main(args=args, prog_name=name)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/cli.py#L614-L622
| 40 |
[
0
] | 11.111111 |
[
1,
2,
4,
5,
6,
8
] | 66.666667 | false | 37.681159 | 9 | 2 | 33.333333 | 0 |
def main(as_module=False):
args = sys.argv[1:]
name = None
if as_module:
name = "python -m lektor"
sys.argv = ["-m", "lektor"] + args
cli.main(args=args, prog_name=name)
| 26,560 |
|||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/assets.py
|
get_asset
|
(pad, filename, parent=None)
|
return cls(pad, filename, parent=parent)
| 8 | 23 |
def get_asset(pad, filename, parent=None):
env = pad.db.env
if env.is_uninteresting_source_name(filename):
return None
try:
stat_obj = os.stat(os.path.join(parent.source_filename, filename))
except OSError:
return None
if stat.S_ISDIR(stat_obj.st_mode):
return Directory(pad, filename, parent=parent)
ext = os.path.splitext(filename)[1]
cls = env.special_file_assets.get(ext, File)
return cls(pad, filename, parent=parent)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/assets.py#L8-L23
| 40 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15
] | 100 |
[] | 0 | true | 97.777778 | 16 | 4 | 100 | 0 |
def get_asset(pad, filename, parent=None):
env = pad.db.env
if env.is_uninteresting_source_name(filename):
return None
try:
stat_obj = os.stat(os.path.join(parent.source_filename, filename))
except OSError:
return None
if stat.S_ISDIR(stat_obj.st_mode):
return Directory(pad, filename, parent=parent)
ext = os.path.splitext(filename)[1]
cls = env.special_file_assets.get(ext, File)
return cls(pad, filename, parent=parent)
| 26,561 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/assets.py
|
Asset.__init__
|
(self, pad, name, path=None, parent=None)
| 34 | 43 |
def __init__(self, pad, name, path=None, parent=None):
SourceObject.__init__(self, pad)
if parent is not None:
if path is None:
path = name
path = os.path.join(parent.source_filename, path)
self.source_filename = path
self.name = name
self.parent = parent
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/assets.py#L34-L43
| 40 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9
] | 100 |
[] | 0 | true | 97.777778 | 10 | 3 | 100 | 0 |
def __init__(self, pad, name, path=None, parent=None):
SourceObject.__init__(self, pad)
if parent is not None:
if path is None:
path = name
path = os.path.join(parent.source_filename, path)
self.source_filename = path
self.name = name
self.parent = parent
| 26,562 |
|||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/assets.py
|
Asset.url_name
|
(self)
|
return base + ext + self.artifact_extension
| 46 | 55 |
def url_name(self):
name = self.name
base, ext = posixpath.splitext(name)
# If this is a known extension from an attachment then convert it
# to lowercase
if ext.lower() in self.pad.db.config["ATTACHMENT_TYPES"]:
ext = ext.lower()
return base + ext + self.artifact_extension
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/assets.py#L46-L55
| 40 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9
] | 100 |
[] | 0 | true | 97.777778 | 10 | 2 | 100 | 0 |
def url_name(self):
name = self.name
base, ext = posixpath.splitext(name)
# If this is a known extension from an attachment then convert it
# to lowercase
if ext.lower() in self.pad.db.config["ATTACHMENT_TYPES"]:
ext = ext.lower()
return base + ext + self.artifact_extension
| 26,563 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/assets.py
|
Asset.url_path
|
(self)
|
return posixpath.join(self.parent.url_path, self.url_name)
| 58 | 61 |
def url_path(self):
if self.parent is None:
return "/" + self.name
return posixpath.join(self.parent.url_path, self.url_name)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/assets.py#L58-L61
| 40 |
[
0,
1,
2,
3
] | 100 |
[] | 0 | true | 97.777778 | 4 | 2 | 100 | 0 |
def url_path(self):
if self.parent is None:
return "/" + self.name
return posixpath.join(self.parent.url_path, self.url_name)
| 26,564 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/assets.py
|
Asset.artifact_name
|
(self)
|
return self.url_path
| 64 | 67 |
def artifact_name(self):
if self.parent is not None:
return self.parent.artifact_name.rstrip("/") + "/" + self.url_name
return self.url_path
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/assets.py#L64-L67
| 40 |
[
0,
1,
2,
3
] | 100 |
[] | 0 | true | 97.777778 | 4 | 2 | 100 | 0 |
def artifact_name(self):
if self.parent is not None:
return self.parent.artifact_name.rstrip("/") + "/" + self.url_name
return self.url_path
| 26,565 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/assets.py
|
Asset.children
|
(self)
|
return iter(())
| 73 | 74 |
def children(self):
return iter(())
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/assets.py#L73-L74
| 40 |
[
0,
1
] | 100 |
[] | 0 | true | 97.777778 | 2 | 1 | 100 | 0 |
def children(self):
return iter(())
| 26,566 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/assets.py
|
Asset.get_child
|
(self, name, from_url=False)
|
return None
| 76 | 78 |
def get_child(self, name, from_url=False):
# pylint: disable=no-self-use
return None
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/assets.py#L76-L78
| 40 |
[
0,
1,
2
] | 100 |
[] | 0 | true | 97.777778 | 3 | 1 | 100 | 0 |
def get_child(self, name, from_url=False):
# pylint: disable=no-self-use
return None
| 26,567 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/assets.py
|
Asset.resolve_url_path
|
(self, url_path)
|
return None
| 80 | 87 |
def resolve_url_path(self, url_path):
if not url_path:
return self
# pylint: disable=assignment-from-none
child = self.get_child(url_path[0], from_url=True)
if child is not None:
return child.resolve_url_path(url_path[1:])
return None
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/assets.py#L80-L87
| 40 |
[
0,
1,
2,
3,
4,
5,
6,
7
] | 100 |
[] | 0 | true | 97.777778 | 8 | 3 | 100 | 0 |
def resolve_url_path(self, url_path):
if not url_path:
return self
# pylint: disable=assignment-from-none
child = self.get_child(url_path[0], from_url=True)
if child is not None:
return child.resolve_url_path(url_path[1:])
return None
| 26,568 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/assets.py
|
Asset.__repr__
|
(self)
|
return "<%s %r>" % (
self.__class__.__name__,
self.artifact_name,
)
| 89 | 93 |
def __repr__(self):
return "<%s %r>" % (
self.__class__.__name__,
self.artifact_name,
)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/assets.py#L89-L93
| 40 |
[
0,
1
] | 40 |
[] | 0 | false | 97.777778 | 5 | 1 | 100 | 0 |
def __repr__(self):
return "<%s %r>" % (
self.__class__.__name__,
self.artifact_name,
)
| 26,569 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/assets.py
|
Directory.children
|
(self)
| 100 | 109 |
def children(self):
try:
files = os.listdir(self.source_filename)
except OSError:
return
for filename in files:
asset = self.get_child(filename)
if asset is not None:
yield asset
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/assets.py#L100-L109
| 40 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9
] | 100 |
[] | 0 | true | 97.777778 | 10 | 4 | 100 | 0 |
def children(self):
try:
files = os.listdir(self.source_filename)
except OSError:
return
for filename in files:
asset = self.get_child(filename)
if asset is not None:
yield asset
| 26,570 |
|||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/assets.py
|
Directory.get_child
|
(self, name, from_url=False)
|
return None
| 111 | 124 |
def get_child(self, name, from_url=False):
asset = get_asset(self.pad, name, parent=self)
if asset is not None or not from_url:
return asset
# At this point it means we did not find a child yet, but we
# came from an URL. We can try to chop off product suffixes to
# find the original source asset. For instance a file called
# foo.less.css will be reduced to foo.less.
prod_suffix = "." + ".".join(name.rsplit(".", 2)[1:])
ext = self.pad.db.env.special_file_suffixes.get(prod_suffix)
if ext is not None:
return get_asset(self.pad, name[: -len(prod_suffix)] + ext, parent=self)
return None
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/assets.py#L111-L124
| 40 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
13
] | 92.857143 |
[
12
] | 7.142857 | false | 97.777778 | 14 | 4 | 92.857143 | 0 |
def get_child(self, name, from_url=False):
asset = get_asset(self.pad, name, parent=self)
if asset is not None or not from_url:
return asset
# At this point it means we did not find a child yet, but we
# came from an URL. We can try to chop off product suffixes to
# find the original source asset. For instance a file called
# foo.less.css will be reduced to foo.less.
prod_suffix = "." + ".".join(name.rsplit(".", 2)[1:])
ext = self.pad.db.env.special_file_suffixes.get(prod_suffix)
if ext is not None:
return get_asset(self.pad, name[: -len(prod_suffix)] + ext, parent=self)
return None
| 26,571 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/assets.py
|
Directory.url_path
|
(self)
|
return path
| 127 | 131 |
def url_path(self):
path = super().url_path
if not path.endswith("/"):
path += "/"
return path
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/assets.py#L127-L131
| 40 |
[
0,
1,
2,
3,
4
] | 100 |
[] | 0 | true | 97.777778 | 5 | 2 | 100 | 0 |
def url_path(self):
path = super().url_path
if not path.endswith("/"):
path += "/"
return path
| 26,572 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/watcher.py
|
_fullname
|
(cls)
|
return f"{cls.__module__}.{cls.__qualname__}"
|
Return the full name of a class (including the module name).
|
Return the full name of a class (including the module name).
| 31 | 33 |
def _fullname(cls):
"""Return the full name of a class (including the module name)."""
return f"{cls.__module__}.{cls.__qualname__}"
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/watcher.py#L31-L33
| 40 |
[
0,
1,
2
] | 100 |
[] | 0 | true | 93.103448 | 3 | 1 | 100 | 1 |
def _fullname(cls):
return f"{cls.__module__}.{cls.__qualname__}"
| 26,573 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/watcher.py
|
_unique_everseen
|
(seq)
|
return OrderedDict.fromkeys(seq).keys()
|
Return the unique elements in sequence, preserving order.
|
Return the unique elements in sequence, preserving order.
| 36 | 38 |
def _unique_everseen(seq):
"""Return the unique elements in sequence, preserving order."""
return OrderedDict.fromkeys(seq).keys()
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/watcher.py#L36-L38
| 40 |
[
0,
1,
2
] | 100 |
[] | 0 | true | 93.103448 | 3 | 1 | 100 | 1 |
def _unique_everseen(seq):
return OrderedDict.fromkeys(seq).keys()
| 26,574 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/watcher.py
|
watch
|
(env)
|
Returns a generator of file system events in the environment.
|
Returns a generator of file system events in the environment.
| 124 | 131 |
def watch(env):
"""Returns a generator of file system events in the environment."""
with Watcher(env) as watcher:
try:
for event in watcher:
yield event
except KeyboardInterrupt:
pass
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/watcher.py#L124-L131
| 40 |
[
0,
1
] | 25 |
[
2,
3,
4,
5,
6,
7
] | 75 | false | 93.103448 | 8 | 4 | 25 | 1 |
def watch(env):
with Watcher(env) as watcher:
try:
for event in watcher:
yield event
except KeyboardInterrupt:
pass
| 26,575 |
|
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/watcher.py
|
EventHandler.__init__
|
(self)
| 18 | 20 |
def __init__(self):
super().__init__()
self.queue = queue.Queue()
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/watcher.py#L18-L20
| 40 |
[
0,
1,
2
] | 100 |
[] | 0 | true | 93.103448 | 3 | 1 | 100 | 0 |
def __init__(self):
super().__init__()
self.queue = queue.Queue()
| 26,576 |
|||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/watcher.py
|
EventHandler.on_any_event
|
(self, event)
| 22 | 28 |
def on_any_event(self, event):
if not isinstance(event, DirModifiedEvent):
if isinstance(event, FileMovedEvent):
path = event.dest_path
else:
path = event.src_path
self.queue.put((time.time(), event.event_type, path))
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/watcher.py#L22-L28
| 40 |
[
0,
1,
2,
3,
5,
6
] | 85.714286 |
[] | 0 | false | 93.103448 | 7 | 3 | 100 | 0 |
def on_any_event(self, event):
if not isinstance(event, DirModifiedEvent):
if isinstance(event, FileMovedEvent):
path = event.dest_path
else:
path = event.src_path
self.queue.put((time.time(), event.event_type, path))
| 26,577 |
|||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/watcher.py
|
BasicWatcher.__init__
|
(self, paths, observer_classes=(Observer, PollingObserver))
| 42 | 46 |
def __init__(self, paths, observer_classes=(Observer, PollingObserver)):
self.event_handler = EventHandler()
self.paths = paths
self.observer_classes = observer_classes
self.observer = None
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/watcher.py#L42-L46
| 40 |
[
0,
1,
2,
3,
4
] | 100 |
[] | 0 | true | 93.103448 | 5 | 1 | 100 | 0 |
def __init__(self, paths, observer_classes=(Observer, PollingObserver)):
self.event_handler = EventHandler()
self.paths = paths
self.observer_classes = observer_classes
self.observer = None
| 26,578 |
|||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/watcher.py
|
BasicWatcher.start
|
(self)
| 48 | 70 |
def start(self):
# Remove duplicates since there is no point in trying a given
# observer class more than once. (This also simplifies the logic
# for presenting sensible warning messages about broken
# observers.)
observer_classes = list(_unique_everseen(self.observer_classes))
for observer_class, next_observer_class in zip_longest(
observer_classes, observer_classes[1:]
):
try:
self._start_observer(observer_class)
return
except Exception as exc:
if next_observer_class is None:
raise
click.secho(
f"Creation of {_fullname(observer_class)} failed with exception:\n"
f" {exc.__class__.__name__}: {exc!s}\n"
"This may be due to a configuration or other issue with your system.\n"
f"Falling back to {_fullname(next_observer_class)}.",
fg="red",
bold=True,
)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/watcher.py#L48-L70
| 40 |
[
0,
1,
2,
3,
4,
5,
6,
9,
10,
11,
12,
13,
14,
15
] | 60.869565 |
[] | 0 | false | 93.103448 | 23 | 4 | 100 | 0 |
def start(self):
# Remove duplicates since there is no point in trying a given
# observer class more than once. (This also simplifies the logic
# for presenting sensible warning messages about broken
# observers.)
observer_classes = list(_unique_everseen(self.observer_classes))
for observer_class, next_observer_class in zip_longest(
observer_classes, observer_classes[1:]
):
try:
self._start_observer(observer_class)
return
except Exception as exc:
if next_observer_class is None:
raise
click.secho(
f"Creation of {_fullname(observer_class)} failed with exception:\n"
f" {exc.__class__.__name__}: {exc!s}\n"
"This may be due to a configuration or other issue with your system.\n"
f"Falling back to {_fullname(next_observer_class)}.",
fg="red",
bold=True,
)
| 26,579 |
|||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/watcher.py
|
BasicWatcher.stop
|
(self)
| 72 | 73 |
def stop(self):
self.observer.stop()
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/watcher.py#L72-L73
| 40 |
[
0,
1
] | 100 |
[] | 0 | true | 93.103448 | 2 | 1 | 100 | 0 |
def stop(self):
self.observer.stop()
| 26,580 |
|||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/watcher.py
|
BasicWatcher.__enter__
|
(self)
|
return self
| 75 | 77 |
def __enter__(self):
self.start()
return self
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/watcher.py#L75-L77
| 40 |
[
0,
1,
2
] | 100 |
[] | 0 | true | 93.103448 | 3 | 1 | 100 | 0 |
def __enter__(self):
self.start()
return self
| 26,581 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/watcher.py
|
BasicWatcher.__exit__
|
(self, ex_type, ex_value, ex_tb)
| 79 | 80 |
def __exit__(self, ex_type, ex_value, ex_tb):
self.stop()
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/watcher.py#L79-L80
| 40 |
[
0,
1
] | 100 |
[] | 0 | true | 93.103448 | 2 | 1 | 100 | 0 |
def __exit__(self, ex_type, ex_value, ex_tb):
self.stop()
| 26,582 |
|||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/watcher.py
|
BasicWatcher._start_observer
|
(self, observer_class=Observer)
| 82 | 90 |
def _start_observer(self, observer_class=Observer):
if self.observer is not None:
raise RuntimeError("Watcher already started.")
observer = observer_class()
for path in self.paths:
observer.schedule(self.event_handler, path, recursive=True)
observer.daemon = True
observer.start()
self.observer = observer
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/watcher.py#L82-L90
| 40 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8
] | 100 |
[] | 0 | true | 93.103448 | 9 | 3 | 100 | 0 |
def _start_observer(self, observer_class=Observer):
if self.observer is not None:
raise RuntimeError("Watcher already started.")
observer = observer_class()
for path in self.paths:
observer.schedule(self.event_handler, path, recursive=True)
observer.daemon = True
observer.start()
self.observer = observer
| 26,583 |
|||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/watcher.py
|
BasicWatcher.is_interesting
|
(self, time, event_type, path)
|
return True
| 92 | 94 |
def is_interesting(self, time, event_type, path):
# pylint: disable=no-self-use
return True
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/watcher.py#L92-L94
| 40 |
[
0,
1,
2
] | 100 |
[] | 0 | true | 93.103448 | 3 | 1 | 100 | 0 |
def is_interesting(self, time, event_type, path):
# pylint: disable=no-self-use
return True
| 26,584 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/watcher.py
|
BasicWatcher.__iter__
|
(self)
| 96 | 100 |
def __iter__(self):
while 1:
time_, event_type, path = self.event_handler.queue.get()
if self.is_interesting(time_, event_type, path):
yield time_, event_type, path
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/watcher.py#L96-L100
| 40 |
[
0,
1,
2,
3,
4
] | 100 |
[] | 0 | true | 93.103448 | 5 | 3 | 100 | 0 |
def __iter__(self):
while 1:
time_, event_type, path = self.event_handler.queue.get()
if self.is_interesting(time_, event_type, path):
yield time_, event_type, path
| 26,585 |
|||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/watcher.py
|
Watcher.__init__
|
(self, env, output_path=None)
| 104 | 108 |
def __init__(self, env, output_path=None):
BasicWatcher.__init__(self, paths=[env.root_path] + env.theme_paths)
self.env = env
self.output_path = output_path
self.cache_dir = os.path.abspath(get_cache_dir())
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/watcher.py#L104-L108
| 40 |
[
0,
1,
2,
3,
4
] | 100 |
[] | 0 | true | 93.103448 | 5 | 1 | 100 | 0 |
def __init__(self, env, output_path=None):
BasicWatcher.__init__(self, paths=[env.root_path] + env.theme_paths)
self.env = env
self.output_path = output_path
self.cache_dir = os.path.abspath(get_cache_dir())
| 26,586 |
|||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/watcher.py
|
Watcher.is_interesting
|
(self, time, event_type, path)
|
return True
| 110 | 121 |
def is_interesting(self, time, event_type, path):
path = os.path.abspath(path)
if self.env.is_uninteresting_source_name(os.path.basename(path)):
return False
if path.startswith(self.cache_dir):
return False
if self.output_path is not None and path.startswith(
os.path.abspath(self.output_path)
):
return False
return True
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/watcher.py#L110-L121
| 40 |
[
0,
1,
2,
3,
4,
5,
6,
7,
10,
11
] | 83.333333 |
[] | 0 | false | 93.103448 | 12 | 5 | 100 | 0 |
def is_interesting(self, time, event_type, path):
path = os.path.abspath(path)
if self.env.is_uninteresting_source_name(os.path.basename(path)):
return False
if path.startswith(self.cache_dir):
return False
if self.output_path is not None and path.startswith(
os.path.abspath(self.output_path)
):
return False
return True
| 26,587 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/metaformat.py
|
_line_is_dashes
|
(line)
|
return line == "-" * len(line) and len(line) >= 3
| 1 | 3 |
def _line_is_dashes(line):
line = line.strip()
return line == "-" * len(line) and len(line) >= 3
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/metaformat.py#L1-L3
| 40 |
[
0,
1,
2
] | 100 |
[] | 0 | true | 87.323944 | 3 | 2 | 100 | 0 |
def _line_is_dashes(line):
line = line.strip()
return line == "-" * len(line) and len(line) >= 3
| 26,588 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/metaformat.py
|
_process_buf
|
(buf)
|
return buf[:]
| 6 | 15 |
def _process_buf(buf):
for idx, line in enumerate(buf):
if _line_is_dashes(line):
line = line[1:]
buf[idx] = line
if buf and buf[-1][-1:] == "\n":
buf[-1] = buf[-1][:-1]
return buf[:]
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/metaformat.py#L6-L15
| 40 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9
] | 100 |
[] | 0 | true | 87.323944 | 10 | 5 | 100 | 0 |
def _process_buf(buf):
for idx, line in enumerate(buf):
if _line_is_dashes(line):
line = line[1:]
buf[idx] = line
if buf and buf[-1][-1:] == "\n":
buf[-1] = buf[-1][:-1]
return buf[:]
| 26,589 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/metaformat.py
|
tokenize
|
(iterable, interesting_keys=None, encoding=None)
|
This tokenizes an iterable of newlines as bytes into key value
pairs out of the lektor bulk format. By default it will process all
fields, but optionally it can skip values of uninteresting keys and
will instead yield `None`. The values are left as list of decoded
lines with their endings preserved.
This will not perform any other processing on the data other than
decoding and basic tokenizing.
|
This tokenizes an iterable of newlines as bytes into key value
pairs out of the lektor bulk format. By default it will process all
fields, but optionally it can skip values of uninteresting keys and
will instead yield `None`. The values are left as list of decoded
lines with their endings preserved.
| 18 | 76 |
def tokenize(iterable, interesting_keys=None, encoding=None):
"""This tokenizes an iterable of newlines as bytes into key value
pairs out of the lektor bulk format. By default it will process all
fields, but optionally it can skip values of uninteresting keys and
will instead yield `None`. The values are left as list of decoded
lines with their endings preserved.
This will not perform any other processing on the data other than
decoding and basic tokenizing.
"""
key = []
buf = []
want_newline = False
is_interesting = True
def _flush_item():
the_key = key[0]
if not is_interesting:
value = None
else:
value = _process_buf(buf)
del key[:], buf[:]
return the_key, value
if encoding is not None:
iterable = (x.decode(encoding, "replace") for x in iterable)
for line in iterable:
line = line.rstrip("\r\n") + "\n"
if line.rstrip() == "---":
want_newline = False
if key:
yield _flush_item()
elif key:
if want_newline:
want_newline = False
if not line.strip():
continue
if is_interesting:
buf.append(line)
else:
bits = line.split(":", 1)
if len(bits) == 2:
key = [bits[0].strip()]
if interesting_keys is None:
is_interesting = True
else:
is_interesting = key[0] in interesting_keys
if is_interesting:
first_bit = bits[1].strip("\t ")
if first_bit.strip():
buf = [first_bit]
else:
buf = []
want_newline = True
if key:
yield _flush_item()
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/metaformat.py#L18-L76
| 40 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
19,
20,
21,
22,
23,
24,
25,
26,
27,
28,
29,
30,
31,
32,
33,
34,
35,
36,
37,
38,
39,
40,
41,
42,
43,
44,
45,
46,
47,
49,
50,
51,
52,
53,
54,
55,
56,
57,
58
] | 96.610169 |
[
18,
48
] | 3.389831 | false | 87.323944 | 59 | 16 | 96.610169 | 8 |
def tokenize(iterable, interesting_keys=None, encoding=None):
key = []
buf = []
want_newline = False
is_interesting = True
def _flush_item():
the_key = key[0]
if not is_interesting:
value = None
else:
value = _process_buf(buf)
del key[:], buf[:]
return the_key, value
if encoding is not None:
iterable = (x.decode(encoding, "replace") for x in iterable)
for line in iterable:
line = line.rstrip("\r\n") + "\n"
if line.rstrip() == "---":
want_newline = False
if key:
yield _flush_item()
elif key:
if want_newline:
want_newline = False
if not line.strip():
continue
if is_interesting:
buf.append(line)
else:
bits = line.split(":", 1)
if len(bits) == 2:
key = [bits[0].strip()]
if interesting_keys is None:
is_interesting = True
else:
is_interesting = key[0] in interesting_keys
if is_interesting:
first_bit = bits[1].strip("\t ")
if first_bit.strip():
buf = [first_bit]
else:
buf = []
want_newline = True
if key:
yield _flush_item()
| 26,590 |
|
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/metaformat.py
|
serialize
|
(iterable, encoding=None)
|
Serializes an iterable of key value pairs into a stream of
string chunks. If an encoding is provided, it will be encoded into that.
This is primarily used by the editor to write back data to a source file.
|
Serializes an iterable of key value pairs into a stream of
string chunks. If an encoding is provided, it will be encoded into that.
| 79 | 105 |
def serialize(iterable, encoding=None):
"""Serializes an iterable of key value pairs into a stream of
string chunks. If an encoding is provided, it will be encoded into that.
This is primarily used by the editor to write back data to a source file.
"""
def _produce(item, escape=False):
if escape:
if _line_is_dashes(item):
item = "-" + item
if encoding is not None:
item = item.encode(encoding)
return item
for idx, (key, value) in enumerate(iterable):
value = value.replace("\r\n", "\n").replace("\r", "\n")
if idx > 0:
yield _produce("---\n")
if "\n" in value or value.strip("\t ") != value:
yield _produce(key + ":\n")
yield _produce("\n")
for line in value.splitlines(True):
yield _produce(line, escape=True)
yield _produce("\n")
else:
yield _produce("%s: %s\n" % (key, value))
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/metaformat.py#L79-L105
| 40 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
11,
12,
13,
14,
15,
16,
17,
18,
19,
25,
26
] | 74.074074 |
[
9,
10,
20,
21,
22,
23,
24
] | 25.925926 | false | 87.323944 | 27 | 10 | 74.074074 | 4 |
def serialize(iterable, encoding=None):
def _produce(item, escape=False):
if escape:
if _line_is_dashes(item):
item = "-" + item
if encoding is not None:
item = item.encode(encoding)
return item
for idx, (key, value) in enumerate(iterable):
value = value.replace("\r\n", "\n").replace("\r", "\n")
if idx > 0:
yield _produce("---\n")
if "\n" in value or value.strip("\t ") != value:
yield _produce(key + ":\n")
yield _produce("\n")
for line in value.splitlines(True):
yield _produce(line, escape=True)
yield _produce("\n")
else:
yield _produce("%s: %s\n" % (key, value))
| 26,591 |
|
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/admin/utils.py
|
eventstream
|
(f: Callable[..., Iterable[Any]])
|
return update_wrapper(new_func, f)
| 12 | 22 |
def eventstream(f: Callable[..., Iterable[Any]]) -> Callable[..., Response]:
def new_func(*args: Any, **kwargs: Any) -> Response:
def generate() -> Iterator[bytes]:
for event in chain(f(*args, **kwargs), (None,)):
yield ("data: %s\n\n" % json.dumps(event)).encode()
return Response(
generate(), mimetype="text/event-stream", direct_passthrough=True
)
return update_wrapper(new_func, f)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/admin/utils.py#L12-L22
| 40 |
[
0,
1,
2,
3,
4,
5,
6,
9,
10
] | 81.818182 |
[] | 0 | false | 100 | 11 | 4 | 100 | 0 |
def eventstream(f: Callable[..., Iterable[Any]]) -> Callable[..., Response]:
def new_func(*args: Any, **kwargs: Any) -> Response:
def generate() -> Iterator[bytes]:
for event in chain(f(*args, **kwargs), (None,)):
yield ("data: %s\n\n" % json.dumps(event)).encode()
return Response(
generate(), mimetype="text/event-stream", direct_passthrough=True
)
return update_wrapper(new_func, f)
| 26,592 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/admin/context.py
|
get_lektor_context
|
()
|
return g.lektor_context
| 84 | 90 |
def get_lektor_context() -> LektorContext:
if not hasattr(g, "lektor_context"):
assert isinstance(current_app, LektorApp)
lektor_info = current_app.lektor_info
# pylint: disable=assigning-non-slot
g.lektor_context = LektorContext._make(lektor_info)
return g.lektor_context
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/admin/context.py#L84-L90
| 40 |
[
0,
1,
2,
3,
4,
5,
6
] | 100 |
[] | 0 | true | 98.305085 | 7 | 3 | 100 | 0 |
def get_lektor_context() -> LektorContext:
if not hasattr(g, "lektor_context"):
assert isinstance(current_app, LektorApp)
lektor_info = current_app.lektor_info
# pylint: disable=assigning-non-slot
g.lektor_context = LektorContext._make(lektor_info)
return g.lektor_context
| 26,593 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/admin/context.py
|
LektorContext.project_id
|
(self)
|
return self.env.project.id
| 41 | 42 |
def project_id(self) -> str:
return self.env.project.id
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/admin/context.py#L41-L42
| 40 |
[
0,
1
] | 100 |
[] | 0 | true | 98.305085 | 2 | 1 | 100 | 0 |
def project_id(self) -> str:
return self.env.project.id
| 26,594 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/admin/context.py
|
LektorContext.database
|
(self)
|
return Database(self.env)
| 45 | 46 |
def database(self) -> Database:
return Database(self.env)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/admin/context.py#L45-L46
| 40 |
[
0,
1
] | 100 |
[] | 0 | true | 98.305085 | 2 | 1 | 100 | 0 |
def database(self) -> Database:
return Database(self.env)
| 26,595 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/admin/context.py
|
LektorContext.pad
|
(self)
|
return self.database.new_pad()
| 49 | 50 |
def pad(self) -> Pad:
return self.database.new_pad()
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/admin/context.py#L49-L50
| 40 |
[
0,
1
] | 100 |
[] | 0 | true | 98.305085 | 2 | 1 | 100 | 0 |
def pad(self) -> Pad:
return self.database.new_pad()
| 26,596 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/admin/context.py
|
LektorContext.tree
|
(self)
|
return Tree(self.pad)
| 53 | 54 |
def tree(self) -> Tree:
return Tree(self.pad)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/admin/context.py#L53-L54
| 40 |
[
0,
1
] | 100 |
[] | 0 | true | 98.305085 | 2 | 1 | 100 | 0 |
def tree(self) -> Tree:
return Tree(self.pad)
| 26,597 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/admin/context.py
|
LektorContext.config
|
(self)
|
return self.database.config
| 57 | 58 |
def config(self) -> Config:
return self.database.config
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/admin/context.py#L57-L58
| 40 |
[
0,
1
] | 100 |
[] | 0 | true | 98.305085 | 2 | 1 | 100 | 0 |
def config(self) -> Config:
return self.database.config
| 26,598 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/admin/context.py
|
LektorContext.builder
|
(self)
|
return Builder(self.pad, self.output_path, extra_flags=self.extra_flags)
| 61 | 62 |
def builder(self) -> Builder:
return Builder(self.pad, self.output_path, extra_flags=self.extra_flags)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/admin/context.py#L61-L62
| 40 |
[
0,
1
] | 100 |
[] | 0 | true | 98.305085 | 2 | 1 | 100 | 0 |
def builder(self) -> Builder:
return Builder(self.pad, self.output_path, extra_flags=self.extra_flags)
| 26,599 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/admin/context.py
|
LektorContext.failure_controller
|
(self)
|
return FailureController(self.pad, self.output_path)
| 65 | 66 |
def failure_controller(self) -> FailureController:
return FailureController(self.pad, self.output_path)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/admin/context.py#L65-L66
| 40 |
[
0,
1
] | 100 |
[] | 0 | true | 98.305085 | 2 | 1 | 100 | 0 |
def failure_controller(self) -> FailureController:
return FailureController(self.pad, self.output_path)
| 26,600 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/admin/context.py
|
LektorContext.cli_reporter
|
(self)
|
return CliReporter(self.env, verbosity=self.verbosity)
| 68 | 69 |
def cli_reporter(self) -> CliReporter:
return CliReporter(self.env, verbosity=self.verbosity)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/admin/context.py#L68-L69
| 40 |
[
0,
1
] | 100 |
[] | 0 | true | 98.305085 | 2 | 1 | 100 | 0 |
def cli_reporter(self) -> CliReporter:
return CliReporter(self.env, verbosity=self.verbosity)
| 26,601 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/admin/context.py
|
LektorApp.__init__
|
(
self,
lektor_info: LektorInfo,
**kwargs: Any,
)
| 75 | 81 |
def __init__(
self,
lektor_info: LektorInfo,
**kwargs: Any,
) -> None:
Flask.__init__(self, "lektor.admin", **kwargs)
self.lektor_info = lektor_info
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/admin/context.py#L75-L81
| 40 |
[
0,
5,
6
] | 42.857143 |
[] | 0 | false | 98.305085 | 7 | 1 | 100 | 0 |
def __init__(
self,
lektor_info: LektorInfo,
**kwargs: Any,
) -> None:
Flask.__init__(self, "lektor.admin", **kwargs)
self.lektor_info = lektor_info
| 26,602 |
|||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/admin/webui.py
|
_common_configuration
|
(app: Flask, debug: bool = False)
| 24 | 26 |
def _common_configuration(app: Flask, debug: bool = False) -> None:
app.debug = debug
app.config["PROPAGATE_EXCEPTIONS"] = True
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/admin/webui.py#L24-L26
| 40 |
[
0,
1,
2
] | 100 |
[] | 0 | true | 91.666667 | 3 | 1 | 100 | 0 |
def _common_configuration(app: Flask, debug: bool = False) -> None:
app.debug = debug
app.config["PROPAGATE_EXCEPTIONS"] = True
| 26,603 |
|||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/admin/webui.py
|
make_app
|
(
env: Environment,
debug: bool = False,
output_path: Optional[Union[str, "os.PathLike[Any]"]] = None,
ui_lang: str = "en",
verbosity: int = 0,
extra_flags: Optional[Sequence[str]] = None,
reload: bool = True,
*,
admin_path: str = "/admin",
)
|
return app
| 29 | 80 |
def make_app(
env: Environment,
debug: bool = False,
output_path: Optional[Union[str, "os.PathLike[Any]"]] = None,
ui_lang: str = "en",
verbosity: int = 0,
extra_flags: Optional[Sequence[str]] = None,
reload: bool = True,
*,
admin_path: str = "/admin",
) -> LektorApp:
if output_path is None:
output_path = env.project.get_output_path()
lektor_info = LektorInfo(env, output_path, verbosity, extra_flags)
# The top-level app has a route that matches anything
# ("/<path:path>" in the serve blueprint). That means that if
# there is another route whose doesn't match based on request
# method, the serve view will take over and try to serve it. To
# prevent this from happening for the paths under /admin, we
# structure them as a separate flask app.
admin_app = LektorApp(lektor_info)
_common_configuration(admin_app, debug=debug)
admin_app.config["lektor.ui_lang"] = ui_lang
admin_app.register_blueprint(dash.bp, url_prefix="/")
admin_app.register_blueprint(api.bp, url_prefix="/api")
# Serve static files from top-level app
app = LektorApp(lektor_info, static_url_path=f"{admin_path}/static")
_common_configuration(app, debug=debug)
app.config["ENABLE_LIVERELOAD"] = reload
if reload:
app.register_blueprint(livereload.bp, url_prefix="/__reload__")
app.register_blueprint(serve.bp)
# Pass requests for /admin/... to the admin app
@app.route(f"{admin_path}/", defaults={"page": ""})
@app.route(f"{admin_path}/<path:page>", methods=["GET", "POST", "PUT"])
def admin_view(page: str) -> "WSGIApplication":
environ = request.environ
# Save top-level SCRIPT_NAME (used by dash)
environ["lektor.site_root"] = request.root_path
while environ.get("PATH_INFO", "") != f"/{page}":
assert environ["PATH_INFO"]
shift_path_info(request.environ)
return admin_app.wsgi_app
# Add rule to construct URL to /admin/edit
app.add_url_rule(f"{admin_path}/edit", "url.edit", build_only=True)
return app
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/admin/webui.py#L29-L80
| 40 |
[
0,
11,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
25,
26,
27,
28,
29,
30,
31,
32,
33,
34,
35,
36,
37,
38,
39,
40,
41,
42,
43,
44,
45,
46,
47,
48,
49,
50,
51
] | 78.846154 |
[
12
] | 1.923077 | false | 91.666667 | 52 | 6 | 98.076923 | 0 |
def make_app(
env: Environment,
debug: bool = False,
output_path: Optional[Union[str, "os.PathLike[Any]"]] = None,
ui_lang: str = "en",
verbosity: int = 0,
extra_flags: Optional[Sequence[str]] = None,
reload: bool = True,
*,
admin_path: str = "/admin",
) -> LektorApp:
if output_path is None:
output_path = env.project.get_output_path()
lektor_info = LektorInfo(env, output_path, verbosity, extra_flags)
# The top-level app has a route that matches anything
# ("/<path:path>" in the serve blueprint). That means that if
# there is another route whose doesn't match based on request
# method, the serve view will take over and try to serve it. To
# prevent this from happening for the paths under /admin, we
# structure them as a separate flask app.
admin_app = LektorApp(lektor_info)
_common_configuration(admin_app, debug=debug)
admin_app.config["lektor.ui_lang"] = ui_lang
admin_app.register_blueprint(dash.bp, url_prefix="/")
admin_app.register_blueprint(api.bp, url_prefix="/api")
# Serve static files from top-level app
app = LektorApp(lektor_info, static_url_path=f"{admin_path}/static")
_common_configuration(app, debug=debug)
app.config["ENABLE_LIVERELOAD"] = reload
if reload:
app.register_blueprint(livereload.bp, url_prefix="/__reload__")
app.register_blueprint(serve.bp)
# Pass requests for /admin/... to the admin app
@app.route(f"{admin_path}/", defaults={"page": ""})
@app.route(f"{admin_path}/<path:page>", methods=["GET", "POST", "PUT"])
def admin_view(page: str) -> "WSGIApplication":
environ = request.environ
# Save top-level SCRIPT_NAME (used by dash)
environ["lektor.site_root"] = request.root_path
while environ.get("PATH_INFO", "") != f"/{page}":
assert environ["PATH_INFO"]
shift_path_info(request.environ)
return admin_app.wsgi_app
# Add rule to construct URL to /admin/edit
app.add_url_rule(f"{admin_path}/edit", "url.edit", build_only=True)
return app
| 26,604 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/admin/modules/livereload.py
|
events
|
()
| 20 | 30 |
def events():
events = queue.Queue()
with reporter.on_build_change(events.put):
while True:
yield {"type": "ping", "versionId": version_id}
try:
change = events.get(timeout=PING_DELAY)
except queue.Empty:
continue
yield {"type": "reload", "path": change.artifact_name}
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/admin/modules/livereload.py#L20-L30
| 40 |
[
0
] | 9.090909 |
[
1,
2,
3,
4,
6,
7,
8,
9,
10
] | 81.818182 | false | 60 | 11 | 4 | 18.181818 | 0 |
def events():
events = queue.Queue()
with reporter.on_build_change(events.put):
while True:
yield {"type": "ping", "versionId": version_id}
try:
change = events.get(timeout=PING_DELAY)
except queue.Empty:
continue
yield {"type": "reload", "path": change.artifact_name}
| 26,605 |
|||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/admin/modules/livereload.py
|
worker_script
|
()
|
return (
render_template("livereload-worker.js", events_url=url_for(".events")),
200,
{"Content-Type": "text/javascript"},
)
| 34 | 39 |
def worker_script():
return (
render_template("livereload-worker.js", events_url=url_for(".events")),
200,
{"Content-Type": "text/javascript"},
)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/admin/modules/livereload.py#L34-L39
| 40 |
[
0
] | 16.666667 |
[
1
] | 16.666667 | false | 60 | 6 | 1 | 83.333333 | 0 |
def worker_script():
return (
render_template("livereload-worker.js", events_url=url_for(".events")),
200,
{"Content-Type": "text/javascript"},
)
| 26,606 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/admin/modules/api.py
|
pass_lektor_context
|
(
endpoint: Optional[str], values: Optional[Dict[str, Any]]
)
|
Pass LektorContext to each view callable in a `ctx` parameter
|
Pass LektorContext to each view callable in a `ctx` parameter
| 41 | 46 |
def pass_lektor_context(
endpoint: Optional[str], values: Optional[Dict[str, Any]]
) -> None:
"""Pass LektorContext to each view callable in a `ctx` parameter"""
assert isinstance(values, dict)
values["ctx"] = get_lektor_context()
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/admin/modules/api.py#L41-L46
| 40 |
[
0,
3,
4,
5
] | 66.666667 |
[] | 0 | false | 86.85259 | 6 | 2 | 100 | 1 |
def pass_lektor_context(
endpoint: Optional[str], values: Optional[Dict[str, Any]]
) -> None:
assert isinstance(values, dict)
values["ctx"] = get_lektor_context()
| 26,607 |
|
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/admin/modules/api.py
|
_is_valid_alt
|
(value: str)
|
return bool(lektor_config.is_valid_alternative(value))
| 65 | 67 |
def _is_valid_alt(value: str) -> bool:
lektor_config = get_lektor_context().config
return bool(lektor_config.is_valid_alternative(value))
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/admin/modules/api.py#L65-L67
| 40 |
[
0,
1,
2
] | 100 |
[] | 0 | true | 86.85259 | 3 | 1 | 100 | 0 |
def _is_valid_alt(value: str) -> bool:
lektor_config = get_lektor_context().config
return bool(lektor_config.is_valid_alternative(value))
| 26,608 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/admin/modules/api.py
|
_with_validated
|
(param_type: type)
|
return wrap
|
Flask view decorator to validate parameters.
The validated parameters are placed into the ``validated`` keyword
arg of the decorated view.
If the request has a JSON body, the parameters are parsed from that.
Otherwise, the parameters are parsed from ``request.values``.
:param param_type: A dataclass which specifies the parameters.
|
Flask view decorator to validate parameters.
| 86 | 127 |
def _with_validated(param_type: type) -> Callable[[F], F]:
"""Flask view decorator to validate parameters.
The validated parameters are placed into the ``validated`` keyword
arg of the decorated view.
If the request has a JSON body, the parameters are parsed from that.
Otherwise, the parameters are parsed from ``request.values``.
:param param_type: A dataclass which specifies the parameters.
"""
schema_class = mdcls.class_schema(param_type, base_schema=_SchemaBase)
schema = schema_class()
def wrap(f: F) -> F:
@wraps(f)
def wrapper(*args: Any, **kwargs: Any) -> Response:
if (
request.method in ("POST", "PUT")
and request.mimetype == "application/json"
):
data = request.get_json() or {}
else:
data = request.values
schema.context = {
"lektor_config": kwargs["ctx"].config,
}
try:
kwargs["validated"] = schema.load(data)
except marshmallow.ValidationError as exc:
error = {
"title": "Invalid parameters",
"messages": exc.messages,
}
return make_response(jsonify(error=error), 400)
return f(*args, **kwargs)
# This cast seems necessary, atm.
# https://github.com/python/mypy/issues/1927
return cast(F, wrapper)
return wrap
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/admin/modules/api.py#L86-L127
| 40 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
25,
26,
27,
28,
29,
30,
31,
32,
33,
34,
35,
36,
37,
38,
39,
40,
41
] | 100 |
[] | 0 | true | 86.85259 | 42 | 7 | 100 | 9 |
def _with_validated(param_type: type) -> Callable[[F], F]:
schema_class = mdcls.class_schema(param_type, base_schema=_SchemaBase)
schema = schema_class()
def wrap(f: F) -> F:
@wraps(f)
def wrapper(*args: Any, **kwargs: Any) -> Response:
if (
request.method in ("POST", "PUT")
and request.mimetype == "application/json"
):
data = request.get_json() or {}
else:
data = request.values
schema.context = {
"lektor_config": kwargs["ctx"].config,
}
try:
kwargs["validated"] = schema.load(data)
except marshmallow.ValidationError as exc:
error = {
"title": "Invalid parameters",
"messages": exc.messages,
}
return make_response(jsonify(error=error), 400)
return f(*args, **kwargs)
# This cast seems necessary, atm.
# https://github.com/python/mypy/issues/1927
return cast(F, wrapper)
return wrap
| 26,609 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/admin/modules/api.py
|
get_path_info
|
(validated: _PathAndAlt, ctx: LektorContext)
|
return jsonify(segments=segments)
|
Returns the path segment information for a record.
|
Returns the path segment information for a record.
| 138 | 157 |
def get_path_info(validated: _PathAndAlt, ctx: LektorContext) -> Response:
"""Returns the path segment information for a record."""
alt = validated.alt
tree_item = ctx.tree.get(validated.path)
segments = []
while tree_item is not None:
segments.append(
{
"id": tree_item.id,
"path": tree_item.path,
"label_i18n": tree_item.get_record_label_i18n(alt),
"exists": tree_item.exists,
"can_have_children": tree_item.can_have_children,
}
)
tree_item = tree_item.get_parent()
segments.reverse()
return jsonify(segments=segments)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/admin/modules/api.py#L138-L157
| 40 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19
] | 100 |
[] | 0 | true | 86.85259 | 20 | 2 | 100 | 1 |
def get_path_info(validated: _PathAndAlt, ctx: LektorContext) -> Response:
alt = validated.alt
tree_item = ctx.tree.get(validated.path)
segments = []
while tree_item is not None:
segments.append(
{
"id": tree_item.id,
"path": tree_item.path,
"label_i18n": tree_item.get_record_label_i18n(alt),
"exists": tree_item.exists,
"can_have_children": tree_item.can_have_children,
}
)
tree_item = tree_item.get_parent()
segments.reverse()
return jsonify(segments=segments)
| 26,610 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/admin/modules/api.py
|
get_record_info
|
(validated: _PathAndAlt, ctx: LektorContext)
|
return jsonify(
id=tree_item.id,
path=tree_item.path,
label_i18n=tree_item.get_record_label_i18n(alt),
exists=tree_item.exists,
is_attachment=tree_item.is_attachment,
attachments=[
{
"id": x.id,
"path": x.path,
"type": x.attachment_type,
}
for x in tree_item.iter_attachments()
],
children=[
{
"id": x.id,
"path": x.path,
"label": x.id,
"label_i18n": x.get_record_label_i18n(alt),
"visible": x.is_visible,
}
for x in tree_item.iter_subpages()
],
alts=[
{
"alt": _.id,
"is_primary": _.id == PRIMARY_ALT,
"primary_overlay": _.is_primary_overlay,
"name_i18n": _.name_i18n,
"exists": _.exists,
}
for _ in tree_item.alts.values()
],
can_have_children=tree_item.can_have_children,
can_have_attachments=tree_item.can_have_attachments,
can_be_deleted=tree_item.can_be_deleted,
)
| 162 | 203 |
def get_record_info(validated: _PathAndAlt, ctx: LektorContext) -> Response:
alt = validated.alt
tree_item = ctx.tree.get(validated.path)
return jsonify(
id=tree_item.id,
path=tree_item.path,
label_i18n=tree_item.get_record_label_i18n(alt),
exists=tree_item.exists,
is_attachment=tree_item.is_attachment,
attachments=[
{
"id": x.id,
"path": x.path,
"type": x.attachment_type,
}
for x in tree_item.iter_attachments()
],
children=[
{
"id": x.id,
"path": x.path,
"label": x.id,
"label_i18n": x.get_record_label_i18n(alt),
"visible": x.is_visible,
}
for x in tree_item.iter_subpages()
],
alts=[
{
"alt": _.id,
"is_primary": _.id == PRIMARY_ALT,
"primary_overlay": _.is_primary_overlay,
"name_i18n": _.name_i18n,
"exists": _.exists,
}
for _ in tree_item.alts.values()
],
can_have_children=tree_item.can_have_children,
can_have_attachments=tree_item.can_have_attachments,
can_be_deleted=tree_item.can_be_deleted,
)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/admin/modules/api.py#L162-L203
| 40 |
[
0,
1,
2,
3,
4
] | 11.904762 |
[] | 0 | false | 86.85259 | 42 | 4 | 100 | 0 |
def get_record_info(validated: _PathAndAlt, ctx: LektorContext) -> Response:
alt = validated.alt
tree_item = ctx.tree.get(validated.path)
return jsonify(
id=tree_item.id,
path=tree_item.path,
label_i18n=tree_item.get_record_label_i18n(alt),
exists=tree_item.exists,
is_attachment=tree_item.is_attachment,
attachments=[
{
"id": x.id,
"path": x.path,
"type": x.attachment_type,
}
for x in tree_item.iter_attachments()
],
children=[
{
"id": x.id,
"path": x.path,
"label": x.id,
"label_i18n": x.get_record_label_i18n(alt),
"visible": x.is_visible,
}
for x in tree_item.iter_subpages()
],
alts=[
{
"alt": _.id,
"is_primary": _.id == PRIMARY_ALT,
"primary_overlay": _.is_primary_overlay,
"name_i18n": _.name_i18n,
"exists": _.exists,
}
for _ in tree_item.alts.values()
],
can_have_children=tree_item.can_have_children,
can_have_attachments=tree_item.can_have_attachments,
can_be_deleted=tree_item.can_be_deleted,
)
| 26,611 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/admin/modules/api.py
|
get_preview_info
|
(validated: _PathAndAlt, ctx: LektorContext)
|
return jsonify(exists=True, url=record.url_path, is_hidden=record.is_hidden)
| 208 | 212 |
def get_preview_info(validated: _PathAndAlt, ctx: LektorContext) -> Response:
record = ctx.pad.get(validated.path, alt=validated.alt)
if record is None:
return jsonify(exists=False, url=None, is_hidden=True)
return jsonify(exists=True, url=record.url_path, is_hidden=record.is_hidden)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/admin/modules/api.py#L208-L212
| 40 |
[
0,
1,
2,
3,
4
] | 100 |
[] | 0 | true | 86.85259 | 5 | 2 | 100 | 0 |
def get_preview_info(validated: _PathAndAlt, ctx: LektorContext) -> Response:
record = ctx.pad.get(validated.path, alt=validated.alt)
if record is None:
return jsonify(exists=False, url=None, is_hidden=True)
return jsonify(exists=True, url=record.url_path, is_hidden=record.is_hidden)
| 26,612 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/admin/modules/api.py
|
find
|
(validated: _FindParams, ctx: LektorContext)
|
return jsonify(
results=ctx.builder.find_files(validated.q, alt=validated.alt, lang=lang)
)
| 224 | 228 |
def find(validated: _FindParams, ctx: LektorContext) -> Response:
lang = validated.lang or current_app.config.get("lektor.ui_lang", "en")
return jsonify(
results=ctx.builder.find_files(validated.q, alt=validated.alt, lang=lang)
)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/admin/modules/api.py#L224-L228
| 40 |
[
0,
1,
2
] | 60 |
[] | 0 | false | 86.85259 | 5 | 2 | 100 | 0 |
def find(validated: _FindParams, ctx: LektorContext) -> Response:
lang = validated.lang or current_app.config.get("lektor.ui_lang", "en")
return jsonify(
results=ctx.builder.find_files(validated.q, alt=validated.alt, lang=lang)
)
| 26,613 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.