Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
juga
sbws
Commits
666b9d7f
Commit
666b9d7f
authored
Jun 25, 2018
by
juga
Committed by
Matt Traudt
Jul 03, 2018
Browse files
Move back write function to V3BWFile
but not allowing /dev/stdout
parent
a00625b0
Changes
2
Hide whitespace changes
Inline
Side-by-side
sbws/core/generate.py
View file @
666b9d7f
...
...
@@ -4,7 +4,6 @@ from sbws.lib.resultdump import load_recent_results_in_datadir
from
argparse
import
ArgumentDefaultsHelpFormatter
import
os
import
logging
from
sbws.util.filelock
import
DirectoryLock
from
sbws.util.timestamp
import
now_fname
log
=
logging
.
getLogger
(
__name__
)
...
...
@@ -33,31 +32,6 @@ def gen_parser(sub):
'out, and we do so proportionally'
)
def
_write_v3bw_file
(
v3bwfile
,
output
):
log
.
info
(
'Writing v3bw file to %s'
,
output
)
out_dir
=
os
.
path
.
dirname
(
output
)
out_link
=
os
.
path
.
join
(
out_dir
,
'latest.v3bw'
)
if
os
.
path
.
exists
(
out_link
):
log
.
debug
(
'Deleting existing symlink before creating a new one.'
)
os
.
remove
(
out_link
)
# to keep test_generate.py working
if
output
!=
'/dev/stdout'
:
with
DirectoryLock
(
out_dir
):
with
open
(
output
,
'wt'
)
as
fd
:
fd
.
write
(
str
(
v3bwfile
.
header
))
for
line
in
v3bwfile
.
bw_lines
:
fd
.
write
(
str
(
line
))
output_basename
=
os
.
path
.
basename
(
output
)
log
.
debug
(
'Creating symlink from {} to {}.'
.
format
(
output_basename
,
out_link
))
os
.
symlink
(
output_basename
,
out_link
)
else
:
with
open
(
output
,
'wt'
)
as
fd
:
fd
.
write
(
str
(
v3bwfile
.
header
))
for
line
in
v3bwfile
.
bw_lines
:
fd
.
write
(
str
(
line
))
def
main
(
args
,
conf
):
if
not
is_initted
(
args
.
directory
):
fail_hard
(
'Sbws isn
\'
t initialized. Try sbws init'
)
...
...
@@ -83,5 +57,5 @@ def main(args, conf):
return
bw_file
=
V3BWFile
.
from_arg_results
(
args
,
conf
,
results
)
output
=
args
.
output
or
conf
[
'paths'
][
'v3bw_fname'
].
format
(
now_fname
())
_write_v3bw_file
(
bw_file
,
output
)
V3BWFile
.
write
(
output
)
log
.
info
(
'Mean bandwidth per line: %f "KiB"'
,
bw_file
.
avg_bw
)
sbws/lib/v3bwfile.py
View file @
666b9d7f
...
...
@@ -3,12 +3,13 @@
(v3bw) used by bandwidth authorities."""
import
logging
import
os
from
statistics
import
median
from
sbws
import
__version__
from
sbws.globals
import
SPEC_VERSION
,
BW_LINE_SIZE
from
sbws.lib.resultdump
import
ResultSuccess
,
_ResultType
from
sbws.util.filelock
import
FileLock
from
sbws.util.filelock
import
FileLock
,
DirectoryLock
from
sbws.util.timestamp
import
now_isodt_str
,
unixts_to_isodt_str
log
=
logging
.
getLogger
(
__name__
)
...
...
@@ -405,3 +406,23 @@ class V3BWFile(object):
header
=
V3BWHeader
.
from_results
(
conf
,
results
)
f
=
cls
(
header
,
bw_lines
)
return
f
def
write
(
self
,
output
):
if
output
==
'/dev/stdout'
:
log
.
info
(
"Writing to stdout is not supported."
)
return
log
.
info
(
'Writing v3bw file to %s'
,
output
)
out_dir
=
os
.
path
.
dirname
(
output
)
out_link
=
os
.
path
.
join
(
out_dir
,
'latest.v3bw'
)
if
os
.
path
.
exists
(
out_link
):
log
.
debug
(
'Deleting existing symlink before creating a new one.'
)
os
.
remove
(
out_link
)
with
DirectoryLock
(
out_dir
):
with
open
(
output
,
'wt'
)
as
fd
:
fd
.
write
(
str
(
self
.
header
))
for
line
in
self
.
bw_lines
:
fd
.
write
(
str
(
line
))
output_basename
=
os
.
path
.
basename
(
output
)
log
.
debug
(
'Creating symlink from {} to {}.'
.
format
(
output_basename
,
out_link
))
os
.
symlink
(
output_basename
,
out_link
)
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment