Grammalecte  Diff

Differences From Artifact [f66c7bb7d2]:

To Artifact [20b8bddd75]:


1
2
3
4
5
6
7
8
9
10
11















12
13
14
15
16
17
18
"""
Tools for handling files
"""

import os
import shutil
import errno
import zipfile

from string import Template

















class CD:
    "Context manager for changing the current working directory"
    def __init__ (self, newPath):
        self.newPath = os.path.expanduser(newPath)
        self.savedPath = ""












>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







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
"""
Tools for handling files
"""

import os
import shutil
import errno
import zipfile

from string import Template


def convertDictToString (dDict, nDepth=1, nIndent=2):
    "returns <dDict> as a indented string"
    sResult = "{\n"
    sIndent = " " * nIndent
    for key, val in dDict.items():
        sKey = f"'{key}'"  if type(key) is str  else str(key)
        if nDepth > 0 and type(val) is dict:
            sVal = convertDictToString(val, nDepth-1, nIndent+nIndent)
        else:
            sVal = f"'{val}'"  if type(val) is str  else str(val)
        sResult += f'{sIndent}{sKey}: {sVal},\n'
    sResult = sResult + sIndent[:-2] + "}"
    return sResult


class CD:
    "Context manager for changing the current working directory"
    def __init__ (self, newPath):
        self.newPath = os.path.expanduser(newPath)
        self.savedPath = ""