Commit 62a68eb1 authored by snuverink_j's avatar snuverink_j
Browse files

abort with useful message before recursive directory creation, fixes #9

parent a72fc04a
......@@ -9,6 +9,26 @@ Simulation class handles batch job related things
import sys,os,shutil, subprocess
#import numpy as np
# Helper methods
def isInDirectory(filepath, directory):
# From https://stackoverflow.com/questions/3812849/how-to-check-whether-a-directory-is-a-sub-directory-of-another-directory
''' Check if filepath is inside directory '''
return os.path.realpath(filepath).startswith(os.path.realpath(directory) + os.sep)
def linkDirectory(path, name=''):
'''Make files available in working directory with recursive symbolic links'''
# Check for recursiveness
if isInDirectory(os.getcwd(),path):
print (name + ' directory is subdirectory of working directory! runOPAL cannot handle this.. bye!')
sys.exit()
# lndir and if fails try cp
if os.system('lndir ' + path) != 0:
#print("lndir failed (possibly doesn't exist on this system), using cp -rs..."),
if os.listdir(path):
os.system('cp -rs ' + path + '/* .')
class Simulation:
def __init__(self, opaldict):
......@@ -59,20 +79,13 @@ class Simulation:
print( 'Fieldmap directory unknown exiting ...')
sys.exit()
if os.system('lndir ' + fieldmapPath) != 0:
#print("lndir failed (possibly doesn't exist on this system), using cp -rs..."),
if os.listdir(fieldmapPath):
os.system('cp -rs ' + fieldmapPath + '/* .')
linkDirectory(fieldmapPath,'Fieldmap')
# Link distribution directory if present
if (os.environ.get('DISTRIBUTIONS')):
distributionPath = os.environ.get('DISTRIBUTIONS')
if os.path.isdir(distributionPath):
if os.system('lndir ' + distributionPath) != 0:
#print("lndir failed (possibly doesn't exist on this system), using cp -rs..."),
if os.listdir(distributionPath):
os.system('cp -rs ' + distributionPath + '/* .')
linkDirectory(distributionPath,'Distribution')
# Read in the file
filedata = None
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment