File: 2012-05-24.makedirs.py-python3.1

package info (click to toggle)
cdist 7.0.0-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 9,992 kB
  • sloc: sh: 16,815; python: 9,199; makefile: 344; awk: 261
file content (27 lines) | stat: -rw-r--r-- 591 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# From curl  http://armstrong.cc/~steven/tmp/makedirs.py:

#!/usr/bin/env python2

import os

def makedirs(path, mode=0o777, exist_ok=False):
    try:
        os.makedirs(path, mode=mode, exist_ok=exist_ok)
    except TypeError:
        try:
            os.makedirs(path, mode=mode)
        except OSError as e:
            if exist_ok and e.errno == 17: # File exists
                pass
            else:
                raise


makedirs('/tmp/python/makedirs')

try:
    makedirs('/tmp/python/makedirs')
except OSError as e:
    print(e)

makedirs('/tmp/python/makedirs', exist_ok=True)