summaryrefslogtreecommitdiff
path: root/src/leap/util
diff options
context:
space:
mode:
authorTomás Touceda <chiiph@leap.se>2013-03-13 10:21:15 -0300
committerTomás Touceda <chiiph@leap.se>2013-03-13 10:21:15 -0300
commit12d2835c7d1f3c3d11eaa587b2196c104e6859e7 (patch)
tree47dd63b13781ae3d54fc3e26669d17489b5af7a0 /src/leap/util
parentb15f28b73afc31fd4176bee1a615e4095b0f4479 (diff)
Add mkdir_p method to util.files
Diffstat (limited to 'src/leap/util')
-rw-r--r--src/leap/util/files.py41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/leap/util/files.py b/src/leap/util/files.py
index 8c7a5af3..97741433 100644
--- a/src/leap/util/files.py
+++ b/src/leap/util/files.py
@@ -1,7 +1,29 @@
+# -*- coding: utf-8 -*-
+# files.py
+# Copyright (C) 2013 LEAP
+#
+# 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 3 of the License, or
+# (at your option) any later version.
+#
+# This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
+
+"""
+Implements file helper methods
+"""
+
import os
import stat
import logging
import time
+import errno
logger = logging.getLogger(__name__)
@@ -43,3 +65,22 @@ def get_mtime(filename):
return mtime
except OSError:
return None
+
+
+def mkdir_p(path):
+ """
+ Creates the path and all the intermediate directories that don't
+ exist
+
+ Might raise OSError
+
+ @param path: path to create
+ @type path: str
+ """
+ try:
+ os.makedirs(path)
+ except OSError as exc:
+ if exc.errno == errno.EEXIST and os.path.isdir(path):
+ pass
+ else:
+ raise