Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
CIRCLE
/
agent
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
7
Merge Requests
0
Wiki
Members
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
682c53d2
authored
Jul 24, 2014
by
Őry Máté
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
try to figure out DISPLAY
(agent will run as an upstart process, so it wont have the DISPLAY envvar)
parent
8d3d3713
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
8 deletions
+42
-8
notify.py
+42
-8
No files found.
notify.py
View file @
682c53d2
...
...
@@ -14,7 +14,7 @@ import urllib2
import
webbrowser
logger
=
logging
.
getLogger
()
file_name
=
"vm_renewal.
p
"
file_name
=
"vm_renewal.
json
"
def
parse_arguments
():
...
...
@@ -72,17 +72,51 @@ def accept():
def
notify
(
url
):
if
os
.
getenv
(
"DISPLAY"
)
and
platform
.
system
()
in
(
'Linux'
,
'Windows'
):
webbrowser
.
open
(
url
,
new
=
2
,
autoraise
=
True
)
elif
not
os
.
getenv
(
"DISPLAY"
):
if
os
.
path
.
isfile
(
"
%
s/
%
s"
%
(
get_temp_dir
(),
file_name
)):
logger
.
info
(
"There is on old request already saved"
)
json
.
dump
(
url
,
open
(
"
%
s/
%
s"
%
(
get_temp_dir
(),
file_name
),
"wb"
))
olddisplay
=
os
.
environ
.
get
(
"DISPLAY"
)
try
:
file_path
=
os
.
path
.
join
(
get_temp_dir
(),
file_name
)
with
open
(
file_path
,
"w"
)
as
f
:
json
.
dump
(
url
,
f
)
if
platform
.
system
()
!=
"Windows"
:
display
=
search_display
()
if
display
:
os
.
environ
[
'DISPLAY'
]
=
display
wall
(
"This virtual machine is going to expire! Please type
\n
"
" vm_renewal
\n
"
"command to keep it running."
)
else
:
raise
Exception
(
'Not supported system type'
)
display
=
True
webbrowser
.
open
(
url
,
new
=
2
,
autoraise
=
True
)
finally
:
os
.
environ
[
"DISPLAY"
]
=
olddisplay
def
search_display
():
"""Search a valid DISPLAY env var in processes
"""
env
=
os
.
getenv
(
"DISPLAY"
)
if
env
:
return
env
for
pid
in
os
.
listdir
(
"/proc"
):
if
not
pid
.
isdigit
():
continue
env
=
os
.
path
.
join
(
"/proc"
,
pid
,
"environ"
)
try
:
with
open
(
env
,
"r"
)
as
f
:
envs
=
dict
(
line
.
split
(
"="
,
1
)
for
line
in
f
.
read
()
.
split
(
"
\0
"
)
if
"="
in
line
)
except
:
continue
else
:
if
"DISPLAY"
in
envs
and
":"
in
envs
[
"DISPLAY"
]:
return
envs
[
"DISPLAY"
]
return
None
def
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