+
+
+def warn(message):
+ LOG.warning('%s\n' % message)
+
+
+def check_file_exists(file_path):
+ if not os.path.dirname(file_path):
+ file_path = '%s/%s' % (CWD, file_path)
+ if not os.path.isfile(file_path):
+ err('ERROR: File %s not found\n' % file_path)
+
+
+def check_dir_exists(dir_path):
+ if not os.path.dirname(dir_path):
+ dir_path = '%s/%s' % (CWD, dir_path)
+ if not os.path.isdir(dir_path):
+ err('ERROR: Directory %s not found\n' % dir_path)
+
+
+def create_dir_if_not_exists(dir_path):
+ if not os.path.isdir(dir_path):
+ log('Creating directory %s' % dir_path)
+ os.makedirs(dir_path)
+
+
+def delete(f):
+ if os.path.isfile(f):
+ log('Deleting file %s' % f)
+ os.remove(f)
+ elif os.path.isdir(f):
+ log('Deleting directory %s' % f)
+ shutil.rmtree(f)
+
+
+def commafy(comma_separated_list):
+ l = [c.strip() for c in comma_separated_list.split(',')]
+ return ','.join(l)
+
+
+def check_if_root():
+ r = exec_cmd('whoami')
+ if r != 'root':
+ err('You need be root to run this application')
+
+
+def log(message):
+ LOG.debug('%s\n' % message)
+
+
+class ArgParser(argparse.ArgumentParser):
+
+ def error(self, message):
+ sys.stderr.write('ERROR: %s\n' % message)
+ self.print_help()
+ sys.exit(2)
+
+
+def backup(path):
+ src = path
+ dst = path + '_orig'
+ delete(dst)
+ try:
+ shutil.copytree(src, dst)
+ except OSError as e:
+ if e.errno == errno.ENOTDIR:
+ shutil.copy(src, dst)
+ else:
+ raise