def testFileSearch(self): self.assertEqual(file_name[1], dt.file_by_name(file_name[0], default_dir)) self.assertEqual(file_names[1], dt.files_by_name(file_names[0], default_dir)) self.assertEqual(file_extension1[1], dt.file_by_extension(file_extension1[0], default_dir)) self.assertEqual(file_extension2[1], dt.file_by_extension(file_extension2[0], default_dir)) self.assertEqual(file_extensions[1], dt.files_by_extension(file_extensions[0], default_dir)) self.assertEqual(file_partial[1], dt.file_by_partial(file_partial[0], default_dir)) self.assertEqual(file_partials[1], dt.files_by_partial(file_partials[0], default_dir)) self.assertIsNone(dt.file_by_name(missing_file, sub_dir))
def file_hash(fname): m = md5() with open(fname, "rb") as fh: for data in fh.read(8192): m.update(data) return m.hexdigest() conn = sqlite3.connect(DB_LOC) setup_db(conn) folders = listdir(FEED_DIR) for f in folders: files = listdir(FEED_DIR + f) for fname in files: if fname.startswith("vipFeed") and fname.split(".")[0].endswith("2012-11-06"): fullpath = FEED_DIR + f + "/" + fname if has_changed(conn, fullpath): flatfiledir = fname.split(".")[0] + "_flatfiles/" dt.clear_or_create(flatfiledir) dt.clear_or_create(TEMP_DIR) unpack.unpack(fullpath, TEMP_DIR) unpack.flatten_folder(TEMP_DIR) xml_file = dt.file_by_extension(".xml", TEMP_DIR) ftff.feed_to_db_files(flatfiledir, xml_file) make_archive(fname.split(".")[0] + "_flatfiles", "zip", flatfiledir) move(fname.split(".")[0] + "_flatfiles.zip", FEED_DIR + f + "/" + fname.split(".")[0] + "_flatfiles.zip") rmtree(TEMP_DIR) rmtree(flatfiledir)