def process_htime_file(brick_path, filename): last_processed = db_get_last_processed() logger.info("Last processed Changelog TS from cache is {0}".format( last_processed)) htime_file_path = os.path.join(brick_path, ".glusterfs/changelogs/htime", filename) changelog_ts = 0 with open(htime_file_path) as f: # Read first few bytes and split into paths # get length of first path to get path size data = f.read(300) path_length = len(data.split(SEP)[0]) f.seek(0) # Get each Changelog file name and process it while True: changelog_file = f.read(path_length + 1).strip(SEP) if not changelog_file: break changelog_ts = int(changelog_file.split(".")[-1]) fname = changelog_file.split("/")[-1] # Avoid Reprocess if the changelog is already processed if changelog_ts < last_processed: if fname.startswith("CHANGELOG."): logger.debug("Skipped processing Changelog {0}" "(Already processed)".format(fname)) continue # If no real changelog file, Changelog filename starts # with lower case changelog.TS instead of CHANGELOG.TS # Parse Changelog file only if it is real Changelog file if fname.startswith("CHANGELOG."): logger.debug("Processing Changelog {0}".format(fname)) changelog.parse(changelog_file.strip(SEP), callback=process_changelog_record) # Update last processed Time db_update_last_processed(changelog_ts) conn.commit() if changelog_ts > 0: logger.info("Changelogs processed Till {0}".format( changelog_ts))
def run(args): if os.path.exists(args.path): changelog.parse(args.path) else: sys.stderr.write("Invalid Changelog file\n") sys.exit(1)