diff --git a/gapi/drive_api.py b/gapi/drive_api.py index c4553a3..2a33d85 100644 --- a/gapi/drive_api.py +++ b/gapi/drive_api.py @@ -26,28 +26,24 @@ class drive_api(API): del root_meta['kind'] self.filesystem['/'][0] = root_meta - def __inner_path_func__(self,path,parent): - if len(path) > 1: - n = path.pop() - try: - new_parent = parent[n] - except KeyError: - self.fill_in(parent) - new_parent = parent[n] - return self.__inner_path_func__(path,new_parent) - else: + def get_file_by_path(self,path): + path = split_path(path) + parent = self.filesystem + for sub in path[:-1]: try: - return parent[path[0]] + parent = parent[sub] except KeyError: self.fill_in(parent) - try: - return parent[path[0]] - except KeyError: - raise FileNotFoundError() - - def get_file_by_path(self,path): - path = split_path(path,True) - return self.__inner_path_func__(path,self.filesystem) + parent = parent[sub] + end = path[-1] + try: + return parent[end] + except KeyError: + self.fill_in(parent) + try: + return parent[end] + except KeyError: + raise FileNotFoundError() # finds all files and folders from a parent def fill_in(self,parent): diff --git a/test_drive.py b/test_drive.py new file mode 100644 index 0000000..38f8150 --- /dev/null +++ b/test_drive.py @@ -0,0 +1,3 @@ +from gapi.drive_api import drive_api,APPLICATION_NAME +my_api = drive_api(APPLICATION_NAME,r'test\drive\client_secret.json',r'test\drive') +file = my_api.get_file_by_path('/Python/Lib/site-packages/sympy/calculus/tests/__init__.py') \ No newline at end of file