Browse Source

support recursively addition for loading

master
TA 3 years ago
parent
commit
0492861890
1 changed files with 5 additions and 5 deletions
  1. +5
    -5
      load.py

+ 5
- 5
load.py View File

@ -29,8 +29,6 @@ if __name__ == "__main__":
fm = None
for r in os.listdir(dir_path):
res_path = os.path.join(dir_path, r)
if os.path.isdir(res_path):
raise Exception(f'{res_path} is a 3-level directory, which is not allowed in our design.')
if r == 'format.json':
with open(res_path, 'r') as f:
fm = json.load(f)
@ -51,7 +49,9 @@ if __name__ == "__main__":
raise Exception('the legnth of the name of note is too long: {}'.format(fm['note']))
# add directory and immediate files in the directory except format.json
res = ipfs_client.add(dir_path, pattern = re.compile(r'^(?!format.json$)'))
res = ipfs_client.add(dir_path,
recursive = True,
pattern = re.compile(r'^(?!format.json$)'))
file_hash = ''
for r in res:
@ -74,6 +74,6 @@ if __name__ == "__main__":
db.session.add(paper)
db.session.commit()
print(f'item {dir_path} is added')
print(f'item {dir_path} is added with hash {file_hash}')
else:
print(f'{dir_path} has been added before')
print(f'{dir_path} has been added with hash {file_hash} before')

Loading…
Cancel
Save