File: comment_17_9ea2c23d6099281f55122e39655d7353._comment

package info (click to toggle)
git-annex 8.20210223-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 68,764 kB
  • sloc: haskell: 70,359; javascript: 9,103; sh: 1,304; makefile: 212; perl: 136; ansic: 44
file content (49 lines) | stat: -rw-r--r-- 1,298 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
[[!comment format=mdwn
 username="thk"
 avatar="http://cdn.libravatar.org/avatar/bfef10a428769701aeee1db978951461"
 subject="Delete duplicates and specify preferred locations"
 date="2020-04-26T11:18:39Z"
 content="""
I leave this here for people who understand python. I wrote the output of Joey's first script in file \"duplicates\". You want to comment out the last line while trying and add some print statements.


```
from itertools import *
from functools import partial
from pprint import pprint
import subprocess

with open('duplicates', 'rb') as f:
  duplicates = f.read()

duplicates = duplicates.split(b\"\n\n\")

preferences = b\"\"\"XXXXXXXXXXXXXXXXXXXXXXXXX Add more lines below
\"\"\".splitlines()

ignore = b\"\"\"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX Add more lines below
\"\"\".splitlines()

deletes = []

def matches(prefixes, f):
  for prefix in prefixes:
    if f.startswith(prefix):
      return True
  return False

for block in duplicates:
  files = block.splitlines()
  if any(filter(partial(matches, ignore), files)):
    continue

  delete = list(filterfalse(partial(matches, preferences), files))

  if len(delete) + 1 == len(files):
    deletes.extend(delete)

for d in deletes:
  pprint(d)
  subprocess.run([b\"git\", b\"rm\", d], capture_output=True, check=True)
```
"""]]