1
1
from __future__ import print_function
2
2
3
- from .download import download
4
- from bs4 import BeautifulSoup
5
-
6
3
from builtins import bytes
7
4
from itertools import islice
8
5
import json
6
+ import os
7
+ import os .path as osp
9
8
import re
10
- import requests
11
9
import sys
12
10
13
- if sys .version_info .major < 3 :
14
- from pathlib2 import Path
15
- else :
16
- from pathlib import Path
11
+ from bs4 import BeautifulSoup
12
+ import requests
13
+
14
+ from .download import download
15
+
16
+
17
17
client = requests .session ()
18
18
19
19
folders_url = "https://drive.google.com/drive/folders/"
@@ -218,7 +218,7 @@ def get_directory_structure(gdrive_file, previous_path):
218
218
----------
219
219
gdrive_file: GoogleDriveFile
220
220
Google Drive folder structure.
221
- previous_path: pathlib.Path
221
+ previous_path: str
222
222
Path containing the parent's file path.
223
223
224
224
Returns
@@ -229,11 +229,17 @@ def get_directory_structure(gdrive_file, previous_path):
229
229
directory_structure = []
230
230
for file in gdrive_file .children :
231
231
if file .is_folder ():
232
- directory_structure .append ((None , previous_path / file .name ))
233
- for i in get_directory_structure (file , previous_path / file .name ):
232
+ directory_structure .append (
233
+ (None , osp .join (previous_path , file .name ))
234
+ )
235
+ for i in get_directory_structure (
236
+ file , osp .join (previous_path , file .name )
237
+ ):
234
238
directory_structure .append (i )
235
239
elif not file .children :
236
- directory_structure .append ((file .id , previous_path / file .name ))
240
+ directory_structure .append (
241
+ (file .id , osp .join (previous_path , file .name ))
242
+ )
237
243
return directory_structure
238
244
239
245
@@ -302,12 +308,11 @@ def download_folder(
302
308
print ("Retrieving folder list completed" , file = sys .stderr )
303
309
print ("Building directory structure" , file = sys .stderr )
304
310
if output is None :
305
- output = Path .cwd ()
306
- else :
307
- output = Path (output )
308
- root_folder = output / gdrive_file .name
311
+ output = os .getcwd ()
312
+ root_folder = osp .join (output , gdrive_file .name )
309
313
directory_structure = get_directory_structure (gdrive_file , root_folder )
310
- root_folder .mkdir (parents = True , exist_ok = True )
314
+ if not osp .exists (root_folder ):
315
+ os .makedirs (root_folder )
311
316
312
317
if not quiet :
313
318
print ("Building directory structure completed" )
0 commit comments