forked from GleamingGlaceon94/folderclone
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathremove.py
More file actions
49 lines (38 loc) · 1.25 KB
/
remove.py
File metadata and controls
49 lines (38 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from google.oauth2.service_account import Credentials
import googleapiclient.discovery, glob, progress.bar, sys, time
stt = time.time()
controls = glob.glob('controller/*.json')
try:
key = controls[0]
except IndexError:
print('No controller found.')
sys.exit(0)
try:
sid = sys.argv[1]
except:
sid = input("Shared Drive ID? ").strip()
credentials = Credentials.from_service_account_file(key, scopes=[
"https://www.googleapis.com/auth/drive"
])
drive = googleapiclient.discovery.build("drive", "v3", credentials=credentials)
print('Getting permissions...')
tbr = []
rp = drive.permissions().list(fileId=sid,supportsAllDrives=True).execute()
cont = True
while cont:
for i in rp['permissions']:
if i['role'] != 'organizer':
tbr.append(i['id'])
if "nextPageToken" in rp:
rp = drive.permissions().list(fileId=sid,supportsAllDrives=True,pageToken=rp["nextPageToken"]).execute()
else:
cont = False
pbar = progress.bar.Bar("Removing accounts",max=len(tbr))
for i in tbr:
drive.permissions().delete(fileId=sid,permissionId=i,supportsAllDrives=True).execute()
pbar.next()
pbar.finish()
print('Complete.')
hours, rem = divmod((time.time() - stt),3600)
minutes, sec = divmod(rem,60)
print("Elapsed Time:\n{:0>2}:{:0>2}:{:05.2f}".format(int(hours),int(minutes),sec))