|
|
|
@ -55,12 +55,29 @@ class drive_file: |
|
|
|
self.api = api |
|
|
|
self.info = info |
|
|
|
self.parent = parent |
|
|
|
self._fullpath = None |
|
|
|
|
|
|
|
@classmethod |
|
|
|
def from_id(cls,id,api,parent): |
|
|
|
info = api.service.files().get(fileId='root').execute() |
|
|
|
return cls(api,info,parent) |
|
|
|
|
|
|
|
@property |
|
|
|
def fullpath(self): |
|
|
|
if self._fullpath is None: |
|
|
|
if self.parent is None: |
|
|
|
path = '/' |
|
|
|
else: |
|
|
|
path = pathjoin(self.parent.fullpath,self.name) |
|
|
|
self._fullpath = path |
|
|
|
return self._fullpath |
|
|
|
|
|
|
|
def __str__(self): |
|
|
|
return '{}@{}'.format(type(self).__name__,self.fullpath) |
|
|
|
|
|
|
|
def __repr__(self): |
|
|
|
return str(self) |
|
|
|
|
|
|
|
class drive_folder(drive_file): |
|
|
|
def __init__(self, |
|
|
|
api, |
|
|
|
@ -87,9 +104,9 @@ class drive_folder(drive_file): |
|
|
|
for child in child_list: |
|
|
|
name = child['name'] |
|
|
|
if is_folder(child): |
|
|
|
parent.folders[name] = drive_folder(self.api,child,self) |
|
|
|
self.folders[name] = drive_folder(self.api,child,self) |
|
|
|
else: |
|
|
|
parent.files[name] = drive_file(self.api,child,self) |
|
|
|
self.files[name] = drive_file(self.api,child,self) |
|
|
|
|
|
|
|
def __list_children__(self): |
|
|
|
page_token = None |
|
|
|
@ -114,7 +131,6 @@ class drive_api(API): |
|
|
|
): |
|
|
|
super().__init__('drive',scopes,app_name,client_secret_file,credentials_dir,version) |
|
|
|
self.root = drive_folder.from_id('root',self,None) |
|
|
|
root |
|
|
|
|
|
|
|
def get_file_by_path(self,path,ret_file = True): |
|
|
|
if path == '/': |
|
|
|
|