Grammalecte  Check-in [583ae99a7b]

Overview
Comment:[build] handle errors in helpers
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk | build
Files: files | file ages | folders
SHA3-256: 583ae99a7b7aa52208e8f21de178283c04fcf988fd37e756e880b091ce2f8a4b
User & Date: olr on 2020-04-05 10:37:44
Other Links: manifest | tags
Context
2020-04-05
11:31
[fr] ajustements check-in: a4aed19c9b user: olr tags: trunk, fr
10:37
[build] handle errors in helpers check-in: 583ae99a7b user: olr tags: trunk, build
10:00
[build] test if folders exist before moving content check-in: 9b3cc7f615 user: olr tags: trunk, build
Changes

Modified helpers.py from [d28c812f24] to [dfd3e5f00c].

58
59
60
61
62
63
64
65

66
67
68
69
70
71
72
73

74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93



94
95
96
97
98
99
100
58
59
60
61
62
63
64

65
66
67
68
69
70
71
72

73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91


92
93
94
95
96
97
98
99
100
101







-
+







-
+


















-
-
+
+
+







    "make an empty folder or erase its content if not empty"
    if not os.path.exists(sp):
        os.makedirs(sp, exist_ok=True)
    else:
        eraseFolder(sp)


def copyFolderContent (spSrc, spDst):
def copyFolder (spSrc, spDst):
    "copy folder content from src to dst"
    try:
        shutil.copytree(spSrc, spDst)
    except OSError as e:
        if e.errno == errno.ENOTDIR:
            shutil.copy(spSrc, spDst)
        else:
            raise
            print("Error while copying folder <"+spSrc+"> to <"+spDst+">.")


def moveFolderContent (spSrc, spDst, sPrefix="", bLog=False):
    "move folder content from <spSrc> to <spDst>: if files already exist in <spDst>, they are replaced. (not recursive)"
    try:
        if not os.path.isdir(spSrc):
            print("Folder <"+spSrc+"> not found. Can’t move files.")
            return
        if not os.path.isdir(spDst)
            print("Folder <"+spDst+"> not found. Can’t move files.")
            return
        for sf in os.listdir(spSrc):
            spfSrc = os.path.join(spSrc, sf)
            if os.path.isfile(spfSrc):
                spfDst = os.path.join(spDst, sPrefix + sf)
                shutil.move(spfSrc, spfDst)
                if bLog:
                    print("file <" + spfSrc + "> moved to <"+spfDst+">")
    except:
        raise
    except Error as e:
        print("Error while moving folder <"+spSrc+"> to <"+spDst+">.")
        print(e)


def fileFile (spf, dVars):
    "return file <spf> as a text filed with variables from <dVars>"
    return Template(open(spf, "r", encoding="utf-8").read()).safe_substitute(dVars)