Created
January 1, 2016 02:49
-
-
Save nyanpasu64/95ba9e768985a8a3e373 to your computer and use it in GitHub Desktop.
Seafile merge fixer (replace remote with local state by renaming files)
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
#!/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