def parsestructure(path, userid, date):
with open(f'/backups/{userid}/{date}') as structfile:
content = structfile.readlines()
parsed = []
for line in content:
item = line.split(' ')
fullname = item[0]
if fullname.startswith(path):
name = fullname.replace(path, '')
namelst = name.split('/')
if item[1] == 'dir':
isdir = True
isfile = False
name = namelst[0]
else:
isdir = False
isfile = True
pdict = {'path': path, 'name': name, 'is_dir': isdir, 'is_file': isfile}
parsed.append(pdict)
/home/user/vasya/file.html file
/home/user/vasya dir
<code>
def parsestructure(path, userid, date):
with open(f'/backups/{userid}/{date}') as structfile:
parsed = []
for line in structfile:
item = line.split() # https://docs.python.org/3/library/stdtypes.html#str.split
fullname = item[0]
if fullname.startswith(path):
name = fullname.replace(path, '') # для этого существует
namelst = name.split('/') # модуль os.path
isdir = item[1] == 'dir'
isfile = not isdir # нафиг вообще нужно
if isdir:
name = namelst[0]
pdict = {'path': path, 'name': name, 'is_dir': isdir, 'is_file': isfile}
parsed.append(pdict)