1
0
mirror of https://github.com/wting/autojump synced 2024-10-27 20:34:07 +00:00
wting_autojump/bin/utils.py

43 lines
859 B
Python
Raw Normal View History

2013-12-16 17:20:40 +00:00
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import print_function
2013-12-16 17:20:40 +00:00
import os
2013-12-16 17:20:40 +00:00
import platform
import sys
def create_dir(path):
"""Creates a directory atomically."""
try:
os.makedirs(path)
except OSError as exception:
if exception.errno != errno.EEXIST:
raise
2013-12-16 17:20:40 +00:00
def is_linux():
return platform.system() == 'Linux'
def is_osx():
return platform.system() == 'Darwin'
def is_windows():
return platform.system() == 'Windows'
def move_file(src, dst):
"""
Atomically move file.
Windows does not allow for atomic file renaming (which is used by
os.rename / shutil.move) so destination paths must first be deleted.
"""
if is_windows() and os.path.exists(dst):
# raises exception if file is in use on Windows
os.remove(dst)
shutil.move(src, dst)