easier to read

This commit is contained in:
Martin Diehl 2020-06-03 13:32:47 +02:00
parent c67fbacfc7
commit 3be1a33820
5 changed files with 44 additions and 68 deletions

View File

@ -1,56 +1,30 @@
#!/usr/bin/env python3
# Makes postprocessing routines accessible from everywhere.
import os
import sys
from pathlib import Path
import damask
damaskEnv = damask.Environment()
baseDir = damaskEnv.relPath('processing/')
binDir = damaskEnv.relPath('bin/')
env = damask.Environment()
bin_dir = env.root_dir/Path('bin')
if not os.path.isdir(binDir):
os.mkdir(binDir)
if not bin_dir.exists():
bin_dir.mkdir()
#define ToDo list
processing_subDirs = ['pre',
'post',
]
sys.stdout.write('\nsymbolic linking...\n')
for sub_dir in ['pre','post']:
the_dir = env.root_dir/Path('processing')/Path(sub_dir)
for subDir in processing_subDirs:
theDir = os.path.abspath(os.path.join(baseDir,subDir))
sys.stdout.write('\n'+binDir+' ->\n'+theDir+damask.util.deemph(' ...')+'\n')
for theFile in os.listdir(theDir):
theName,theExt = os.path.splitext(theFile)
if theExt in ['.py']:
src = os.path.abspath(os.path.join(theDir,theFile))
sym_link = os.path.abspath(os.path.join(binDir,theName))
if os.path.lexists(sym_link):
os.remove(sym_link)
output = theName+damask.util.deemph(theExt)
else:
output = damask.util.emph(theName)+damask.util.deemph(theExt)
sys.stdout.write(damask.util.deemph('... ')+output+'\n')
os.symlink(src,sym_link)
for the_file in the_dir.glob('*.py'):
src = the_dir/the_file
dst = bin_dir/Path(the_file.with_suffix('').name)
dst.unlink(True)
dst.symlink_to(src)
sys.stdout.write('\npruning broken links...\n')
brokenLinks = 0
for filename in os.listdir(binDir):
path = os.path.join(binDir,filename)
if os.path.islink(path) and not os.path.exists(path):
sys.stdout.write(' '+damask.util.delete(path)+'\n')
os.remove(path)
brokenLinks += 1
sys.stdout.write(('none.' if brokenLinks == 0 else '')+'\n')
for filename in bin_dir.glob('*'):
if not filename.is_file():
filename.unlink

View File

@ -6,7 +6,7 @@ import numpy as np
from optparse import OptionParser
import damask
sys.path.append(damask.solver.Marc().libraryPath())
sys.path.append(str(damask.solver.Marc().library_path))
scriptName = os.path.splitext(os.path.basename(__file__))[0]
scriptID = ' '.join([scriptName,damask.version])

View File

@ -9,7 +9,7 @@ import damask
scriptName = os.path.splitext(os.path.basename(__file__))[0]
scriptID = ' '.join([scriptName,damask.version])
sys.path.append(damask.solver.Marc().libraryPath())
sys.path.append(str(damask.solver.Marc().library_path))
#-------------------------------------------------------------------------------------------------
def outMentat(cmd,locals):

View File

@ -1,11 +1,11 @@
import os
from pathlib import Path
import tkinter
class Environment:
def __init__(self):
"""Read and provide values of DAMASK configuration."""
self.options = self._get_options()
try:
tk = tkinter.Tk()
self.screen_width = tk.winfo_screenwidth()
@ -15,17 +15,8 @@ class Environment:
self.screen_width = 1024
self.screen_height = 768
def relPath(self,relative = '.'):
"""Return absolute path from path relative to DAMASK root."""
return os.path.join(self.rootDir(),relative)
def rootDir(self):
"""Return DAMASK root path."""
return os.path.normpath(os.path.join(os.path.realpath(__file__),'../../../'))
def _get_options(self):
@property
def options(self):
options = {}
for item in ['DAMASK_NUM_THREADS',
'MSC_ROOT',
@ -34,3 +25,13 @@ class Environment:
options[item] = os.environ[item] if item in os.environ else None
return options
@property
def root_dir(self):
"""Return DAMASK root path."""
return Path(__file__).parents[2]
# for compatibility
def rootDir(self):
return str(self.root_dir)

View File

@ -2,6 +2,7 @@ import os
import subprocess
import shlex
import string
from pathlib import Path
from .._environment import Environment
@ -25,22 +26,22 @@ class Marc:
self.version = -1
#--------------------------
def libraryPath(self):
@property
def library_path(self):
path_MSC = Environment().options['MSC_ROOT']
path_lib = '{}/mentat{}/shlib/linux64'.format(path_MSC,self.version)
path_lib = Path('{}/mentat{}/shlib/linux64'.format(path_MSC,self.version))
return path_lib if os.path.exists(path_lib) else ''
return path_lib if path_lib.is_file() else None
#--------------------------
def toolsPath(self):
@property
def tools_path(self):
path_MSC = Environment().options['MSC_ROOT']
path_tools = '{}/marc{}/tools'.format(path_MSC,self.version)
return path_tools if os.path.exists(path_tools) else ''
return path_tools if path_tools.is_file() else None
#--------------------------
@ -53,21 +54,21 @@ class Marc:
):
damaskEnv = Environment()
env = Environment()
user = os.path.join(damaskEnv.relPath('src'),'DAMASK_marc{}.{}'.format(self.version,'f90' if compile else 'marc'))
if not os.path.isfile(user):
user = env.root_dir/Path('src')/Path('DAMASK_marc{}'.format(version)).with_suffix('.f90' if compile else '.marc')
if not user.is_file():
raise FileNotFoundError("DAMASK4Marc ({}) '{}' not found".format(('source' if compile else 'binary'),user))
# Define options [see Marc Installation and Operation Guide, pp 23]
script = 'run_damask_{}mp'.format(optimization)
cmd = os.path.join(self.toolsPath(),script) + \
cmd = str(self.tools_path/Path(script)) + \
' -jid ' + model + '_' + job + \
' -nprocd 1 -autorst 0 -ci n -cr n -dcoup 0 -b no -v no'
if compile: cmd += ' -u ' + user + ' -save y'
else: cmd += ' -prog ' + os.path.splitext(user)[0]
if compile: cmd += ' -u ' + str(user) + ' -save y'
else: cmd += ' -prog ' + str(user.with_suffix(''))
print('job submission {} compilation: {}'.format('with' if compile else 'without',user))
if logfile: log = open(logfile, 'w')