Add volumes in init start

dev
Marko Semet 2020-03-29 16:20:42 +02:00
parent 6b4da35bae
commit 5df2e21217
1 changed files with 35 additions and 7 deletions

View File

@ -1,6 +1,7 @@
import abc
import asyncio
import os
import shutil
import yaml
from . import paths, wine
@ -12,16 +13,40 @@ class Step(abc.ABC):
raise NotImplementedError()
@abc.abstractclassmethod
async def content_to_hash(self):
async def content_to_hash(self, wine, instance):
raise NotImplementedError()
class _StepPreInit(Step):
async def run(self, wine, instance):
pass
def _find_drive_c(self, wine):
return os.path.join(os.path.abspath(wine.path), "drive_c")
async def content_to_hash(self):
return b""
def _gen_paths(self, wine, instance):
# Find paths
drive_c = self._find_drive_c(wine)
volume_dir = os.path.abspath(os.path.join(paths.VOLUME_DIR, instance.get_instance()))
# Iterate
for volume, path in instance.get_volumes().items():
if "\x00" in volume or "/" in volume or "\\" in volume:
raise ValueError("Volume name contains slash or backslash")
voldir = os.path.join(volume_dir, volume)
pathdir = os.path.join(drive_c, path)
yield (voldir, pathdir)
async def run(self, wine:wine.WineConfig, instance):
# Reset path
shutil.rmtree(wine.path)
os.makedirs(self._find_drive_c(wine), exist_ok=True)
# Create volumes
for volume, path in self._gen_paths(wine, instance):
os.makedirs(volume)
os.makedirs(os.path.dirname(path), exist_ok=True)
os.symlink(os.path.relpath(volume, os.path.dirname(path)), path)
async def content_to_hash(self, wine, instance):
return b"\x00".join(map(lambda x: "%s\x00%s" % x, sorted(self._gen_paths(wine, instance))))
class _StepWineInit(Step):
@ -32,7 +57,7 @@ class _StepWineInit(Step):
return result
# TODO: gen volumes
async def content_to_hash(self):
async def content_to_hash(self, wine, instance):
version = await asyncio.create_subprocess_exec(["wine", "--version"], stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE)
result = version.communicate()
if result != 0:
@ -60,7 +85,7 @@ class _StepExec(Step):
raise RuntimeError() # TODO: Exception
return result
async def content_to_hash(self):
async def content_to_hash(self, wine, isinstance):
return b"\x00".join(self.__command)
@ -103,6 +128,9 @@ class Instance():
def get_instance(self):
return self.__instance
def get_volumes(self):
return dict(self.__volumes)
async def is_installed(self):
return False # TODO