def get_first_formatted_dir_in_dir(folder, fmt): """ Get the (alphabetically) first directory in a directory which can be formatted according to fmt. Parameters ---------- folder : str Folder name. fmt : str Format string. Returns ------- first_elem : str First formatted directory. """ first_elem = None root_elements = sorted(os.listdir(folder)) for root_element in root_elements: if os.path.isdir(os.path.join(folder, root_element)): if validate(fmt, root_element): first_elem = root_element break return first_elem
def get_first_formatted_dir_in_dir(folder, fmt): """ Get the (alphabetically) first directory in a directory which can be formatted according to fmt. Parameters ---------- folder : string path to folder fmt : ... formatting rule Returns ------- first_elem: string path to last directory """ first_elem = None root_elements = sorted(os.listdir(folder)) for root_element in root_elements: if os.path.isdir(os.path.join(folder, root_element)): if parser.validate(fmt, root_element): first_elem = root_element break return first_elem
def get_first_formatted_dir_in_dir(folder, fmt): """ Get the (alphabetically) first directory in a directory which can be formatted according to fmt. """ first_elem = None root_elements = sorted(os.listdir(folder)) for root_element in root_elements: if os.path.isdir(os.path.join(folder, root_element)): if parser.validate(fmt, root_element): first_elem = root_element break return first_elem
def test_validate(self): # These cases are True self.assertTrue( validate( self.fmt, "/somedir/avhrr/2014/hrpt_noaa19_20140212_1412_12345.l1b")) self.assertTrue( validate( self.fmt, "/somedir/avhrr/2014/hrpt_noaa01_19790530_0705_00000.l1b")) self.assertTrue( validate( self.fmt, "/somedir/funny-char$dir/hrpt_noaa19_20140212_1412_12345.l1b")) self.assertTrue( validate(self.fmt, "/somedir//hrpt_noaa19_20140212_1412_12345.l1b")) # These cases are False self.assertFalse( validate(self.fmt, "/somedir/bla/bla/hrpt_noaa19_20140212_1412_1A345.l1b")) self.assertFalse( validate(self.fmt, "/somedir/bla/bla/hrpt_noaa19_2014021_1412_00000.l1b")) self.assertFalse( validate(self.fmt, "/somedir/bla/bla/hrpt_noaa19_20140212__412_00000.l1b")) self.assertFalse( validate(self.fmt, "/somedir/bla/bla/hrpt_noaa19_20140212__1412_00000.l1b")) self.assertFalse( validate(self.fmt, "/somedir/bla/bla/hrpt_noaa19_20140212_1412_00000.l1")) self.assertFalse( validate(self.fmt, "/somedir/bla/bla/hrpt_noaa19_20140212_1412_00000")) self.assertFalse( validate(self.fmt, "{}/somedir/bla/bla/hrpt_noaa19_20140212_1412_00000.l1b"))
def test_validate(self): # These cases are True self.assertTrue( validate(self.fmt, "/somedir/avhrr/2014/hrpt_noaa19_20140212_1412_12345.l1b")) self.assertTrue( validate(self.fmt, "/somedir/avhrr/2014/hrpt_noaa01_19790530_0705_00000.l1b")) self.assertTrue(validate( self.fmt, "/somedir/funny-char$dir/hrpt_noaa19_20140212_1412_12345.l1b")) self.assertTrue( validate(self.fmt, "/somedir//hrpt_noaa19_20140212_1412_12345.l1b")) # These cases are False self.assertFalse( validate(self.fmt, "/somedir/bla/bla/hrpt_noaa19_20140212_1412_1A345.l1b")) self.assertFalse( validate(self.fmt, "/somedir/bla/bla/hrpt_noaa19_2014021_1412_00000.l1b")) self.assertFalse( validate(self.fmt, "/somedir/bla/bla/hrpt_noaa19_20140212__412_00000.l1b")) self.assertFalse( validate(self.fmt, "/somedir/bla/bla/hrpt_noaa19_20140212__1412_00000.l1b")) self.assertFalse( validate(self.fmt, "/somedir/bla/bla/hrpt_noaa19_20140212_1412_00000.l1")) self.assertFalse( validate(self.fmt, "/somedir/bla/bla/hrpt_noaa19_20140212_1412_00000")) self.assertFalse( validate(self.fmt, "{}/somedir/bla/bla/hrpt_noaa19_20140212_1412_00000.l1b"))