aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSeongJae Park <sj38.park@gmail.com>2024-03-17 11:57:58 -0700
committerSeongJae Park <sj38.park@gmail.com>2024-03-17 11:57:58 -0700
commit0d98d68b221ac0cf7a4636dc7594f09a4ef60c7e (patch)
tree5c77ef810c01ee4312c2108fa5f8725eecab7e75
parent92cba7facb9cece52b62edb6aeb59402b872d497 (diff)
downloaddamo-0d98d68b221ac0cf7a4636dc7594f09a4ef60c7e.tar.gz
_damo_fs: Remove write_files()
write_files() was designed for handling multiple file i/o operations that supposed to all success. It is convenient and useful, but makes it complicated to handle failures in the middle of the operations. Now all _damo_fs users are using write_file() instead. Remove the function that not really being used. Signed-off-by: SeongJae Park <sj38.park@gmail.com>
-rw-r--r--_damo_fs.py57
1 files changed, 0 insertions, 57 deletions
diff --git a/_damo_fs.py b/_damo_fs.py
index 50289917..b50930d0 100644
--- a/_damo_fs.py
+++ b/_damo_fs.py
@@ -65,63 +65,6 @@ def write_file(filepath, content):
return 'writing %s to %s failed (%s)' % (content.strip(), filepath, e)
return None
-'''
-operations can be either {path: content}, or [operations]. In the former case,
-this function writes content to path, for all path/content pairs in the
-dictionary. In the latter case, operations in the list is executed
-sequentially. If the path is for a file, content should be a string. If the
-path is for a directory, the content should be yet another operations. In the
-latter case, upper-level path is prefixed to paths of the lower-level
-operations paths.
-
-For example:
- {
- 'foo': 'bar',
- 'dirA': {
- 'fileA': '123',
- 'fileB': '456',
- },
- [
- {'fileA': '42'},
- {'fileB': '4242'},
- ]
- }
-
- writes 'bar' to 'foo',
- writes '123' to 'dirA/fileA',
- writes '456' to 'dirA/fileB', and
- writes '42' to 'fileA' then writes '4242' to 'fileB',
- in any order
-
-Return an error string if fails any write, or None otherwise.
-'''
-def write_files(operations, root=''):
- if not type(operations) in [list, dict]:
- return ('write_files() received none-list, none-dict content: %s' %
- operations)
-
- if isinstance(operations, list):
- for o in operations:
- err = write_files(o, root)
- if err != None:
- return err
- return None
-
- for filename in operations:
- filepath = os.path.join(root, filename)
- content = operations[filename]
- if os.path.isfile(filepath):
- err = write_file(filepath, content)
- if err != None:
- return err
- elif os.path.isdir(filepath):
- err = write_files(content, filepath)
- if err != None:
- return err
- else:
- return 'filepath (%s) is neither dir nor file' % (filepath)
- return None
-
def dev_mount_point(dev):
'''Returns mount point of specific device. None if not mounted'''
with open('/proc/mounts', 'r') as f: