Add body parameter to specify parent id
This commit is contained in:
parent
7a978a178c
commit
0fc328ab0c
1 changed files with 8 additions and 8 deletions
|
|
@ -32,7 +32,7 @@ class GoogleDrive(object):
|
||||||
**params).execute().get('files')
|
**params).execute().get('files')
|
||||||
return files
|
return files
|
||||||
|
|
||||||
def create_file_from_path(self, path, content=None, mime_type=None, permissions=None):
|
def create_file_from_path(self, path, content=None, mime_type=None, body=None, permissions=None):
|
||||||
"""Creates a file on google drive from a path
|
"""Creates a file on google drive from a path
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
|
|
@ -61,27 +61,27 @@ class GoogleDrive(object):
|
||||||
parent_folders = []
|
parent_folders = []
|
||||||
|
|
||||||
for folder_name in folders:
|
for folder_name in folders:
|
||||||
params = {}
|
folder_body = {}
|
||||||
|
|
||||||
if parent_id:
|
if parent_id:
|
||||||
params['body'] = {'parents': [parent_id]}
|
folder_body = {'parents': [parent_id]}
|
||||||
|
|
||||||
google_file = GoogleFile.get_or_create(self.service, folder_name,
|
google_file = GoogleFile.get_or_create(self.service, folder_name,
|
||||||
mime_type=MimeTypes.Folder,
|
mime_type=MimeTypes.Folder,
|
||||||
**params)
|
body=folder_body)
|
||||||
|
|
||||||
parent_id = google_file.meta_data['id']
|
parent_id = google_file.meta_data['id']
|
||||||
parent_folders.append(google_file)
|
parent_folders.append(google_file)
|
||||||
|
|
||||||
main_params = {}
|
body = body or {}
|
||||||
|
|
||||||
if parent_id:
|
if parent_id and 'parents' not in body:
|
||||||
main_params['body'] = {'parents': [parent_id]}
|
body.update({'parents': [parent_id]})
|
||||||
|
|
||||||
main_file = GoogleFile.get_or_create(self.service, file_name,
|
main_file = GoogleFile.get_or_create(self.service, file_name,
|
||||||
mime_type=mime_type,
|
mime_type=mime_type,
|
||||||
content=content,
|
content=content,
|
||||||
**main_params)
|
body=body)
|
||||||
|
|
||||||
result = parent_folders + [main_file]
|
result = parent_folders + [main_file]
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue