Log function works, need to start using it now
This commit is contained in:
parent
b5aac62357
commit
99b87aeffb
2 changed files with 42 additions and 6 deletions
11
4grab.py
11
4grab.py
|
@ -25,6 +25,7 @@ import os
|
|||
|
||||
import config
|
||||
from util import raw_input_with_default
|
||||
import util
|
||||
|
||||
import download
|
||||
import progressbar
|
||||
|
@ -110,6 +111,12 @@ under certain conditions.""")
|
|||
dest="sort",
|
||||
help="Sort downloaded images, most handy if you've used "
|
||||
"older versions which didn't sort yet")
|
||||
parser.add_option("-l",
|
||||
"--loglevel",
|
||||
nargs=1,
|
||||
dest="loglevel",
|
||||
metavar="LEVEL",
|
||||
help="Changes the default log level to LEVEL")
|
||||
(options, args) = parser.parse_args()
|
||||
|
||||
if options.confval and (options.tempcat
|
||||
|
@ -175,7 +182,8 @@ under certain conditions.""")
|
|||
elif options.tempcat:
|
||||
conf.set_categories([options.tempcat])
|
||||
|
||||
#base_url = "%s%s/" % (base_url, conf.get_categories())
|
||||
elif options.loglevel is not None:
|
||||
util.loglevel = util.LogType.from_int(options.loglevel)
|
||||
|
||||
if __name__ == "__main__":
|
||||
conf = config.Configuration()
|
||||
|
@ -196,3 +204,4 @@ if __name__ == "__main__":
|
|||
except KeyboardInterrupt:
|
||||
print
|
||||
print "So you don't want these images? Fine! I'll stop then."
|
||||
util.log(util.LogType.Err, "Quit on user request")
|
||||
|
|
35
util.py
35
util.py
|
@ -1,13 +1,40 @@
|
|||
import os
|
||||
import sys
|
||||
|
||||
homedir = os.getenv("HOME")
|
||||
if homedir is None:
|
||||
homedir = os.path.dirname(sys.argv[0])
|
||||
confdir = os.path.join(homedir, ".4grab")
|
||||
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
|
||||
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")
|
||||
|
|
Loading…
Reference in a new issue