mirror of
https://github.com/gryf/boxpy.git
synced 2025-12-19 05:30:18 +01:00
Add ability to write files to be written on guest by providing filename.
This commit is contained in:
20
box.py
20
box.py
@@ -304,6 +304,26 @@ class Config:
|
|||||||
continue
|
continue
|
||||||
setattr(self, key, str(val))
|
setattr(self, key, str(val))
|
||||||
|
|
||||||
|
# check if there are files to be written
|
||||||
|
if conf.get('boxpy_data', {}).get('write_files'):
|
||||||
|
for file_data in conf['boxpy_data']['write_files']:
|
||||||
|
fname = file_data.get('filename')
|
||||||
|
if not fname:
|
||||||
|
print("WARNING: one of the entries in boxpy.write_files "
|
||||||
|
"doesn't provide a filename.")
|
||||||
|
else:
|
||||||
|
fname = os.path.expanduser(os.path.expandvars(fname))
|
||||||
|
if not os.path.exists(fname):
|
||||||
|
print(f"WARNING: file '{file_data['filename']}' "
|
||||||
|
f"doesn't exists.")
|
||||||
|
else:
|
||||||
|
with open(fname) as fobj:
|
||||||
|
file_data['content'] = fobj.read()
|
||||||
|
del file_data['filename']
|
||||||
|
if 'write_files' not in conf:
|
||||||
|
conf['write_files'] = []
|
||||||
|
conf['write_files'].append(file_data)
|
||||||
|
|
||||||
# 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'):
|
||||||
if conf['boxpy_data'].get('advanced'):
|
if conf['boxpy_data'].get('advanced'):
|
||||||
|
|||||||
Reference in New Issue
Block a user