Skip to content

Instantly share code, notes, and snippets.

@nyanpasu64
Created January 1, 2016 02:49
Show Gist options
  • Save nyanpasu64/95ba9e768985a8a3e373 to your computer and use it in GitHub Desktop.
Save nyanpasu64/95ba9e768985a8a3e373 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