diff options
| author | Michael E Brown <michael_e_brown@dell.com> | 2007-10-16 16:20:30 -0500 |
|---|---|---|
| committer | Michael E Brown <michael_e_brown@dell.com> | 2007-10-16 16:20:30 -0500 |
| commit | b277b6238cb995377ba0c6ada9603bd2eba54a5a (patch) | |
| tree | e154f867d42bbc7d8395ba4a8ccca44178d14cd4 /src | |
| parent | 5c2aba6ac0472e6ee2e7c4c4bc7f58c515518b22 (diff) | |
| download | mock-b277b6238cb995377ba0c6ada9603bd2eba54a5a.tar.gz mock-b277b6238cb995377ba0c6ada9603bd2eba54a5a.tar.xz mock-b277b6238cb995377ba0c6ada9603bd2eba54a5a.zip | |
start adding utility functions.
Diffstat (limited to 'src')
| -rw-r--r-- | src/py-libs/util.py | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/src/py-libs/util.py b/src/py-libs/util.py index b6610fb..dc34831 100644 --- a/src/py-libs/util.py +++ b/src/py-libs/util.py @@ -1,4 +1,6 @@ #!/usr/bin/python -tt +# vim:expandtab:autoindent:tabstop=4:shiftwidth=4:filetype=python:textwidth=0: +# # This program 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 @@ -17,13 +19,33 @@ # revised and adapted by Michael Brown # python library imports +import logging +import os +import os.path # our imports import mock.exception +from mock.trace_decorator import trace + +# set up logging +log = logging.getLogger("mock.util") # classes -class commandTimeoutExpired(Error): +class commandTimeoutExpired(mock.exception.Error): def __init__(self, msg): Error.__init__(self, msg) self.msg = msg self.resultcode = 10 + +# functions +@trace +def mkdirIfAbsent(dir): + log.debug("ensuring that dir exists: %s" % dir) + if not os.path.exists(dir): + try: + log.debug("creating dir: %s" % dir) + os.makedirs(dir) + except OSError, e: + log.exception() + raise mock.exception.Error, "Could not create dir %s. Error: %s" % (dir, e) + |
