4grab/util.py

40 lines
896 B
Python
Raw Permalink Normal View History

import os
import sys
class LogType:
Non = 0
Err = 1
Warn = 2
Msg = 3
@staticmethod
def from_int(lloglevel):
iloglevel = int(lloglevel)
if iloglevel == 0:
return LogType.Non
if iloglevel == 1:
return LogType.Err
if iloglevel == 2:
return LogType.Warn
if iloglevel == 3:
return LogType.Msg
loglevel = LogType.Non
def raw_input_with_default(default, prompt):
inp = raw_input("%s (default=%s): " % (prompt, default))
if inp == "":
return default
return inp
def log(logtype, message, data = None):
global loglevel
if loglevel >= logtype:
print message
if not data is None:
print "data:\n\tdata"
homedir = os.getenv("HOME")
if homedir is None:
homedir = os.path.dirname(sys.argv[0])
confdir = os.path.join(homedir, ".4grab")