Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F90752579
bibclassify_utils.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Mon, Nov 4, 10:54
Size
1 KB
Mime Type
text/x-python
Expires
Wed, Nov 6, 10:54 (2 d)
Engine
blob
Format
Raw Data
Handle
22129589
Attached To
R3600 invenio-infoscience
bibclassify_utils.py
View Options
# -*- coding: utf-8 -*-
##
## This file is part of Invenio.
## Copyright (C) 2008, 2010, 2011, CERN.
##
## Invenio is free software; you can redistribute it and/or
## modify it under the terms of the GNU General Public License as
## published by the Free Software Foundation; either version 2 of the
## License, or (at your option) any later version.
##
## Invenio is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
## General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with Invenio; if not, write to the Free Software Foundation, Inc.,
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
"""
Some common utilities for BibClassify.
"""
import
sys
import
time
# Verbose levels are as such:
# 0: No verbose.
# 1: Error messages.
# 2: Warning messages.
# 3 (and more): Info messages.
# By default, output error messages.
VERBOSE_LEVEL
=
1
def
set_verbose_level
(
level
):
"""Sets the verbose level."""
global
VERBOSE_LEVEL
VERBOSE_LEVEL
=
int
(
level
)
def
write_message
(
msg
,
stream
=
sys
.
stdout
,
verbose
=
1
):
"""Write message and flush output stream (may be sys.stdout or sys.stderr).
Useful for debugging stuff. Copied and adapted from bibtask.py."""
if
msg
and
verbose
<=
VERBOSE_LEVEL
:
if
stream
==
sys
.
stdout
or
stream
==
sys
.
stderr
:
stream
.
write
(
time
.
strftime
(
"%Y-%m-
%d
%H:%M:%S --> "
,
time
.
localtime
()))
try
:
stream
.
write
(
"
%s
\n
"
%
msg
)
except
UnicodeEncodeError
:
stream
.
write
(
"
%s
\n
"
%
msg
.
encode
(
'ascii'
,
'backslashreplace'
))
stream
.
flush
()
else
:
sys
.
stderr
.
write
(
"Unknown stream
%s
. [must be sys.stdout or "
"sys.stderr]
\n
"
%
stream
)
Event Timeline
Log In to Comment