Exemplo n.º 1
0
 def test_cat(self):
     f1 = MutableFile("file_2.txt")
     f1.touch()
     f1.append("123\n")
     f1.append("123\n")
     self.assertEqual(f1.cat(), "123\n123\n")
     f1.rm()
Exemplo n.º 2
0
 def test_append(self):
     f1 = MutableFile("file_2.txt")
     f1.touch()
     f1.append("123\n")
     with open(f1.get_name(), "r") as fhin:
         self.assertEqual(fhin.read(), "123\n")
     f1.rm()
Exemplo n.º 3
0
 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()
Exemplo n.º 4
0
 def test_directory(self):
     d1 = MutableFile("mf_test/")
     self.assertEqual(os.path.exists(d1.get_name()), False)
     d1.touch()
     self.assertEqual(d1.exists(), True)
     self.assertEqual(os.path.exists(d1.get_name()), True)
     d1.rm()
     self.assertEqual(os.path.exists(d1.get_name()), False)
Exemplo n.º 5
0
 def test_file(self):
     f1 = MutableFile("file_1.root")
     self.assertEqual(os.path.exists(f1.get_name()), False)
     f1.touch()
     self.assertEqual(f1.exists(), True)
     self.assertEqual(os.path.exists(f1.get_name()), True)
     f1.rm()
     self.assertEqual(os.path.exists(f1.get_name()), False)
Exemplo n.º 6
0
    def test_textfile(self):
        dsname = "/blah/blah/BLAH/"
        fname = "tfsampletest.tmp"

        # make a temporary file putting in some dummy filenames
        # to be picked up by FilelistSample
        mf = MutableFile(fname)
        mf.touch()
        nfiles = 3
        for i in range(1, nfiles + 1):
            mf.append("ntuple{}.root\n".format(i))
        tfsamp = FilelistSample(dataset=dsname, filelist=fname)
        self.assertEqual(len(tfsamp.get_files()), nfiles)

        # clean up
        mf.rm()
Exemplo n.º 7
0
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()
Exemplo n.º 8
0
one per text file, which will take the file, multiply the content by two, and
copy back an output file. When the jobs are complete, we will sum up the outputs.
"""

if __name__ == "__main__":

    # Make a base directory
    basedir = "/hadoop/cms/store/user/{0}/metis_test/example/".format(
        os.getenv("USER"))
    MutableFile(basedir).touch()

    # Make 3 text files (file_<i>.txt) in the base directory and fill them with text "10"
    mfs = []
    for i in range(3):
        mf = MutableFile("{0}/file_{1}.txt".format(basedir, i))
        mf.rm()
        mf.append("10\n")
        mfs.append(mf)

    # Make a directory sample, giving it the location and a dataset name for bookkeeping purposes
    # The globber must be customized (by default, it is *.root) in order to pick up the text files
    ds = DirectorySample(location=basedir,
                         dataset="/TEST/Examplev1/TEST",
                         globber="*.txt")

    # 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