Skip to content
Snippets Groups Projects
Commit a0c5f5a3 authored by Manuela Kuhn's avatar Manuela Kuhn
Browse files

First version of file removal at start up of receiverLiveViewer

parent f66a1f66
No related branches found
No related tags found
No related merge requests found
......@@ -76,6 +76,7 @@ def argumentParsing():
# check target directory for existance
helperScript.checkDirExistance(targetDir)
# helperScript.checkDirEmpty(targetDir)
# check if logfile is writable
helperScript.checkLogFileWritable(logfilePath, logfileName)
......
......@@ -79,6 +79,69 @@ class FakeSecHead(object):
else:
return self.fp.readline()
# http://code.activestate.com/recipes/541096-prompt-the-user-for-confirmation/
def confirm(prompt=None, resp=False):
"""prompts for yes or no response from the user. Returns True for yes and
False for no.
'resp' should be set to the default value assumed by the caller when
user simply types ENTER.
>>> confirm(prompt='Create Directory?', resp=True)
Create Directory? [y]|n:
True
>>> confirm(prompt='Create Directory?', resp=False)
Create Directory? [n]|y:
False
>>> confirm(prompt='Create Directory?', resp=False)
Create Directory? [n]|y: y
True
"""
if prompt is None:
prompt = 'Confirm'
if resp:
prompt = '%s [%s]|%s: ' % (prompt, 'y', 'n')
else:
prompt = '%s [%s]|%s: ' % (prompt, 'n', 'y')
while True:
try:
ans = raw_input(prompt)
except KeyboardInterrupt:
logging.error("Keyboard Interruption detected.")
break
except Exception as e:
logging.error("Something went wrong with the confirmation.")
logging.debug("Error was: " + str(e))
break
if not ans:
return resp
if ans not in ['y', 'Y', 'n', 'N']:
logging.error("please enter y or n.")
continue
if ans == 'y' or ans == 'Y':
return True
if ans == 'n' or ans == 'N':
return False
def checkDirEmpty(dirPath):
#check if directory is empty
if os.listdir(dirPath):
logging.info("Directory '%s' is not empty." % str(dirPath))
if confirm(prompt="Directory " + str(dirPath) + " is not empty.\nShould its content be removed?",
resp = True):
for element in os.listdir(dirPath):
print "Removing elements"
os.remove(element)
def checkSubDirExistance(dirPath, subDirs):
"""
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment