-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a4564b1
commit e38dc9c
Showing
1 changed file
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import os | ||
import time | ||
import compute_hash | ||
|
||
class Megadata: | ||
def __init__(self, file_path): | ||
self.file_path = file_path | ||
self.hash = self.calculate_hash(file_path) | ||
self.size = os.path.getsize(file_path) | ||
self.creation_time = os.path.getctime(file_path) | ||
self.modification_time = os.path.getmtime(file_path) | ||
|
||
def calculate_hash(self, file_path): | ||
pass | ||
|
||
def __eq__(self, other): | ||
return (self.hash == other.hash and | ||
self.size == other.size and | ||
self.creation_time == other.creation_time and | ||
self.modification_time == other.modification_time) | ||
|
||
|
||
def record_megadata(directory): | ||
file_megadata = {} | ||
for root, _, files in os.walk(directory): | ||
for file in files: | ||
file_path = os.path.join(root, file) | ||
file_megadata[file_path] = Megadata(file_path) | ||
return file_megadata | ||
|
||
def check_for_updates(old_megadata, current_directory): | ||
current_megadata = record_megadata(current_directory) | ||
updates = [] | ||
for old_path, old_data in old_megadata.items(): | ||
for current_path, current_data in current_megadata.items(): | ||
if old_data == current_data and old_path != current_path: | ||
updates.append((old_path, current_path)) | ||
return updates |