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/pagination.py
|
Pagination.pages
|
(self)
|
return max(pages, 1)
|
The total number of pages.
|
The total number of pages.
| 20 | 24 |
def pages(self):
"""The total number of pages."""
pages = (self.total + self.per_page - 1) // self.per_page
# Even when there are no children, we want at least one page
return max(pages, 1)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/pagination.py#L20-L24
| 40 |
[
0,
1,
2,
3,
4
] | 100 |
[] | 0 | true | 98.148148 | 5 | 1 | 100 | 1 |
def pages(self):
pages = (self.total + self.per_page - 1) // self.per_page
# Even when there are no children, we want at least one page
return max(pages, 1)
| 26,414 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/pagination.py
|
Pagination.prev_num
|
(self)
|
return None
|
The page number of the previous page.
|
The page number of the previous page.
| 27 | 31 |
def prev_num(self):
"""The page number of the previous page."""
if self.page > 1:
return self.page - 1
return None
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/pagination.py#L27-L31
| 40 |
[
0,
1,
2,
4
] | 80 |
[
3
] | 20 | false | 98.148148 | 5 | 2 | 80 | 1 |
def prev_num(self):
if self.page > 1:
return self.page - 1
return None
| 26,415 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/pagination.py
|
Pagination.has_prev
|
(self)
|
return self.page > 1
|
True if a previous page exists.
|
True if a previous page exists.
| 34 | 36 |
def has_prev(self):
"""True if a previous page exists."""
return self.page > 1
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/pagination.py#L34-L36
| 40 |
[
0,
1,
2
] | 100 |
[] | 0 | true | 98.148148 | 3 | 1 | 100 | 1 |
def has_prev(self):
return self.page > 1
| 26,416 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/pagination.py
|
Pagination.prev
|
(self)
|
return self.config.get_record_for_page(self.current, self.page - 1)
|
The record for the previous page.
|
The record for the previous page.
| 39 | 43 |
def prev(self):
"""The record for the previous page."""
if not self.has_prev:
return None
return self.config.get_record_for_page(self.current, self.page - 1)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/pagination.py#L39-L43
| 40 |
[
0,
1,
2,
3,
4
] | 100 |
[] | 0 | true | 98.148148 | 5 | 2 | 100 | 1 |
def prev(self):
if not self.has_prev:
return None
return self.config.get_record_for_page(self.current, self.page - 1)
| 26,417 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/pagination.py
|
Pagination.has_next
|
(self)
|
return self.page < self.pages
|
True if a following page exists.
|
True if a following page exists.
| 46 | 48 |
def has_next(self):
"""True if a following page exists."""
return self.page < self.pages
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/pagination.py#L46-L48
| 40 |
[
0,
1,
2
] | 100 |
[] | 0 | true | 98.148148 | 3 | 1 | 100 | 1 |
def has_next(self):
return self.page < self.pages
| 26,418 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/pagination.py
|
Pagination.next_num
|
(self)
|
return None
|
The page number of the following page.
|
The page number of the following page.
| 51 | 55 |
def next_num(self):
"""The page number of the following page."""
if self.page < self.pages:
return self.page + 1
return None
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/pagination.py#L51-L55
| 40 |
[
0,
1,
2,
3,
4
] | 100 |
[] | 0 | true | 98.148148 | 5 | 2 | 100 | 1 |
def next_num(self):
if self.page < self.pages:
return self.page + 1
return None
| 26,419 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/pagination.py
|
Pagination.next
|
(self)
|
return self.config.get_record_for_page(self.current, self.page + 1)
|
The record for the following page.
|
The record for the following page.
| 58 | 62 |
def next(self):
"""The record for the following page."""
if not self.has_next:
return None
return self.config.get_record_for_page(self.current, self.page + 1)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/pagination.py#L58-L62
| 40 |
[
0,
1,
2,
3,
4
] | 100 |
[] | 0 | true | 98.148148 | 5 | 2 | 100 | 1 |
def next(self):
if not self.has_next:
return None
return self.config.get_record_for_page(self.current, self.page + 1)
| 26,420 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/pagination.py
|
Pagination.for_page
|
(self, page)
|
return None
|
Returns the record for a specific page.
|
Returns the record for a specific page.
| 64 | 68 |
def for_page(self, page):
"""Returns the record for a specific page."""
if 1 <= page <= self.pages:
return self.config.get_record_for_page(self.current, page)
return None
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/pagination.py#L64-L68
| 40 |
[
0,
1,
2,
3,
4
] | 100 |
[] | 0 | true | 98.148148 | 5 | 2 | 100 | 1 |
def for_page(self, page):
if 1 <= page <= self.pages:
return self.config.get_record_for_page(self.current, page)
return None
| 26,421 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/pagination.py
|
Pagination.iter_pages
|
(self, left_edge=2, left_current=2, right_current=5, right_edge=2)
|
Iterate over the page numbers in the pagination, with elision.
In the general case, this returns the concatenation of three ranges:
1. A range (always starting at page one) at the beginning
of the page number sequence. The length of the this
range is specified by the ``left_edge`` argument (which
may be zero).
2. A range around the current page. This range will
include ``left_current`` pages before, and
``right_current`` pages after the current page. This
range always includes the current page.
3. Finally, a range (always ending at the last page) at
the end of the page sequence. The length of this range
is specified by the ``right_edge`` argument.
If any of these ranges overlap, they will be merged. A
``None`` will be inserted between non-overlapping ranges to
signify that pages have been elided.
This is how you could render such a pagination in the templates:
.. sourcecode:: html+jinja
{% macro render_pagination(pagination, endpoint) %}
<div class=pagination>
{%- for page in pagination.iter_pages() %}
{% if page %}
{% if page != pagination.page %}
<a href="{{ url_for(endpoint, page=page) }}">{{ page }}</a>
{% else %}
<strong>{{ page }}</strong>
{% endif %}
{% else %}
<span class=ellipsis>...</span>
{% endif %}
{%- endfor %}
</div>
{% endmacro %}
|
Iterate over the page numbers in the pagination, with elision.
| 70 | 127 |
def iter_pages(self, left_edge=2, left_current=2, right_current=5, right_edge=2):
"""Iterate over the page numbers in the pagination, with elision.
In the general case, this returns the concatenation of three ranges:
1. A range (always starting at page one) at the beginning
of the page number sequence. The length of the this
range is specified by the ``left_edge`` argument (which
may be zero).
2. A range around the current page. This range will
include ``left_current`` pages before, and
``right_current`` pages after the current page. This
range always includes the current page.
3. Finally, a range (always ending at the last page) at
the end of the page sequence. The length of this range
is specified by the ``right_edge`` argument.
If any of these ranges overlap, they will be merged. A
``None`` will be inserted between non-overlapping ranges to
signify that pages have been elided.
This is how you could render such a pagination in the templates:
.. sourcecode:: html+jinja
{% macro render_pagination(pagination, endpoint) %}
<div class=pagination>
{%- for page in pagination.iter_pages() %}
{% if page %}
{% if page != pagination.page %}
<a href="{{ url_for(endpoint, page=page) }}">{{ page }}</a>
{% else %}
<strong>{{ page }}</strong>
{% endif %}
{% else %}
<span class=ellipsis>...</span>
{% endif %}
{%- endfor %}
</div>
{% endmacro %}
"""
last = 0
for num in range(1, self.pages + 1):
# pylint: disable=chained-comparison
if (
num <= left_edge
or (
num >= self.page - left_current and num <= self.page + right_current
)
or num > self.pages - right_edge
):
if last + 1 != num:
yield None
yield num
last = num
if last != self.pages:
yield None
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/pagination.py#L70-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,
42,
43,
44,
45,
46,
47,
48,
49,
50,
51,
52,
53,
54,
55,
56,
57
] | 100 |
[] | 0 | true | 98.148148 | 58 | 8 | 100 | 39 |
def iter_pages(self, left_edge=2, left_current=2, right_current=5, right_edge=2):
last = 0
for num in range(1, self.pages + 1):
# pylint: disable=chained-comparison
if (
num <= left_edge
or (
num >= self.page - left_current and num <= self.page + right_current
)
or num > self.pages - right_edge
):
if last + 1 != num:
yield None
yield num
last = num
if last != self.pages:
yield None
| 26,422 |
|
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/devcli.py
|
ensure_plugin
|
()
|
return info
| 21 | 30 |
def ensure_plugin():
here = os.getcwd()
if not os.path.isfile(os.path.join(here, "setup.py")):
raise click.UsageError("This command must be run in a Lektor plugin folder")
info = get_package_info(here)
if not info["name"].lower().startswith("lektor-"):
raise click.UsageError(
"Python package is misnamed. Needs to start with lektor-"
)
return info
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/devcli.py#L21-L30
| 40 |
[
0
] | 10 |
[
1,
2,
3,
4,
5,
6,
9
] | 70 | false | 45.714286 | 10 | 3 | 30 | 0 |
def ensure_plugin():
here = os.getcwd()
if not os.path.isfile(os.path.join(here, "setup.py")):
raise click.UsageError("This command must be run in a Lektor plugin folder")
info = get_package_info(here)
if not info["name"].lower().startswith("lektor-"):
raise click.UsageError(
"Python package is misnamed. Needs to start with lektor-"
)
return info
| 26,423 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/devcli.py
|
cli
|
()
|
Development commands for Lektor.
This provides various development support commands for Lektor. This is
primarily useful for Lektor plugin development but also if you want to
extend Lektor itself. Additional functionality can be unlocked by
exporting the `LEKTOR_DEV=1` environment variable.
|
Development commands for Lektor.
| 34 | 41 |
def cli():
"""Development commands for Lektor.
This provides various development support commands for Lektor. This is
primarily useful for Lektor plugin development but also if you want to
extend Lektor itself. Additional functionality can be unlocked by
exporting the `LEKTOR_DEV=1` environment variable.
"""
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/devcli.py#L34-L41
| 40 |
[
0,
1,
2,
3,
4,
5,
6,
7
] | 100 |
[] | 0 | true | 45.714286 | 8 | 1 | 100 | 6 |
def cli():
| 26,424 |
|
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/devcli.py
|
shell_cmd
|
(ctx, extra_flags)
|
Starts a Python shell in the context of a Lektor project.
This is particularly useful for debugging plugins and to explore the
API. To quit the shell just use `quit()`. Within the shell various
utilities are available right from the get-go for you.
\b
- `project`: the loaded project as object.
- `env`: an environment for the loaded project.
- `pad`: a database pad initialized for the project and environment
that is ready to use.
|
Starts a Python shell in the context of a Lektor project.
| 47 | 92 |
def shell_cmd(ctx, extra_flags):
"""Starts a Python shell in the context of a Lektor project.
This is particularly useful for debugging plugins and to explore the
API. To quit the shell just use `quit()`. Within the shell various
utilities are available right from the get-go for you.
\b
- `project`: the loaded project as object.
- `env`: an environment for the loaded project.
- `pad`: a database pad initialized for the project and environment
that is ready to use.
"""
ctx.load_plugins(extra_flags=extra_flags)
import code
from lektor.db import F, Tree
from lektor.builder import Builder
banner = "Python %s on %s\nLektor Project: %s" % (
sys.version,
sys.platform,
ctx.get_env().root_path,
)
ns = {}
startup = os.environ.get("PYTHONSTARTUP")
if startup and os.path.isfile(startup):
with open(startup, "r", encoding="utf-8") as f:
eval(compile(f.read(), startup, "exec"), ns) # pylint: disable=eval-used
pad = ctx.get_env().new_pad()
ns.update(
project=ctx.get_project(),
env=ctx.get_env(),
pad=pad,
tree=Tree(pad),
config=ctx.get_env().load_config(),
make_builder=lambda: Builder(
ctx.get_env().new_pad(), ctx.get_default_output_path()
),
F=F,
)
try:
c = Config()
c.TerminalInteractiveShell.banner2 = banner
embed(config=c, user_ns=ns)
except NameError: # No IPython
code.interact(banner=banner, local=ns)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/devcli.py#L47-L92
| 40 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12
] | 28.26087 |
[
13,
14,
15,
16,
18,
23,
24,
25,
26,
27,
28,
29,
40,
41,
42,
43,
44,
45
] | 39.130435 | false | 45.714286 | 46 | 5 | 60.869565 | 11 |
def shell_cmd(ctx, extra_flags):
ctx.load_plugins(extra_flags=extra_flags)
import code
from lektor.db import F, Tree
from lektor.builder import Builder
banner = "Python %s on %s\nLektor Project: %s" % (
sys.version,
sys.platform,
ctx.get_env().root_path,
)
ns = {}
startup = os.environ.get("PYTHONSTARTUP")
if startup and os.path.isfile(startup):
with open(startup, "r", encoding="utf-8") as f:
eval(compile(f.read(), startup, "exec"), ns) # pylint: disable=eval-used
pad = ctx.get_env().new_pad()
ns.update(
project=ctx.get_project(),
env=ctx.get_env(),
pad=pad,
tree=Tree(pad),
config=ctx.get_env().load_config(),
make_builder=lambda: Builder(
ctx.get_env().new_pad(), ctx.get_default_output_path()
),
F=F,
)
try:
c = Config()
c.TerminalInteractiveShell.banner2 = banner
embed(config=c, user_ns=ns)
except NameError: # No IPython
code.interact(banner=banner, local=ns)
| 26,425 |
|
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/devcli.py
|
publish_plugin_cmd
|
()
|
Publishes the current version of the plugin in the current folder.
This generally requires that your setup.py has at least the bare minimum
configuration for valid publishing to PyPI.
|
Publishes the current version of the plugin in the current folder.
| 96 | 109 |
def publish_plugin_cmd():
"""Publishes the current version of the plugin in the current folder.
This generally requires that your setup.py has at least the bare minimum
configuration for valid publishing to PyPI.
"""
info = ensure_plugin()
for key in "author", "author_email", "license", "url":
if not info[key]:
raise click.UsageError(
"Cannot publish plugin without setting " '"%s" in setup.py.' % key
)
register_package(info["path"])
publish_package(info["path"])
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/devcli.py#L96-L109
| 40 |
[
0,
1,
2,
3,
4,
5
] | 42.857143 |
[
6,
7,
8,
9,
12,
13
] | 42.857143 | false | 45.714286 | 14 | 3 | 57.142857 | 4 |
def publish_plugin_cmd():
info = ensure_plugin()
for key in "author", "author_email", "license", "url":
if not info[key]:
raise click.UsageError(
"Cannot publish plugin without setting " '"%s" in setup.py.' % key
)
register_package(info["path"])
publish_package(info["path"])
| 26,426 |
|
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/devcli.py
|
new_plugin
|
(ctx, **defaults)
|
This command creates a new plugin.
This will present you with a very short wizard that guides you through
creation of a new plugin. At the end of it, it will create a plugin
in the packages folder of the current project or the path you defined.
This is the fastest way to creating a new plugin.
|
This command creates a new plugin.
| 116 | 128 |
def new_plugin(ctx, **defaults):
"""This command creates a new plugin.
This will present you with a very short wizard that guides you through
creation of a new plugin. At the end of it, it will create a plugin
in the packages folder of the current project or the path you defined.
This is the fastest way to creating a new plugin.
"""
from .quickstart import plugin_quickstart
project = ctx.get_project(silent=True)
plugin_quickstart(defaults, project=project)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/devcli.py#L116-L128
| 40 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8
] | 69.230769 |
[
9,
11,
12
] | 23.076923 | false | 45.714286 | 13 | 1 | 76.923077 | 7 |
def new_plugin(ctx, **defaults):
from .quickstart import plugin_quickstart
project = ctx.get_project(silent=True)
plugin_quickstart(defaults, project=project)
| 26,427 |
|
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/devcli.py
|
new_theme
|
(ctx, **defaults)
|
This command creates a new theme.
This will present you with a very short wizard that guides you through
creation of a new theme. At the end of it, it will create a theme
in the packages folder of the current project or the path you defined.
This is the fastest way to creating a new theme.
|
This command creates a new theme.
| 135 | 147 |
def new_theme(ctx, **defaults):
"""This command creates a new theme.
This will present you with a very short wizard that guides you through
creation of a new theme. At the end of it, it will create a theme
in the packages folder of the current project or the path you defined.
This is the fastest way to creating a new theme.
"""
from .quickstart import theme_quickstart
project = ctx.get_project(silent=True)
theme_quickstart(defaults, project=project)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/devcli.py#L135-L147
| 40 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8
] | 69.230769 |
[
9,
11,
12
] | 23.076923 | false | 45.714286 | 13 | 1 | 76.923077 | 7 |
def new_theme(ctx, **defaults):
from .quickstart import theme_quickstart
project = ctx.get_project(silent=True)
theme_quickstart(defaults, project=project)
| 26,428 |
|
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/compat.py
|
_ensure_tree_writeable
|
(path: str)
|
Attempt to ensure that all files in the tree rooted at path are writeable.
|
Attempt to ensure that all files in the tree rooted at path are writeable.
| 11 | 31 |
def _ensure_tree_writeable(path: str) -> None:
"""Attempt to ensure that all files in the tree rooted at path are writeable."""
dirscans = []
def fix_mode(path, statfunc):
try:
# paranoia regarding symlink attacks
current_mode = statfunc(follow_symlinks=False).st_mode
if not stat.S_ISLNK(current_mode):
isdir = stat.S_ISDIR(current_mode)
fixed_mode = current_mode | (0o700 if isdir else 0o200)
if current_mode != fixed_mode:
os.chmod(path, fixed_mode)
if isdir:
dirscans.append(os.scandir(path))
except FileNotFoundError:
pass
fix_mode(path, partial(os.stat, path))
for entry in chain.from_iterable(dirscans):
fix_mode(entry.path, entry.stat)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/compat.py#L11-L31
| 40 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
17,
18,
19,
20
] | 90.47619 |
[
15,
16
] | 9.52381 | false | 87.878788 | 21 | 7 | 90.47619 | 1 |
def _ensure_tree_writeable(path: str) -> None:
dirscans = []
def fix_mode(path, statfunc):
try:
# paranoia regarding symlink attacks
current_mode = statfunc(follow_symlinks=False).st_mode
if not stat.S_ISLNK(current_mode):
isdir = stat.S_ISDIR(current_mode)
fixed_mode = current_mode | (0o700 if isdir else 0o200)
if current_mode != fixed_mode:
os.chmod(path, fixed_mode)
if isdir:
dirscans.append(os.scandir(path))
except FileNotFoundError:
pass
fix_mode(path, partial(os.stat, path))
for entry in chain.from_iterable(dirscans):
fix_mode(entry.path, entry.stat)
| 26,429 |
|
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/compat.py
|
FixedTemporaryDirectory.cleanup
|
(self)
| 47 | 49 |
def cleanup(self) -> None:
_ensure_tree_writeable(self.name)
super().cleanup()
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/compat.py#L47-L49
| 40 |
[
0,
1,
2
] | 100 |
[] | 0 | true | 87.878788 | 3 | 1 | 100 | 0 |
def cleanup(self) -> None:
_ensure_tree_writeable(self.name)
super().cleanup()
| 26,430 |
|||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/project.py
|
Project.__init__
|
(self, name, project_file, tree, themes=None)
| 15 | 20 |
def __init__(self, name, project_file, tree, themes=None):
self.name = name
self.project_file = project_file
self.tree = os.path.normpath(tree)
self.themes = themes or []
self.id = hashlib.md5(self.tree.encode("utf-8")).hexdigest()
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/project.py#L15-L20
| 40 |
[
0,
1,
2,
3,
4,
5
] | 100 |
[] | 0 | true | 61 | 6 | 2 | 100 | 0 |
def __init__(self, name, project_file, tree, themes=None):
self.name = name
self.project_file = project_file
self.tree = os.path.normpath(tree)
self.themes = themes or []
self.id = hashlib.md5(self.tree.encode("utf-8")).hexdigest()
| 26,431 |
|||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/project.py
|
Project.open_config
|
(self)
|
return IniFile(self.project_file)
| 22 | 25 |
def open_config(self):
if self.project_file is None:
raise RuntimeError("This project has no project file.")
return IniFile(self.project_file)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/project.py#L22-L25
| 40 |
[
0,
1,
3
] | 75 |
[
2
] | 25 | false | 61 | 4 | 2 | 75 | 0 |
def open_config(self):
if self.project_file is None:
raise RuntimeError("This project has no project file.")
return IniFile(self.project_file)
| 26,432 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/project.py
|
Project.from_file
|
(cls, filename)
|
return cls(
name=name,
project_file=filename,
tree=path,
themes=themes,
)
|
Reads a project from a project file.
|
Reads a project from a project file.
| 28 | 54 |
def from_file(cls, filename):
"""Reads a project from a project file."""
inifile = IniFile(filename)
if inifile.is_new:
return None
name = (
inifile.get("project.name")
or os.path.basename(filename).rsplit(".")[0].title()
)
path = os.path.join(
os.path.dirname(filename),
untrusted_to_os_path(inifile.get("project.path") or "."),
)
themes = inifile.get("project.themes")
if themes is not None:
themes = [x.strip() for x in themes.split(",")]
else:
themes = []
return cls(
name=name,
project_file=filename,
tree=path,
themes=themes,
)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/project.py#L28-L54
| 40 |
[
0,
1,
2,
3,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
25,
26
] | 96.296296 |
[
4
] | 3.703704 | false | 61 | 27 | 6 | 96.296296 | 1 |
def from_file(cls, filename):
inifile = IniFile(filename)
if inifile.is_new:
return None
name = (
inifile.get("project.name")
or os.path.basename(filename).rsplit(".")[0].title()
)
path = os.path.join(
os.path.dirname(filename),
untrusted_to_os_path(inifile.get("project.path") or "."),
)
themes = inifile.get("project.themes")
if themes is not None:
themes = [x.strip() for x in themes.split(",")]
else:
themes = []
return cls(
name=name,
project_file=filename,
tree=path,
themes=themes,
)
| 26,433 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/project.py
|
Project.from_path
|
(cls, path, extension_required=False)
|
return None
|
Locates the project for a path.
|
Locates the project for a path.
| 57 | 83 |
def from_path(cls, path, extension_required=False):
"""Locates the project for a path."""
path = os.path.abspath(path)
if os.path.isfile(path) and (
not extension_required or path.endswith(".lektorproject")
):
return cls.from_file(path)
try:
files = [
x for x in os.listdir(path) if x.lower().endswith(".lektorproject")
]
except OSError:
return None
if len(files) == 1:
return cls.from_file(os.path.join(path, files[0]))
if os.path.isdir(path) and os.path.isfile(
os.path.join(path, "content/contents.lr")
):
return cls(
name=os.path.basename(path),
project_file=None,
tree=path,
)
return None
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/project.py#L57-L83
| 40 |
[
0,
1,
2,
3,
4,
5,
7,
8,
9,
10,
11,
14,
15,
16,
17
] | 55.555556 |
[
6,
12,
13,
18,
21,
26
] | 22.222222 | false | 61 | 27 | 9 | 77.777778 | 1 |
def from_path(cls, path, extension_required=False):
path = os.path.abspath(path)
if os.path.isfile(path) and (
not extension_required or path.endswith(".lektorproject")
):
return cls.from_file(path)
try:
files = [
x for x in os.listdir(path) if x.lower().endswith(".lektorproject")
]
except OSError:
return None
if len(files) == 1:
return cls.from_file(os.path.join(path, files[0]))
if os.path.isdir(path) and os.path.isfile(
os.path.join(path, "content/contents.lr")
):
return cls(
name=os.path.basename(path),
project_file=None,
tree=path,
)
return None
| 26,434 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/project.py
|
Project.discover
|
(cls, base=None)
|
return None
|
Auto discovers the closest project.
|
Auto discovers the closest project.
| 86 | 99 |
def discover(cls, base=None):
"""Auto discovers the closest project."""
if base is None:
base = os.getcwd()
here = base
while 1:
project = cls.from_path(here, extension_required=True)
if project is not None:
return project
node = os.path.dirname(here)
if node == here:
break
here = node
return None
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/project.py#L86-L99
| 40 |
[
0,
1
] | 14.285714 |
[
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13
] | 85.714286 | false | 61 | 14 | 5 | 14.285714 | 1 |
def discover(cls, base=None):
if base is None:
base = os.getcwd()
here = base
while 1:
project = cls.from_path(here, extension_required=True)
if project is not None:
return project
node = os.path.dirname(here)
if node == here:
break
here = node
return None
| 26,435 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/project.py
|
Project.project_path
|
(self)
|
return self.project_file or self.tree
| 102 | 103 |
def project_path(self):
return self.project_file or self.tree
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/project.py#L102-L103
| 40 |
[
0
] | 50 |
[
1
] | 50 | false | 61 | 2 | 2 | 50 | 0 |
def project_path(self):
return self.project_file or self.tree
| 26,436 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/project.py
|
Project.get_output_path
|
(self)
|
return os.path.join(get_cache_dir(), "builds", self.id)
|
The path where output files are stored.
|
The path where output files are stored.
| 105 | 112 |
def get_output_path(self):
"""The path where output files are stored."""
config = self.open_config()
output_path = config.get("project.output_path")
if output_path:
return os.path.join(self.tree, os.path.normpath(output_path))
return os.path.join(get_cache_dir(), "builds", self.id)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/project.py#L105-L112
| 40 |
[
0,
1
] | 25 |
[
2,
3,
4,
5,
7
] | 62.5 | false | 61 | 8 | 2 | 37.5 | 1 |
def get_output_path(self):
config = self.open_config()
output_path = config.get("project.output_path")
if output_path:
return os.path.join(self.tree, os.path.normpath(output_path))
return os.path.join(get_cache_dir(), "builds", self.id)
| 26,437 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/project.py
|
Project.get_package_cache_path
|
(self)
|
return os.path.join(get_cache_dir(), "packages", h.hexdigest())
|
The path where plugin packages are stored.
|
The path where plugin packages are stored.
| 114 | 120 |
def get_package_cache_path(self):
"""The path where plugin packages are stored."""
h = hashlib.md5()
h.update(self.id.encode("utf-8"))
h.update(sys.version.encode("utf-8"))
h.update(sys.prefix.encode("utf-8"))
return os.path.join(get_cache_dir(), "packages", h.hexdigest())
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/project.py#L114-L120
| 40 |
[
0,
1,
2,
3,
4,
5,
6
] | 100 |
[] | 0 | true | 61 | 7 | 1 | 100 | 1 |
def get_package_cache_path(self):
h = hashlib.md5()
h.update(self.id.encode("utf-8"))
h.update(sys.version.encode("utf-8"))
h.update(sys.prefix.encode("utf-8"))
return os.path.join(get_cache_dir(), "packages", h.hexdigest())
| 26,438 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/project.py
|
Project.content_path_from_filename
|
(self, filename)
|
return None
|
Given a filename returns the content path or None if
not in project.
|
Given a filename returns the content path or None if
not in project.
| 122 | 139 |
def content_path_from_filename(self, filename):
"""Given a filename returns the content path or None if
not in project.
"""
dirname, basename = os.path.split(os.path.abspath(filename))
if basename == "contents.lr":
path = dirname
elif basename.endswith(".lr"):
path = os.path.join(dirname, basename[:-3])
else:
return None
content_path = os.path.normpath(self.tree).split(os.path.sep) + ["content"]
file_path = os.path.normpath(path).split(os.path.sep)
prefix = os.path.commonprefix([content_path, file_path])
if prefix == content_path:
return "/" + "/".join(file_path[len(content_path) :])
return None
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/project.py#L122-L139
| 40 |
[
0,
1,
2,
3
] | 22.222222 |
[
4,
5,
6,
7,
8,
10,
12,
13,
14,
15,
16,
17
] | 66.666667 | false | 61 | 18 | 4 | 33.333333 | 2 |
def content_path_from_filename(self, filename):
dirname, basename = os.path.split(os.path.abspath(filename))
if basename == "contents.lr":
path = dirname
elif basename.endswith(".lr"):
path = os.path.join(dirname, basename[:-3])
else:
return None
content_path = os.path.normpath(self.tree).split(os.path.sep) + ["content"]
file_path = os.path.normpath(path).split(os.path.sep)
prefix = os.path.commonprefix([content_path, file_path])
if prefix == content_path:
return "/" + "/".join(file_path[len(content_path) :])
return None
| 26,439 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/project.py
|
Project.make_env
|
(self, load_plugins=True)
|
return Environment(self, load_plugins=load_plugins)
|
Create a new environment for this project.
|
Create a new environment for this project.
| 141 | 143 |
def make_env(self, load_plugins=True):
"""Create a new environment for this project."""
return Environment(self, load_plugins=load_plugins)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/project.py#L141-L143
| 40 |
[
0,
1,
2
] | 100 |
[] | 0 | true | 61 | 3 | 1 | 100 | 1 |
def make_env(self, load_plugins=True):
return Environment(self, load_plugins=load_plugins)
| 26,440 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/project.py
|
Project.excluded_assets
|
(self)
|
return list(comma_delimited(config.get("project.excluded_assets", "")))
|
List of glob patterns matching filenames of excluded assets.
Combines with default EXCLUDED_ASSETS.
|
List of glob patterns matching filenames of excluded assets.
| 146 | 152 |
def excluded_assets(self):
"""List of glob patterns matching filenames of excluded assets.
Combines with default EXCLUDED_ASSETS.
"""
config = self.open_config()
return list(comma_delimited(config.get("project.excluded_assets", "")))
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/project.py#L146-L152
| 40 |
[
0,
1,
2,
3,
4,
5,
6
] | 100 |
[] | 0 | true | 61 | 7 | 1 | 100 | 3 |
def excluded_assets(self):
config = self.open_config()
return list(comma_delimited(config.get("project.excluded_assets", "")))
| 26,441 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/project.py
|
Project.included_assets
|
(self)
|
return list(comma_delimited(config.get("project.included_assets", "")))
|
List of glob patterns matching filenames of included assets.
Overrides both excluded_assets and the default excluded patterns.
|
List of glob patterns matching filenames of included assets.
| 155 | 161 |
def included_assets(self):
"""List of glob patterns matching filenames of included assets.
Overrides both excluded_assets and the default excluded patterns.
"""
config = self.open_config()
return list(comma_delimited(config.get("project.included_assets", "")))
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/project.py#L155-L161
| 40 |
[
0,
1,
2,
3,
4,
5,
6
] | 100 |
[] | 0 | true | 61 | 7 | 1 | 100 | 3 |
def included_assets(self):
config = self.open_config()
return list(comma_delimited(config.get("project.included_assets", "")))
| 26,442 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/project.py
|
Project.to_json
|
(self)
|
return {
"name": self.name,
"project_file": self.project_file,
"project_path": self.project_path,
"default_output_path": self.get_output_path(),
"id": self.id,
"tree": self.tree,
}
| 163 | 171 |
def to_json(self):
return {
"name": self.name,
"project_file": self.project_file,
"project_path": self.project_path,
"default_output_path": self.get_output_path(),
"id": self.id,
"tree": self.tree,
}
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/project.py#L163-L171
| 40 |
[
0
] | 11.111111 |
[
1
] | 11.111111 | false | 61 | 9 | 1 | 88.888889 | 0 |
def to_json(self):
return {
"name": self.name,
"project_file": self.project_file,
"project_path": self.project_path,
"default_output_path": self.get_output_path(),
"id": self.id,
"tree": self.tree,
}
| 26,443 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/exception.py
|
LektorException.__init__
|
(self, message=None)
| 2 | 6 |
def __init__(self, message=None):
Exception.__init__(self)
if isinstance(message, bytes):
message = message.decode("utf-8", "replace")
self.message = message
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/exception.py#L2-L6
| 40 |
[
0,
1,
2,
4
] | 80 |
[
3
] | 20 | false | 75 | 5 | 2 | 80 | 0 |
def __init__(self, message=None):
Exception.__init__(self)
if isinstance(message, bytes):
message = message.decode("utf-8", "replace")
self.message = message
| 26,444 |
|||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/exception.py
|
LektorException.to_json
|
(self)
|
return {
"type": self.__class__.__name__,
"message": self.message,
}
| 8 | 12 |
def to_json(self):
return {
"type": self.__class__.__name__,
"message": self.message,
}
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/exception.py#L8-L12
| 40 |
[
0
] | 20 |
[
1
] | 20 | false | 75 | 5 | 1 | 80 | 0 |
def to_json(self):
return {
"type": self.__class__.__name__,
"message": self.message,
}
| 26,445 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/exception.py
|
LektorException.__str__
|
(self)
|
return str(self.message)
| 14 | 15 |
def __str__(self):
return str(self.message)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/exception.py#L14-L15
| 40 |
[
0,
1
] | 100 |
[] | 0 | true | 75 | 2 | 1 | 100 | 0 |
def __str__(self):
return str(self.message)
| 26,446 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/exception.py
|
LektorException.__repr__
|
(self)
|
return "%s(%r)" % (self.__class__.__name__, self.message)
| 17 | 18 |
def __repr__(self):
return "%s(%r)" % (self.__class__.__name__, self.message)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/exception.py#L17-L18
| 40 |
[
0
] | 50 |
[
1
] | 50 | false | 75 | 2 | 1 | 50 | 0 |
def __repr__(self):
return "%s(%r)" % (self.__class__.__name__, self.message)
| 26,447 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/builder.py
|
create_tables
|
(con)
| 26 | 86 |
def create_tables(con):
can_disable_rowid = (3, 8, 2) <= sqlite3.sqlite_version_info
if can_disable_rowid:
without_rowid = "without rowid"
else:
without_rowid = ""
try:
con.execute(
f"""
create table if not exists artifacts (
artifact text,
source text,
source_mtime integer,
source_size integer,
source_checksum text,
is_dir integer,
is_primary_source integer,
primary key (artifact, source)
) {without_rowid};
"""
)
con.execute(
"""
create index if not exists artifacts_source on artifacts (
source
);
"""
)
con.execute(
f"""
create table if not exists artifact_config_hashes (
artifact text,
config_hash text,
primary key (artifact)
) {without_rowid};
"""
)
con.execute(
f"""
create table if not exists dirty_sources (
source text,
primary key (source)
) {without_rowid};
"""
)
con.execute(
f"""
create table if not exists source_info (
path text,
alt text,
lang text,
type text,
source text,
title text,
primary key (path, alt, lang)
) {without_rowid};
"""
)
finally:
con.close()
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/builder.py#L26-L86
| 40 |
[
0,
1,
2,
3,
6,
7,
8,
22,
23,
24,
25,
26,
27,
28,
29,
30,
38,
46,
60
] | 31.147541 |
[
5
] | 1.639344 | false | 85.756677 | 61 | 2 | 98.360656 | 0 |
def create_tables(con):
can_disable_rowid = (3, 8, 2) <= sqlite3.sqlite_version_info
if can_disable_rowid:
without_rowid = "without rowid"
else:
without_rowid = ""
try:
con.execute(
f"""
create table if not exists artifacts (
artifact text,
source text,
source_mtime integer,
source_size integer,
source_checksum text,
is_dir integer,
is_primary_source integer,
primary key (artifact, source)
) {without_rowid};
create index if not exists artifacts_source on artifacts (
source
);
create table if not exists artifact_config_hashes (
artifact text,
config_hash text,
primary key (artifact)
) {without_rowid};
create table if not exists dirty_sources (
source text,
primary key (source)
) {without_rowid};
create table if not exists source_info (
path text,
alt text,
lang text,
type text,
source text,
title text,
primary key (path, alt, lang)
) {without_rowid};
"""
)
finally:
con.close()
| 26,448 |
|||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/builder.py
|
_describe_fs_path_for_checksum
|
(path)
|
return b"\x00"
|
Given a file system path this returns a basic description of what
this is. This is used for checksum hashing on directories.
|
Given a file system path this returns a basic description of what
this is. This is used for checksum hashing on directories.
| 476 | 489 |
def _describe_fs_path_for_checksum(path):
"""Given a file system path this returns a basic description of what
this is. This is used for checksum hashing on directories.
"""
# This is not entirely correct as it does not detect changes for
# contents from alternatives. However for the moment it's good
# enough.
if os.path.isfile(path):
return b"\x01"
if os.path.isfile(os.path.join(path, "contents.lr")):
return b"\x02"
if os.path.isdir(path):
return b"\x03"
return b"\x00"
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/builder.py#L476-L489
| 40 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12
] | 92.857143 |
[
13
] | 7.142857 | false | 85.756677 | 14 | 4 | 92.857143 | 2 |
def _describe_fs_path_for_checksum(path):
# This is not entirely correct as it does not detect changes for
# contents from alternatives. However for the moment it's good
# enough.
if os.path.isfile(path):
return b"\x01"
if os.path.isfile(os.path.join(path, "contents.lr")):
return b"\x02"
if os.path.isdir(path):
return b"\x03"
return b"\x00"
| 26,449 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/builder.py
|
BuildState.__init__
|
(self, builder, path_cache)
| 90 | 96 |
def __init__(self, builder, path_cache):
self.builder = builder
self.named_temporaries = set()
self.updated_artifacts = []
self.failed_artifacts = []
self.path_cache = path_cache
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/builder.py#L90-L96
| 40 |
[
0,
1,
2,
3,
4,
5,
6
] | 100 |
[] | 0 | true | 85.756677 | 7 | 1 | 100 | 0 |
def __init__(self, builder, path_cache):
self.builder = builder
self.named_temporaries = set()
self.updated_artifacts = []
self.failed_artifacts = []
self.path_cache = path_cache
| 26,450 |
|||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/builder.py
|
BuildState.pad
|
(self)
|
return self.builder.pad
|
The pad for this buildstate.
|
The pad for this buildstate.
| 99 | 101 |
def pad(self):
"""The pad for this buildstate."""
return self.builder.pad
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/builder.py#L99-L101
| 40 |
[
0,
1,
2
] | 100 |
[] | 0 | true | 85.756677 | 3 | 1 | 100 | 1 |
def pad(self):
return self.builder.pad
| 26,451 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/builder.py
|
BuildState.env
|
(self)
|
return self.builder.env
|
The environment backing this buildstate.
|
The environment backing this buildstate.
| 104 | 106 |
def env(self):
"""The environment backing this buildstate."""
return self.builder.env
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/builder.py#L104-L106
| 40 |
[
0,
1,
2
] | 100 |
[] | 0 | true | 85.756677 | 3 | 1 | 100 | 1 |
def env(self):
return self.builder.env
| 26,452 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/builder.py
|
BuildState.config
|
(self)
|
return self.builder.pad.db.config
|
The config for this buildstate.
|
The config for this buildstate.
| 109 | 111 |
def config(self):
"""The config for this buildstate."""
return self.builder.pad.db.config
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/builder.py#L109-L111
| 40 |
[
0,
1,
2
] | 100 |
[] | 0 | true | 85.756677 | 3 | 1 | 100 | 1 |
def config(self):
return self.builder.pad.db.config
| 26,453 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/builder.py
|
BuildState.__enter__
|
(self)
|
return self
| 113 | 114 |
def __enter__(self):
return self
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/builder.py#L113-L114
| 40 |
[
0,
1
] | 100 |
[] | 0 | true | 85.756677 | 2 | 1 | 100 | 0 |
def __enter__(self):
return self
| 26,454 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/builder.py
|
BuildState.__exit__
|
(self, exc_type, exc_value, tb)
| 116 | 117 |
def __exit__(self, exc_type, exc_value, tb):
self.close()
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/builder.py#L116-L117
| 40 |
[
0,
1
] | 100 |
[] | 0 | true | 85.756677 | 2 | 1 | 100 | 0 |
def __exit__(self, exc_type, exc_value, tb):
self.close()
| 26,455 |
|||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/builder.py
|
BuildState.close
|
(self)
| 119 | 124 |
def close(self):
for fn in self.named_temporaries:
try:
os.remove(fn)
except OSError:
pass
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/builder.py#L119-L124
| 40 |
[
0,
1
] | 33.333333 |
[
2,
3,
4,
5
] | 66.666667 | false | 85.756677 | 6 | 3 | 33.333333 | 0 |
def close(self):
for fn in self.named_temporaries:
try:
os.remove(fn)
except OSError:
pass
| 26,456 |
|||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/builder.py
|
BuildState.notify_failure
|
(self, artifact, exc_info)
|
Notify about a failure. This marks a failed artifact and stores
a failure.
|
Notify about a failure. This marks a failed artifact and stores
a failure.
| 126 | 132 |
def notify_failure(self, artifact, exc_info):
"""Notify about a failure. This marks a failed artifact and stores
a failure.
"""
self.failed_artifacts.append(artifact)
self.builder.failure_controller.store_failure(artifact.artifact_name, exc_info)
reporter.report_failure(artifact, exc_info)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/builder.py#L126-L132
| 40 |
[
0,
1,
2,
3,
4,
5,
6
] | 100 |
[] | 0 | true | 85.756677 | 7 | 1 | 100 | 2 |
def notify_failure(self, artifact, exc_info):
self.failed_artifacts.append(artifact)
self.builder.failure_controller.store_failure(artifact.artifact_name, exc_info)
reporter.report_failure(artifact, exc_info)
| 26,457 |
|
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/builder.py
|
BuildState.make_named_temporary
|
(self, identifier=None)
|
return fn
|
Creates a named temporary file and returns the filename for it.
This can be usedful in some scenarious when building with external
tools.
|
Creates a named temporary file and returns the filename for it.
This can be usedful in some scenarious when building with external
tools.
| 134 | 149 |
def make_named_temporary(self, identifier=None):
"""Creates a named temporary file and returns the filename for it.
This can be usedful in some scenarious when building with external
tools.
"""
tmpdir = os.path.join(self.builder.meta_path, "tmp")
try:
os.makedirs(tmpdir)
except OSError:
pass
fn = os.path.join(
dir,
"nt-%s-%s.tmp" % (identifier or "generic", os.urandom(20).encode("hex")),
)
self.named_temporaries.add(fn)
return fn
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/builder.py#L134-L149
| 40 |
[
0,
1,
2,
3,
4
] | 31.25 |
[
5,
6,
7,
8,
9,
10,
14,
15
] | 50 | false | 85.756677 | 16 | 3 | 50 | 3 |
def make_named_temporary(self, identifier=None):
tmpdir = os.path.join(self.builder.meta_path, "tmp")
try:
os.makedirs(tmpdir)
except OSError:
pass
fn = os.path.join(
dir,
"nt-%s-%s.tmp" % (identifier or "generic", os.urandom(20).encode("hex")),
)
self.named_temporaries.add(fn)
return fn
| 26,458 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/builder.py
|
BuildState.get_file_info
|
(self, filename)
|
return None
| 151 | 154 |
def get_file_info(self, filename):
if filename:
return self.path_cache.get_file_info(filename)
return None
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/builder.py#L151-L154
| 40 |
[
0,
1,
2
] | 75 |
[
3
] | 25 | false | 85.756677 | 4 | 2 | 75 | 0 |
def get_file_info(self, filename):
if filename:
return self.path_cache.get_file_info(filename)
return None
| 26,459 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/builder.py
|
BuildState.to_source_filename
|
(self, filename)
|
return self.path_cache.to_source_filename(filename)
| 156 | 157 |
def to_source_filename(self, filename):
return self.path_cache.to_source_filename(filename)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/builder.py#L156-L157
| 40 |
[
0,
1
] | 100 |
[] | 0 | true | 85.756677 | 2 | 1 | 100 | 0 |
def to_source_filename(self, filename):
return self.path_cache.to_source_filename(filename)
| 26,460 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/builder.py
|
BuildState.get_virtual_source_info
|
(self, virtual_source_path)
|
return VirtualSourceInfo(virtual_source_path, mtime, checksum)
| 159 | 165 |
def get_virtual_source_info(self, virtual_source_path):
virtual_source = self.pad.get(virtual_source_path)
if not virtual_source:
return VirtualSourceInfo(virtual_source_path, None, None)
mtime = virtual_source.get_mtime(self.path_cache)
checksum = virtual_source.get_checksum(self.path_cache)
return VirtualSourceInfo(virtual_source_path, mtime, checksum)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/builder.py#L159-L165
| 40 |
[
0,
1,
2,
4,
5,
6
] | 85.714286 |
[
3
] | 14.285714 | false | 85.756677 | 7 | 2 | 85.714286 | 0 |
def get_virtual_source_info(self, virtual_source_path):
virtual_source = self.pad.get(virtual_source_path)
if not virtual_source:
return VirtualSourceInfo(virtual_source_path, None, None)
mtime = virtual_source.get_mtime(self.path_cache)
checksum = virtual_source.get_checksum(self.path_cache)
return VirtualSourceInfo(virtual_source_path, mtime, checksum)
| 26,461 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/builder.py
|
BuildState.connect_to_database
|
(self)
|
return self.builder.connect_to_database()
|
Returns a database connection for the build state db.
|
Returns a database connection for the build state db.
| 167 | 169 |
def connect_to_database(self):
"""Returns a database connection for the build state db."""
return self.builder.connect_to_database()
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/builder.py#L167-L169
| 40 |
[
0,
1,
2
] | 100 |
[] | 0 | true | 85.756677 | 3 | 1 | 100 | 1 |
def connect_to_database(self):
return self.builder.connect_to_database()
| 26,462 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/builder.py
|
BuildState.get_destination_filename
|
(self, artifact_name)
|
return os.path.join(
self.builder.destination_path,
artifact_name.strip("/").replace("/", os.path.sep),
)
|
Returns the destination filename for an artifact name.
|
Returns the destination filename for an artifact name.
| 171 | 176 |
def get_destination_filename(self, artifact_name):
"""Returns the destination filename for an artifact name."""
return os.path.join(
self.builder.destination_path,
artifact_name.strip("/").replace("/", os.path.sep),
)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/builder.py#L171-L176
| 40 |
[
0,
1,
2,
3,
4,
5
] | 100 |
[] | 0 | true | 85.756677 | 6 | 1 | 100 | 1 |
def get_destination_filename(self, artifact_name):
return os.path.join(
self.builder.destination_path,
artifact_name.strip("/").replace("/", os.path.sep),
)
| 26,463 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/builder.py
|
BuildState.artifact_name_from_destination_filename
|
(self, filename)
|
return filename.replace(os.path.sep, "/")
|
Returns the artifact name for a destination filename.
|
Returns the artifact name for a destination filename.
| 178 | 186 |
def artifact_name_from_destination_filename(self, filename):
"""Returns the artifact name for a destination filename."""
dst = self.builder.destination_path
filename = os.path.join(dst, filename)
if filename.startswith(dst):
filename = filename[len(dst) :].lstrip(os.path.sep)
if os.path.altsep:
filename = filename.lstrip(os.path.altsep)
return filename.replace(os.path.sep, "/")
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/builder.py#L178-L186
| 40 |
[
0,
1,
2,
3,
4,
5,
6,
8
] | 88.888889 |
[
7
] | 11.111111 | false | 85.756677 | 9 | 3 | 88.888889 | 1 |
def artifact_name_from_destination_filename(self, filename):
dst = self.builder.destination_path
filename = os.path.join(dst, filename)
if filename.startswith(dst):
filename = filename[len(dst) :].lstrip(os.path.sep)
if os.path.altsep:
filename = filename.lstrip(os.path.altsep)
return filename.replace(os.path.sep, "/")
| 26,464 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/builder.py
|
BuildState.new_artifact
|
(
self, artifact_name, sources=None, source_obj=None, extra=None, config_hash=None
)
|
return Artifact(
self,
key,
dst_filename,
sources,
source_obj=source_obj,
extra=extra,
config_hash=config_hash,
)
|
Creates a new artifact and returns it.
|
Creates a new artifact and returns it.
| 188 | 202 |
def new_artifact(
self, artifact_name, sources=None, source_obj=None, extra=None, config_hash=None
):
"""Creates a new artifact and returns it."""
dst_filename = self.get_destination_filename(artifact_name)
key = self.artifact_name_from_destination_filename(dst_filename)
return Artifact(
self,
key,
dst_filename,
sources,
source_obj=source_obj,
extra=extra,
config_hash=config_hash,
)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/builder.py#L188-L202
| 40 |
[
0,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14
] | 86.666667 |
[] | 0 | false | 85.756677 | 15 | 1 | 100 | 1 |
def new_artifact(
self, artifact_name, sources=None, source_obj=None, extra=None, config_hash=None
):
dst_filename = self.get_destination_filename(artifact_name)
key = self.artifact_name_from_destination_filename(dst_filename)
return Artifact(
self,
key,
dst_filename,
sources,
source_obj=source_obj,
extra=extra,
config_hash=config_hash,
)
| 26,465 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/builder.py
|
BuildState.artifact_exists
|
(self, artifact_name)
|
return os.path.exists(dst_filename)
|
Given an artifact name this checks if it was already produced.
|
Given an artifact name this checks if it was already produced.
| 204 | 207 |
def artifact_exists(self, artifact_name):
"""Given an artifact name this checks if it was already produced."""
dst_filename = self.get_destination_filename(artifact_name)
return os.path.exists(dst_filename)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/builder.py#L204-L207
| 40 |
[
0,
1
] | 50 |
[
2,
3
] | 50 | false | 85.756677 | 4 | 1 | 50 | 1 |
def artifact_exists(self, artifact_name):
dst_filename = self.get_destination_filename(artifact_name)
return os.path.exists(dst_filename)
| 26,466 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/builder.py
|
BuildState.get_artifact_dependency_infos
|
(self, artifact_name, sources)
|
return rv
| 209 | 216 |
def get_artifact_dependency_infos(self, artifact_name, sources):
con = self.connect_to_database()
try:
cur = con.cursor()
rv = list(self._iter_artifact_dependency_infos(cur, artifact_name, sources))
finally:
con.close()
return rv
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/builder.py#L209-L216
| 40 |
[
0
] | 12.5 |
[
1,
2,
3,
4,
6,
7
] | 75 | false | 85.756677 | 8 | 1 | 25 | 0 |
def get_artifact_dependency_infos(self, artifact_name, sources):
con = self.connect_to_database()
try:
cur = con.cursor()
rv = list(self._iter_artifact_dependency_infos(cur, artifact_name, sources))
finally:
con.close()
return rv
| 26,467 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/builder.py
|
BuildState._iter_artifact_dependency_infos
|
(self, cur, artifact_name, sources)
|
This iterates over all dependencies as file info objects.
|
This iterates over all dependencies as file info objects.
| 218 | 249 |
def _iter_artifact_dependency_infos(self, cur, artifact_name, sources):
"""This iterates over all dependencies as file info objects."""
cur.execute(
"""
select source, source_mtime, source_size,
source_checksum, is_dir
from artifacts
where artifact = ?
""",
[artifact_name],
)
rv = cur.fetchall()
found = set()
for path, mtime, size, checksum, is_dir in rv:
if "@" in path:
yield path, VirtualSourceInfo(path, mtime, checksum)
else:
file_info = FileInfo(
self.env, path, mtime, size, checksum, bool(is_dir)
)
filename = self.to_source_filename(file_info.filename)
found.add(filename)
yield filename, file_info
# In any case we also iterate over our direct sources, even if the
# build state does not know about them yet. This can be caused by
# an initial build or a change in original configuration.
for source in sources:
filename = self.to_source_filename(source)
if filename not in found:
yield source, None
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/builder.py#L218-L249
| 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
] | 96.875 |
[
31
] | 3.125 | false | 85.756677 | 32 | 5 | 96.875 | 1 |
def _iter_artifact_dependency_infos(self, cur, artifact_name, sources):
cur.execute(,
[artifact_name],
)
rv = cur.fetchall()
found = set()
for path, mtime, size, checksum, is_dir in rv:
if "@" in path:
yield path, VirtualSourceInfo(path, mtime, checksum)
else:
file_info = FileInfo(
self.env, path, mtime, size, checksum, bool(is_dir)
)
filename = self.to_source_filename(file_info.filename)
found.add(filename)
yield filename, file_info
# In any case we also iterate over our direct sources, even if the
# build state does not know about them yet. This can be caused by
# an initial build or a change in original configuration.
for source in sources:
filename = self.to_source_filename(source)
if filename not in found:
yield source, None
| 26,468 |
|
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/builder.py
|
BuildState.write_source_info
|
(self, info)
|
Writes the source info into the database. The source info is
an instance of :class:`lektor.build_programs.SourceInfo`.
|
Writes the source info into the database. The source info is
an instance of :class:`lektor.build_programs.SourceInfo`.
| 251 | 271 |
def write_source_info(self, info):
"""Writes the source info into the database. The source info is
an instance of :class:`lektor.build_programs.SourceInfo`.
"""
reporter.report_write_source_info(info)
source = self.to_source_filename(info.filename)
con = self.connect_to_database()
try:
cur = con.cursor()
for lang, title in info.title_i18n.items():
cur.execute(
"""
insert or replace into source_info
(path, alt, lang, type, source, title)
values (?, ?, ?, ?, ?, ?)
""",
[info.path, info.alt, lang, info.type, source, title],
)
con.commit()
finally:
con.close()
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/builder.py#L251-L271
| 40 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20
] | 100 |
[] | 0 | true | 85.756677 | 21 | 2 | 100 | 2 |
def write_source_info(self, info):
reporter.report_write_source_info(info)
source = self.to_source_filename(info.filename)
con = self.connect_to_database()
try:
cur = con.cursor()
for lang, title in info.title_i18n.items():
cur.execute(,
[info.path, info.alt, lang, info.type, source, title],
)
con.commit()
finally:
con.close()
| 26,469 |
|
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/builder.py
|
BuildState.prune_source_infos
|
(self)
|
Remove all source infos of files that no longer exist.
|
Remove all source infos of files that no longer exist.
| 273 | 307 |
def prune_source_infos(self):
"""Remove all source infos of files that no longer exist."""
MAX_VARS = 999 # Default SQLITE_MAX_VARIABLE_NUMBER.
con = self.connect_to_database()
to_clean = []
try:
cur = con.cursor()
cur.execute(
"""
select distinct source from source_info
"""
)
for (source,) in cur.fetchall():
fs_path = os.path.join(self.env.root_path, source)
if not os.path.exists(fs_path):
to_clean.append(source)
if to_clean:
for i in range(0, len(to_clean), MAX_VARS):
chunk = to_clean[i : i + MAX_VARS]
cur.execute(
"""
delete from source_info
where source in (%s)
"""
% ", ".join(["?"] * len(chunk)),
chunk,
)
con.commit()
finally:
con.close()
for source in to_clean:
reporter.report_prune_source_info(source)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/builder.py#L273-L307
| 40 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
16,
17,
30,
31,
32,
33
] | 60 |
[
15,
18,
19,
20,
29,
34
] | 17.142857 | false | 85.756677 | 35 | 6 | 82.857143 | 1 |
def prune_source_infos(self):
MAX_VARS = 999 # Default SQLITE_MAX_VARIABLE_NUMBER.
con = self.connect_to_database()
to_clean = []
try:
cur = con.cursor()
cur.execute(
)
for (source,) in cur.fetchall():
fs_path = os.path.join(self.env.root_path, source)
if not os.path.exists(fs_path):
to_clean.append(source)
if to_clean:
for i in range(0, len(to_clean), MAX_VARS):
chunk = to_clean[i : i + MAX_VARS]
cur.execute(
% ", ".join(["?"] * len(chunk)),
chunk,
)
con.commit()
finally:
con.close()
for source in to_clean:
reporter.report_prune_source_info(source)
| 26,470 |
|
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/builder.py
|
BuildState.remove_artifact
|
(self, artifact_name)
|
Removes an artifact from the build state.
|
Removes an artifact from the build state.
| 309 | 322 |
def remove_artifact(self, artifact_name):
"""Removes an artifact from the build state."""
con = self.connect_to_database()
try:
cur = con.cursor()
cur.execute(
"""
delete from artifacts where artifact = ?
""",
[artifact_name],
)
con.commit()
finally:
con.close()
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/builder.py#L309-L322
| 40 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13
] | 100 |
[] | 0 | true | 85.756677 | 14 | 1 | 100 | 1 |
def remove_artifact(self, artifact_name):
con = self.connect_to_database()
try:
cur = con.cursor()
cur.execute(,
[artifact_name],
)
con.commit()
finally:
con.close()
| 26,471 |
|
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/builder.py
|
BuildState._any_sources_are_dirty
|
(self, cur, sources)
|
return cur.fetchone() is not None
|
Given a list of sources this checks if any of them are marked
as dirty.
|
Given a list of sources this checks if any of them are marked
as dirty.
| 324 | 339 |
def _any_sources_are_dirty(self, cur, sources):
"""Given a list of sources this checks if any of them are marked
as dirty.
"""
sources = [self.to_source_filename(x) for x in sources]
if not sources:
return False
cur.execute(
"""
select source from dirty_sources where source in (%s) limit 1
"""
% ", ".join(["?"] * len(sources)),
sources,
)
return cur.fetchone() is not None
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/builder.py#L324-L339
| 40 |
[
0,
1,
2,
3,
4,
5,
7,
8,
9,
10,
11,
12,
13,
14,
15
] | 93.75 |
[
6
] | 6.25 | false | 85.756677 | 16 | 3 | 93.75 | 2 |
def _any_sources_are_dirty(self, cur, sources):
sources = [self.to_source_filename(x) for x in sources]
if not sources:
return False
cur.execute(
% ", ".join(["?"] * len(sources)),
sources,
)
return cur.fetchone() is not None
| 26,472 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/builder.py
|
BuildState._get_artifact_config_hash
|
(cur, artifact_name)
|
return rv[0] if rv else None
|
Returns the artifact's config hash.
|
Returns the artifact's config hash.
| 342 | 352 |
def _get_artifact_config_hash(cur, artifact_name):
"""Returns the artifact's config hash."""
cur.execute(
"""
select config_hash from artifact_config_hashes
where artifact = ?
""",
[artifact_name],
)
rv = cur.fetchone()
return rv[0] if rv else None
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/builder.py#L342-L352
| 40 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10
] | 100 |
[] | 0 | true | 85.756677 | 11 | 1 | 100 | 1 |
def _get_artifact_config_hash(cur, artifact_name):
cur.execute(,
[artifact_name],
)
rv = cur.fetchone()
return rv[0] if rv else None
| 26,473 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/builder.py
|
BuildState.check_artifact_is_current
|
(self, artifact_name, sources, config_hash)
| 354 | 388 |
def check_artifact_is_current(self, artifact_name, sources, config_hash):
con = self.connect_to_database()
cur = con.cursor()
try:
# The artifact config changed
if config_hash != self._get_artifact_config_hash(cur, artifact_name):
return False
# If one of our source files is explicitly marked as dirty in the
# build state, we are not current.
if self._any_sources_are_dirty(cur, sources):
return False
# If we do have an already existing artifact, we need to check if
# any of the source files we depend on changed.
for _, info in self._iter_artifact_dependency_infos(
cur, artifact_name, sources
):
# if we get a missing source info it means that we never
# saw this before. This means we need to build it.
if info is None:
return False
if isinstance(info, VirtualSourceInfo):
new_vinfo = self.get_virtual_source_info(info.path)
if not info.unchanged(new_vinfo):
return False
# If the file info is different, then it clearly changed.
elif not info.unchanged(self.get_file_info(info.filename)):
return False
return True
finally:
con.close()
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/builder.py#L354-L388
| 40 |
[
0,
1,
2,
3,
4,
5,
9,
10,
14,
15,
19,
20,
22,
23,
24,
25,
26,
27,
28,
29,
30,
31,
32,
34
] | 68.571429 |
[
6,
11,
21
] | 8.571429 | false | 85.756677 | 35 | 8 | 91.428571 | 0 |
def check_artifact_is_current(self, artifact_name, sources, config_hash):
con = self.connect_to_database()
cur = con.cursor()
try:
# The artifact config changed
if config_hash != self._get_artifact_config_hash(cur, artifact_name):
return False
# If one of our source files is explicitly marked as dirty in the
# build state, we are not current.
if self._any_sources_are_dirty(cur, sources):
return False
# If we do have an already existing artifact, we need to check if
# any of the source files we depend on changed.
for _, info in self._iter_artifact_dependency_infos(
cur, artifact_name, sources
):
# if we get a missing source info it means that we never
# saw this before. This means we need to build it.
if info is None:
return False
if isinstance(info, VirtualSourceInfo):
new_vinfo = self.get_virtual_source_info(info.path)
if not info.unchanged(new_vinfo):
return False
# If the file info is different, then it clearly changed.
elif not info.unchanged(self.get_file_info(info.filename)):
return False
return True
finally:
con.close()
| 26,474 |
|||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/builder.py
|
BuildState.iter_existing_artifacts
|
(self)
|
Scan output directory for artifacts.
Returns an iterable of the artifact_names for artifacts found.
|
Scan output directory for artifacts.
| 390 | 405 |
def iter_existing_artifacts(self):
"""Scan output directory for artifacts.
Returns an iterable of the artifact_names for artifacts found.
"""
is_ignored = self.env.is_ignored_artifact
def _unignored(filenames):
return filter(lambda fn: not is_ignored(fn), filenames)
dst = self.builder.destination_path
for dirpath, dirnames, filenames in os.walk(dst):
dirnames[:] = _unignored(dirnames)
for filename in _unignored(filenames):
full_path = os.path.join(dst, dirpath, filename)
yield self.artifact_name_from_destination_filename(full_path)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/builder.py#L390-L405
| 40 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15
] | 100 |
[] | 0 | true | 85.756677 | 16 | 4 | 100 | 3 |
def iter_existing_artifacts(self):
is_ignored = self.env.is_ignored_artifact
def _unignored(filenames):
return filter(lambda fn: not is_ignored(fn), filenames)
dst = self.builder.destination_path
for dirpath, dirnames, filenames in os.walk(dst):
dirnames[:] = _unignored(dirnames)
for filename in _unignored(filenames):
full_path = os.path.join(dst, dirpath, filename)
yield self.artifact_name_from_destination_filename(full_path)
| 26,475 |
|
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/builder.py
|
BuildState.iter_unreferenced_artifacts
|
(self, all=False)
|
Finds all unreferenced artifacts in the build folder and yields
them.
|
Finds all unreferenced artifacts in the build folder and yields
them.
| 407 | 445 |
def iter_unreferenced_artifacts(self, all=False):
"""Finds all unreferenced artifacts in the build folder and yields
them.
"""
if all:
yield from self.iter_existing_artifacts()
con = self.connect_to_database()
cur = con.cursor()
def _is_unreferenced(artifact_name):
# Check whether any of the primary sources for the artifact
# exist and — if the source can be resolved to a record —
# correspond to non-hidden records.
cur.execute(
"""
SELECT DISTINCT source, path, alt
FROM artifacts LEFT JOIN source_info USING(source)
WHERE artifact = ?
AND is_primary_source""",
[artifact_name],
)
for source, path, alt in cur.fetchall():
if self.get_file_info(source).exists:
if path is None:
return False # no record to check
record = self.pad.get(path, alt)
if record is None:
# I'm not sure this should happen, but be safe
return False
if record.is_visible:
return False
# no sources exist, or those that do belong to hidden records
return True
try:
yield from filter(_is_unreferenced, self.iter_existing_artifacts())
finally:
con.close()
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/builder.py#L407-L445
| 40 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
22,
23,
24,
26,
27,
28,
30,
31,
32,
33,
34,
35,
36,
38
] | 87.179487 |
[
25,
29
] | 5.128205 | false | 85.756677 | 39 | 8 | 94.871795 | 2 |
def iter_unreferenced_artifacts(self, all=False):
if all:
yield from self.iter_existing_artifacts()
con = self.connect_to_database()
cur = con.cursor()
def _is_unreferenced(artifact_name):
# Check whether any of the primary sources for the artifact
# exist and — if the source can be resolved to a record —
# correspond to non-hidden records.
cur.execute(,
[artifact_name],
)
for source, path, alt in cur.fetchall():
if self.get_file_info(source).exists:
if path is None:
return False # no record to check
record = self.pad.get(path, alt)
if record is None:
# I'm not sure this should happen, but be safe
return False
if record.is_visible:
return False
# no sources exist, or those that do belong to hidden records
return True
try:
yield from filter(_is_unreferenced, self.iter_existing_artifacts())
finally:
con.close()
| 26,476 |
|
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/builder.py
|
BuildState.iter_artifacts
|
(self)
|
Iterates over all artifact and their file infos..
|
Iterates over all artifact and their file infos..
| 447 | 465 |
def iter_artifacts(self):
"""Iterates over all artifact and their file infos.."""
con = self.connect_to_database()
try:
cur = con.cursor()
cur.execute(
"""
select distinct artifact from artifacts order by artifact
"""
)
rows = cur.fetchall()
con.close()
for (artifact_name,) in rows:
path = self.get_destination_filename(artifact_name)
info = FileInfo(self.builder.env, path)
if info.exists:
yield artifact_name, info
finally:
con.close()
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/builder.py#L447-L465
| 40 |
[
0,
1
] | 10.526316 |
[
2,
3,
4,
5,
10,
11,
12,
13,
14,
15,
16,
18
] | 63.157895 | false | 85.756677 | 19 | 3 | 36.842105 | 1 |
def iter_artifacts(self):
con = self.connect_to_database()
try:
cur = con.cursor()
cur.execute(
)
rows = cur.fetchall()
con.close()
for (artifact_name,) in rows:
path = self.get_destination_filename(artifact_name)
info = FileInfo(self.builder.env, path)
if info.exists:
yield artifact_name, info
finally:
con.close()
| 26,477 |
|
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/builder.py
|
BuildState.vacuum
|
(self)
|
Vacuums the build db.
|
Vacuums the build db.
| 467 | 473 |
def vacuum(self):
"""Vacuums the build db."""
con = self.connect_to_database()
try:
con.execute("vacuum")
finally:
con.close()
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/builder.py#L467-L473
| 40 |
[
0,
1,
2,
3,
4,
5,
6
] | 100 |
[] | 0 | true | 85.756677 | 7 | 1 | 100 | 1 |
def vacuum(self):
con = self.connect_to_database()
try:
con.execute("vacuum")
finally:
con.close()
| 26,478 |
|
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/builder.py
|
FileInfo.__init__
|
(
self, env, filename, mtime=None, size=None, checksum=None, is_dir=None
)
| 497 | 506 |
def __init__(
self, env, filename, mtime=None, size=None, checksum=None, is_dir=None
):
self.env = env
self.filename = filename
if mtime is not None and size is not None and is_dir is not None:
self._stat = (mtime, size, is_dir)
else:
self._stat = None
self._checksum = checksum
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/builder.py#L497-L506
| 40 |
[
0,
3,
4,
5,
6,
8,
9
] | 70 |
[] | 0 | false | 85.756677 | 10 | 4 | 100 | 0 |
def __init__(
self, env, filename, mtime=None, size=None, checksum=None, is_dir=None
):
self.env = env
self.filename = filename
if mtime is not None and size is not None and is_dir is not None:
self._stat = (mtime, size, is_dir)
else:
self._stat = None
self._checksum = checksum
| 26,479 |
|||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/builder.py
|
FileInfo._get_stat
|
(self)
|
return rv
| 508 | 526 |
def _get_stat(self):
rv = self._stat
if rv is not None:
return rv
try:
st = os.stat(self.filename)
mtime = int(st.st_mtime)
if stat.S_ISDIR(st.st_mode):
size = len(os.listdir(self.filename))
is_dir = True
else:
size = int(st.st_size)
is_dir = False
rv = mtime, size, is_dir
except OSError:
rv = 0, -1, False
self._stat = rv
return rv
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/builder.py#L508-L526
| 40 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
12,
13,
14,
15,
16,
17,
18
] | 94.736842 |
[] | 0 | false | 85.756677 | 19 | 4 | 100 | 0 |
def _get_stat(self):
rv = self._stat
if rv is not None:
return rv
try:
st = os.stat(self.filename)
mtime = int(st.st_mtime)
if stat.S_ISDIR(st.st_mode):
size = len(os.listdir(self.filename))
is_dir = True
else:
size = int(st.st_size)
is_dir = False
rv = mtime, size, is_dir
except OSError:
rv = 0, -1, False
self._stat = rv
return rv
| 26,480 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/builder.py
|
FileInfo.mtime
|
(self)
|
return self._get_stat()[0]
|
The timestamp of the last modification.
|
The timestamp of the last modification.
| 529 | 531 |
def mtime(self):
"""The timestamp of the last modification."""
return self._get_stat()[0]
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/builder.py#L529-L531
| 40 |
[
0,
1,
2
] | 100 |
[] | 0 | true | 85.756677 | 3 | 1 | 100 | 1 |
def mtime(self):
return self._get_stat()[0]
| 26,481 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/builder.py
|
FileInfo.size
|
(self)
|
return self._get_stat()[1]
|
The size of the file in bytes. If the file is actually a
dictionary then the size is actually the number of files in it.
|
The size of the file in bytes. If the file is actually a
dictionary then the size is actually the number of files in it.
| 534 | 538 |
def size(self):
"""The size of the file in bytes. If the file is actually a
dictionary then the size is actually the number of files in it.
"""
return self._get_stat()[1]
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/builder.py#L534-L538
| 40 |
[
0,
1,
2,
3,
4
] | 100 |
[] | 0 | true | 85.756677 | 5 | 1 | 100 | 2 |
def size(self):
return self._get_stat()[1]
| 26,482 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/builder.py
|
FileInfo.is_dir
|
(self)
|
return self._get_stat()[2]
|
Is this a directory?
|
Is this a directory?
| 541 | 543 |
def is_dir(self):
"""Is this a directory?"""
return self._get_stat()[2]
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/builder.py#L541-L543
| 40 |
[
0,
1,
2
] | 100 |
[] | 0 | true | 85.756677 | 3 | 1 | 100 | 1 |
def is_dir(self):
return self._get_stat()[2]
| 26,483 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/builder.py
|
FileInfo.exists
|
(self)
|
return self.size >= 0
| 546 | 547 |
def exists(self):
return self.size >= 0
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/builder.py#L546-L547
| 40 |
[
0,
1
] | 100 |
[] | 0 | true | 85.756677 | 2 | 1 | 100 | 0 |
def exists(self):
return self.size >= 0
| 26,484 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/builder.py
|
FileInfo.checksum
|
(self)
|
return checksum
|
The checksum of the file or directory.
|
The checksum of the file or directory.
| 550 | 583 |
def checksum(self):
"""The checksum of the file or directory."""
rv = self._checksum
if rv is not None:
return rv
try:
h = hashlib.sha1()
if os.path.isdir(self.filename):
h.update(b"DIR\x00")
for filename in sorted(os.listdir(self.filename)):
if self.env.is_uninteresting_source_name(filename):
continue
if isinstance(filename, str):
filename = filename.encode("utf-8")
h.update(filename)
h.update(
_describe_fs_path_for_checksum(
os.path.join(self.filename, filename.decode("utf-8"))
)
)
h.update(b"\x00")
else:
with open(self.filename, "rb") as f:
while 1:
chunk = f.read(16 * 1024)
if not chunk:
break
h.update(chunk)
checksum = h.hexdigest()
except (OSError, IOError):
checksum = "0" * 40
self._checksum = checksum
return checksum
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/builder.py#L550-L583
| 40 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
25,
26,
27,
28,
29,
30,
31,
32,
33
] | 97.058824 |
[
12
] | 2.941176 | false | 85.756677 | 34 | 10 | 97.058824 | 1 |
def checksum(self):
rv = self._checksum
if rv is not None:
return rv
try:
h = hashlib.sha1()
if os.path.isdir(self.filename):
h.update(b"DIR\x00")
for filename in sorted(os.listdir(self.filename)):
if self.env.is_uninteresting_source_name(filename):
continue
if isinstance(filename, str):
filename = filename.encode("utf-8")
h.update(filename)
h.update(
_describe_fs_path_for_checksum(
os.path.join(self.filename, filename.decode("utf-8"))
)
)
h.update(b"\x00")
else:
with open(self.filename, "rb") as f:
while 1:
chunk = f.read(16 * 1024)
if not chunk:
break
h.update(chunk)
checksum = h.hexdigest()
except (OSError, IOError):
checksum = "0" * 40
self._checksum = checksum
return checksum
| 26,485 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/builder.py
|
FileInfo.filename_and_checksum
|
(self)
|
return "%s:%s" % (self.filename, self.checksum)
|
Like 'filename:checksum'.
|
Like 'filename:checksum'.
| 586 | 588 |
def filename_and_checksum(self):
"""Like 'filename:checksum'."""
return "%s:%s" % (self.filename, self.checksum)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/builder.py#L586-L588
| 40 |
[
0,
1,
2
] | 100 |
[] | 0 | true | 85.756677 | 3 | 1 | 100 | 1 |
def filename_and_checksum(self):
return "%s:%s" % (self.filename, self.checksum)
| 26,486 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/builder.py
|
FileInfo.unchanged
|
(self, other)
|
return self.checksum == other.checksum
|
Given another file info checks if the are similar enough to
not consider it changed.
|
Given another file info checks if the are similar enough to
not consider it changed.
| 590 | 603 |
def unchanged(self, other):
"""Given another file info checks if the are similar enough to
not consider it changed.
"""
if not isinstance(other, FileInfo):
raise TypeError("'other' must be a FileInfo, not %r" % other)
# If mtime and size match, we skip the checksum comparison which
# might require a file read which we do not want in those cases.
# (Except if it's a directory, then we won't do that)
if not self.is_dir and self.mtime == other.mtime and self.size == other.size:
return True
return self.checksum == other.checksum
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/builder.py#L590-L603
| 40 |
[
0,
1,
2,
3,
4,
9,
10,
11,
12,
13
] | 71.428571 |
[
5
] | 7.142857 | false | 85.756677 | 14 | 5 | 92.857143 | 2 |
def unchanged(self, other):
if not isinstance(other, FileInfo):
raise TypeError("'other' must be a FileInfo, not %r" % other)
# If mtime and size match, we skip the checksum comparison which
# might require a file read which we do not want in those cases.
# (Except if it's a directory, then we won't do that)
if not self.is_dir and self.mtime == other.mtime and self.size == other.size:
return True
return self.checksum == other.checksum
| 26,487 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/builder.py
|
VirtualSourceInfo.__init__
|
(self, path, mtime=None, checksum=None)
| 607 | 610 |
def __init__(self, path, mtime=None, checksum=None):
self.path = path
self.mtime = mtime
self.checksum = checksum
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/builder.py#L607-L610
| 40 |
[
0,
1,
2,
3
] | 100 |
[] | 0 | true | 85.756677 | 4 | 1 | 100 | 0 |
def __init__(self, path, mtime=None, checksum=None):
self.path = path
self.mtime = mtime
self.checksum = checksum
| 26,488 |
|||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/builder.py
|
VirtualSourceInfo.unchanged
|
(self, other)
|
return (self.mtime, self.checksum) == (other.mtime, other.checksum)
| 612 | 622 |
def unchanged(self, other):
if not isinstance(other, VirtualSourceInfo):
raise TypeError("'other' must be a VirtualSourceInfo, not %r" % other)
if self.path != other.path:
raise ValueError(
"trying to compare mismatched virtual paths: "
"%r.unchanged(%r)" % (self, other)
)
return (self.mtime, self.checksum) == (other.mtime, other.checksum)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/builder.py#L612-L622
| 40 |
[
0,
1,
3,
4,
9,
10
] | 54.545455 |
[
2,
5
] | 18.181818 | false | 85.756677 | 11 | 3 | 81.818182 | 0 |
def unchanged(self, other):
if not isinstance(other, VirtualSourceInfo):
raise TypeError("'other' must be a VirtualSourceInfo, not %r" % other)
if self.path != other.path:
raise ValueError(
"trying to compare mismatched virtual paths: "
"%r.unchanged(%r)" % (self, other)
)
return (self.mtime, self.checksum) == (other.mtime, other.checksum)
| 26,489 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/builder.py
|
VirtualSourceInfo.__repr__
|
(self)
|
return "VirtualSourceInfo(%r, %r, %r)" % (self.path, self.mtime, self.checksum)
| 624 | 625 |
def __repr__(self):
return "VirtualSourceInfo(%r, %r, %r)" % (self.path, self.mtime, self.checksum)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/builder.py#L624-L625
| 40 |
[
0
] | 50 |
[
1
] | 50 | false | 85.756677 | 2 | 1 | 50 | 0 |
def __repr__(self):
return "VirtualSourceInfo(%r, %r, %r)" % (self.path, self.mtime, self.checksum)
| 26,490 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/builder.py
|
Artifact.__init__
|
(
self,
build_state,
artifact_name,
dst_filename,
sources,
source_obj=None,
extra=None,
config_hash=None,
)
| 645 | 666 |
def __init__(
self,
build_state,
artifact_name,
dst_filename,
sources,
source_obj=None,
extra=None,
config_hash=None,
):
self.build_state = build_state
self.artifact_name = artifact_name
self.dst_filename = dst_filename
self.sources = sources
self.in_update_block = False
self.updated = False
self.source_obj = source_obj
self.extra = extra
self.config_hash = config_hash
self._new_artifact_file = None
self._pending_update_ops = []
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/builder.py#L645-L666
| 40 |
[
0,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21
] | 59.090909 |
[] | 0 | false | 85.756677 | 22 | 1 | 100 | 0 |
def __init__(
self,
build_state,
artifact_name,
dst_filename,
sources,
source_obj=None,
extra=None,
config_hash=None,
):
self.build_state = build_state
self.artifact_name = artifact_name
self.dst_filename = dst_filename
self.sources = sources
self.in_update_block = False
self.updated = False
self.source_obj = source_obj
self.extra = extra
self.config_hash = config_hash
self._new_artifact_file = None
self._pending_update_ops = []
| 26,491 |
|||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/builder.py
|
Artifact.__repr__
|
(self)
|
return "<%s %r>" % (
self.__class__.__name__,
self.dst_filename,
)
| 668 | 672 |
def __repr__(self):
return "<%s %r>" % (
self.__class__.__name__,
self.dst_filename,
)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/builder.py#L668-L672
| 40 |
[
0
] | 20 |
[
1
] | 20 | false | 85.756677 | 5 | 1 | 80 | 0 |
def __repr__(self):
return "<%s %r>" % (
self.__class__.__name__,
self.dst_filename,
)
| 26,492 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/builder.py
|
Artifact.is_current
|
(self)
|
return self.build_state.check_artifact_is_current(
self.artifact_name, self.sources, self.config_hash
)
|
Checks if the artifact is current.
|
Checks if the artifact is current.
| 675 | 683 |
def is_current(self):
"""Checks if the artifact is current."""
# If the artifact does not exist, we're not current.
if not os.path.isfile(self.dst_filename):
return False
return self.build_state.check_artifact_is_current(
self.artifact_name, self.sources, self.config_hash
)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/builder.py#L675-L683
| 40 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8
] | 100 |
[] | 0 | true | 85.756677 | 9 | 2 | 100 | 1 |
def is_current(self):
# If the artifact does not exist, we're not current.
if not os.path.isfile(self.dst_filename):
return False
return self.build_state.check_artifact_is_current(
self.artifact_name, self.sources, self.config_hash
)
| 26,493 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/builder.py
|
Artifact.get_dependency_infos
|
(self)
|
return self.build_state.get_artifact_dependency_infos(
self.artifact_name, self.sources
)
| 685 | 688 |
def get_dependency_infos(self):
return self.build_state.get_artifact_dependency_infos(
self.artifact_name, self.sources
)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/builder.py#L685-L688
| 40 |
[
0
] | 25 |
[
1
] | 25 | false | 85.756677 | 4 | 1 | 75 | 0 |
def get_dependency_infos(self):
return self.build_state.get_artifact_dependency_infos(
self.artifact_name, self.sources
)
| 26,494 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/builder.py
|
Artifact.ensure_dir
|
(self)
|
Creates the directory if it does not exist yet.
|
Creates the directory if it does not exist yet.
| 690 | 696 |
def ensure_dir(self):
"""Creates the directory if it does not exist yet."""
dst_dir = os.path.dirname(self.dst_filename)
try:
os.makedirs(dst_dir)
except OSError:
pass
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/builder.py#L690-L696
| 40 |
[
0,
1,
2,
3,
4,
5,
6
] | 100 |
[] | 0 | true | 85.756677 | 7 | 2 | 100 | 1 |
def ensure_dir(self):
dst_dir = os.path.dirname(self.dst_filename)
try:
os.makedirs(dst_dir)
except OSError:
pass
| 26,495 |
|
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/builder.py
|
Artifact.open
|
(self, mode="rb", encoding=None, ensure_dir=None)
|
return open(self._new_artifact_file, mode=mode, encoding=encoding)
|
Opens the artifact for reading or writing. This is transaction
safe by writing into a temporary file and by moving it over the
actual source in commit.
|
Opens the artifact for reading or writing. This is transaction
safe by writing into a temporary file and by moving it over the
actual source in commit.
| 698 | 717 |
def open(self, mode="rb", encoding=None, ensure_dir=None):
"""Opens the artifact for reading or writing. This is transaction
safe by writing into a temporary file and by moving it over the
actual source in commit.
"""
if ensure_dir is None:
ensure_dir = "r" not in mode
if ensure_dir:
self.ensure_dir()
if "r" in mode:
fn = self._new_artifact_file or self.dst_filename
return open(fn, mode=mode, encoding=encoding)
if self._new_artifact_file is None:
fd, tmp_filename = tempfile.mkstemp(
dir=os.path.dirname(self.dst_filename), prefix=".__trans"
)
os.chmod(tmp_filename, 0o644)
self._new_artifact_file = tmp_filename
return os.fdopen(fd, mode)
return open(self._new_artifact_file, mode=mode, encoding=encoding)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/builder.py#L698-L717
| 40 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18
] | 95 |
[
19
] | 5 | false | 85.756677 | 20 | 6 | 95 | 3 |
def open(self, mode="rb", encoding=None, ensure_dir=None):
if ensure_dir is None:
ensure_dir = "r" not in mode
if ensure_dir:
self.ensure_dir()
if "r" in mode:
fn = self._new_artifact_file or self.dst_filename
return open(fn, mode=mode, encoding=encoding)
if self._new_artifact_file is None:
fd, tmp_filename = tempfile.mkstemp(
dir=os.path.dirname(self.dst_filename), prefix=".__trans"
)
os.chmod(tmp_filename, 0o644)
self._new_artifact_file = tmp_filename
return os.fdopen(fd, mode)
return open(self._new_artifact_file, mode=mode, encoding=encoding)
| 26,496 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/builder.py
|
Artifact.replace_with_file
|
(self, filename, ensure_dir=True, copy=False)
|
This is similar to open but it will move over a given named
file. The file will be deleted by a rollback or renamed by a
commit.
|
This is similar to open but it will move over a given named
file. The file will be deleted by a rollback or renamed by a
commit.
| 719 | 731 |
def replace_with_file(self, filename, ensure_dir=True, copy=False):
"""This is similar to open but it will move over a given named
file. The file will be deleted by a rollback or renamed by a
commit.
"""
if ensure_dir:
self.ensure_dir()
if copy:
with self.open("wb") as df:
with open(filename, "rb") as sf:
shutil.copyfileobj(sf, df)
else:
self._new_artifact_file = filename
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/builder.py#L719-L731
| 40 |
[
0,
1,
2,
3,
4
] | 38.461538 |
[
5,
6,
7,
8,
9,
10,
12
] | 53.846154 | false | 85.756677 | 13 | 5 | 46.153846 | 3 |
def replace_with_file(self, filename, ensure_dir=True, copy=False):
if ensure_dir:
self.ensure_dir()
if copy:
with self.open("wb") as df:
with open(filename, "rb") as sf:
shutil.copyfileobj(sf, df)
else:
self._new_artifact_file = filename
| 26,497 |
|
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/builder.py
|
Artifact.render_template_into
|
(self, template_name, this, **extra)
|
Renders a template into the artifact. The default behavior is to
catch the error and render it into the template with a failure marker.
|
Renders a template into the artifact. The default behavior is to
catch the error and render it into the template with a failure marker.
| 733 | 741 |
def render_template_into(self, template_name, this, **extra):
"""Renders a template into the artifact. The default behavior is to
catch the error and render it into the template with a failure marker.
"""
rv = self.build_state.env.render_template(
template_name, self.build_state.pad, this=this, **extra
)
with self.open("wb") as f:
f.write(rv.encode("utf-8") + b"\n")
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/builder.py#L733-L741
| 40 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8
] | 100 |
[] | 0 | true | 85.756677 | 9 | 2 | 100 | 2 |
def render_template_into(self, template_name, this, **extra):
rv = self.build_state.env.render_template(
template_name, self.build_state.pad, this=this, **extra
)
with self.open("wb") as f:
f.write(rv.encode("utf-8") + b"\n")
| 26,498 |
|
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/builder.py
|
Artifact._memorize_dependencies
|
(
self, dependencies=None, virtual_dependencies=None, for_failure=False
)
|
This updates the dependencies recorded for the artifact based
on the direct sources plus the provided dependencies. This also
stores the config hash.
This normally defers the operation until commit but the `for_failure`
more will immediately commit into a new connection.
|
This updates the dependencies recorded for the artifact based
on the direct sources plus the provided dependencies. This also
stores the config hash.
| 743 | 843 |
def _memorize_dependencies(
self, dependencies=None, virtual_dependencies=None, for_failure=False
):
"""This updates the dependencies recorded for the artifact based
on the direct sources plus the provided dependencies. This also
stores the config hash.
This normally defers the operation until commit but the `for_failure`
more will immediately commit into a new connection.
"""
def operation(con):
primary_sources = set(
self.build_state.to_source_filename(x) for x in self.sources
)
seen = set()
rows = []
for source in chain(self.sources, dependencies or ()):
source = self.build_state.to_source_filename(source)
if source in seen:
continue
info = self.build_state.get_file_info(source)
rows.append(
artifacts_row(
artifact=self.artifact_name,
source=source,
source_mtime=info.mtime,
source_size=info.size,
source_checksum=info.checksum,
is_dir=info.is_dir,
is_primary_source=source in primary_sources,
)
)
seen.add(source)
for v_source in virtual_dependencies or ():
checksum = v_source.get_checksum(self.build_state.path_cache)
mtime = v_source.get_mtime(self.build_state.path_cache)
rows.append(
artifacts_row(
artifact=self.artifact_name,
source=v_source.path,
source_mtime=mtime,
source_size=None,
source_checksum=checksum,
is_dir=False,
is_primary_source=False,
)
)
reporter.report_dependencies(rows)
cur = con.cursor()
if not for_failure:
cur.execute(
"delete from artifacts where artifact = ?", [self.artifact_name]
)
if rows:
cur.executemany(
"""
insert or replace into artifacts (
artifact, source, source_mtime, source_size,
source_checksum, is_dir, is_primary_source)
values (?, ?, ?, ?, ?, ?, ?)
""",
rows,
)
if self.config_hash is None:
cur.execute(
"""
delete from artifact_config_hashes
where artifact = ?
""",
[self.artifact_name],
)
else:
cur.execute(
"""
insert or replace into artifact_config_hashes
(artifact, config_hash) values (?, ?)
""",
[self.artifact_name, self.config_hash],
)
cur.close()
if for_failure:
con = self.build_state.connect_to_database()
try:
operation(con)
except: # noqa
con.rollback()
con.close()
raise
con.commit()
con.close()
else:
self._auto_deferred_update_operation(operation)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/builder.py#L743-L843
| 40 |
[
0,
10,
11,
12,
15,
16,
17,
18,
19,
20,
21,
22,
23,
34,
35,
36,
37,
38,
39,
40,
51,
52,
53,
54,
55,
56,
59,
60,
61,
62,
63,
64,
65,
66,
67,
68,
69,
70,
71,
72,
73,
74,
75,
76,
77,
78,
86,
87,
88,
89,
90,
91,
92,
97,
98,
99,
100
] | 56.435644 |
[
79,
93,
94,
95,
96
] | 4.950495 | false | 85.756677 | 101 | 12 | 95.049505 | 6 |
def _memorize_dependencies(
self, dependencies=None, virtual_dependencies=None, for_failure=False
):
def operation(con):
primary_sources = set(
self.build_state.to_source_filename(x) for x in self.sources
)
seen = set()
rows = []
for source in chain(self.sources, dependencies or ()):
source = self.build_state.to_source_filename(source)
if source in seen:
continue
info = self.build_state.get_file_info(source)
rows.append(
artifacts_row(
artifact=self.artifact_name,
source=source,
source_mtime=info.mtime,
source_size=info.size,
source_checksum=info.checksum,
is_dir=info.is_dir,
is_primary_source=source in primary_sources,
)
)
seen.add(source)
for v_source in virtual_dependencies or ():
checksum = v_source.get_checksum(self.build_state.path_cache)
mtime = v_source.get_mtime(self.build_state.path_cache)
rows.append(
artifacts_row(
artifact=self.artifact_name,
source=v_source.path,
source_mtime=mtime,
source_size=None,
source_checksum=checksum,
is_dir=False,
is_primary_source=False,
)
)
reporter.report_dependencies(rows)
cur = con.cursor()
if not for_failure:
cur.execute(
"delete from artifacts where artifact = ?", [self.artifact_name]
)
if rows:
cur.executemany(,
rows,
)
if self.config_hash is None:
cur.execute(,
[self.artifact_name],
)
else:
cur.execute(,
[self.artifact_name, self.config_hash],
)
cur.close()
if for_failure:
con = self.build_state.connect_to_database()
try:
operation(con)
except: # noqa
con.rollback()
con.close()
raise
con.commit()
con.close()
else:
self._auto_deferred_update_operation(operation)
| 26,499 |
|
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/builder.py
|
Artifact.clear_dirty_flag
|
(self)
|
Clears the dirty flag for all sources.
|
Clears the dirty flag for all sources.
| 845 | 861 |
def clear_dirty_flag(self):
"""Clears the dirty flag for all sources."""
def operation(con):
sources = [self.build_state.to_source_filename(x) for x in self.sources]
cur = con.cursor()
cur.execute(
"""
delete from dirty_sources where source in (%s)
"""
% ", ".join(["?"] * len(sources)),
list(sources),
)
cur.close()
reporter.report_dirty_flag(False)
self._auto_deferred_update_operation(operation)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/builder.py#L845-L861
| 40 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16
] | 100 |
[] | 0 | true | 85.756677 | 17 | 3 | 100 | 1 |
def clear_dirty_flag(self):
def operation(con):
sources = [self.build_state.to_source_filename(x) for x in self.sources]
cur = con.cursor()
cur.execute(
% ", ".join(["?"] * len(sources)),
list(sources),
)
cur.close()
reporter.report_dirty_flag(False)
self._auto_deferred_update_operation(operation)
| 26,500 |
|
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/builder.py
|
Artifact.set_dirty_flag
|
(self)
|
Given a list of artifacts this will mark all of their sources
as dirty so that they will be rebuilt next time.
|
Given a list of artifacts this will mark all of their sources
as dirty so that they will be rebuilt next time.
| 863 | 887 |
def set_dirty_flag(self):
"""Given a list of artifacts this will mark all of their sources
as dirty so that they will be rebuilt next time.
"""
def operation(con):
sources = set()
for source in self.sources:
sources.add(self.build_state.to_source_filename(source))
if not sources:
return
cur = con.cursor()
cur.executemany(
"""
insert or replace into dirty_sources (source) values (?)
""",
[(x,) for x in sources],
)
cur.close()
reporter.report_dirty_flag(True)
self._auto_deferred_update_operation(operation)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/builder.py#L863-L887
| 40 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24
] | 96 |
[
11
] | 4 | false | 85.756677 | 25 | 5 | 96 | 2 |
def set_dirty_flag(self):
def operation(con):
sources = set()
for source in self.sources:
sources.add(self.build_state.to_source_filename(source))
if not sources:
return
cur = con.cursor()
cur.executemany(,
[(x,) for x in sources],
)
cur.close()
reporter.report_dirty_flag(True)
self._auto_deferred_update_operation(operation)
| 26,501 |
|
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/builder.py
|
Artifact._auto_deferred_update_operation
|
(self, f)
|
Helper that defers an update operation when inside an update
block to a later point. Otherwise it's auto committed.
|
Helper that defers an update operation when inside an update
block to a later point. Otherwise it's auto committed.
| 889 | 902 |
def _auto_deferred_update_operation(self, f):
"""Helper that defers an update operation when inside an update
block to a later point. Otherwise it's auto committed.
"""
if self.in_update_block:
self._pending_update_ops.append(f)
return
con = self.build_state.connect_to_database()
try:
f(con)
except: # noqa
con.rollback()
raise
con.commit()
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/builder.py#L889-L902
| 40 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
13
] | 78.571429 |
[
10,
11,
12
] | 21.428571 | false | 85.756677 | 14 | 3 | 78.571429 | 2 |
def _auto_deferred_update_operation(self, f):
if self.in_update_block:
self._pending_update_ops.append(f)
return
con = self.build_state.connect_to_database()
try:
f(con)
except: # noqa
con.rollback()
raise
con.commit()
| 26,502 |
|
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/builder.py
|
Artifact.update
|
(self)
|
Opens the artifact for modifications. At the start the dirty
flag is cleared out and if the commit goes through without errors it
stays cleared. The setting of the dirty flag has to be done by the
caller however based on the `exc_info` on the context.
|
Opens the artifact for modifications. At the start the dirty
flag is cleared out and if the commit goes through without errors it
stays cleared. The setting of the dirty flag has to be done by the
caller however based on the `exc_info` on the context.
| 905 | 918 |
def update(self):
"""Opens the artifact for modifications. At the start the dirty
flag is cleared out and if the commit goes through without errors it
stays cleared. The setting of the dirty flag has to be done by the
caller however based on the `exc_info` on the context.
"""
ctx = self.begin_update()
try:
yield ctx
except: # pylint: disable=bare-except # noqa
exc_info = sys.exc_info()
self.finish_update(ctx, exc_info)
else:
self.finish_update(ctx)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/builder.py#L905-L918
| 40 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13
] | 100 |
[] | 0 | true | 85.756677 | 14 | 2 | 100 | 4 |
def update(self):
ctx = self.begin_update()
try:
yield ctx
except: # pylint: disable=bare-except # noqa
exc_info = sys.exc_info()
self.finish_update(ctx, exc_info)
else:
self.finish_update(ctx)
| 26,503 |
|
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/builder.py
|
Artifact.begin_update
|
(self)
|
return ctx
|
Begins an update block.
|
Begins an update block.
| 920 | 929 |
def begin_update(self):
"""Begins an update block."""
if self.in_update_block:
raise RuntimeError("Artifact is already open for updates.")
self.updated = False
ctx = Context(self)
ctx.push()
self.in_update_block = True
self.clear_dirty_flag()
return ctx
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/builder.py#L920-L929
| 40 |
[
0,
1,
2,
4,
5,
6,
7,
8,
9
] | 90 |
[
3
] | 10 | false | 85.756677 | 10 | 2 | 90 | 1 |
def begin_update(self):
if self.in_update_block:
raise RuntimeError("Artifact is already open for updates.")
self.updated = False
ctx = Context(self)
ctx.push()
self.in_update_block = True
self.clear_dirty_flag()
return ctx
| 26,504 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/builder.py
|
Artifact._commit
|
(self)
| 931 | 955 |
def _commit(self):
con = None
try:
for op in self._pending_update_ops:
if con is None:
con = self.build_state.connect_to_database()
op(con)
if self._new_artifact_file is not None:
os.replace(self._new_artifact_file, self.dst_filename)
self._new_artifact_file = None
if con is not None:
con.commit()
con.close()
con = None
self.build_state.updated_artifacts.append(self)
self.build_state.builder.failure_controller.clear_failure(
self.artifact_name
)
finally:
if con is not None:
con.rollback()
con.close()
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/builder.py#L931-L955
| 40 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
22
] | 80 |
[
23,
24
] | 8 | false | 85.756677 | 25 | 6 | 92 | 0 |
def _commit(self):
con = None
try:
for op in self._pending_update_ops:
if con is None:
con = self.build_state.connect_to_database()
op(con)
if self._new_artifact_file is not None:
os.replace(self._new_artifact_file, self.dst_filename)
self._new_artifact_file = None
if con is not None:
con.commit()
con.close()
con = None
self.build_state.updated_artifacts.append(self)
self.build_state.builder.failure_controller.clear_failure(
self.artifact_name
)
finally:
if con is not None:
con.rollback()
con.close()
| 26,505 |
|||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/builder.py
|
Artifact._rollback
|
(self)
| 957 | 964 |
def _rollback(self):
if self._new_artifact_file is not None:
try:
os.remove(self._new_artifact_file)
except OSError:
pass
self._new_artifact_file = None
self._pending_update_ops = []
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/builder.py#L957-L964
| 40 |
[
0,
1,
7
] | 37.5 |
[
2,
3,
4,
5,
6
] | 62.5 | false | 85.756677 | 8 | 3 | 37.5 | 0 |
def _rollback(self):
if self._new_artifact_file is not None:
try:
os.remove(self._new_artifact_file)
except OSError:
pass
self._new_artifact_file = None
self._pending_update_ops = []
| 26,506 |
|||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/builder.py
|
Artifact.finish_update
|
(self, ctx, exc_info=None)
|
Finalizes an update block.
|
Finalizes an update block.
| 966 | 1,000 |
def finish_update(self, ctx, exc_info=None):
"""Finalizes an update block."""
if not self.in_update_block:
raise RuntimeError("Artifact is not open for updates.")
ctx.pop()
self.in_update_block = False
self.updated = True
# If there was no error, we memoize the dependencies like normal
# and then commit our transaction.
if exc_info is None:
self._memorize_dependencies(
ctx.referenced_dependencies,
ctx.referenced_virtual_dependencies.values(),
)
self._commit()
return
# If an error happened we roll back all changes and record the
# stacktrace in two locations: we record it on the context so
# that a called can respond to our failure, and we also persist
# it so that the dev server can render it out later.
self._rollback()
# This is a special form of dependency memorization where we do
# not prune old dependencies and we just append new ones and we
# use a new database connection that immediately commits.
self._memorize_dependencies(
ctx.referenced_dependencies,
ctx.referenced_virtual_dependencies.values(),
for_failure=True,
)
ctx.exc_info = exc_info
self.build_state.notify_failure(self, exc_info)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/builder.py#L966-L1000
| 40 |
[
0,
1,
2,
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
] | 97.142857 |
[
3
] | 2.857143 | false | 85.756677 | 35 | 3 | 97.142857 | 1 |
def finish_update(self, ctx, exc_info=None):
if not self.in_update_block:
raise RuntimeError("Artifact is not open for updates.")
ctx.pop()
self.in_update_block = False
self.updated = True
# If there was no error, we memoize the dependencies like normal
# and then commit our transaction.
if exc_info is None:
self._memorize_dependencies(
ctx.referenced_dependencies,
ctx.referenced_virtual_dependencies.values(),
)
self._commit()
return
# If an error happened we roll back all changes and record the
# stacktrace in two locations: we record it on the context so
# that a called can respond to our failure, and we also persist
# it so that the dev server can render it out later.
self._rollback()
# This is a special form of dependency memorization where we do
# not prune old dependencies and we just append new ones and we
# use a new database connection that immediately commits.
self._memorize_dependencies(
ctx.referenced_dependencies,
ctx.referenced_virtual_dependencies.values(),
for_failure=True,
)
ctx.exc_info = exc_info
self.build_state.notify_failure(self, exc_info)
| 26,507 |
|
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/builder.py
|
PathCache.__init__
|
(self, env)
| 1,004 | 1,007 |
def __init__(self, env):
self.file_info_cache = {}
self.source_filename_cache = {}
self.env = env
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/builder.py#L1004-L1007
| 40 |
[
0,
1,
2,
3
] | 100 |
[] | 0 | true | 85.756677 | 4 | 1 | 100 | 0 |
def __init__(self, env):
self.file_info_cache = {}
self.source_filename_cache = {}
self.env = env
| 26,508 |
|||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/builder.py
|
PathCache.to_source_filename
|
(self, filename)
|
return rv
|
Given a path somewhere below the environment this will return the
short source filename that is used internally. Unlike the given
path, this identifier is also platform independent.
|
Given a path somewhere below the environment this will return the
short source filename that is used internally. Unlike the given
path, this identifier is also platform independent.
| 1,009 | 1,033 |
def to_source_filename(self, filename):
"""Given a path somewhere below the environment this will return the
short source filename that is used internally. Unlike the given
path, this identifier is also platform independent.
"""
key = filename
rv = self.source_filename_cache.get(key)
if rv is not None:
return rv
folder = os.path.abspath(self.env.root_path)
if isinstance(folder, str) and not isinstance(filename, str):
filename = filename.decode(fs_enc)
filename = os.path.normpath(os.path.join(folder, filename))
if filename.startswith(folder):
filename = filename[len(folder) :].lstrip(os.path.sep)
if os.path.altsep:
filename = filename.lstrip(os.path.altsep)
else:
raise ValueError(
"The given value (%r) is not below the "
"source folder (%r)" % (filename, self.env.root_path)
)
rv = filename.replace(os.path.sep, "/")
self.source_filename_cache[key] = rv
return rv
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/builder.py#L1009-L1033
| 40 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
12,
13,
14,
15,
21,
22,
23,
24
] | 76 |
[
11,
16,
18
] | 12 | false | 85.756677 | 25 | 6 | 88 | 3 |
def to_source_filename(self, filename):
key = filename
rv = self.source_filename_cache.get(key)
if rv is not None:
return rv
folder = os.path.abspath(self.env.root_path)
if isinstance(folder, str) and not isinstance(filename, str):
filename = filename.decode(fs_enc)
filename = os.path.normpath(os.path.join(folder, filename))
if filename.startswith(folder):
filename = filename[len(folder) :].lstrip(os.path.sep)
if os.path.altsep:
filename = filename.lstrip(os.path.altsep)
else:
raise ValueError(
"The given value (%r) is not below the "
"source folder (%r)" % (filename, self.env.root_path)
)
rv = filename.replace(os.path.sep, "/")
self.source_filename_cache[key] = rv
return rv
| 26,509 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/builder.py
|
PathCache.get_file_info
|
(self, filename)
|
return rv
|
Returns the file info for a given file. This will be cached
on the generator for the lifetime of it. This means that further
accesses to this file info will not cause more IO but it might not
be safe to use the generator after modifications to the original
files have been performed on the outside.
Generally this function can be used to acquire the file info for
any file on the file system but it should onl be used for source
files or carefully for other things.
The filename given can be a source filename.
|
Returns the file info for a given file. This will be cached
on the generator for the lifetime of it. This means that further
accesses to this file info will not cause more IO but it might not
be safe to use the generator after modifications to the original
files have been performed on the outside.
| 1,035 | 1,052 |
def get_file_info(self, filename):
"""Returns the file info for a given file. This will be cached
on the generator for the lifetime of it. This means that further
accesses to this file info will not cause more IO but it might not
be safe to use the generator after modifications to the original
files have been performed on the outside.
Generally this function can be used to acquire the file info for
any file on the file system but it should onl be used for source
files or carefully for other things.
The filename given can be a source filename.
"""
fn = os.path.join(self.env.root_path, filename)
rv = self.file_info_cache.get(fn)
if rv is None:
self.file_info_cache[fn] = rv = FileInfo(self.env, fn)
return rv
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/builder.py#L1035-L1052
| 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 | 2 | 100 | 11 |
def get_file_info(self, filename):
fn = os.path.join(self.env.root_path, filename)
rv = self.file_info_cache.get(fn)
if rv is None:
self.file_info_cache[fn] = rv = FileInfo(self.env, fn)
return rv
| 26,510 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/builder.py
|
Builder.__init__
|
(self, pad, destination_path, buildstate_path=None, extra_flags=None)
| 1,056 | 1,090 |
def __init__(self, pad, destination_path, buildstate_path=None, extra_flags=None):
self.extra_flags = process_extra_flags(extra_flags)
self.pad = pad
self.destination_path = os.path.abspath(
os.path.join(pad.db.env.root_path, destination_path)
)
if buildstate_path:
self.meta_path = buildstate_path
else:
self.meta_path = os.path.join(self.destination_path, ".lektor")
self.failure_controller = FailureController(pad, self.destination_path)
try:
os.makedirs(self.meta_path)
if os.listdir(self.destination_path) != [".lektor"]:
if not click.confirm(
click.style(
"The build dir %s hasn't been used before, and other "
"files or folders already exist there. If you prune "
"(which normally follows the build step), "
"they will be deleted. Proceed with building?"
% self.destination_path,
fg="yellow",
)
):
os.rmdir(self.meta_path)
raise click.Abort()
except OSError:
pass
con = self.connect_to_database()
try:
create_tables(con)
finally:
con.close()
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/builder.py#L1056-L1090
| 40 |
[
0,
1,
2,
3,
6,
9,
10,
11,
12,
13,
14,
27,
28,
29,
30,
31,
32,
34
] | 51.428571 |
[
7,
15,
25,
26
] | 11.428571 | false | 85.756677 | 35 | 5 | 88.571429 | 0 |
def __init__(self, pad, destination_path, buildstate_path=None, extra_flags=None):
self.extra_flags = process_extra_flags(extra_flags)
self.pad = pad
self.destination_path = os.path.abspath(
os.path.join(pad.db.env.root_path, destination_path)
)
if buildstate_path:
self.meta_path = buildstate_path
else:
self.meta_path = os.path.join(self.destination_path, ".lektor")
self.failure_controller = FailureController(pad, self.destination_path)
try:
os.makedirs(self.meta_path)
if os.listdir(self.destination_path) != [".lektor"]:
if not click.confirm(
click.style(
"The build dir %s hasn't been used before, and other "
"files or folders already exist there. If you prune "
"(which normally follows the build step), "
"they will be deleted. Proceed with building?"
% self.destination_path,
fg="yellow",
)
):
os.rmdir(self.meta_path)
raise click.Abort()
except OSError:
pass
con = self.connect_to_database()
try:
create_tables(con)
finally:
con.close()
| 26,511 |
|||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/builder.py
|
Builder.env
|
(self)
|
return self.pad.db.env
|
The environment backing this generator.
|
The environment backing this generator.
| 1,093 | 1,095 |
def env(self):
"""The environment backing this generator."""
return self.pad.db.env
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/builder.py#L1093-L1095
| 40 |
[
0,
1,
2
] | 100 |
[] | 0 | true | 85.756677 | 3 | 1 | 100 | 1 |
def env(self):
return self.pad.db.env
| 26,512 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/builder.py
|
Builder.buildstate_database_filename
|
(self)
|
return os.path.join(self.meta_path, "buildstate")
|
The filename for the build state database.
|
The filename for the build state database.
| 1,098 | 1,100 |
def buildstate_database_filename(self):
"""The filename for the build state database."""
return os.path.join(self.meta_path, "buildstate")
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/builder.py#L1098-L1100
| 40 |
[
0,
1,
2
] | 100 |
[] | 0 | true | 85.756677 | 3 | 1 | 100 | 1 |
def buildstate_database_filename(self):
return os.path.join(self.meta_path, "buildstate")
| 26,513 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.