Browse Source

removed recursion

event_class
Raphael Roberts 7 years ago
parent
commit
d5e42595b3
  1. 34
      gapi/drive_api.py
  2. 3
      test_drive.py

34
gapi/drive_api.py

@ -26,28 +26,24 @@ class drive_api(API):
del root_meta['kind'] del root_meta['kind']
self.filesystem['/'][0] = root_meta 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: try:
return parent[path[0]]
parent = parent[sub]
except KeyError: except KeyError:
self.fill_in(parent) 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 # finds all files and folders from a parent
def fill_in(self,parent): def fill_in(self,parent):

3
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')
Loading…
Cancel
Save