From 9352699b0a769d6973609787a978c5bec6866ab9 Mon Sep 17 00:00:00 2001 From: Leandro Lucarella Date: Mon, 12 May 2008 12:29:53 -0300 Subject: [PATCH] Use os.makedirs to create directories instead of exec mkdir (refs #22). Also check for errors creating the new diretory. --- pymin/services/vpn/__init__.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/pymin/services/vpn/__init__.py b/pymin/services/vpn/__init__.py index 3b5046e..fa5d5ce 100644 --- a/pymin/services/vpn/__init__.py +++ b/pymin/services/vpn/__init__.py @@ -1,6 +1,7 @@ # vim: set encoding=utf-8 et sw=4 sts=4 : import os +import errno import signal from os import path import logging ; log = logging.getLogger('pymin.services.vpn') @@ -144,9 +145,14 @@ class VpnHandler(Restorable, ConfigWriter, path.join(self._config_writer_cfg_dir, v.vpn_src ,'hosts')) #first create the directory for the vpn - call(('mkdir', '-p', path.join( - self._config_writer_cfg_dir, - v.vpn_src, 'hosts'))) + try: + os.makedirs(path.join(self._config_writer_cfg_dir, + v.vpn_src, 'hosts')) + except (IOError, OSError), e: + if e.errno != errno.EEXIST: + raise HandlerError(u"Can't create VPN config " + "directory '%s' (%s)'" + % (e.filename, e.strerror)) #this command should generate 2 files inside the vpn #dir, one rsa_key.priv and one rsa_key.pub #for some reason debian does not work like this -- 2.43.0