Exemplo n.º 1
0
    def test_find_files_matching(self):
        # Check that find_files_matching finds files that exist.
        for mfile in find_files_matching(self.test_dir,
                                         patterns=self.test_patterns):
            self.assertTrue(os.path.isfile(mfile))

        # Check that nothing is returned when no files are found
        count = 0
        for mfile in find_files_matching(self.test_dir,
                                         patterns='nequetamlimanoexisteelarchivo42.txt'):
            count += 1
        self.assertEqual(count, 0)
Exemplo n.º 2
0
def main(path, settings=None, overwrite=False):
    # Search for FITS files in the given path.
    # single_level=False means all subfolders will be searched.
    filenames = []
    for filename in find_files_matching(path,
                                        patterns='*.fits',
                                        single_level=False):
        filenames.append(filename)

    print("%i files to be converted...\n" % len(filenames))
    success_count = failure_count = 0

    for filename in filenames:
        bfilename = os.path.basename(filename)
        outputfile = filename + "_new.fits"
        try:
            # TODO: When different conversions are possible, insert if-then-else block here.
            datatype = convert_cdp_2to3(filename,
                                        outputfile,
                                        settings=settings,
                                        overwrite=overwrite)
            print("File \'%s\' of data type \'%s\'\n  has been converted." % \
                  (bfilename, datatype))
            success_count += 1
        except Exception as e:
            print("File \'%s\' failed to convert." % bfilename)
            print("  " + str(e))
            failure_count += 1

    print("\n%d files were successfully converted." % success_count)
    if failure_count > 0:
        print(
            "*** WARNING: %d files failed to convert! Scroll up for details. ***"
            % failure_count)
Exemplo n.º 3
0
 def setUp(self):
     # Search for all the left over test files in the current
     # directory matching the known pattern.
     self.tempfiles = find_files_matching('.',
                                          patterns='Miri*_test.fits',
                                          single_level=True,
                                          sortfiles=False,
                                          yield_folders=False,
                                          yield_path_only=False)
Exemplo n.º 4
0
def verify_path(path,
                overwrite=False,
                pattern='*.fits',
                keepfile=False,
                nopass=False):
    """
    
    Verify the CDP files contained within a given path.
    
    """
    # Search for FITS files in the given path.
    # single_level=False means all subfolders will be searched.
    filenames = []
    for filename in find_files_matching(path,
                                        patterns=pattern,
                                        single_level=False):
        filenames.append(filename)

    print("%i files to be tested...\n" % len(filenames))
    success_count = failure_count = untested_count = 0

    for filename in filenames:
        bfilename = os.path.basename(filename)
        try:
            verify_fits_file(filename, cdp_checks=True, fitsverify_checks=True)
            time.sleep(0.1)  # Allow the file to close.
            datatype = verify_cdp_file(filename,
                                       overwrite=overwrite,
                                       keepfile=keepfile)
            if not nopass:
                print("File \'%s\' of data type \'%s\' has passed the test." % \
                      (bfilename, datatype))
            success_count += 1
        except MemoryError:
            print("*** Insufficient memory to verify file \'%s\'!" % bfilename)
            untested_count += 1
        except Exception as e:
            print("File \'%s\' has failed the test." % bfilename)
            print("  " + str(e))
            failure_count += 1

    print("\n%d files passed the test." % success_count)
    if untested_count > 0:
        print(
            "*** WARNING: %d files could not be tested! Scroll up for details. ***"
            % untested_count)
    if failure_count > 0:
        print(
            "*** WARNING: %d files failed the test! Scroll up for details. ***"
            % failure_count)
Exemplo n.º 5
0
 def setUp(self):
     # Search for all the left over test files in the current
     # directory matching the known pattern. To protect against
     # accidental removal of needed CDP files, only remove files
     # from a current directory called "tests".
     self.tempdir = './CDP'
     if os.path.isdir(self.tempdir) and \
         ('tests' in os.path.abspath(self.tempdir)):
         self.tidyup = True
         self.tempfiles = find_files_matching('./CDP',
                                              patterns='MIRI_*.fits',
                                              single_level=True,
                                              sortfiles=False,
                                              yield_folders=False,
                                              yield_path_only=False)
     else:
         self.tidyup = False
         self.tempfiles = []