-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #54 from djs55/audit-python
Audit and restructure package hiearchy
- Loading branch information
Showing
9 changed files
with
106 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,3 +27,5 @@ python/build | |
python/d.py | ||
python/v.py | ||
python/p.py | ||
*.pyc | ||
*.pyo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,6 @@ | |
description='Xapi storage interface', | ||
author='David Scott', | ||
author_email='[email protected]', | ||
url='https://github.com/djs55/xapi-storage/', | ||
packages=['xapi'], | ||
url='https://github.com/xapi-project/xapi-storage/', | ||
packages=['xapi', 'xapi.storage', 'xapi.storage.api'], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
#!/usr/bin/env python |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
#!/usr/bin/env python |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/usr/bin/env python | ||
|
||
from xapi.storage import log | ||
import xapi | ||
import subprocess | ||
|
||
|
||
# [call dbg cmd_args] executes [cmd_args] | ||
# if [error] and exit code != expRc, log and throws a BackendError | ||
# if [simple], returns only stdout | ||
|
||
|
||
def call(dbg, cmd_args, error=True, simple=True, expRc=0): | ||
log.debug("%s: Running cmd %s" % (dbg, cmd_args)) | ||
p = subprocess.Popen( | ||
cmd_args, | ||
stdout=subprocess.PIPE, | ||
stderr=subprocess.PIPE, | ||
close_fds=True) | ||
stdout, stderr = p.communicate() | ||
if error and p.returncode != expRc: | ||
log.error("%s: %s exitted with code %d: %s" % | ||
(dbg, " ".join(cmd_args), p.returncode, stderr)) | ||
raise xapi.InternalError("%s exitted with non-zero code %d: %s" | ||
% (" ".join(cmd_args), p.returncode, stderr)) | ||
if simple: | ||
return stdout | ||
return stdout, stderr, p.returncode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import logging | ||
import logging.handlers | ||
import sys | ||
import xapi | ||
|
||
|
||
LOG_LEVEL = logging.DEBUG | ||
# LOG to local2 which is currently mapped to /var/log/SMlog for SM | ||
LOG_SYSLOG_FACILITY = logging.handlers.SysLogHandler.LOG_LOCAL2 | ||
LOG_TO_STDERR = False | ||
|
||
|
||
def configure_logging(): | ||
_LOGGER.setLevel(LOG_LEVEL) | ||
|
||
formatter = logging.Formatter( | ||
'%(asctime)s - [%(process)d] - %(levelname)s - %(message)s', | ||
'%Y-%m-%d %H:%M:%S') | ||
|
||
handlers = [] | ||
|
||
# Log to syslog | ||
handlers.append(logging.handlers.SysLogHandler( | ||
address='/dev/log', | ||
facility=LOG_SYSLOG_FACILITY)) | ||
|
||
if LOG_TO_STDERR: | ||
# Write to stderr | ||
handlers.append(logging.StreamHandler(sys.stderr)) | ||
|
||
# Configure and add handlers | ||
for handler in handlers: | ||
handler.setLevel(LOG_LEVEL) | ||
handler.setFormatter(formatter) | ||
_LOGGER.addHandler(handler) | ||
|
||
|
||
def debug(message, *args, **kwargs): | ||
_LOGGER.debug(message, *args, **kwargs) | ||
|
||
|
||
def info(message, *args, **kwargs): | ||
_LOGGER.info(message, *args, **kwargs) | ||
|
||
|
||
def error(message, *args, **kwargs): | ||
_LOGGER.error(message, *args, **kwargs) | ||
|
||
|
||
def log_call_argv(): | ||
info("called as: %s" % (sys.argv)) | ||
|
||
|
||
def handle_unhandled_exceptions(exception_type, exception_value, | ||
exception_traceback): | ||
if not issubclass(exception_type, KeyboardInterrupt): | ||
if issubclass(exception_type, xapi.XenAPIException): | ||
info("Returned exception to XAPI", exc_info=(exception_type, | ||
exception_value, | ||
exception_traceback)) | ||
else: | ||
error("Unhandled exception", exc_info=(exception_type, | ||
exception_value, | ||
exception_traceback)) | ||
sys.__excepthook__(exception_type, exception_value, exception_traceback) | ||
|
||
|
||
_LOGGER = logging.getLogger() | ||
configure_logging() | ||
sys.excepthook = handle_unhandled_exceptions |