-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathpaths.py
More file actions
41 lines (34 loc) · 1.17 KB
/
paths.py
File metadata and controls
41 lines (34 loc) · 1.17 KB
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import os
import re
IN_DIR = '.'
OUT_DIR = '.'
def setInDir( inPath ):
'''Sets the input path to the given path. If it does not exist, raises an OSError'''
global IN_DIR
if ( not os.path.exists( inPath ) ):
print "Input path does not exist!"
raise OSError
if ( not os.path.isdir( inPath ) ):
print "Input path does not specify a folder!"
raise OSError
IN_DIR = inPath
def setOutDir( outPath ):
'''Sets the output directory. If it doesn't already exist, it creates it.'''
global OUT_DIR
if ( not os.path.exists( outPath ) ):
print "Path does not exist! Creating:", outPath
os.makedirs( outPath )
OUT_DIR = outPath
def getPath( path, asInput=True ):
'''Given the input path, computes the global path to it.
It only applies the global in dir if path is a relative address'''
if ( path == '' ):
# empty paths just get returned
return path
if ( os.path.isabs( path ) ):
# paths beginning with a slash are already absolute
return path
root = OUT_DIR
if ( asInput ):
root = IN_DIR
return os.path.normpath( os.path.join( root, path ) )