Commit d27a5208 authored by dylan grafmyre's avatar dylan grafmyre
Browse files

add new mount

parent cd0f2826
......@@ -57,6 +57,33 @@ def update_mount(buf, name, path):
return ret.getvalue()
RE_EOB = re.compile(
r'^(\s*\}\s*)$',
re.MULTILINE
)
def add_mount(buf, name, path):
ret = io.StringIO()
match = RE_EOB.search(buf)
if not match:
raise NotImplementedError('failed to add mount, no match for {!r} on \n\n\t{!r}'.format(
RE_EOB,
buf
))
match_span = match.span()
match_groups = match.groups()
ret.write(buf[:match_span[0]])
ret.write('\t')
ret.write('"{}"'.format(name))
ret.write('\t')
ret.write('"{}"'.format(path))
ret.write('\n')
ret.write(match_groups[0])
ret.write(buf[match_span[1]:])
return ret.getvalue()
def main_set_mount(argp):
name, path = argp.set_mount
......@@ -73,10 +100,11 @@ def main_set_mount(argp):
mbuf = None
if is_update:
mbuf = update_mount(buf, name, path)
sanity = pyvmf.Cfg.loads(mbuf)
else: # is addative
mbuf = add_mount(buf, name, path)
sanity = pyvmf.Cfg.loads(mbuf)
fh.seek(0)
nbytes = fh.write(mbuf)
fh.truncate()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment