mirror of
https://github.com/gryf/boxpy.git
synced 2025-12-20 22:27:58 +01:00
Parse filenames in global write_files section
This commit is contained in:
24
box.py
24
box.py
@@ -305,24 +305,26 @@ class Config:
|
|||||||
setattr(self, key, str(val))
|
setattr(self, key, str(val))
|
||||||
|
|
||||||
# check if there are files to be written
|
# check if there are files to be written
|
||||||
if conf.get('boxpy_data', {}).get('write_files'):
|
if conf.get('write_files'):
|
||||||
for file_data in conf['boxpy_data']['write_files']:
|
new_list = []
|
||||||
|
for file_data in conf['write_files']:
|
||||||
fname = file_data.get('filename')
|
fname = file_data.get('filename')
|
||||||
if not fname:
|
if not fname:
|
||||||
print("WARNING: one of the entries in boxpy.write_files "
|
new_list.append(file_data)
|
||||||
"doesn't provide a filename.")
|
continue
|
||||||
else:
|
|
||||||
fname = os.path.expanduser(os.path.expandvars(fname))
|
fname = os.path.expanduser(os.path.expandvars(fname))
|
||||||
if not os.path.exists(fname):
|
if not os.path.exists(fname):
|
||||||
print(f"WARNING: file '{file_data['filename']}' "
|
print(f"WARNING: file '{file_data['filename']}' doesn't "
|
||||||
f"doesn't exists.")
|
f"exists.")
|
||||||
else:
|
continue
|
||||||
|
|
||||||
with open(fname) as fobj:
|
with open(fname) as fobj:
|
||||||
file_data['content'] = fobj.read()
|
file_data['content'] = fobj.read()
|
||||||
del file_data['filename']
|
del file_data['filename']
|
||||||
if 'write_files' not in conf:
|
new_list.append(file_data)
|
||||||
conf['write_files'] = []
|
|
||||||
conf['write_files'].append(file_data)
|
conf['write_files'] = new_list
|
||||||
|
|
||||||
# remove boxpy_data since it will be not needed on the guest side
|
# remove boxpy_data since it will be not needed on the guest side
|
||||||
if conf.get('boxpy_data'):
|
if conf.get('boxpy_data'):
|
||||||
|
|||||||
Reference in New Issue
Block a user