Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
U
url-checker
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
Romain Courteaud
url-checker
Commits
43d944f1
Commit
43d944f1
authored
Dec 06, 2019
by
Romain Courteaud
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow to quickly check one site status with memory DB
parent
b2fbb79f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
41 additions
and
19 deletions
+41
-19
urlchecker_bot.py
urlchecker_bot.py
+27
-9
urlchecker_cli.py
urlchecker_cli.py
+10
-10
urlchecker_configuration.py
urlchecker_configuration.py
+4
-0
No files found.
urlchecker_bot.py
View file @
43d944f1
...
...
@@ -28,6 +28,10 @@ class WebBot:
def
__init__
(
self
,
**
kw
):
self
.
config
=
createConfiguration
(
**
kw
)
def
closeDB
(
self
):
if
hasattr
(
self
,
"_db"
):
self
.
_db
.
close
()
def
initDB
(
self
):
self
.
_db
=
LogDB
(
self
.
config
[
"SQLITE"
])
self
.
_db
.
createTables
()
...
...
@@ -98,9 +102,6 @@ class WebBot:
# XXX Check HTTP Cache
def
status
(
self
):
# XXX
self
.
initDB
()
# Report the bot status
print
(
"# STATUS"
)
status
=
reportStatus
(
self
.
_db
).
get
()
...
...
@@ -150,7 +151,7 @@ class WebBot:
if
server_ip
not
in
server_ip_dict
:
server_ip_dict
[
server_ip
]
=
[]
if
dns_change
[
"domain"
]
not
in
server_ip_dict
[
server_ip
]:
server_ip_dict
[
server_ip
].
append
(
dns_change
[
"domain"
])
server_ip_dict
[
server_ip
].
append
(
dns_change
[
"domain"
])
# Report the list of CDN status
query
=
reportNetwork
(
...
...
@@ -206,11 +207,8 @@ class WebBot:
def
stop
(
self
):
self
.
_running
=
False
logStatus
(
self
.
_db
,
"stop"
)
if
hasattr
(
self
,
"_db"
):
self
.
_db
.
close
()
def
run
(
self
):
self
.
initDB
()
def
crawl
(
self
):
status_id
=
logStatus
(
self
.
_db
,
"start"
)
logConfiguration
(
self
.
_db
,
status_id
,
self
.
config
)
...
...
@@ -228,9 +226,29 @@ class WebBot:
except
:
# XXX Put traceback in the log?
logStatus
(
self
.
_db
,
"error"
)
self
.
stop
()
raise
def
run
(
self
,
mode
):
if
mode
not
in
[
"crawl"
,
"status"
]:
raise
NotImplementedError
(
"Unexpected mode: %s"
%
mode
)
if
self
.
config
[
"SQLITE"
]
==
":memory:"
:
# Crawl/report are mandatory when using memory
mode
=
"all"
self
.
initDB
()
try
:
if
mode
in
[
"crawl"
,
"all"
]:
self
.
crawl
()
if
mode
in
[
"status"
,
"all"
]:
self
.
status
()
except
:
self
.
closeDB
()
raise
else
:
self
.
closeDB
()
def
create_bot
(
**
kw
):
return
WebBot
(
**
kw
)
urlchecker_cli.py
View file @
43d944f1
...
...
@@ -2,11 +2,16 @@ import click
import
sys
from
urlchecker_bot
import
create_bot
@
click
.
command
(
short_help
=
"Runs url checker bot."
)
@
click
.
option
(
'--run'
,
'-r'
,
help
=
"The bot operation to run."
,
show_default
=
True
,
default
=
'status'
,
type
=
click
.
Choice
([
'crawl'
,
'status'
]))
@
click
.
option
(
"--run"
,
"-r"
,
help
=
"The bot operation mode to run."
,
show_default
=
True
,
default
=
"status"
,
type
=
click
.
Choice
([
"crawl"
,
"status"
]),
)
@
click
.
option
(
"--sqlite"
,
"-s"
,
help
=
"The path of the sqlite DB. (default: :memory:)"
)
...
...
@@ -32,12 +37,7 @@ def runUrlChecker(run, sqlite, dns, url, domain, configuration):
if
dns
:
mapping
[
"DNS"
]
=
dns
bot
=
create_bot
(
cfgfile
=
configuration
,
mapping
=
mapping
)
if
run
==
'status'
:
return
bot
.
status
()
elif
run
==
'crawl'
:
return
bot
.
run
()
else
:
raise
NotImplementedError
(
'Unexpected run: %s'
%
run
)
return
bot
.
run
(
run
)
if
__name__
==
"__main__"
:
...
...
urlchecker_configuration.py
View file @
43d944f1
...
...
@@ -29,6 +29,10 @@ def createConfiguration(
get_default_resolver
().
nameservers
)
if
config
[
CONFIG_SECTION
][
"SQLITE"
]
==
":memory:"
:
# Do not loop when using temporary DB
config
[
CONFIG_SECTION
][
"INTERVAL"
]
=
"-1"
return
config
[
CONFIG_SECTION
]
...
...
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