Add support to FileManager to change working directory

This commit is contained in:
Kristóf Tóth 2018-03-09 08:37:08 +01:00
parent 491bbe5df6
commit b224ed519d

View File

@ -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!')