Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.toolbox
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
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Nicolas Wavrant
slapos.toolbox
Commits
c739d038
Commit
c739d038
authored
Sep 07, 2016
by
Nicolas Wavrant
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
checkFeedAsPromise: new python script which can be used to create promises on RSS feeds
parent
0d5cd3ed
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
80 additions
and
0 deletions
+80
-0
setup.py
setup.py
+1
-0
slapos/resilient/checkFeedAsPromise.py
slapos/resilient/checkFeedAsPromise.py
+79
-0
No files found.
setup.py
View file @
c739d038
...
@@ -65,6 +65,7 @@ setup(name=name,
...
@@ -65,6 +65,7 @@ setup(name=name,
'console_scripts'
:
[
'console_scripts'
:
[
'agent = slapos.agent.agent:main [agent]'
,
'agent = slapos.agent.agent:main [agent]'
,
'check-web-page-http-cache-hit = slapos.promise.check_web_page_http_cache_hit:main'
,
'check-web-page-http-cache-hit = slapos.promise.check_web_page_http_cache_hit:main'
,
'check-feed-as-promise = slapos.resilient.checkFeedAsPromise:main'
,
'clouddestroy = slapos.cloudmgr.destroy:main'
,
'clouddestroy = slapos.cloudmgr.destroy:main'
,
'cloudgetprivatekey = slapos.cloudmgr.getprivatekey:main'
,
'cloudgetprivatekey = slapos.cloudmgr.getprivatekey:main'
,
'cloudgetpubliciplist = slapos.cloudmgr.getpubliciplist:main'
,
'cloudgetpubliciplist = slapos.cloudmgr.getpubliciplist:main'
,
...
...
slapos/resilient/checkFeedAsPromise.py
0 → 100644
View file @
c739d038
# Command line script to test a RSS feed in a promise
# Checks that a given pattern can be found (or not) in the title or the
# description of the latest feed item.
# A time buffer option can be given, so the promise really gets true, or false,
# only if the last item is older or younger than the allowed time buffer.
import
argparse
import
datetime
import
feedparser
import
sys
def
parseArguments
():
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
'--feed-path'
,
dest
=
'feed_path'
,
help
=
'Path or Url of the feed to search'
)
parser
.
add_argument
(
'--title'
,
dest
=
'title'
,
action
=
'store_true'
,
help
=
'Patterns should be looked for in feed item
\
'
s title'
)
parser
.
add_argument
(
'--description'
,
dest
=
'description'
,
action
=
'store_true'
,
help
=
'Patterns should be looked for in feed item
\
'
s description'
)
parser
.
add_argument
(
'--ok-pattern'
,
dest
=
'ok_pattern_list'
,
action
=
'append'
,
default
=
[],
help
=
'If this pattern is found, then promise succeeds'
)
parser
.
add_argument
(
'--ko-pattern'
,
dest
=
'ko_pattern_list'
,
action
=
'append'
,
default
=
[],
help
=
'If this pattern is found, then promise fails'
)
parser
.
add_argument
(
'--time-buffer'
,
dest
=
'time_buffer'
,
type
=
int
,
help
=
'Time delta in seconds before the promise really succeeds or fails'
)
return
parser
.
parse_args
()
def
containsPattern
(
string
,
pattern_list
):
for
pattern
in
pattern_list
:
if
string
.
find
(
pattern
)
>=
0
:
return
True
return
False
def
main
():
option
=
parseArguments
()
feed
=
feedparser
.
parse
(
option
.
feed_path
)
if
feed
.
bozo
:
sys
.
exit
(
'Feed malformed'
)
last_item
=
feed
.
entries
[
-
1
]
if
option
.
title
:
candidate_string
=
last_item
.
title
elif
option
.
description
:
candidate_string
=
last_item
.
description
else
:
sys
.
exit
(
'At least one in [--title|--description] should be provided'
)
publication_date
=
datetime
.
datetime
(
*
last_item
.
published_parsed
[:
7
])
publication_age
=
datetime
.
datetime
.
now
()
-
publication_date
time_buffer
=
datetime
.
timedelta
(
seconds
=
option
.
time_buffer
)
ok_pattern_found
=
containsPattern
(
candidate_string
,
option
.
ok_pattern_list
)
ko_pattern_found
=
containsPattern
(
candidate_string
,
option
.
ko_pattern_list
)
if
ok_pattern_found
and
ko_pattern_found
:
sys
.
exit
(
'Both OK and KO patterns found: please check arguments'
)
# Expectations fulfilled
if
ok_pattern_found
:
sys
.
exit
(
0
)
if
ko_pattern_found
:
sys
.
exit
(
'KO pattern found'
)
if
not
ok_pattern_found
:
if
publication_age
<
time_buffer
:
# We have to wait for buffer to expire
sys
.
exit
(
0
)
else
:
# If time-buffer is out, we are in stalled state
sys
.
exit
(
'Stalled situation'
)
# If not ok, and not stalled, what can have possibly happen ?
sys
.
exit
(
1
)
if
__name__
==
'__main__'
:
main
()
\ No newline at end of file
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