| 144 | return (from_hash, to_hash) |
| 145 | |
| 146 | def process(path, fromfile, tofile, processor_function, hash_db): |
| 147 | fullfrompath = os.path.join(path, fromfile) |
| 148 | fulltopath = os.path.join(path, tofile) |
| 149 | current_hash = get_hash(fullfrompath, fulltopath) |
| 150 | if current_hash == hash_db.get(normpath(fullfrompath), None): |
| 151 | print(f'{fullfrompath} has not changed') |
| 152 | return |
| 153 | |
| 154 | orig_cwd = os.getcwd() |
| 155 | try: |
| 156 | os.chdir(path) |
| 157 | print(f'Processing {fullfrompath}') |
| 158 | processor_function(fromfile, tofile) |
| 159 | finally: |
| 160 | os.chdir(orig_cwd) |
| 161 | # changed target file, recompute hash |
| 162 | current_hash = get_hash(fullfrompath, fulltopath) |
| 163 | # store hash in db |
| 164 | hash_db[normpath(fullfrompath)] = current_hash |
| 165 | |
| 166 | |
| 167 | def find_process_files(root_dir): |