First few changes for the image diffs feature.
This commit is contained in:
parent
b22a4aa24c
commit
93b856bdb3
9 changed files with 189 additions and 2 deletions
56
util/changes.py
Normal file
56
util/changes.py
Normal file
|
@ -0,0 +1,56 @@
|
|||
import marisa_trie
|
||||
import os
|
||||
|
||||
|
||||
AUFS_METADATA = u'.wh..wh.'
|
||||
|
||||
AUFS_WHITEOUT = u'.wh.'
|
||||
AUFS_WHITEOUT_PREFIX_LENGTH = len(AUFS_WHITEOUT)
|
||||
|
||||
|
||||
def files_and_dirs(root_path, removed_prefix_collector):
|
||||
for root, dirs, files in os.walk(unicode(root_path)):
|
||||
|
||||
rel_root = os.path.relpath(root, root_path)
|
||||
yield rel_root
|
||||
|
||||
for one_file in files:
|
||||
if one_file.startswith(AUFS_METADATA):
|
||||
# Skip
|
||||
continue
|
||||
|
||||
elif one_file.startswith(AUFS_WHITEOUT):
|
||||
filename = one_file[AUFS_WHITEOUT_PREFIX_LENGTH:]
|
||||
removed_prefix_collector.add(os.path.join(rel_root, filename))
|
||||
continue
|
||||
|
||||
else:
|
||||
yield os.path.join(rel_root, one_file)
|
||||
|
||||
|
||||
def compute_removed(base_trie, removed_prefixes):
|
||||
for prefix in removed_prefixes:
|
||||
for filename in base_trie.keys(prefix):
|
||||
yield filename
|
||||
|
||||
|
||||
def compute_added_changed(base_trie, delta_trie):
|
||||
added = set()
|
||||
changed = set()
|
||||
|
||||
for filename in delta_trie.keys():
|
||||
if filename not in base_trie:
|
||||
added.add(filename)
|
||||
else:
|
||||
changed.add(filename)
|
||||
|
||||
return added, changed
|
||||
|
||||
|
||||
def new_fs(base_trie, added, removed):
|
||||
for filename in base_trie.keys():
|
||||
if filename not in removed:
|
||||
yield filename
|
||||
|
||||
for filename in added:
|
||||
yield filename
|
Reference in a new issue