Open Sedreh opened 5 years ago
You do not need to open new issue when you fix mistakes I mensioned. Just write a message here that you fixed problems
FSItem.rename
. There is the following problem:
f = File('a.txt')
f.rename('b.exe')
print(f.getname()) # prints still 'a.txt'
FSItem.create
- the same issue as in my previous commentFSItem.getname
- it is almost good. But on my platfomr (I have windows) it doesn't work because there is no /
symbol in windows path. You can use os.sep
instead or try to find special function in module os
for extracting name of fileDirectory.items
. Thats ok. But this method can be implemented using files
and subdirectories
:
def items(self):
yield from self.files()
yield from self.subdirectories()
Directory.getsubdirectory
. The second problem is still present. When we execute code below method getsubdirectory
raises an error:
d = Directory('.')
sd = d.getsubdirectory('some_subdir') # raise Error
sd.create()
Dear Dimitry, I did some changes and subdirectory works in my system. Maybe I can not understand your idea!
FSItem.rename
. New path can be incorrect. If old path was a/b/c
and newname is asdf
then new path should be /a/b/asdf
FSItem.create
os.makedirs
can raise an error when directory already exist. So this branch doesn't workFile
and Directory
'/'
File.getcontent
. max_lines
can be greater than number of lines in file. You should bound it in such caseDirectory.items
. You yield 2 object from this generator. Are you sure you want to implement it like this?
FSItem.rename
. You moved file in OS, but fieldpath
of currentFSItem
-instance is still the same. You sohuld change itFSItem.create
. You decide if current object isFile
orDirectory
by the last symbol of path (if self.path[-1] == '/':
). But it is possible that last symbol of directory path is not/
. This problem should be solved using inheritance (you should implement separate implementations ofcreate
in child classes -File.create
andDirectory.create
)FSItem.getname
. Now it returns full path to file (e.g.~/a/b/f.txt
) but this method should return only base name (f.txt
in previous example)File.putcontent
- good initiative :)Directory.items
. It yieldFSItem
-instances. It means that I take some file fromFSItem.items()
and try to callgetcontent
here I face a problem: I can't do it. This is because I don't know if every item is file or directory. So this method should yieldFile
andDirectory
instances, not justFSItem
instancesDirectory.files
. You useself.path + "/" + path
expression here. But what ifself.path = ~/a/
andpath =
f.txt. This expression will be incorrect. Please use
os.path.join` in such contextDirectory.getsubdirectory
. Two problemsDirectory.files
: useos.path.join
instead of expressionself.path + "/" + name