2010-04-08 15:14:12 +02:00
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
|
2010-04-21 15:40:20 +02:00
|
|
|
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
|
2010-04-19 09:16:04 +02:00
|
|
|
|
|
|
|
def raw_input_with_default(default, prompt):
|
|
|
|
inp = raw_input("%s (default=%s): " % (prompt, default))
|
|
|
|
if inp == "":
|
|
|
|
return default
|
|
|
|
return inp
|
2010-04-21 15:40:20 +02:00
|
|
|
|
|
|
|
def log(logtype, message, data = None):
|
|
|
|
global loglevel
|
|
|
|
print logtype, loglevel, loglevel >= logtype
|
|
|
|
if loglevel >= logtype:
|
|
|
|
print message
|
|
|
|
if not data is None:
|
|
|
|
print data
|
|
|
|
|
|
|
|
homedir = os.getenv("HOME")
|
|
|
|
if homedir is None:
|
|
|
|
homedir = os.path.dirname(sys.argv[0])
|
|
|
|
confdir = os.path.join(homedir, ".4grab")
|