Exemple #1
0
 def test3(self):
     """CleanFileCache: "age" parameter
     """
     age = 10
     # create a temporary directory with fake cache files
     # and other files
     cache_root = tempfile.mkdtemp()
     _hash = lambda s: hashlib.sha1(s).hexdigest()
     cache1, _ = CreateCacheFilename(CacheDir=cache_root,
                                     OtherProperties=["A=newer"])
     cache2, _ = CreateCacheFilename(
         CacheDir=cache_root,
         OtherProperties=["B=rightonedge"],
     )
     cache3, _ = CreateCacheFilename(
         CacheDir=cache_root,
         OtherProperties=["C=old"],
     )
     createFile(cache1, age - 1)
     createFile(cache2, age)
     createFile(cache3, age + 1)
     non_cache = [
         os.path.join(cache_root, f) for f in [
             'a' * 39 + ".nxs",
             '0' * 41 + ".nxs",
             'alpha_' + 'b' * 39 + ".nxs",
             'beta_' + 'e' * 41 + ".nxs",
         ]
     ]
     for p in non_cache:
         touch(p)
     # print glob.glob(os.path.join(cache_root, '*'))
     # Execute
     code = "CleanFileCache(CacheDir = %r, AgeInDays = %s)" % (cache_root,
                                                               age)
     code = "from mantid.simpleapi import CleanFileCache; %s" % code
     cmd = '%s -c "%s"' % (sys.executable, code)
     if os.system(cmd):
         raise RuntimeError("Failed to excute %s" % cmd)
     # executed?
     # self.assertTrue(alg_test.isExecuted())
     # Verify ....
     files_remained = glob.glob(os.path.join(cache_root, '*'))
     try:
         self.assertEqual(set(files_remained), set(non_cache + [cache1]))
     finally:
         # remove the temporary directory
         shutil.rmtree(cache_root)
     return
Exemple #2
0
 def test2(self):
     """CleanFileCache: 'normal' files with 39 and 41-character filenames etc
     """
     # create a temporary directory with fake cache files
     # and other files
     cache_root = tempfile.mkdtemp()
     _hash = lambda s: hashlib.sha1(s).hexdigest()
     cache1, _ = CreateCacheFilename(CacheDir=cache_root,
                                     OtherProperties=["A=1"])
     cache2, _ = CreateCacheFilename(
         CacheDir=cache_root,
         OtherProperties=["B='silly'"],
     )
     touch(cache1)
     touch(cache2)
     non_cache = [
         os.path.join(cache_root, f) for f in [
             'a' * 39 + ".nxs",
             '0' * 41 + ".nxs",
             'alpha_' + 'b' * 39 + ".nxs",
             'beta_' + 'e' * 41 + ".nxs",
         ]
     ]
     for p in non_cache:
         touch(p)
     # print glob.glob(os.path.join(cache_root, '*'))
     # Execute
     code = "CleanFileCache(CacheDir = %r, AgeInDays = 0)" % cache_root
     code = "from mantid.simpleapi import CleanFileCache; %s" % code
     cmd = '%s -c "%s"' % (sys.executable, code)
     if os.system(cmd):
         raise RuntimeError("Failed to excute %s" % cmd)
     # executed?
     # self.assertTrue(alg_test.isExecuted())
     # Verify ....
     files_remained = glob.glob(os.path.join(cache_root, '*'))
     try:
         self.assertEqual(set(files_remained), set(non_cache))
     finally:
         # remove the temporary directory
         shutil.rmtree(cache_root)
     return
Exemple #3
0
    def __getCacheName(self, wkspname, additional_props=None):
        """additional_props: list. additional properties to be hashed
        """
        cachedir = self.getProperty('CacheDir').value
        if len(cachedir) <= 0:
            return None

        # fix up the workspace name
        prefix = wkspname.replace('__', '')

        propman_properties = [
            'bank', 'd_min', 'd_max', 'tof_min', 'tof_max', 'wavelength_min',
            'wavelength_max'
        ]
        alignandfocusargs = []

        # calculate general properties
        for name in PROPS_FOR_ALIGN + PROPS_IN_PD_CHARACTER:
            # skip these because this has been reworked to only worry about information in workspaces
            if name in (CAL_FILE, GROUP_FILE, CAL_WKSP, GRP_WKSP, MASK_WKSP):
                continue
            prop = self.getProperty(name)
            if name == 'PreserveEvents' or not prop.isDefault:
                value = prop.valueAsStr  # default representation for everything
                alignandfocusargs.append('%s=%s' % (name, value))

        # special calculations for workspaces
        if self.absorption:
            alignandfocusargs.append(
                uniqueDescription('AbsorptionWorkspace', self.absorption))
        if self.__calWksp:
            alignandfocusargs.append(
                uniqueDescription(CAL_WKSP, self.__calWksp))
        if self.__grpWksp:
            alignandfocusargs.append(
                uniqueDescription(GRP_WKSP, self.__grpWksp))
        if self.__mskWksp:
            alignandfocusargs.append(
                uniqueDescription(MASK_WKSP, self.__mskWksp))

        alignandfocusargs += additional_props or []
        reductionPropertiesName = self.getProperty(
            'ReductionProperties').valueAsStr
        if reductionPropertiesName not in PropertyManagerDataService:
            reductionPropertiesName = ''  # do not specify non-existant manager

        return CreateCacheFilename(Prefix=prefix,
                                   PropertyManager=reductionPropertiesName,
                                   Properties=propman_properties,
                                   OtherProperties=alignandfocusargs,
                                   CacheDir=cachedir).OutputFilename
Exemple #4
0
 def test1(self):
     """CleanFileCache: simple test with two cache files and two normal files
     """
     # create a temporary directory with fake cache files
     # and other files
     cache_root = tempfile.mkdtemp()
     _hash = lambda s: hashlib.sha1(s).hexdigest()
     cache1, _ = CreateCacheFilename(CacheDir=cache_root,
                                     OtherProperties=["A=1", "B=2"])
     cache2, _ = CreateCacheFilename(
         CacheDir=cache_root,
         OtherProperties=["C=3"],
     )
     touch(cache1)
     touch(cache2)
     non_cache = [
         os.path.join(cache_root, f)
         for f in ["normal1.txt", "normal2.dat"]
     ]
     for p in non_cache:
         touch(p)
     # print glob.glob(os.path.join(cache_root, '*'))
     # Execute
     code = "CleanFileCache(CacheDir = %r, AgeInDays = 0)" % cache_root
     code = "from mantid.simpleapi import CleanFileCache; %s" % code
     cmd = '%s -c "%s"' % (sys.executable, code)
     if os.system(cmd):
         raise RuntimeError("Failed to excute %s" % cmd)
     # executed?
     # self.assertTrue(alg_test.isExecuted())
     # Verify ....
     files_remained = glob.glob(os.path.join(cache_root, '*'))
     try:
         self.assertEqual(set(files_remained), set(non_cache))
     finally:
         # remove the temporary directory
         shutil.rmtree(cache_root)
     return
Exemple #5
0
    def __getCacheName(self, wkspname):
        cachedir = self.getProperty('CacheDir').value
        if len(cachedir) <= 0:
            return None

        propman_properties = ['bank', 'd_min', 'd_max', 'tof_min', 'tof_max', 'wavelength_min', 'wavelength_max']
        alignandfocusargs = []
        for name in PROPS_FOR_ALIGN:
            prop = self.getProperty(name)
            if name == 'PreserveEvents' or not prop.isDefault:
                # TODO need unique identifier for absorption workspace
                alignandfocusargs.append('%s=%s' % (name, prop.valueAsStr))

        return CreateCacheFilename(Prefix=wkspname,
                                   PropertyManager=self.getProperty('ReductionProperties').valueAsStr,
                                   Properties=propman_properties,
                                   OtherProperties=alignandfocusargs,
                                   CacheDir=cachedir).OutputFilename