As I read other people’s Python code, I notice almost every project has a utils.py file. I’m going to shamelessly post the most interesting (or most useful) bits that I find, with proper credit. The first one is from my work on modifying Gitosis to use a MySQL backend. Here’s a quick way to make a directory:
"""
Create a new directory on a Unix system
@param directory_path
@param (optional) permissions
@exception OSERROR If directory cannot be made
"""
def mkdir(*a, **kw):
try:
os.mkdir(*a, **kw)
except OSError, e:
if e.errno == errno.EEXIST:
pass
else:
raise
Credit goes to the Gitosis project.
About Josh Gachnang
Josh Gachnang is a small business consultant with 5 years of experience in developing IT systems. His specialties include moving IT infrastructure to the cloud, standard and mobile web development using Python and Django, and promoting with social media. Python , Scripts
