#! /usr/bin/python3
# -*- coding: utf-8 -*-

import os
import re
import sys

from utils.printer import *

PrinterThread().start()

def check_root():
	"""
	check for root/admin & exit if not
	"""
	if os.getuid() != 0:
		if sys.platform == "win32":
			print_error("you must be admin")

		else:
			print_error("you must be root")

		return False

	return True

def check_regex(pattern):
	"""
	check regex pattern & print error message
	"""
	try:
		re.compile(pattern)

	except re.error as e:
		msg = "regex error at pos: {0}: {1}"
		msg = msg.format(e.pos, e.msg)

		print_error("invalid regex pattern:")
		print_info(msg)
		return False

	else:
		return True
