mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-22 19:01:33 +00:00
Fix files in subdirectories killing everything I stand for
This commit is contained in:
parent
d0a04240b6
commit
c2c5353f98
@ -1,5 +1,5 @@
|
|||||||
from shutil import copy, rmtree, copytree
|
from shutil import copy, rmtree, copytree
|
||||||
from os.path import splitext, isfile, join, basename
|
from os.path import splitext, isfile, join, relpath
|
||||||
from glob import glob
|
from glob import glob
|
||||||
|
|
||||||
from tfw.util import SupervisorMixin
|
from tfw.util import SupervisorMixin
|
||||||
@ -15,7 +15,7 @@ class FileManager:
|
|||||||
self._sourcedir = source_directory
|
self._sourcedir = source_directory
|
||||||
self._workdir = working_directory
|
self._workdir = working_directory
|
||||||
self._reload_files()
|
self._reload_files()
|
||||||
self.filename = selected_file or basename(self.files[0])
|
self.filename = selected_file or self._relpath(self.files[0])
|
||||||
self.language = map_file_extension_to_language(self.filename)
|
self.language = map_file_extension_to_language(self.filename)
|
||||||
|
|
||||||
def select_file(self, filename):
|
def select_file(self, filename):
|
||||||
@ -26,7 +26,7 @@ class FileManager:
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def files(self):
|
def files(self):
|
||||||
return [basename(file) for file in glob(join(self._workdir, '**/*'), recursive=True) if isfile(file)]
|
return [self._relpath(file) for file in glob(join(self._workdir, '**/*'), recursive=True) if isfile(file)]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def file_contents(self):
|
def file_contents(self):
|
||||||
@ -41,6 +41,9 @@ class FileManager:
|
|||||||
def _filepath(self, filename):
|
def _filepath(self, filename):
|
||||||
return join(self._workdir, filename)
|
return join(self._workdir, filename)
|
||||||
|
|
||||||
|
def _relpath(self, filename):
|
||||||
|
return relpath(self._filepath(filename), start=self._workdir)
|
||||||
|
|
||||||
def _reload_files(self):
|
def _reload_files(self):
|
||||||
rmtree(self._workdir, ignore_errors=True)
|
rmtree(self._workdir, ignore_errors=True)
|
||||||
copytree(self._sourcedir, self._workdir)
|
copytree(self._sourcedir, self._workdir)
|
||||||
|
Loading…
Reference in New Issue
Block a user