Skip to content
GitLab
Menu
Why GitLab
Pricing
Contact Sales
Explore
Why GitLab
Pricing
Contact Sales
Explore
Sign in
Get free trial
Primary navigation
Search or go to…
Project
buildstream
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Privacy statement
Keyboard shortcuts
?
What's new
6
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
BuildStream
buildstream
Commits
be20f411
Commit
be20f411
authored
7 years ago
by
Tristan Maat
Committed by
Tristan Maat
7 years ago
Browse files
Options
Downloads
Patches
Plain Diff
widget.py: Replace tail with a python implementation
parent
5d5d388e
No related branches found
No related tags found
1 merge request
!81
Cross platform
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
buildstream/_frontend/widget.py
+23
-6
23 additions, 6 deletions
buildstream/_frontend/widget.py
with
23 additions
and
6 deletions
buildstream/_frontend/widget.py
+
23
−
6
View file @
be20f411
...
...
@@ -23,7 +23,9 @@ import subprocess
import
datetime
import
pkg_resources
from
collections
import
OrderedDict
from
contextlib
import
ExitStack
from
ruamel
import
yaml
from
mmap
import
mmap
from
..
import
utils
,
_yaml
from
..plugin
import
_plugin_lookup
...
...
@@ -386,12 +388,27 @@ class LogLine(Widget):
return
text
def
read_last_lines
(
self
,
logfile
):
tail_command
=
utils
.
get_host_tool
(
'
tail
'
)
# Lets just expect this to always pass for now...
output
=
subprocess
.
check_output
([
tail_command
,
'
-n
'
,
str
(
self
.
log_lines
),
logfile
])
output
=
output
.
decode
(
'
UTF-8
'
)
return
output
.
rstrip
()
with
ExitStack
()
as
stack
:
# mmap handles low-level memory details, allowing for
# faster searches
f
=
stack
.
enter_context
(
open
(
logfile
,
'
r+
'
))
log
=
stack
.
enter_context
(
mmap
(
f
.
fileno
(),
os
.
path
.
getsize
(
f
.
name
)))
count
=
0
end
=
log
.
size
()
-
1
while
count
<
self
.
log_lines
and
end
>=
0
:
location
=
log
.
rfind
(
b
'
\n
'
,
0
,
end
)
count
+=
1
# If location is -1 (none found), this will print the
# first character despite the later +1
end
=
location
# end+1 since we do not want to print the first newline
# (consistent with `tail` behavior)
lines
=
log
[
end
:].
splitlines
()
return
'
\n
'
.
join
([
line
.
decode
(
'
utf-8
'
)
for
line
in
lines
]).
rstrip
()
#
# A message to be printed at program startup, indicating
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment