Commit 7059917a by Őry Máté

fix style to match pep8

parent c56ff392
......@@ -67,6 +67,7 @@ def linux_set_time(time):
class Context(object):
@staticmethod
def change_password(password):
if system == 'Linux':
......@@ -287,7 +288,9 @@ class Context(object):
import notify
notify.notify(msg)
class SerialLineReceiver(SerialLineReceiverBase):
def connectionMade(self):
self.send_command(
command='agent_started',
......
......@@ -5,18 +5,23 @@
# Test program that informs the user about vm incoming time out
##
import platform, logging, os, subprocess, webbrowser, sys
import platform
import logging
import os
import subprocess
import webbrowser
import cPickle as pickle
system = platform.system()
logger = logging.getLogger()
file_name = "vm_renewal.p"
def pars_arguments():
import argparse
parser = argparse.ArgumentParser();
parser = argparse.ArgumentParser()
parser.add_argument("-u", "--url", type=str, required=True)
args = parser.parse_args();
args = parser.parse_args()
return args
......@@ -31,6 +36,7 @@ def get_temp_dir():
temp_dir = "/var/tmp"
return temp_dir
def wall(text):
if text is None:
logger.error("Incorrect function call")
......@@ -48,10 +54,10 @@ def accept():
# Load the saved url
url = pickle.load(open("%s/%s" % (get_temp_dir(), file_name), "rb"))
# Fake data to post so we make urllib2 send a POST instead of a GET
# do POST request to
# do POST request to
req = urllib2.Request(url, "")
rsp = urllib2.urlopen(req)
rsp = urllib2.urlopen(req)
# Get the result of the request
success = rsp.info()['renewal']
if success is not None or rsp.getcode() == 200:
......@@ -67,6 +73,7 @@ def accept():
print "Successfull renewal of this vm!"
os.remove("%s/%s" % (get_temp_dir(), file_name))
def notify(url):
if os.getenv("DISPLAY") and system == 'Linux' or system == 'Windows':
webbrowser.open(url, new=2, autoraise=True)
......@@ -74,13 +81,16 @@ def notify(url):
if os.path.isfile("%s/%s" % (get_temp_dir(), file_name)):
logger.info("There is on old request already saved")
pickle.dump(url, open("%s/%s" % (get_temp_dir(), file_name), "wb"))
wall("This vm is about to time out! Please type vm_renewal command to renew your current process")
wall("This virtual machine is going to expire! Please type \n"
" vm_renewal\n"
"command to keep it running.")
else:
raise StandardError('Not supported system type')
raise Exception('Not supported system type')
def main():
args = pars_arguments()
notify(args.url)
if __name__ == '__main__':
main()
\ No newline at end of file
main()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment