-#!/usr/bin/env python
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright (c) 2011 OpenStack Foundation.
def _exit_error(execname, message, errorcode, log=True):
- print("%s: %s" % (execname, message))
+ print("%s: %s" % (execname, message), file=sys.stderr)
if log:
logging.error(message)
sys.exit(errorcode)
+def _getlogin():
+ try:
+ return os.getlogin()
+ except OSError:
+ return (os.getenv('USER') or
+ os.getenv('USERNAME') or
+ os.getenv('LOGNAME'))
+
+
def main():
# Split arguments, require at least a command
execname = sys.argv.pop(0)
exec_dirs=config.exec_dirs)
if config.use_syslog:
logging.info("(%s > %s) Executing %s (filter match = %s)" % (
- os.getlogin(), pwd.getpwuid(os.getuid())[0],
+ _getlogin(), pwd.getpwuid(os.getuid())[0],
command, filtermatch.name))
obj = subprocess.Popen(command,
# under the License.
-import ConfigParser
import logging
import logging.handlers
import os
import string
+from six import moves
+
from cinder.openstack.common.rootwrap import filters
for filterdir in filters_path:
if not os.path.isdir(filterdir):
continue
- for filterfile in os.listdir(filterdir):
- filterconfig = ConfigParser.RawConfigParser()
+ for filterfile in filter(lambda f: not f.startswith('.'),
+ os.listdir(filterdir)):
+ filterconfig = moves.configparser.RawConfigParser()
filterconfig.read(os.path.join(filterdir, filterfile))
for (name, value) in filterconfig.items("Filters"):
filterdefinition = [string.strip(s) for s in value.split(',')]