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
Kirill Smelkov
slapos.toolbox
Commits
e734bd59
Commit
e734bd59
authored
Jun 23, 2021
by
Xavier Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
pubsub: Fix Python3 incompatibilities
parent
95726826
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
9 deletions
+15
-9
slapos/pubsub/__init__.py
slapos/pubsub/__init__.py
+6
-4
slapos/pubsub/notifier.py
slapos/pubsub/notifier.py
+9
-5
No files found.
slapos/pubsub/__init__.py
View file @
e734bd59
...
@@ -13,6 +13,8 @@ import time
...
@@ -13,6 +13,8 @@ import time
from
datetime
import
datetime
from
datetime
import
datetime
from
hashlib
import
sha512
from
hashlib
import
sha512
from
slapos.util
import
bytes2str
,
str2bytes
from
atomize
import
Entry
from
atomize
import
Entry
from
atomize
import
Feed
from
atomize
import
Feed
from
atomize
import
Content
from
atomize
import
Content
...
@@ -81,7 +83,7 @@ def notify(transaction_id):
...
@@ -81,7 +83,7 @@ def notify(transaction_id):
try
:
try
:
callback_filepath
=
os
.
path
.
join
(
app
.
config
[
'CALLBACKS'
],
callback_filepath
=
os
.
path
.
join
(
app
.
config
[
'CALLBACKS'
],
sha512
(
str
(
feed
.
feed
.
id
)).
hexdigest
())
sha512
(
feed
.
feed
.
id
.
encode
(
)).
hexdigest
())
if
not
os
.
path
.
exists
(
callback_filepath
):
if
not
os
.
path
.
exists
(
callback_filepath
):
abort
(
httplib
.
NOT_FOUND
)
abort
(
httplib
.
NOT_FOUND
)
except
AttributeError
:
except
AttributeError
:
...
@@ -90,17 +92,17 @@ def notify(transaction_id):
...
@@ -90,17 +92,17 @@ def notify(transaction_id):
abort_it
=
False
abort_it
=
False
for
callback
in
io
.
open
(
callback_filepath
,
'r
'
,
encoding
=
'utf8
'
):
for
callback
in
io
.
open
(
callback_filepath
,
'r
b
'
):
timestamp
=
int
(
math
.
floor
(
time
.
mktime
(
feed
.
feed
.
updated_parsed
)))
timestamp
=
int
(
math
.
floor
(
time
.
mktime
(
feed
.
feed
.
updated_parsed
)))
equeue_request
=
json
.
dumps
({
equeue_request
=
json
.
dumps
({
'command'
:
'%s
\
0
--transaction-id
\
0
%s'
%
(
callback
,
transaction_id
),
'command'
:
'%s
\
0
--transaction-id
\
0
%s'
%
(
bytes2str
(
callback
)
,
transaction_id
),
'timestamp'
:
timestamp
,
'timestamp'
:
timestamp
,
})
})
equeue_socket
=
socket
.
socket
(
socket
.
AF_UNIX
,
socket
.
SOCK_STREAM
)
equeue_socket
=
socket
.
socket
(
socket
.
AF_UNIX
,
socket
.
SOCK_STREAM
)
equeue_socket
.
connect
(
app
.
config
[
'EQUEUE_SOCKET'
])
equeue_socket
.
connect
(
app
.
config
[
'EQUEUE_SOCKET'
])
equeue_socket
.
send
(
equeue_request
)
equeue_socket
.
send
(
str2bytes
(
equeue_request
)
)
result
=
equeue_socket
.
recv
(
len
(
callback
))
result
=
equeue_socket
.
recv
(
len
(
callback
))
equeue_socket
.
close
()
equeue_socket
.
close
()
...
...
slapos/pubsub/notifier.py
View file @
e734bd59
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
from
__future__
import
print_function
from
__future__
import
print_function
import
argparse
import
argparse
import
cgi
import
csv
import
csv
import
datetime
import
datetime
import
json
import
json
...
@@ -84,15 +85,19 @@ def main():
...
@@ -84,15 +85,19 @@ def main():
while
args
.
max_run
>
0
:
while
args
.
max_run
>
0
:
try
:
try
:
kwargs
=
{}
if
str
is
not
bytes
:
kwargs
[
'errors'
]
=
'replace'
content
=
subprocess
.
check_output
(
content
=
subprocess
.
check_output
(
args
.
executable
[
0
],
args
.
executable
[
0
],
stderr
=
subprocess
.
STDOUT
stderr
=
subprocess
.
STDOUT
,
**
kwargs
)
)
exit_code
=
0
exit_code
=
0
content
=
(
"OK</br><p>%s ran successfully</p>"
content
=
(
"OK</br><p>%s ran successfully</p>"
"<p>Output is: </p><pre>%s</pre>"
%
(
"<p>Output is: </p><pre>%s</pre>"
%
(
args
.
executable
[
0
],
args
.
executable
[
0
],
c
ontent
.
replace
(
'&'
,
'&'
).
replace
(
'<'
,
'<'
).
replace
(
'>'
,
'>'
)
c
gi
.
escape
(
content
)
))
))
saveStatus
(
'FINISHED'
)
saveStatus
(
'FINISHED'
)
break
break
...
@@ -105,7 +110,7 @@ def main():
...
@@ -105,7 +110,7 @@ def main():
"<p>Output is: </p><pre>%s</pre>"
%
(
"<p>Output is: </p><pre>%s</pre>"
%
(
args
.
executable
[
0
],
args
.
executable
[
0
],
exit_code
,
exit_code
,
c
ontent
.
replace
(
'&'
,
'&'
).
replace
(
'<'
,
'<'
).
replace
(
'>'
,
'>'
)
c
gi
.
escape
(
content
)
))
))
print
(
content
)
print
(
content
)
...
@@ -163,7 +168,7 @@ def main():
...
@@ -163,7 +168,7 @@ def main():
transaction_id
=
args
.
transaction_id
[
0
]
if
args
.
transaction_id
else
int
(
time
.
time
()
*
1e6
)
transaction_id
=
args
.
transaction_id
[
0
]
if
args
.
transaction_id
else
int
(
time
.
time
()
*
1e6
)
notification_path
+=
str
(
transaction_id
)
notification_path
+=
str
(
transaction_id
)
headers
=
{
'Content-Type'
:
feed
.
info
().
get
header
(
'Content-Type'
)}
headers
=
{
'Content-Type'
:
feed
.
info
().
get
(
'Content-Type'
)}
try
:
try
:
notification
=
httplib
.
HTTPConnection
(
notification_url
.
hostname
,
notification
=
httplib
.
HTTPConnection
(
notification_url
.
hostname
,
notification_port
)
notification_port
)
...
@@ -189,4 +194,3 @@ def main():
...
@@ -189,4 +194,3 @@ def main():
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
main
()
main
()
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