File: rename_add_contr.py

package info (click to toggle)
yasnippet-snippets 0~git20161123-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 5,000 kB
  • ctags: 19
  • sloc: lisp: 73; python: 23; ada: 4; makefile: 2
file content (36 lines) | stat: -rwxr-xr-x 813 bytes parent folder | download
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
#!/usr/bin/env python
import os
import re
from os.path import join
from shutil import move


def rename(root, f):
    if f.endswith('.yasnippet'):
        base, _ = f.split('.')
        print("move %s to %s" % (join(root, f), join(root, base)))
        move(join(root, f), join(root, base))


CONT = "# contributor: Andrea crotti\n# --"
END = "# --\n\n"

orig = "# --\n\n"
to  = "# --\n"

def insert(root, f, orig, to):
    fname = join(root, f)
    text = open(fname).read()
    nex_text = re.sub(orig, to, text)
    open(fname, 'w').write(nex_text)

if __name__ == '__main__':
    for root, dirs, files in os.walk('.'):
        if "mode" in root:
            # os.popen("git add *yasnippet")
            for f in files:
                rename(root, f)
                # insert(root, f, orig, to)