If a file doesn't exist, create it

This commit is contained in:
Hugo Trippaers 2014-09-03 09:00:35 +02:00 committed by wilderrodrigues
parent 762e05ddee
commit 576564e744
1 changed files with 3 additions and 0 deletions

View File

@ -62,6 +62,9 @@ def definedinfile(filename, val):
def addifmissing(filename, val):
""" Add something to a file
if it is not already there """
if not os.path.isfile(filename):
logging.debug("File %s doesn't exist, so create" % filename)
open(filename,"w").close()
if not definedinfile(filename, val):
updatefile(filename, val + "\n", "a")
logging.debug("Added %s to file %s" % (val, filename))