Skip to content
Snippets Groups Projects
Commit 35ecdead authored by Guillaume HEUSCH's avatar Guillaume HEUSCH
Browse files

[ssr] python 2 and 3 compatibility, bob logger

parent 8e0ce2fc
Branches
Tags
No related merge requests found
#!/usr/bin/env python #!/usr/bin/env python
# encoding: utf-8 # encoding: utf-8
# Copyright (c) 2017 Idiap Research Institute, http://www.idiap.ch/ """Pulse extraction using 2SR algorithm (%(version)s)
# Written by Guillaume Heusch <guillaume.heusch@idiap.ch>,
#
# This file is part of bob.rpgg.base.
#
# bob.rppg.base is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 3 as
# published by the Free Software Foundation.
#
# bob.rppg.base 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 bob.rppg.base. If not, see <http://www.gnu.org/licenses/>.
'''Pulse extraction for database videos (%(version)s)
Usage: Usage:
%(prog)s (cohface | hci) [--protocol=<string>] [--subset=<string> ...] %(prog)s (cohface | hci) [--protocol=<string>] [--subset=<string> ...]
...@@ -70,16 +53,15 @@ Examples: ...@@ -70,16 +53,15 @@ Examples:
See '%(prog)s --help' for more information. See '%(prog)s --help' for more information.
''' """
from __future__ import print_function
import os import os
import sys import sys
import pkg_resources import pkg_resources
import logging from bob.core.log import setup
__logging_format__='[%(levelname)s] %(message)s' logger = setup("bob.rppg.base")
logging.basicConfig(format=__logging_format__)
logger = logging.getLogger("ssr_logger")
from docopt import docopt from docopt import docopt
...@@ -104,19 +86,12 @@ def main(user_input=None): ...@@ -104,19 +86,12 @@ def main(user_input=None):
arguments = sys.argv[1:] arguments = sys.argv[1:]
prog = os.path.basename(sys.argv[0]) prog = os.path.basename(sys.argv[0])
completions = dict( completions = dict(prog=prog, version=version,)
prog=prog, args = docopt(__doc__ % completions, argv=arguments, version='Signal extractor for videos (%s)' % version,)
version=version,
)
args = docopt(
__doc__ % completions,
argv=arguments,
version='Spatial subspace rotation for videos (%s)' % version,
)
# if the user wants more verbosity, lowers the logging level # if the user wants more verbosity, lowers the logging level
if args['--verbose'] == 1: logging.getLogger("ssr_logger").setLevel(logging.INFO) from bob.core.log import set_verbosity_level
elif args['--verbose'] >= 2: logging.getLogger("ssr_logger").setLevel(logging.DEBUG) set_verbosity_level(logger, args['--verbose'])
# chooses the database driver to use # chooses the database driver to use
if args['cohface']: if args['cohface']:
...@@ -154,19 +129,22 @@ def main(user_input=None): ...@@ -154,19 +129,22 @@ def main(user_input=None):
sys.exit() sys.exit()
objects = db.objects(args['--protocol'], args['--subset']) objects = db.objects(args['--protocol'], args['--subset'])
# tells the number of grid objects, and exit
if args['--gridcount']:
print len(objects)
sys.exit()
# if we are on a grid environment, just find what I have to process. # if we are on a grid environment, just find what I have to process.
if os.environ.has_key('SGE_TASK_ID'): sge = False
try:
sge = os.environ.has_key('SGE_TASK_ID') # python2
except AttributeError:
sge = 'SGE_TASK_ID' in os.environ # python3
if sge:
pos = int(os.environ['SGE_TASK_ID']) - 1 pos = int(os.environ['SGE_TASK_ID']) - 1
if pos >= len(objects): if pos >= len(objects):
raise RuntimeError, "Grid request for job %d on a setup with %d jobs" % \ raise RuntimeError("Grid request for job {} on a setup with {} jobs".format(pos, len(objects)))
(pos, len(objects))
objects = [objects[pos]] objects = [objects[pos]]
if args['--gridcount']:
print(len(objects))
# does the actual work # does the actual work
for obj in objects: for obj in objects:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment