def test_chmod(self): f1 = MutableFile("chmodtest.txt") f1.touch() f1.chmod(644) self.assertEqual(f1.chmod(), 644) f1.chmod("u+x") self.assertEqual(f1.chmod(), 744) f1.rm()
from metis.File import MutableFile """ Showcases some file operations normally done using the os module, but nicely wrapped in the MutableFile object """ if __name__ == "__main__": # Make a mutable file object fo = MutableFile("mutablefile_test.txt") # Touch the file to guarantee its existence fo.touch() # Does it exist? Hint: yes print("File exists?", fo.exists()) # What are the current permissions? print("Permissions =", fo.chmod()) # Add some text to it fo.append("test text\n") fo.append("more text") # And cat it out print("---- Begin contents --->") print(fo.cat()) print("<--- End contents ----") # Clean up by removing the file fo.rm()
# Make the condor executable to be run on the worker node # Need to assume the argument mapping used by CondorTask # The executable just takes an input file and multiplies the content by two to produce the output exefile = MutableFile("dummy_exe.sh") exefile.rm() exefile.append(r"""#!/bin/bash OUTPUTDIR=$1 OUTPUTNAME=$2 INPUTFILENAMES=$3 IFILE=$4 # Make sure OUTPUTNAME doesn't have .root OUTPUTNAME=$(echo $OUTPUTNAME | sed 's/\.root//') echo $(( 2*$(cat $INPUTFILENAMES) )) > tmp.txt gfal-copy -p -f -t 4200 --verbose file://`pwd`/tmp.txt gsiftp://gftp.t2.ucsd.edu${OUTPUTDIR}/${OUTPUTNAME}_${IFILE}.txt --checksum ADLER32 """) exefile.chmod("u+x") # Make a CondorTask (3 in total, one for each input) task = CondorTask( sample=ds, files_per_output=1, tag="v0", output_name="output.txt", executable=exefile.get_name(), condor_submit_params={"sites": "UAF,T2_US_UCSD,UCSB"}, no_load_from_backup= True, # for the purpose of the example, don't use a backup ) do_cmd("rm -rf {0}".format(task.get_outputdir())) # Process and sleep until complete