Skip to content
Snippets Groups Projects
Commit 633dcc58 authored by lkugler's avatar lkugler
Browse files

clean

parent fb089fa3
No related branches found
No related tags found
No related merge requests found
import os import os
from config.cfg import exp from config.cfg import exp
from config.cluster import cluster from config.cluster import cluster
from dartwrf.utils import symlink, copy_scp_srvx8, copy, sed_inplace from dartwrf.utils import symlink, copy, sed_inplace
joinp = os.path.join joinp = os.path.join
......
...@@ -22,7 +22,7 @@ class ClusterConfig(object): ...@@ -22,7 +22,7 @@ class ClusterConfig(object):
Example: Example:
`/users/abcd/data/sim_archive/experiment1/` `/users/abcd/data/sim_archive/experiment1/`
""" """
return self.archive_base+'/'+self.exp.expname return self.archive_base+'/'+self.exp.expname+'/'
@property @property
def scripts_rundir(self): def scripts_rundir(self):
...@@ -44,7 +44,7 @@ class ClusterConfig(object): ...@@ -44,7 +44,7 @@ class ClusterConfig(object):
"""Path to the directory where an ensemble member will run WRF """Path to the directory where an ensemble member will run WRF
Includes the experiment name and the ensemble member index Includes the experiment name and the ensemble member index
""" """
return self.wrf_rundir_base+'/'+self.exp.expname+'/'+str(iens) return self.wrf_rundir_base+'/'+self.exp.expname+'/'+str(iens)+'/'
def run_job(self, cmd, jobname='', cfg_update=dict(), depends_on=None): def run_job(self, cmd, jobname='', cfg_update=dict(), depends_on=None):
"""Run scripts in a shell """Run scripts in a shell
...@@ -63,10 +63,9 @@ class ClusterConfig(object): ...@@ -63,10 +63,9 @@ class ClusterConfig(object):
""" """
if self.use_slurm: if self.use_slurm:
from slurmpy import Slurm from slurmpy import Slurm
Slurm(jobname, slurm_kwargs=dict(self.slurm_cfg, **cfg_update), return Slurm(jobname, slurm_kwargs=dict(self.slurm_cfg, **cfg_update),
log_dir=self.log_dir, log_dir=self.log_dir,
scripts_dir=self.slurm_scripts_dir, scripts_dir=self.slurm_scripts_dir,
**kwargs
).run(cmd, depends_on=depends_on) ).run(cmd, depends_on=depends_on)
else: else:
print(cmd) print(cmd)
...@@ -109,7 +108,8 @@ def clean_wrfdir(dir): ...@@ -109,7 +108,8 @@ def clean_wrfdir(dir):
os.remove(f) os.remove(f)
def symlink(src, dst): def symlink(src, dst):
# Create a symbolic link pointing to src named dst. """Create a symbolic link from src to dst
"""
try: try:
os.symlink(src, dst) os.symlink(src, dst)
except FileExistsError: except FileExistsError:
...@@ -123,12 +123,18 @@ def symlink(src, dst): ...@@ -123,12 +123,18 @@ def symlink(src, dst):
raise e raise e
def link_contents(src, dst): def link_contents(src, dst):
"""Create symbolic links for all files in src to dst
Args:
src (str): Path to source directory
dst (str): Path to destination directory
Returns:
None
"""
for f in os.listdir(src): for f in os.listdir(src):
symlink(src+'/'+f, dst+'/'+f) symlink(src+'/'+f, dst+'/'+f)
def copy_scp_srvx8(src, dst):
os.system('scp '+src+' a1254888@srvx8.img.univie.ac.at:'+dst)
def sed_inplace(filename, pattern, repl): def sed_inplace(filename, pattern, repl):
'''Perform the pure-Python equivalent of in-place `sed` substitution '''Perform the pure-Python equivalent of in-place `sed` substitution
Like `sed -i -e 's/'${pattern}'/'${repl}' "${filename}"`. Like `sed -i -e 's/'${pattern}'/'${repl}' "${filename}"`.
...@@ -162,4 +168,28 @@ def sed_inplace(filename, pattern, repl): ...@@ -162,4 +168,28 @@ def sed_inplace(filename, pattern, repl):
shutil.move(tmp_file.name, filename) shutil.move(tmp_file.name, filename)
def append_file(f_main, f_gets_appended): def append_file(f_main, f_gets_appended):
os.system('cat '+f_gets_appended+' >> '+f_main) """Append the contents of one file to another
\ No newline at end of file
Args:
f_main (str): Path to file that will be appended
f_gets_appended (str): Path to file that will be appended to f_main
Returns:
None
"""
os.system('cat '+f_gets_appended+' >> '+f_main)
def write_txt(lines, fpath):
"""Write a list of strings to a text file
Args:
lines (list): List of strings
fpath (str): Path to file
Returns:
None
"""
try_remove(fpath)
with open(fpath, "w") as file:
for line in lines:
file.write(line+'\n')
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment