source: TI03-DataExtractor/branches/old_stuff/dx-0.1.0/commonFunctions.py @ 793

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI03-DataExtractor/branches/old_stuff/dx-0.1.0/commonFunctions.py@793
Revision 793, 775 bytes checked in by astephen, 13 years ago (diff)

Put all the old code in the old_stuff branch.

Line 
1"""
2
3commonFunctions.py
4==================
5
6Holds common functions used in the Data Extractor software.
7
8"""
9
10# Import python modules
11import os
12
13def makeDirsAndPerms(basedir, dirs, permissions, owner, verbose="no"):
14    """
15    A function for making directories recursively and setting permissions/ownership.
16    """
17    if type(dirs)==str: dirs=[dirs]
18    dirs=[basedir]+list(dirs)
19    dir=None
20
21    while len(dirs)>0:
22
23        if dir:
24            dir=os.path.join(dir, dirs[0])
25        else:
26            dir=dirs[0]
27        dirs=dirs[1:]
28
29        if not os.path.exists(dir):
30            if verbose=="yes":   print "Making directory:", dir
31            os.mkdir(dir)
32            os.chmod(dir, permissions)
33            os.system('/bin/chown %s %s' % (owner, dir))
34
35    return
Note: See TracBrowser for help on using the repository browser.