mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-22 13:51:33 +00:00
Add support to FileManager to change working directory
This commit is contained in:
parent
491bbe5df6
commit
b224ed519d
@ -1,4 +1,4 @@
|
||||
from os.path import isfile, join, relpath
|
||||
from os.path import isfile, join, relpath, exists, isdir
|
||||
from glob import glob
|
||||
|
||||
from tfw.event_handler_base import TriggerlessEventHandler
|
||||
@ -11,9 +11,20 @@ log = logging.getLogger(__name__)
|
||||
class FileManager:
|
||||
def __init__(self, working_directory, selected_file=None):
|
||||
self.exclude = ['__pycache__']
|
||||
self._workdir = working_directory
|
||||
self._workdir = None
|
||||
self.workdir = working_directory
|
||||
self.filename = selected_file or self.files[0]
|
||||
|
||||
@property
|
||||
def workdir(self):
|
||||
return self._workdir
|
||||
|
||||
@workdir.setter
|
||||
def workdir(self, directory):
|
||||
if not exists(directory) or not isdir(directory):
|
||||
raise EnvironmentError('"{}" is not a directory!'.format(directory))
|
||||
self._workdir = directory
|
||||
|
||||
def select_file(self, filename):
|
||||
if not filename in self.files:
|
||||
raise EnvironmentError('No such file in workdir!')
|
||||
|
Loading…
Reference in New Issue
Block a user