~milo/lava-tool/lava-165

« back to all changes in this revision

Viewing changes to lava_tool/utils.py

  • Committer: Milo Casagrande
  • Date: 2013-07-25 15:24:00 UTC
  • Revision ID: milo@ubuntu.com-20130725152400-cdd1gd2gtc3st25n
Refactored the lava init command.

Show diffs side-by-side

added added

removed removed

Lines of Context:
298
298
 
299
299
    return urlparse.urlunparse(
300
300
        (scheme, netloc, path, params, query, fragment))
 
301
 
 
302
 
 
303
def create_dir(path, dir_name=None):
 
304
    """Checks if a directory does not exists, and creates it.
 
305
 
 
306
    :param path: The path where the directory should be created.
 
307
    :param dir_name: An optional name for a directory to be created at
 
308
                     path (dir_name will be joined with path).
 
309
    :return The path of the created directory."""
 
310
    created_dir = path
 
311
    if dir_name:
 
312
        created_dir = os.path.join(path, dir_name)
 
313
 
 
314
    if not os.path.isdir(created_dir):
 
315
        try:
 
316
            os.makedirs(created_dir)
 
317
        except OSError:
 
318
            raise CommandError("Cannot create directory "
 
319
                               "'{0}'.".format(created_dir))
 
320
    return created_dir