Skip to content

Instantly share code, notes, and snippets.

@lolow
Forked from nyanpasu64/seafile-merge-fixer.py
Created June 6, 2016 20:04
Show Gist options
  • Save lolow/7a659d5e9a8f58c5485970e53cf4b770 to your computer and use it in GitHub Desktop.
Save lolow/7a659d5e9a8f58c5485970e53cf4b770 to your computer and use it in GitHub Desktop.
Seafile merge fixer (replace remote with local state by renaming files)
#!/usr/bin/env python3
import os
import sys
import re
import shutil
from pathlib import Path
def reglob(s, folders=False):
p = Path('.')
out = p.glob('**/' + s)
if not folders:
out = [file for file in out if not file.is_dir()]
return out
def main():
sfcs = [str(path) for path in reglob('*SFConflict*', folders=True)]
print(sfcs)
origs = [re.sub(r' \(SFConflict .*(\.[^.]*)', r'\1', s) for s in sfcs]
for sfc, orig in zip(sfcs, origs):
try:
shutil.rmtree(orig)
except NotADirectoryError:
os.remove(orig)
shutil.move(sfc, orig)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment