def makeDirectory(path,interact=True, name="Directory", defaultCreate=True, defaultMakeEmpty=False): if not os.path.exists(path) : CE.printInfo("%s : %s" % (name,path) + " does not exist!") default = 'y' if defaultCreate else 'n' r='' if interact: r = input(CE.makePrompt("Do you want to create directory [y|n, default(%s)]: " % default)).strip() r = r or default if r == 'n': raise CE.MyValueError("Aborted due to not created directory!") else: os.makedirs(path) CE.printInfo("Created %s : %s" % (name,path)) else: mess = "%s : %s" % (name,path) + " does already exist!" if interact: CE.printWarning(mess) else: CE.printInfo(mess) # dir exists default='y' if defaultMakeEmpty else 'n' r='' if interact: r = input(CE.makePrompt("Do you want to remove and recreate the directory [y|n, default(%s)]: " % default) ).strip() r = r or default if r == 'y': shutil.rmtree(path) os.makedirs(path) CE.printInfo("Removed and created %s : %s" % (name,path))
def checkNotExisting(path, interact=True, name="Directory"): if os.path.exists(path): mess = "%s : %s" % (name,path) + " does already exist!" if interact : print(mess) r = input(CE.makePrompt("Do you want to remove the directory: [y|n|c, default(c), c=no and continue]")).strip() if not r: r="c" if r == 'n': raise CE.MyValueError("Aborted due to not removed directory!") elif r == 'y': shutil.rmtree(path) elif r == 'c': pass else: raise CE.MyValueError("Aborted due to not removed directory!") else: raise CE.MyValueError(mess)