Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
surykatka
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
2
Merge Requests
2
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
surykatka
Commits
557155b4
Commit
557155b4
authored
Sep 10, 2021
by
Romain Courteaud
🐙
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Provide file output for status
This allows to have better atomicity than shell redirection
parent
b498c212
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
6 deletions
+28
-6
src/surykatka/bot.py
src/surykatka/bot.py
+23
-6
src/surykatka/cli.py
src/surykatka/cli.py
+5
-0
No files found.
src/surykatka/bot.py
View file @
557155b4
...
@@ -51,6 +51,8 @@ from .ssl import (
...
@@ -51,6 +51,8 @@ from .ssl import (
)
)
import
datetime
import
datetime
from
email.utils
import
parsedate_to_datetime
from
email.utils
import
parsedate_to_datetime
import
tempfile
import
os
__version__
=
"0.6.0"
__version__
=
"0.6.0"
...
@@ -645,24 +647,39 @@ class WebBot:
...
@@ -645,24 +647,39 @@ class WebBot:
float
(
self
.
config
[
"WARNING_PERIOD"
]),
float
(
self
.
config
[
"WARNING_PERIOD"
]),
)
)
if
self
.
config
[
"FORMAT"
]
==
"json"
:
if
self
.
config
[
"FORMAT"
]
==
"json"
:
print
(
json
.
dumps
(
status_dict
)
)
status_output
=
json
.
dumps
(
status_dict
)
else
:
else
:
status_list
=
[]
append_status
=
status_list
.
append
for
table_key
in
status_dict
:
for
table_key
in
status_dict
:
print
(
"# %s"
%
table_key
)
append_status
(
"# %s"
%
table_key
)
print
(
""
)
append_status
(
""
)
table
=
status_dict
[
table_key
]
table
=
status_dict
[
table_key
]
if
table
:
if
table
:
# Print the header
# Print the header
table_key_list
=
[
x
for
x
in
table
[
0
].
keys
()]
table_key_list
=
[
x
for
x
in
table
[
0
].
keys
()]
table_key_list
.
sort
()
table_key_list
.
sort
()
print
(
" | "
.
join
(
table_key_list
))
append_status
(
" | "
.
join
(
table_key_list
))
for
line
in
table
:
for
line
in
table
:
print
(
append_status
(
" | "
.
join
(
" | "
.
join
(
[
"%s"
%
(
line
[
x
])
for
x
in
table_key_list
]
[
"%s"
%
(
line
[
x
])
for
x
in
table_key_list
]
)
)
)
)
print
(
""
)
append_status
(
""
)
status_output
=
"
\
n
"
.
join
(
status_list
)
if
self
.
config
[
"STDOUT"
]
==
""
:
print
(
status_output
)
else
:
# https://blog.gocept.com/2013/07/15/reliable-file-updates-with-python/#write-replace
with
tempfile
.
NamedTemporaryFile
(
"w"
,
dir
=
os
.
path
.
dirname
(
self
.
config
[
"STDOUT"
]),
delete
=
False
,
)
as
temp_file
:
temp_file
.
write
(
status_output
)
temp_file_name
=
temp_file
.
name
os
.
rename
(
temp_file_name
,
self
.
config
[
"STDOUT"
])
def
create_bot
(
**
kw
):
def
create_bot
(
**
kw
):
...
...
src/surykatka/cli.py
View file @
557155b4
...
@@ -48,6 +48,9 @@ from .bot import create_bot
...
@@ -48,6 +48,9 @@ from .bot import create_bot
help
=
"Reload the configuration file between each crawl."
,
help
=
"Reload the configuration file between each crawl."
,
show_default
=
True
,
show_default
=
True
,
)
)
@
click
.
option
(
"--stdout"
,
help
=
"File to store status. (default: stdout)"
,
default
=
""
)
@
click
.
option
(
@
click
.
option
(
"--output"
,
"--output"
,
"-o"
,
"-o"
,
...
@@ -69,6 +72,7 @@ def runSurykatka(
...
@@ -69,6 +72,7 @@ def runSurykatka(
warning
,
warning
,
configuration
,
configuration
,
reload
,
reload
,
stdout
,
output
,
output
,
profile
,
profile
,
):
):
...
@@ -91,6 +95,7 @@ def runSurykatka(
...
@@ -91,6 +95,7 @@ def runSurykatka(
mapping
[
"NAMESERVER"
]
=
nameserver
mapping
[
"NAMESERVER"
]
=
nameserver
if
reload
:
if
reload
:
mapping
[
"RELOAD"
]
=
str
(
reload
)
mapping
[
"RELOAD"
]
=
str
(
reload
)
mapping
[
"STDOUT"
]
=
stdout
mapping
[
"FORMAT"
]
=
output
mapping
[
"FORMAT"
]
=
output
bot
=
create_bot
(
cfgfile
=
configuration
,
mapping
=
mapping
)
bot
=
create_bot
(
cfgfile
=
configuration
,
mapping
=
mapping
)
if
profile
is
None
:
if
profile
is
None
:
...
...
Write
Preview
Markdown
is supported
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