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
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
45 additions
and
11 deletions
+45
-11
notify.py
+45
-11
No files found.
notify.py
View file @
682c53d2
...
@@ -14,7 +14,7 @@ import urllib2
...
@@ -14,7 +14,7 @@ import urllib2
import
webbrowser
import
webbrowser
logger
=
logging
.
getLogger
()
logger
=
logging
.
getLogger
()
file_name
=
"vm_renewal.
p
"
file_name
=
"vm_renewal.
json
"
def
parse_arguments
():
def
parse_arguments
():
...
@@ -72,17 +72,51 @@ def accept():
...
@@ -72,17 +72,51 @@ def accept():
def
notify
(
url
):
def
notify
(
url
):
if
os
.
getenv
(
"DISPLAY"
)
and
platform
.
system
()
in
(
'Linux'
,
'Windows'
):
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
:
display
=
True
webbrowser
.
open
(
url
,
new
=
2
,
autoraise
=
True
)
webbrowser
.
open
(
url
,
new
=
2
,
autoraise
=
True
)
elif
not
os
.
getenv
(
"DISPLAY"
):
finally
:
if
os
.
path
.
isfile
(
"
%
s/
%
s"
%
(
get_temp_dir
(),
file_name
)):
os
.
environ
[
"DISPLAY"
]
=
olddisplay
logger
.
info
(
"There is on old request already saved"
)
json
.
dump
(
url
,
open
(
"
%
s/
%
s"
%
(
get_temp_dir
(),
file_name
),
"wb"
))
wall
(
"This virtual machine is going to expire! Please type
\n
"
def
search_display
():
" vm_renewal
\n
"
"""Search a valid DISPLAY env var in processes
"command to keep it running."
)
"""
else
:
env
=
os
.
getenv
(
"DISPLAY"
)
raise
Exception
(
'Not supported system type'
)
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
():
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