File: purge.py

package info (click to toggle)
grammalecte 2.1.2%2Bds2-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 70,192 kB
  • sloc: python: 17,988; javascript: 9,417; java: 4,716; xml: 144; makefile: 28; sh: 11
file content (46 lines) | stat: -rw-r--r-- 1,024 bytes parent folder | download | duplicates (2)
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
# Python

import os
import argparse
import sys
import shutil

import helpers


def getFolders (sp):
    for sf in os.listdir(sp):
        if os.path.isdir(sp+"/"+sf):
            yield from getFolders(sp+"/"+sf)
            yield (sf, sp+"/"+sf)


def purge (sFolderName, bDeleteContentOnly):
    for sf, sp in getFolders("."):
        if sf == sFolderName:
            if bDeleteContentOnly:
                helpers.eraseFolderContent(sp)
                print(sp, "[content deleted]")
            else:
                shutil.rmtree(sp)
                print(sp, "[erased]")


def main ():
    "purge cruft and other files"
    print("Python: " + sys.version)
    if sys.version < "3.7":
        print("Python 3.7+ required")
        return

    xParser = argparse.ArgumentParser()
    xParser.add_argument("-b", "--build", help="purge _build", action="store_true")
    xArgs = xParser.parse_args()

    purge("__pycache__", False)
    if xArgs.build:
        purge("_build", True)


if __name__ == '__main__':
    main()